aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-03 21:10:11 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-03 21:10:11 -0700
commitecf1aaa25def5a11e4ddc5845401ce6e76f0e147 (patch)
treeec39fa7f785cb625b183d0ff375466ae0e946bfd /subsonic-android/src
parent67bcb7bea9d8df747db55a692bb5c65f4a124916 (diff)
parentb27b809d018665d25512f9707d49941667cbc21c (diff)
downloaddsub-ecf1aaa25def5a11e4ddc5845401ce6e76f0e147.tar.gz
dsub-ecf1aaa25def5a11e4ddc5845401ce6e76f0e147.tar.bz2
dsub-ecf1aaa25def5a11e4ddc5845401ce6e76f0e147.zip
Merge widgets
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.java29
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.java29
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x3.java29
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x4.java29
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java52
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java4
6 files changed, 159 insertions, 13 deletions
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..e00bf02d
--- /dev/null
+++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x1.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 <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package github.daneren2005.dsub.provider;
+
+import android.appwidget.AppWidgetManager;
+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..4908f632
--- /dev/null
+++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidget4x2.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 <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package github.daneren2005.dsub.provider;
+
+import android.appwidget.AppWidgetManager;
+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/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 <http://www.gnu.org/licenses/>.
+
+ 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 <http://www.gnu.org/licenses/>.
+
+ 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 c61e215a..321b0f88 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,40 @@ 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;
+ private static DSubWidget4x3 instance4x3;
+ private static DSubWidget4x4 instance4x4;
- 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();
+ }
+ 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
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 +97,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.appwidget4x2) {
+ views.setTextViewText(R.id.album, "");
+ }
linkButtons(context, views, false);
pushUpdate(context, appWidgetIds, views);
@@ -118,11 +141,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 +164,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 93acfcb8..a8918923 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -730,7 +730,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){
@@ -812,7 +812,7 @@ public final class Util {
});
// Update widget
- DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false);
+ DSubWidgetProvider.notifyInstances(context, downloadService, false);
}
public static void sleepQuietly(long millis) {