[Android] Widgets: implement the macro 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> | Tue May 10 09:01:51 2022 +0200| [667de53bab685ff582e3f0d694070cc15cd34763] | committer: Duncan McNamara

Widgets: implement the macro layout

> https://code.videolan.org/videolan/vlc-android/commit/667de53bab685ff582e3f0d694070cc15cd34763
---

 .../src/main/res/drawable-nodpi/vlc_fake_cover.png | Bin 24136 -> 117517 bytes
 .../vlc-android/res/layout/widget_macro.xml        |  44 +++++++++++++++++++--
 .../vlc/widget/MiniPlayerAppWidgetProvider.kt      |  16 +++++---
 3 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/application/resources/src/main/res/drawable-nodpi/vlc_fake_cover.png b/application/resources/src/main/res/drawable-nodpi/vlc_fake_cover.png
index 54044bf31..9e4ed4596 100644
Binary files a/application/resources/src/main/res/drawable-nodpi/vlc_fake_cover.png and b/application/resources/src/main/res/drawable-nodpi/vlc_fake_cover.png differ
diff --git a/application/vlc-android/res/layout/widget_macro.xml b/application/vlc-android/res/layout/widget_macro.xml
index 9882e7b7b..2192cafcb 100644
--- a/application/vlc-android/res/layout/widget_macro.xml
+++ b/application/vlc-android/res/layout/widget_macro.xml
@@ -27,10 +27,36 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
 
+    <ImageView
+            android:id="@+id/cover_background"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:adjustViewBounds="true"
+            android:layout_above="@+id/player_container"
+            android:layout_marginBottom="16dp"
+            android:contentDescription="@null"
+            android:src="@drawable/widget_rectangle_background" />
+
+    <ImageView
+            android:id="@+id/app_icon"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
+            android:scaleType="center"
+            android:contentDescription="@string/open_vlc"
+            android:layout_alignBottom="@id/cover_background"
+            android:layout_alignTop="@id/cover_background"
+            android:layout_alignLeft="@id/cover_background"
+            android:layout_alignRight="@id/cover_background"
+            android:src="@drawable/ic_widget_icon" />
+
     <ImageView
             android:id="@+id/cover"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:layout_alignBottom="@id/cover_background"
+            android:layout_alignTop="@id/cover_background"
+            android:layout_alignLeft="@id/cover_background"
+            android:layout_alignRight="@id/cover_background"
             android:adjustViewBounds="true"
             android:src="@drawable/ic_widget_icon" />
 
@@ -49,8 +75,20 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true"
+            android:padding="8dp"
             android:orientation="vertical">
 
+        <TextView
+                android:id="@+id/app_name"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="8dp"
+                android:fontFamily="sans-serif-medium"
+                android:gravity="center"
+                android:text="@string/widget_default_text"
+                android:textColor="@color/white"
+                android:textSize="16sp" />
+
         <TextView
                 android:id="@+id/songName"
                 android:layout_width="wrap_content"
@@ -66,8 +104,8 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:paddingStart="8dp"
-                android:paddingTop="4dp"
                 android:paddingEnd="8dp"
+                android:layout_marginBottom="4dp"
                 android:text="Author"
                 android:textColor="@color/white" />
 
@@ -83,7 +121,7 @@
             android:layout_height="48dp"
             android:scaleType="center"
                 android:contentDescription="@string/configure_widget"
-            android:layout_alignParentTop="true"
-            android:layout_alignParentRight="true" />
+            android:layout_alignTop="@+id/cover_background"
+            android:layout_alignRight="@+id/cover_background" />
 
 </RelativeLayout>
\ No newline at end of file
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 dec776921..8db502fb8 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -233,6 +233,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
         views.setOnClickPendingIntent(R.id.seek_forward, piSeekForward)
 
         if (colorChanged) {
+            if (widgetType == WidgetType.MACRO) views.setImageViewBitmap(R.id.cover_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, widgetCacheEntry.widget.getBackgroundColor(context, palette), widgetCacheEntry.widget.width.dp,  widgetCacheEntry.widget.width.dp))
             log(appWidgetId, WidgetLogType.BITMAP_GENERATION, "Bugfix Color changed!!! for widget $appWidgetId // forPreview $forPreview")
             if (android.text.TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) {
                 views.setImageViewBitmap(R.id.forward, context.getColoredBitmapFromColor(R.drawable.ic_widget_previous_normal, foregroundColor))
@@ -256,9 +257,9 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
 
         if (!forPreview) widgetCacheEntry.currentMedia = service?.currentMediaWrapper
         if (!playing)
-            setupTexts(context, views, context.getString(R.string.widget_default_text), "")
+            setupTexts(context, views, widgetType, context.getString(R.string.widget_default_text), "")
         else
-            setupTexts(context, views, widgetCacheEntry.currentMedia?.title, widgetCacheEntry.currentMedia?.artist)
+            setupTexts(context, views, widgetType, widgetCacheEntry.currentMedia?.title, widgetCacheEntry.currentMedia?.artist)
 
         if (widgetCacheEntry.playing != playing || colorChanged) views.setImageViewBitmap(R.id.play_pause, context.getColoredBitmapFromColor(getPlayPauseImage(playing, widgetType), foregroundColor))
         views.setContentDescription(R.id.play_pause, context.getString(if (!playing) R.string.resume_playback_short_title else R.string.pause))
@@ -460,13 +461,14 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
      *
      * @param context the context to use
      * @param views the [RemoteViews] to set the texts into
+     * @param widgetType the widget type
      * @param title the track name
      * @param artist the artist name
      */
-    private fun setupTexts(context: Context, views: RemoteViews, title: String?, artist: String?) {
+    private fun setupTexts(context: Context, views: RemoteViews, widgetType: WidgetType, title: String?, artist: String?) {
         log(-1, WidgetLogType.INFO, "setupTexts: $title /// $artist")
         views.setTextViewText(R.id.songName, title)
-        views.setTextViewText(R.id.artist, if (!artist.isNullOrBlank()) " ${TextUtils.separator} $artist" else artist)
+        views.setTextViewText(R.id.artist, if (!artist.isNullOrBlank()) "${if (widgetType == WidgetType.MACRO) "" else " ${TextUtils.separator} "}$artist" else artist)
         if (title == context.getString(R.string.widget_default_text)) {
             views.setViewVisibility(R.id.app_name, View.VISIBLE)
             views.setViewVisibility(R.id.songName, View.GONE)
@@ -495,7 +497,11 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
         val foregroundColor = widgetCacheEntry.widget.getForegroundColor(context, palette = widgetCacheEntry.palette)
         log(widgetCacheEntry.widget.widgetId, WidgetLogType.INFO, "Bugfix displayCover: widgetType $widgetType /// playing $playing /// foregroundColor $foregroundColor -> ${java.lang.String.format("#%06X", 0xFFFFFF and foregroundColor)}")
         if (!playing) {
-            val iconSize = if (widgetType == WidgetType.PILL) 24.dp else 48.dp
+            val iconSize = when (widgetType) {
+                WidgetType.PILL -> 24.dp
+                WidgetType.MACRO -> 128.dp
+                else -> 48.dp
+            }
             views.setImageViewBitmap(R.id.app_icon, context.getColoredBitmapFromColor(R.drawable.ic_widget_icon, foregroundColor, iconSize, iconSize))
             views.setViewVisibility(R.id.cover, View.INVISIBLE)
             views.setViewVisibility(R.id.app_icon, View.VISIBLE)



More information about the Android mailing list