From de86e87d6d6723a74eaaf24539853c4273f8838a Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 14 Apr 2020 16:18:22 -0500 Subject: [PATCH] Configure header, row, and empty space opacity --- .../preferences/fragments/ScrollableWidget.kt | 3 +- .../java/org/tasks/widget/TasksWidget.java | 33 +++++++-------- .../org/tasks/widget/WidgetPreferences.java | 16 +++++++- app/src/main/res/layout/scrollable_widget.xml | 19 +-------- app/src/main/res/values/keys.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/preferences_widget.xml | 40 ++++++++++++++----- 7 files changed, 68 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt b/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt index e48a24d18..e66fe4e13 100644 --- a/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt +++ b/app/src/main/java/org/tasks/preferences/fragments/ScrollableWidget.kt @@ -22,7 +22,6 @@ import org.tasks.injection.InjectingPreferenceFragment import org.tasks.locale.Locale import org.tasks.preferences.DefaultFilterProvider import org.tasks.preferences.Preferences -import org.tasks.widget.TasksWidget import org.tasks.widget.WidgetPreferences import javax.inject.Inject @@ -60,7 +59,9 @@ class ScrollableWidget : InjectingPreferenceFragment() { appWidgetId = arguments!!.getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) widgetPreferences = WidgetPreferences(context, preferences, appWidgetId) + setupSlider(R.string.p_widget_header_opacity, 100) setupSlider(R.string.p_widget_opacity, 100) + setupSlider(R.string.p_widget_empty_space_opacity, 100) setupSlider(R.string.p_widget_font_size, 16) val showDueDate = setupCheckbox(R.string.p_widget_show_due_date) setupCheckbox(R.string.p_widget_due_date_underneath, false).dependency = showDueDate.key diff --git a/app/src/main/java/org/tasks/widget/TasksWidget.java b/app/src/main/java/org/tasks/widget/TasksWidget.java index 0249f2563..832c5b714 100644 --- a/app/src/main/java/org/tasks/widget/TasksWidget.java +++ b/app/src/main/java/org/tasks/widget/TasksWidget.java @@ -9,13 +9,12 @@ import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.Canvas; import android.net.Uri; import android.view.View; import android.widget.RemoteViews; import androidx.annotation.ColorInt; import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; import com.todoroo.astrid.activity.MainActivity; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.dao.TaskDao; @@ -41,12 +40,6 @@ public class TasksWidget extends InjectingAppWidgetProvider { @Inject TaskDao taskDao; @Inject @ForApplication Context context; - private static Bitmap getSolidBackground(@ColorInt int bgColor) { - Bitmap bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); // Create a Bitmap - new Canvas(bitmap).drawColor(bgColor); // Set the color - return bitmap; - } - @Override protected void inject(BroadcastComponent component) { component.inject(this); @@ -94,20 +87,24 @@ public class TasksWidget extends InjectingAppWidgetProvider { } else { remoteViews.setViewVisibility(R.id.widget_header, View.GONE); } - int opacityPercentage = widgetPreferences.getOpacity(); - int opacity = (int) ((opacityPercentage / 100.0) * 255.0); - remoteViews.setImageViewBitmap( - R.id.widget_background, - getSolidBackground(getBackgroundColor(widgetPreferences.getThemeIndex()))); - remoteViews.setImageViewBitmap( - R.id.widget_header_background, getSolidBackground(color.getPrimaryColor())); - remoteViews.setInt(R.id.widget_background, "setAlpha", opacity); - remoteViews.setInt(R.id.widget_header_background, "setAlpha", opacity); + + remoteViews.setInt( + R.id.widget_header, + "setBackgroundColor", + ColorUtils.setAlphaComponent(color.getPrimaryColor(), widgetPreferences.getHeaderOpacity())); + int bgColor = getBackgroundColor(widgetPreferences.getThemeIndex()); + remoteViews.setInt( + R.id.list_view, + "setBackgroundColor", + ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getRowOpacity())); + remoteViews.setInt( + R.id.empty_view, + "setBackgroundColor", + ColorUtils.setAlphaComponent(bgColor, widgetPreferences.getEmptySpaceOpacity())); Filter filter = defaultFilterProvider.getFilterFromPreference(filterId); remoteViews.setTextViewText(R.id.widget_title, filter.listingTitle); remoteViews.setRemoteAdapter(R.id.list_view, rvIntent); - remoteViews.setEmptyView(R.id.list_view, R.id.empty_view); remoteViews.setOnClickPendingIntent(R.id.widget_title, getOpenListIntent(context, filter, id)); remoteViews.setOnClickPendingIntent(R.id.widget_button, getNewTaskIntent(context, filter, id)); remoteViews.setOnClickPendingIntent(R.id.widget_change_list, getChooseListIntent(context, filter, id)); diff --git a/app/src/main/java/org/tasks/widget/WidgetPreferences.java b/app/src/main/java/org/tasks/widget/WidgetPreferences.java index cb9bc7c68..d080f8e50 100644 --- a/app/src/main/java/org/tasks/widget/WidgetPreferences.java +++ b/app/src/main/java/org/tasks/widget/WidgetPreferences.java @@ -86,8 +86,20 @@ public class WidgetPreferences { return color; } - public int getOpacity() { - return preferences.getInt(getKey(R.string.p_widget_opacity), 100); + int getHeaderOpacity() { + return getAlphaValue(R.string.p_widget_header_opacity); + } + + int getRowOpacity() { + return getAlphaValue(R.string.p_widget_opacity); + } + + int getEmptySpaceOpacity() { + return getAlphaValue(R.string.p_widget_empty_space_opacity); + } + + private int getAlphaValue(int resId) { + return (int) ((preferences.getInt(getKey(resId), 100) / 100.0) * 255.0); } public void setColor(int color) { diff --git a/app/src/main/res/layout/scrollable_widget.xml b/app/src/main/res/layout/scrollable_widget.xml index 2846e120f..7cb831f9b 100644 --- a/app/src/main/res/layout/scrollable_widget.xml +++ b/app/src/main/res/layout/scrollable_widget.xml @@ -11,13 +11,6 @@ android:layout_height="48dp" android:orientation="horizontal"> - - - - diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index b581e208f..356795d37 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -277,6 +277,8 @@ widget-show-settings- widget-show-menu- widget-due-date-underneath- + widget-header-opacity- + widget-empty-space-opacity- widget-spacing- dashclock_filter default_remote_list diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee6c222cd..6c6f155d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -305,6 +305,7 @@ File %1$s contained %2$s.\n\n Show due dates Show checkboxes Due date below title + Hide background Show header Show settings Show menu @@ -411,6 +412,7 @@ File %1$s contained %2$s.\n\n Widget settings Header settings Row settings + Empty space Clear completed tasks? %s copied %s deleted diff --git a/app/src/main/res/xml/preferences_widget.xml b/app/src/main/res/xml/preferences_widget.xml index 8b892f514..c6ce44f06 100644 --- a/app/src/main/res/xml/preferences_widget.xml +++ b/app/src/main/res/xml/preferences_widget.xml @@ -10,15 +10,6 @@ android:key="@string/p_widget_theme" android:title="@string/theme" /> - - + + @@ -41,6 +41,15 @@ + + + + + + + + \ No newline at end of file