[Android] Widgets: fix separator transparency

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:53:13 2022 +0200| [4e3953afe164de8bec18437a4a055122a2ec398d] | committer: Duncan McNamara

Widgets: fix separator transparency

> https://code.videolan.org/videolan/vlc-android/commit/4e3953afe164de8bec18437a4a055122a2ec398d
---

 .../org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt   |  5 +++--
 .../src/org/videolan/vlc/widget/utils/WidgetUtils.kt         | 12 +++++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)

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 12f2e4f7d..6f7316cf7 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -250,7 +250,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
             }
             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))
+            if (widgetType == WidgetType.PILL) views.setImageViewBitmap(R.id.cover_background, context.getColoredBitmapFromColor(R.drawable.widget_circle, widgetCacheEntry.widget.getSeparatorColor(context), 48.dp, 48.dp))
         }
 
 
@@ -279,7 +279,8 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
         log(appWidgetId, WidgetLogType.INFO, "coverPadding: $coverPadding: ${widgetCacheEntry.widget.height} /// ${48.dp}")
         views.setViewPadding(R.id.cover_parent, coverPadding, 0, coverPadding, 0)
 
-        views.setInt(R.id.separator, "setBackgroundColor", widgetCacheEntry.widget.getSeparatorColor(context, palette))
+        views.setInt(R.id.separator, "setBackgroundColor", widgetCacheEntry.widget.getSeparatorColor(context))
+        views.setInt(R.id.separator, "setImageAlpha", (widgetCacheEntry.widget.opacity.toFloat() * 255 / 100).toInt())
 
         if (forPreview) widgetCacheEntry.currentCover = "fake"
         if (forPreview) {
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 61bf85a72..df27edaea 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
@@ -114,11 +114,13 @@ fun Widget.getProgressBackgroundColor(context: Context, palette: Palette?): Int
     return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
 }
 
-fun Widget.getSeparatorColor(context: Context, palette: Palette?): Int {
-    val untreatedColor = ContextCompat.getColor(context, if (lightTheme) R.color.black_transparent_10 else R.color.white_transparent_10)
-
-    return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
-}
+/**
+ * Get the separator view color
+ *
+ * @param context the context to use
+ * @return a color without the transparency added
+ */
+fun Widget.getSeparatorColor(context: Context) = ContextCompat.getColor(context, if (lightTheme) R.color.black_transparent_10 else R.color.white_transparent_10)
 
 fun Widget.getPaletteColor(context: Context, palette: Palette?, foreground: Boolean, secondary: Boolean, lightTheme: Boolean): Int {
     //todo revert



More information about the Android mailing list