Stefan Niedermann 2021-03-03 19:57:24 +01:00 committed by Niedermann IT-Dienstleistungen
parent 00f06e930b
commit 71f4b5da16
16 changed files with 58 additions and 249 deletions

View file

@ -80,48 +80,25 @@ public class NoteListWidget extends AppWidgetProvider {
Log.v(TAG, "-- data - " + data);
if (NotesApplication.isDarkThemeActive(context, darkTheme)) {
views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list_dark);
views.setTextViewText(R.id.widget_note_list_title_tv_dark, getWidgetTitle(context, data.getMode(), category));
views.setOnClickPendingIntent(R.id.widget_note_header_icon_dark, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_title_tv_dark, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_create_icon_dark, newNoteI);
views.setPendingIntentTemplate(R.id.note_list_widget_lv_dark, templatePI);
views.setRemoteAdapter(R.id.note_list_widget_lv_dark, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv_dark, R.id.widget_note_list_placeholder_tv_dark);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv_dark);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header_dark, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon_dark, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon_dark, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv_dark, localAccount.getTextColor());
} else {
views.setInt(R.id.widget_note_header_dark, "setBackgroundColor", ContextCompat.getColor(context, R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon_dark, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon_dark, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv_dark, Color.WHITE);
}
views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list);
views.setTextViewText(R.id.widget_note_list_title_tv, getWidgetTitle(context, data.getMode(), category));
views.setOnClickPendingIntent(R.id.widget_note_header_icon, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_title_tv, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_create_icon, newNoteI);
views.setPendingIntentTemplate(R.id.note_list_widget_lv, templatePI);
views.setRemoteAdapter(R.id.note_list_widget_lv, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_note_list_placeholder_tv);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv, localAccount.getTextColor());
} else {
views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list);
views.setTextViewText(R.id.widget_note_list_title_tv, getWidgetTitle(context, data.getMode(), category));
views.setOnClickPendingIntent(R.id.widget_note_header_icon, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_title_tv, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_create_icon, newNoteI);
views.setPendingIntentTemplate(R.id.note_list_widget_lv, templatePI);
views.setRemoteAdapter(R.id.note_list_widget_lv, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_note_list_placeholder_tv);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv, localAccount.getTextColor());
} else {
views.setInt(R.id.widget_note_header, "setBackgroundColor", ContextCompat.getColor(context, R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv, Color.WHITE);
}
views.setInt(R.id.widget_note_header, "setBackgroundColor", ContextCompat.getColor(context, R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv, Color.WHITE);
}
awm.updateAppWidget(appWidgetId, views);

View file

@ -27,7 +27,6 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
private final Context context;
private final NoteListsWidgetData data;
private final boolean darkTheme;
private NotesDatabase db;
private List<DBNote> dbNotes;
@ -38,8 +37,6 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
db = NotesDatabase.getInstance(context);
data = db.getNoteListWidgetData(appWidgetId);
darkTheme = NotesApplication.isDarkThemeActive(context, DarkModeSetting.fromModeID(data.getThemeMode()));
}
@Override
@ -99,27 +96,18 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
DBNote note = dbNotes.get(position);
final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();
extras.putLong(EditNoteActivity.PARAM_NOTE_ID, note.getId());
extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId());
fillInIntent.putExtras(extras);
fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME)));
if (darkTheme) {
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry_dark);
note_content.setOnClickFillInIntent(R.id.widget_note_list_entry_dark, fillInIntent);
note_content.setTextViewText(R.id.widget_entry_content_tv_dark, note.getTitle());
note_content.setImageViewResource(R.id.widget_entry_fav_icon_dark, note.isFavorite()
? R.drawable.ic_star_yellow_24dp
: R.drawable.ic_star_grey_ccc_24dp);
} else {
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry);
note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent);
note_content.setTextViewText(R.id.widget_entry_content_tv, note.getTitle());
note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.isFavorite()
? R.drawable.ic_star_yellow_24dp
: R.drawable.ic_star_grey_ccc_24dp);
}
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry);
note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent);
note_content.setTextViewText(R.id.widget_entry_content_tv, note.getTitle());
note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.isFavorite()
? R.drawable.ic_star_yellow_24dp
: R.drawable.ic_star_grey_ccc_24dp);
return note_content;

View file

@ -36,25 +36,16 @@ public class SingleNoteWidget extends AppWidgetProvider {
final PendingIntent templatePendingIntent = PendingIntent.getActivity(context, appWidgetId, templateIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent serviceIntent = new Intent(context, SingleNoteWidgetService.class);
final Intent serviceIntent = new Intent(context, SingleNoteWidgetService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews views;
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
views.setPendingIntentTemplate(R.id.single_note_widget_lv, templatePendingIntent);
views.setRemoteAdapter(R.id.single_note_widget_lv, serviceIntent);
views.setEmptyView(R.id.single_note_widget_lv, R.id.widget_single_note_placeholder_tv);
if (NotesApplication.isDarkThemeActive(context, DarkModeSetting.fromModeID(data.getThemeMode()))) {
views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_dark);
views.setPendingIntentTemplate(R.id.single_note_widget_lv_dark, templatePendingIntent);
views.setRemoteAdapter(R.id.single_note_widget_lv_dark, serviceIntent);
views.setEmptyView(R.id.single_note_widget_lv_dark, R.id.widget_single_note_placeholder_tv_dark);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv_dark);
} else {
views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
views.setPendingIntentTemplate(R.id.single_note_widget_lv, templatePendingIntent);
views.setRemoteAdapter(R.id.single_note_widget_lv, serviceIntent);
views.setEmptyView(R.id.single_note_widget_lv, R.id.widget_single_note_placeholder_tv);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv);
}
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv);
awm.updateAppWidget(appWidgetId, views);
} catch (NoSuchElementException e) {
Log.i(TAG, "onUpdate has been triggered before the user finished configuring the widget");

View file

@ -98,16 +98,10 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa
extras.putLong(EditNoteActivity.PARAM_NOTE_ID, note.getId());
extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId());
fillInIntent.putExtras(extras);
if (darkModeActive) {
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content_dark);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv_dark, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv_dark, MarkdownUtil.renderForRemoteView(context, note.getContent()));
} else {
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForRemoteView(context, note.getContent()));
}
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_single_note_content);
note_content.setOnClickFillInIntent(R.id.single_note_content_tv, fillInIntent);
note_content.setTextViewText(R.id.single_note_content_tv, MarkdownUtil.renderForRemoteView(context, note.getContent()));
return note_content;
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/widget_background" />
<corners android:radius="@dimen/widget_outer_radius" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>

View file

@ -32,7 +32,7 @@
android:lines="1"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:textColor="@color/widget_fg_default"
android:textColor="@color/widget_foreground"
tools:text="@tools:sample/lorem/random" />
</LinearLayout>

View file

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_note_list_entry_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="@dimen/spacer_1hx"
android:paddingTop="@dimen/spacer_1x"
android:paddingEnd="@dimen/spacer_1hx"
android:paddingBottom="@dimen/spacer_1x"
tools:background="@color/widget_background_dark_theme">
<ImageView
android:id="@+id/widget_entry_fav_icon_dark"
android:layout_width="@dimen/widget_note_list_fav_icon_width"
android:layout_height="@dimen/widget_note_list_fav_icon_height"
android:layout_gravity="center_vertical"
android:contentDescription="@string/widget_entry_fav_contentDescription"
android:foregroundGravity="center_vertical"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
app:srcCompat="@drawable/ic_star_yellow_24dp" />
<TextView
android:id="@+id/widget_entry_content_tv_dark"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:lines="1"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:textColor="@color/fg_default_dark_theme"
tools:text="@tools:sample/lorem/random" />
</LinearLayout>

View file

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_background"
android:background="@drawable/widget_background"
android:orientation="vertical">
<!-- Widget header -->
@ -38,7 +38,7 @@
android:paddingStart="@dimen/widget_note_list_hdr_padding"
android:paddingEnd="@dimen/widget_note_list_hdr_padding"
android:singleLine="true"
android:textColor="@color/widget_fg_contrast"
android:textColor="@android:color/white"
android:textSize="18sp"
tools:text="@tools:sample/lorem/random" />

View file

@ -1,77 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_background_dark_theme"
android:orientation="vertical"
tools:background="@null">
<!-- Widget header -->
<RelativeLayout
android:id="@+id/widget_note_header_dark"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_note_list_header_height"
android:background="@drawable/ic_launcher_background"
android:padding="@dimen/widget_note_list_hdr_padding">
<ImageView
android:id="@+id/widget_note_header_icon_dark"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:contentDescription="@string/widget_app_launcher_contentDescription"
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:scaleX="2"
android:scaleY="2"
android:src="@drawable/ic_launcher_foreground" />
<TextView
android:id="@+id/widget_note_list_title_tv_dark"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toStartOf="@id/widget_note_list_create_icon_dark"
android:layout_toEndOf="@id/widget_note_header_icon_dark"
android:ellipsize="middle"
android:gravity="center_vertical"
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:singleLine="true"
android:textColor="@color/widget_fg_contrast"
android:textSize="18sp"
tools:text="@tools:sample/lorem/random" />
<ImageView
android:id="@+id/widget_note_list_create_icon_dark"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:contentDescription="@string/widget_create_note"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:src="@drawable/ic_add_white_24dp" />
</RelativeLayout>
<!-- End header -->
<ListView
android:id="@+id/note_list_widget_lv_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/fg_default_low_dark_theme"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/fg_default_dark_theme"
tools:listitem="@layout/widget_entry_dark" />
<TextView
android:id="@+id/widget_note_list_placeholder_tv_dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/widget_note_list_placeholder"
android:textColor="@color/fg_default_dark_theme"
tools:visibility="gone" />
</LinearLayout>

View file

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_background">
android:background="@drawable/widget_background">
<ListView
android:id="@+id/single_note_widget_lv"
@ -20,6 +20,6 @@
android:padding="@dimen/widget_single_note_padding"
android:text="@string/widget_single_note_placeholder_tv"
android:textAlignment="center"
android:textColor="@color/fg_default_high_dark_theme" />
android:textColor="@color/widget_foreground" />
</RelativeLayout>

View file

@ -4,5 +4,5 @@
android:id="@+id/single_note_content_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/widget_fg_default"
android:textColor="@color/widget_foreground"
tools:text="@tools:sample/lorem/random" />

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_note_content_tv_dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/fg_default_dark_theme"
tools:text="@tools:sample/lorem/random" />

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_background_dark_theme">
<ListView
android:id="@+id/single_note_widget_lv_dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_single_note_padding" />
<TextView
android:id="@+id/widget_single_note_placeholder_tv_dark"
android:background="@color/widget_background_dark_theme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/widget_single_note_placeholder_tv"
android:textColor="@color/fg_default_high_dark_theme"
android:textAlignment="center"
android:padding="@dimen/widget_single_note_padding" />
</RelativeLayout>

View file

@ -20,4 +20,7 @@
<color name="appbar">#212121</color>
<color name="category_background">@color/defaultBrand</color>
<color name="widget_background">#dd000000</color>
<color name="widget_foreground">#d8d8d8</color>
</resources>

View file

@ -22,20 +22,11 @@
<color name="icon_color_default">#757575</color>
<color name="widget_background">#dfffffff</color>
<color name="widget_fg_default">#000000</color>
<color name="widget_fg_contrast">#ffffff</color>
<color name="category_background">@color/bg_normal</color>
<color name="category_border">@color/defaultBrand</color>
<color name="appbar">@android:color/white</color>
<!-- Dark Theme -->
<!-- Defined here until appwidgets can use night/colors -->
<color name="fg_default_dark_theme">#eeeeee</color>
<color name="fg_default_low_dark_theme">#666666</color>
<color name="fg_default_high_dark_theme">#cccccc</color>
<color name="widget_background_dark_theme">#bf222222</color>
<color name="widget_background">#ddffffff</color>
<color name="widget_foreground">#222222</color>
</resources>

View file

@ -29,6 +29,9 @@
<dimen name="note_font_size_large">22sp</dimen>
<!-- Widgets -->
<dimen name="widget_outer_radius">@dimen/spacer_1x</dimen>
<dimen name="widget_inner_radius">@dimen/spacer_1hx</dimen>
<dimen name="widget_margin">@dimen/spacer_1x</dimen>
<dimen name="widget_single_note_padding">10dp</dimen>