[Android] Widget : Prepare code for future dark widget

Alexandre Perraud git at videolan.org
Tue Sep 8 12:27:23 CEST 2015


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri Sep  4 17:12:50 2015 +0200| [8207b590c252b4a7e5f5d1b6fdb2ee60d4fffc02] | committer: Alexandre Perraud

Widget : Prepare code for future dark widget

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8207b590c252b4a7e5f5d1b6fdb2ee60d4fffc02
---

 vlc-android/AndroidManifest.xml                    |   10 +++++--
 ...{widget_preview_01.png => widget_preview_w.png} |  Bin 34559 -> 34559 bytes
 .../res/layout/{vlcwidget.xml => widget_w.xml}     |    2 +-
 vlc-android/res/values/strings.xml                 |    5 +++-
 .../xml/{vlcwidget.xml => widget_provider_w.xml}   |    4 +--
 .../src/org/videolan/vlc/PlaybackService.java      |   12 +++-----
 .../videolan/vlc/widget/VLCAppWidgetProvider.java  |    9 ++++--
 .../vlc/widget/VLCAppWidgetProviderWhite.java      |   30 ++++++++++++++++++++
 8 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index 83f4edc..42c2a1e 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -433,16 +433,20 @@
             </intent-filter>
         </receiver>
         <receiver
-            android:name=".widget.VLCAppWidgetProvider"
+            android:name=".widget.VLCAppWidgetProviderWhite"
             android:exported="false"
-            android:label="VLC resizable widget" >
+            android:label="@string/widget_name_w" >
             <intent-filter>
                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+                <action android:name="org.videolan.vlc.widget.INIT" />
+                <action android:name="org.videolan.vlc.widget.UPDATE" />
+                <action android:name="org.videolan.vlc.widget.UPDATE_COVER" />
+                <action android:name="org.videolan.vlc.widget.UPDATE_POSITION" />
             </intent-filter>
 
             <meta-data
                 android:name="android.appwidget.provider"
-                android:resource="@xml/vlcwidget" />
+                android:resource="@xml/widget_provider_w" />
         </receiver>
         <receiver android:name=".RemoteControlClientReceiver" >
             <intent-filter>
diff --git a/vlc-android/res/drawable/widget_preview_01.png b/vlc-android/res/drawable/widget_preview_w.png
similarity index 100%
rename from vlc-android/res/drawable/widget_preview_01.png
rename to vlc-android/res/drawable/widget_preview_w.png
diff --git a/vlc-android/res/layout/vlcwidget.xml b/vlc-android/res/layout/widget_w.xml
similarity index 98%
rename from vlc-android/res/layout/vlcwidget.xml
rename to vlc-android/res/layout/widget_w.xml
index 01e7b91..f28c6f4 100644
--- a/vlc-android/res/layout/vlcwidget.xml
+++ b/vlc-android/res/layout/widget_w.xml
@@ -50,7 +50,7 @@
                 android:layout_marginLeft="@dimen/half_default_margin"
                 android:ellipsize="end"
                 android:singleLine="true"
-                android:text="@string/widget_name"
+                android:text="@string/widget_default_text"
                 android:textColor="@color/grey900"
                 android:textSize="16sp" />
 
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index dc6256a..f79e93e 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -3,7 +3,6 @@
 
     <!-- Main VLC Interface -->
     <string name="app_name" translatable="false">VLC</string>
-    <string name="widget_name" translatable="false">VLC mini player</string>
     <string name="ok">OK</string>
     <string name="cancel">Cancel</string>
     <string name="other">Other</string>
@@ -356,6 +355,10 @@
     <string name="no_subs_found">No subtitles in this directory</string>
     <string name="music_now_playing">Now Playing</string>
 
+    <!--Widget-->
+    <string name="widget_default_text" translatable="false">VLC mini player</string>
+    <string name="widget_name_w">VLC White Widget</string>
+
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
         <item>@string/hardware_acceleration_disabled</item>
diff --git a/vlc-android/res/xml/vlcwidget.xml b/vlc-android/res/xml/widget_provider_w.xml
similarity index 67%
rename from vlc-android/res/xml/vlcwidget.xml
rename to vlc-android/res/xml/widget_provider_w.xml
index b741d2b..4533e3d 100644
--- a/vlc-android/res/xml/vlcwidget.xml
+++ b/vlc-android/res/xml/widget_provider_w.xml
@@ -4,6 +4,6 @@
     android:resizeMode="horizontal"
     android:minResizeWidth="180dp"
     android:updatePeriodMillis="86400000"
-    android:initialLayout="@layout/vlcwidget"
-    android:previewImage="@drawable/widget_preview_01">
+    android:initialLayout="@layout/widget_w"
+    android:previewImage="@drawable/widget_preview_w">
 </appwidget-provider>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 16f4f8f..414706c 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -72,7 +72,6 @@ import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
 import org.videolan.vlc.util.VLCOptions;
 import org.videolan.vlc.util.WeakHandler;
-import org.videolan.vlc.widget.VLCAppWidgetProvider;
 
 import java.io.File;
 import java.net.URI;
@@ -1195,8 +1194,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     private void updateWidgetState() {
-        Intent i = new Intent(this, VLCAppWidgetProvider.class);
-        i.setAction(ACTION_WIDGET_UPDATE);
+        Intent i = new Intent(ACTION_WIDGET_UPDATE);
 
         if (hasCurrentMedia()) {
             final MediaWrapper media = getCurrentMedia();
@@ -1206,7 +1204,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     : Util.getMediaArtist(this, media));
         }
         else {
-            i.putExtra("title", getString(R.string.widget_name));
+            i.putExtra("title", getString(R.string.widget_default_text));
             i.putExtra("artist", "");
         }
         i.putExtra("isplaying", mMediaPlayer.isPlaying());
@@ -1215,8 +1213,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     private void updateWidgetCover() {
-        Intent i = new Intent(this, VLCAppWidgetProvider.class);
-        i.setAction(ACTION_WIDGET_UPDATE_COVER);
+        Intent i = new Intent(ACTION_WIDGET_UPDATE_COVER);
 
         Bitmap cover = hasCurrentMedia() ? AudioUtil.getCover(this, getCurrentMedia(), 64) : null;
         i.putExtra("cover", cover);
@@ -1234,8 +1231,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         updateWidgetState();
 
         mWidgetPositionTimestamp = timestamp;
-        Intent i = new Intent(this, VLCAppWidgetProvider.class);
-        i.setAction(ACTION_WIDGET_UPDATE_POSITION);
+        Intent i = new Intent(ACTION_WIDGET_UPDATE_POSITION);
         i.putExtra("position", pos);
         sendBroadcast(i);
     }
diff --git a/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
index 8352131..fccb968 100644
--- a/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
+++ b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
@@ -38,7 +38,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 
-public class VLCAppWidgetProvider extends AppWidgetProvider {
+abstract public class VLCAppWidgetProvider extends AppWidgetProvider {
     public static final String TAG = "VLC/VLCAppWidgetProvider";
     public static final String ACTION_REMOTE_BACKWARD = "org.videolan.vlc.remote.Backward";
     public static final String ACTION_REMOTE_PLAYPAUSE = "org.videolan.vlc.remote.PlayPause";
@@ -75,7 +75,7 @@ public class VLCAppWidgetProvider extends AppWidgetProvider {
             return;
         }
 
-        RemoteViews views = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.vlcwidget);
+        RemoteViews views = new RemoteViews(BuildConfig.APPLICATION_ID, getLayout());
         boolean partial = AndroidUtil.isHoneycombOrLater();
 
         if (ACTION_WIDGET_INIT.equals(action) || !partial) {
@@ -123,11 +123,14 @@ public class VLCAppWidgetProvider extends AppWidgetProvider {
             views.setProgressBar(R.id.timeline, 100, (int) (100 * pos), false);
         }
 
-        ComponentName widget = new ComponentName(context, VLCAppWidgetProvider.class);
+        ComponentName widget = new ComponentName(context, this.getClass());
         AppWidgetManager manager = AppWidgetManager.getInstance(context);
         if (partial)
             manager.partiallyUpdateAppWidget(manager.getAppWidgetIds(widget), views);
         else
             manager.updateAppWidget(widget, views);
     }
+
+    abstract protected int getLayout();
+
 }
diff --git a/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProviderWhite.java b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProviderWhite.java
new file mode 100644
index 0000000..680447f
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProviderWhite.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * VLCAppWidgetProviderWhite.java
+ *****************************************************************************
+ * Copyright © 2015 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.vlc.widget;
+
+import org.videolan.vlc.R;
+
+public class VLCAppWidgetProviderWhite extends VLCAppWidgetProvider {
+
+    protected int getLayout() {
+        return R.layout.widget_w;
+    }
+}



More information about the Android mailing list