[Android] Widgets: add a secondary background color for the micro layout

Nicolas Pomepuy git at videolan.org
Wed May 18 09:57:57 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed May 11 09:44:46 2022 +0200| [1c4879f6237edadd160f82151cf3b4787ea352eb] | committer: Duncan McNamara

Widgets: add a secondary background color for the micro layout

> https://code.videolan.org/videolan/vlc-android/commit/1c4879f6237edadd160f82151cf3b4787ea352eb
---

 .../videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt   |  2 +-
 .../src/org/videolan/vlc/widget/utils/WidgetUtils.kt     | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
index 1fe496fd0..12f2e4f7d 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -248,7 +248,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
                 views.setImageViewBitmap(R.id.seek_rewind, context.getColoredBitmapFromColor(R.drawable.ic_widget_rewind_10, foregroundColor))
                 views.setImageViewBitmap(R.id.seek_forward, context.getColoredBitmapFromColor(R.drawable.ic_widget_forward_10, foregroundColor))
             }
-            views.setImageViewBitmap(R.id.play_pause_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, backgroundColor, 52.dp, 52.dp))
+            views.setImageViewBitmap(R.id.play_pause_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, widgetCacheEntry.widget.getBackgroundSecondaryColor(context, palette = palette), 52.dp, 52.dp))
             views.setImageViewBitmap(R.id.widget_configure, if (widgetCacheEntry.widget.showConfigure) context.getColoredBitmapFromColor(R.drawable.ic_widget_configure, foregroundColor, 24.dp, 24.dp) else null)
             if (widgetType == WidgetType.PILL) views.setImageViewBitmap(R.id.cover_background, context.getColoredBitmapFromColor(R.drawable.widget_circle, widgetCacheEntry.widget.getSeparatorColor(context, palette), 48.dp, 48.dp))
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
index 1bf70a969..61bf85a72 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
@@ -71,6 +71,22 @@ fun Widget.getBackgroundColor(context: Context, palette: Palette?): Int {
     return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
 }
 
+/**
+ * Get the background secondary color of the widget depending on its theme. Mostly used for the micro widget 'FAB' color
+ * @param context the context to use
+ * @param palette the palette to be used if needed
+ * @return a color
+ */
+ at RequiresApi(Build.VERSION_CODES.S)
+fun Widget.getBackgroundSecondaryColor(context: Context, palette: Palette?): Int {
+    val untreatedColor = when {
+        theme == 0 -> ContextCompat.getColor(context, if (lightTheme) android.R.color.system_accent1_100 else android.R.color.system_accent1_700)
+        theme == 1 -> (if (lightTheme) palette?.lightMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey300) else palette?.darkMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey800))
+        else -> backgroundColor.lightenOrDarkenColor(0.1F)
+    }
+    return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
+}
+
 /**
  * Get the Artist text color of the widget depending on its theme
  * @param context the context to use



More information about the Android mailing list