From 60a8fcaf8ece49d7ca6fcfda792f8935380d0223 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 17 May 2013 19:49:43 -0700 Subject: Added a 4x2 widget --- .../daneren2005/dsub/provider/DSubWidget4x1.java | 30 ++++++++++++++++ .../daneren2005/dsub/provider/DSubWidget4x2.java | 30 ++++++++++++++++ .../dsub/provider/DSubWidgetProvider.java | 42 ++++++++++++++++------ .../src/github/daneren2005/dsub/util/Util.java | 4 +-- 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java (limited to 'subsonic-android/src') diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java new file mode 100644 index 00000000..5461d076 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java @@ -0,0 +1,30 @@ +/* + This file is part of Subsonic. + + Subsonic 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 3 of the License, or + (at your option) any later version. + + Subsonic 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 Subsonic. If not, see . + + Copyright 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.provider; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import github.daneren2005.dsub.R; + +public class DSubWidget4x1 extends DSubWidgetProvider { + @Override + protected int getLayout() { + return R.layout.appwidget4x1; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java new file mode 100644 index 00000000..376a3084 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java @@ -0,0 +1,30 @@ +/* + This file is part of Subsonic. + + Subsonic 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 3 of the License, or + (at your option) any later version. + + Subsonic 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 Subsonic. If not, see . + + Copyright 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.provider; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import github.daneren2005.dsub.R; + +public class DSubWidget4x2 extends DSubWidgetProvider { + @Override + protected int getLayout() { + return R.layout.appwidget4x2; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java index c61e215a..be91fe17 100644 --- a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java @@ -45,6 +45,7 @@ import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; +import java.util.HashMap; /** * Simple widget to show currently playing album art along @@ -55,21 +56,30 @@ import github.daneren2005.dsub.util.FileUtil; * @author Sindre Mehus */ public class DSubWidgetProvider extends AppWidgetProvider { - - private static DSubWidgetProvider instance; private static final String TAG = DSubWidgetProvider.class.getSimpleName(); + private static DSubWidget4x1 instance4x1; + private static DSubWidget4x2 instance4x2; - public static synchronized DSubWidgetProvider getInstance() { - if (instance == null) { - instance = new DSubWidgetProvider(); - } - return instance; - } + public static synchronized void notifyInstances(Context context, DownloadService service, boolean playing) { + if(instance4x1 == null) { + instance4x1 = new DSubWidget4x1(); + } + if(instance4x2 == null) { + instance4x2 = new DSubWidget4x2(); + } + + instance4x1.notifyChange(context, service, playing); + instance4x2.notifyChange(context, service, playing); + } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { defaultAppWidget(context, appWidgetIds); } + + protected int getLayout() { + return 0; + } /** * Initialize given widgets to default state, where we launch Subsonic on default click @@ -77,9 +87,12 @@ public class DSubWidgetProvider extends AppWidgetProvider { */ private void defaultAppWidget(Context context, int[] appWidgetIds) { final Resources res = context.getResources(); - final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget); + final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout()); views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text)); + if(getLayout() != R.layout.appwidget4x1) { + views.setTextViewText(R.id.album, ""); + } linkButtons(context, views, false); pushUpdate(context, appWidgetIds, views); @@ -118,11 +131,12 @@ public class DSubWidgetProvider extends AppWidgetProvider { */ private void performUpdate(Context context, DownloadService service, int[] appWidgetIds, boolean playing) { final Resources res = context.getResources(); - final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget); + final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout()); MusicDirectory.Entry currentPlaying = service.getCurrentPlaying() == null ? null : service.getCurrentPlaying().getSong(); String title = currentPlaying == null ? null : currentPlaying.getTitle(); CharSequence artist = currentPlaying == null ? null : currentPlaying.getArtist(); + CharSequence album = currentPlaying == null ? null : currentPlaying.getAlbum(); CharSequence errorState = null; // Show error message? @@ -140,11 +154,17 @@ public class DSubWidgetProvider extends AppWidgetProvider { // Show error state to user views.setTextViewText(R.id.title,null); views.setTextViewText(R.id.artist, errorState); - views.setImageViewResource(R.id.appwidget_coverart, R.drawable.appwidget_art_default); + views.setTextViewText(R.id.album, ""); + if(getLayout() != R.layout.appwidget4x1) { + views.setImageViewResource(R.id.appwidget_coverart, R.drawable.appwidget_art_default); + } } else { // No error, so show normal titles views.setTextViewText(R.id.title, title); views.setTextViewText(R.id.artist, artist); + if(getLayout() != R.layout.appwidget4x1) { + views.setTextViewText(R.id.album, album); + } } // Set correct drawable for pause state diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 43aad67b..48cb7276 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -672,7 +672,7 @@ public final class Util { }); // Update widget - DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true); + DSubWidgetProvider.notifyInstances(context, downloadService, true); } private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing){ @@ -754,7 +754,7 @@ public final class Util { }); // Update widget - DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false); + DSubWidgetProvider.notifyInstances(context, downloadService, false); } public static void sleepQuietly(long millis) { -- cgit v1.2.3 From b27b809d018665d25512f9707d49941667cbc21c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 3 Jun 2013 21:09:41 -0700 Subject: Finished adding 4x1-4x4 widgets (Thanks archrival) --- subsonic-android/AndroidManifest.xml | 16 ++ subsonic-android/res/layout/appwidget.xml | 89 -------- subsonic-android/res/layout/appwidget4x1.xml | 191 +++++++++-------- subsonic-android/res/layout/appwidget4x2.xml | 226 ++++++++++++--------- subsonic-android/res/layout/appwidget4x3.xml | 112 ++++++++++ subsonic-android/res/layout/appwidget4x4.xml | 114 +++++++++++ subsonic-android/res/values/strings.xml | 2 + subsonic-android/res/xml/appwidget4x3.xml | 7 + subsonic-android/res/xml/appwidget4x4.xml | 7 + subsonic-android/res/xml/appwidget_info.xml | 7 - .../daneren2005/dsub/provider/DSubWidget4x1.java | 1 - .../daneren2005/dsub/provider/DSubWidget4x2.java | 1 - .../daneren2005/dsub/provider/DSubWidget4x3.java | 29 +++ .../daneren2005/dsub/provider/DSubWidget4x4.java | 29 +++ .../dsub/provider/DSubWidgetProvider.java | 12 +- 15 files changed, 555 insertions(+), 288 deletions(-) delete mode 100644 subsonic-android/res/layout/appwidget.xml create mode 100644 subsonic-android/res/layout/appwidget4x3.xml create mode 100644 subsonic-android/res/layout/appwidget4x4.xml create mode 100644 subsonic-android/res/xml/appwidget4x3.xml create mode 100644 subsonic-android/res/xml/appwidget4x4.xml delete mode 100644 subsonic-android/res/xml/appwidget_info.xml create mode 100644 subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x3.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x4.java (limited to 'subsonic-android/src') diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml index 6224cf79..43cff05f 100644 --- a/subsonic-android/AndroidManifest.xml +++ b/subsonic-android/AndroidManifest.xml @@ -114,6 +114,22 @@ + + + + + + + + + + + + diff --git a/subsonic-android/res/layout/appwidget.xml b/subsonic-android/res/layout/appwidget.xml deleted file mode 100644 index fa47a7b9..00000000 --- a/subsonic-android/res/layout/appwidget.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/subsonic-android/res/layout/appwidget4x1.xml b/subsonic-android/res/layout/appwidget4x1.xml index ed08d674..5e55aa37 100644 --- a/subsonic-android/res/layout/appwidget4x1.xml +++ b/subsonic-android/res/layout/appwidget4x1.xml @@ -1,91 +1,106 @@ - - - - - - - - + + + + + + - - - - - - - - + android:layout_height="wrap_content" + android:clickable="true" + android:focusable="true" + android:orientation="vertical" + android:background="@drawable/media_button"> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/layout/appwidget4x2.xml b/subsonic-android/res/layout/appwidget4x2.xml index 6407c298..575ae1c2 100644 --- a/subsonic-android/res/layout/appwidget4x2.xml +++ b/subsonic-android/res/layout/appwidget4x2.xml @@ -1,105 +1,129 @@ - - - - - - + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:minWidth="250dp" + android:minHeight="110dp" + android:background="@drawable/appwidget_bg" + android:orientation="horizontal" > - - - + + + + + + + + + + + + + + - - - - - - - - + android:layout_height="wrap_content" + android:orientation="horizontal" + android:layout_gravity="bottom" + android:gravity="bottom" + android:paddingBottom="4dip" + android:paddingTop="4dip" >" + + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/layout/appwidget4x3.xml b/subsonic-android/res/layout/appwidget4x3.xml new file mode 100644 index 00000000..b4f685bc --- /dev/null +++ b/subsonic-android/res/layout/appwidget4x3.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/layout/appwidget4x4.xml b/subsonic-android/res/layout/appwidget4x4.xml new file mode 100644 index 00000000..6e6c12ab --- /dev/null +++ b/subsonic-android/res/layout/appwidget4x4.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 2d42a66d..7f03003e 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -304,6 +304,8 @@ DSub (4x1) DSub (4x2) + DSub (4x3) + DSub (4x4) Touch to select music SD card unavailable No SD card diff --git a/subsonic-android/res/xml/appwidget4x3.xml b/subsonic-android/res/xml/appwidget4x3.xml new file mode 100644 index 00000000..51ae97ed --- /dev/null +++ b/subsonic-android/res/xml/appwidget4x3.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/subsonic-android/res/xml/appwidget4x4.xml b/subsonic-android/res/xml/appwidget4x4.xml new file mode 100644 index 00000000..40956dcf --- /dev/null +++ b/subsonic-android/res/xml/appwidget4x4.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/subsonic-android/res/xml/appwidget_info.xml b/subsonic-android/res/xml/appwidget_info.xml deleted file mode 100644 index 7ad17ef9..00000000 --- a/subsonic-android/res/xml/appwidget_info.xml +++ /dev/null @@ -1,7 +0,0 @@ - - \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java index 5461d076..e00bf02d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java @@ -19,7 +19,6 @@ package github.daneren2005.dsub.provider; import android.appwidget.AppWidgetManager; -import android.content.Context; import github.daneren2005.dsub.R; public class DSubWidget4x1 extends DSubWidgetProvider { diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java index 376a3084..4908f632 100644 --- a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java @@ -19,7 +19,6 @@ package github.daneren2005.dsub.provider; import android.appwidget.AppWidgetManager; -import android.content.Context; import github.daneren2005.dsub.R; public class DSubWidget4x2 extends DSubWidgetProvider { diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x3.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x3.java new file mode 100644 index 00000000..f1908d0d --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x3.java @@ -0,0 +1,29 @@ +/* + This file is part of Subsonic. + + Subsonic 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 3 of the License, or + (at your option) any later version. + + Subsonic 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 Subsonic. If not, see . + + Copyright 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.provider; + +import android.appwidget.AppWidgetManager; +import github.daneren2005.dsub.R; + +public class DSubWidget4x3 extends DSubWidgetProvider { + @Override + protected int getLayout() { + return R.layout.appwidget4x3; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x4.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x4.java new file mode 100644 index 00000000..7fee2747 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x4.java @@ -0,0 +1,29 @@ +/* + This file is part of Subsonic. + + Subsonic 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 3 of the License, or + (at your option) any later version. + + Subsonic 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 Subsonic. If not, see . + + Copyright 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.provider; + +import android.appwidget.AppWidgetManager; +import github.daneren2005.dsub.R; + +public class DSubWidget4x4 extends DSubWidgetProvider { + @Override + protected int getLayout() { + return R.layout.appwidget4x4; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java index be91fe17..321b0f88 100644 --- a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java @@ -59,6 +59,8 @@ public class DSubWidgetProvider extends AppWidgetProvider { private static final String TAG = DSubWidgetProvider.class.getSimpleName(); private static DSubWidget4x1 instance4x1; private static DSubWidget4x2 instance4x2; + private static DSubWidget4x3 instance4x3; + private static DSubWidget4x4 instance4x4; public static synchronized void notifyInstances(Context context, DownloadService service, boolean playing) { if(instance4x1 == null) { @@ -67,9 +69,17 @@ public class DSubWidgetProvider extends AppWidgetProvider { if(instance4x2 == null) { instance4x2 = new DSubWidget4x2(); } + if(instance4x3 == null) { + instance4x3 = new DSubWidget4x3(); + } + if(instance4x4 == null) { + instance4x4 = new DSubWidget4x4(); + } instance4x1.notifyChange(context, service, playing); instance4x2.notifyChange(context, service, playing); + instance4x3.notifyChange(context, service, playing); + instance4x4.notifyChange(context, service, playing); } @Override @@ -90,7 +100,7 @@ public class DSubWidgetProvider extends AppWidgetProvider { final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout()); views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text)); - if(getLayout() != R.layout.appwidget4x1) { + if(getLayout() == R.layout.appwidget4x2) { views.setTextViewText(R.id.album, ""); } -- cgit v1.2.3