From 52eb32bea99ce67e1aa8115180936227ea19bedb Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 14 Apr 2020 12:46:00 -0500 Subject: [PATCH] Use ripple backgrounds for widget rows (Android 5+) --- .../java/org/tasks/widget/ScrollableViewsFactory.java | 10 +++++++++- app/src/main/java/org/tasks/widget/TasksWidget.java | 1 - app/src/main/res/drawable-v21/widget_ripple_dark.xml | 6 ++++++ app/src/main/res/drawable-v21/widget_ripple_light.xml | 7 +++++++ app/src/main/res/layout/scrollable_widget.xml | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable-v21/widget_ripple_dark.xml create mode 100644 app/src/main/res/drawable-v21/widget_ripple_light.xml diff --git a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.java b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.java index 66466d832..4783bf488 100644 --- a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.java +++ b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.java @@ -1,6 +1,7 @@ package org.tasks.widget; import static androidx.core.content.ContextCompat.getColor; +import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; import android.appwidget.AppWidgetManager; import android.content.Context; @@ -188,6 +189,13 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory { editIntent.putExtra(WidgetClickActivity.EXTRA_TASK, task); row.setOnClickFillInIntent(R.id.widget_row, editIntent); + int theme = widgetPreferences.getThemeIndex(); + if (atLeastLollipop()) { + row.setInt( + R.id.widget_row, + "setBackgroundResource", + theme == 0 ? R.drawable.widget_ripple_light : R.drawable.widget_ripple_dark); + } int horizontalPadding = (int) context.getResources().getDimension(R.dimen.widget_padding); int verticalPadding = widgetPreferences.getWidgetSpacing(); int textBottomPadding = @@ -210,7 +218,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory { row.setViewPadding(R.id.widget_description, horizontalPadding, 0, horizontalPadding, textBottomPadding); } - int dividerColor = ContextCompat.getColor(context, widgetPreferences.getThemeIndex() == 0 ? R.color.black_12 : R.color.white_12); + int dividerColor = ContextCompat.getColor(context, theme == 0 ? R.color.black_12 : R.color.white_12); row.setImageViewBitmap(R.id.divider, getSolidBackground(dividerColor)); row.setInt( diff --git a/app/src/main/java/org/tasks/widget/TasksWidget.java b/app/src/main/java/org/tasks/widget/TasksWidget.java index c93c63d1c..0249f2563 100644 --- a/app/src/main/java/org/tasks/widget/TasksWidget.java +++ b/app/src/main/java/org/tasks/widget/TasksWidget.java @@ -76,7 +76,6 @@ public class TasksWidget extends InjectingAppWidgetProvider { ThemeColor color = new ThemeColor(context, widgetPreferences.getColor()); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget); remoteViews.setInt(R.id.widget, "setLayoutDirection", locale.getDirectionality()); - int rowSpacing = widgetPreferences.getWidgetSpacing(); if (widgetPreferences.showHeader()) { remoteViews.setViewVisibility(R.id.widget_header, View.VISIBLE); remoteViews.setViewVisibility( diff --git a/app/src/main/res/drawable-v21/widget_ripple_dark.xml b/app/src/main/res/drawable-v21/widget_ripple_dark.xml new file mode 100644 index 000000000..2977bb0c2 --- /dev/null +++ b/app/src/main/res/drawable-v21/widget_ripple_dark.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/widget_ripple_light.xml b/app/src/main/res/drawable-v21/widget_ripple_light.xml new file mode 100644 index 000000000..8746dc25d --- /dev/null +++ b/app/src/main/res/drawable-v21/widget_ripple_light.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/scrollable_widget.xml b/app/src/main/res/layout/scrollable_widget.xml index 68288efb5..d1274551e 100644 --- a/app/src/main/res/layout/scrollable_widget.xml +++ b/app/src/main/res/layout/scrollable_widget.xml @@ -90,6 +90,7 @@ android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="fill_parent" + android:listSelector="@android:color/transparent" android:divider="@null" android:dividerHeight="0dp"/>