diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-02-27 20:47:44 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-02-27 20:47:44 +0000 |
commit | 883ff8507e42f7fbba6416e60fb116164219aa5f (patch) | |
tree | 3708181c7a19309f02bb4b93d073745c119338a2 | |
parent | 952d82b7bd20f1bef7f3c316ebeb71c0d1e6d20b (diff) | |
download | rockbox-883ff8507e42f7fbba6416e60fb116164219aa5f.tar.gz rockbox-883ff8507e42f7fbba6416e60fb116164219aa5f.zip |
Android: Show cover art in the widget (including option to hide it).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29437 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | android/res/layout/appwidget_2x2.xml | 8 | ||||
-rw-r--r-- | android/res/layout/appwidget_3x3.xml | 6 | ||||
-rw-r--r-- | android/res/layout/appwidget_4x1.xml | 6 | ||||
-rw-r--r-- | android/res/layout/appwidget_configure.xml | 4 | ||||
-rw-r--r-- | android/res/values/strings.xml | 1 | ||||
-rw-r--r-- | android/src/org/rockbox/Helper/RunForegroundManager.java | 4 | ||||
-rw-r--r-- | android/src/org/rockbox/widgets/RockboxWidgetConfigure.java | 5 | ||||
-rw-r--r-- | android/src/org/rockbox/widgets/RockboxWidgetProvider.java | 11 | ||||
-rw-r--r-- | apps/hosted/notification.c | 13 |
9 files changed, 49 insertions, 9 deletions
diff --git a/android/res/layout/appwidget_2x2.xml b/android/res/layout/appwidget_2x2.xml index a29f416b3d..113384f57b 100644 --- a/android/res/layout/appwidget_2x2.xml +++ b/android/res/layout/appwidget_2x2.xml | |||
@@ -8,10 +8,12 @@ | |||
8 | android:background="@drawable/appwidget_background"> | 8 | android:background="@drawable/appwidget_background"> |
9 | <!-- style="@style/appwidget_background"--> | 9 | <!-- style="@style/appwidget_background"--> |
10 | 10 | ||
11 | <ImageView android:id="@+id/logo" | 11 | <ImageButton android:id="@+id/logo" |
12 | android:layout_marginTop="5dp" | ||
12 | android:layout_width="fill_parent" | 13 | android:layout_width="fill_parent" |
13 | android:layout_height="40dp" | 14 | android:layout_height="80dp" |
14 | android:scaleType="centerInside" | 15 | android:scaleType="centerInside" |
16 | android:background="@drawable/appwidget_infodisplay_background" | ||
15 | android:src="@drawable/rockbox" /> | 17 | android:src="@drawable/rockbox" /> |
16 | <Button android:id="@+id/infoDisplay" | 18 | <Button android:id="@+id/infoDisplay" |
17 | style="@style/appwidget_infodisplay" | 19 | style="@style/appwidget_infodisplay" |
diff --git a/android/res/layout/appwidget_3x3.xml b/android/res/layout/appwidget_3x3.xml index a29f416b3d..b5be5356fa 100644 --- a/android/res/layout/appwidget_3x3.xml +++ b/android/res/layout/appwidget_3x3.xml | |||
@@ -8,10 +8,12 @@ | |||
8 | android:background="@drawable/appwidget_background"> | 8 | android:background="@drawable/appwidget_background"> |
9 | <!-- style="@style/appwidget_background"--> | 9 | <!-- style="@style/appwidget_background"--> |
10 | 10 | ||
11 | <ImageView android:id="@+id/logo" | 11 | <ImageButton android:id="@+id/logo" |
12 | android:layout_marginTop="15dp" | ||
12 | android:layout_width="fill_parent" | 13 | android:layout_width="fill_parent" |
13 | android:layout_height="40dp" | 14 | android:layout_height="130dp" |
14 | android:scaleType="centerInside" | 15 | android:scaleType="centerInside" |
16 | android:background="@drawable/appwidget_infodisplay_background" | ||
15 | android:src="@drawable/rockbox" /> | 17 | android:src="@drawable/rockbox" /> |
16 | <Button android:id="@+id/infoDisplay" | 18 | <Button android:id="@+id/infoDisplay" |
17 | style="@style/appwidget_infodisplay" | 19 | style="@style/appwidget_infodisplay" |
diff --git a/android/res/layout/appwidget_4x1.xml b/android/res/layout/appwidget_4x1.xml index 0d2d6df010..db7ebb5d0d 100644 --- a/android/res/layout/appwidget_4x1.xml +++ b/android/res/layout/appwidget_4x1.xml | |||
@@ -8,6 +8,12 @@ | |||
8 | android:background="@drawable/appwidget_background"> | 8 | android:background="@drawable/appwidget_background"> |
9 | <!-- style="@style/appwidget_background"--> | 9 | <!-- style="@style/appwidget_background"--> |
10 | 10 | ||
11 | <ImageButton android:id="@+id/logo" | ||
12 | android:layout_width="68dp" | ||
13 | android:layout_height="fill_parent" | ||
14 | android:scaleType="centerInside" | ||
15 | android:background="@drawable/appwidget_infodisplay_background" | ||
16 | android:src="@drawable/rockbox" /> | ||
11 | <Button android:id="@+id/infoDisplay" | 17 | <Button android:id="@+id/infoDisplay" |
12 | style="@style/appwidget_infodisplay" | 18 | style="@style/appwidget_infodisplay" |
13 | android:layout_height="fill_parent" | 19 | android:layout_height="fill_parent" |
diff --git a/android/res/layout/appwidget_configure.xml b/android/res/layout/appwidget_configure.xml index 8dd0ff2144..1f33afe61e 100644 --- a/android/res/layout/appwidget_configure.xml +++ b/android/res/layout/appwidget_configure.xml | |||
@@ -15,6 +15,10 @@ | |||
15 | android:layout_height="wrap_content" | 15 | android:layout_height="wrap_content" |
16 | android:text="@string/appwidget_configure_instructions"/> | 16 | android:text="@string/appwidget_configure_instructions"/> |
17 | 17 | ||
18 | <CheckBox android:id="@+id/enable_aa" | ||
19 | android:layout_width="fill_parent" | ||
20 | android:layout_height="wrap_content" | ||
21 | android:text="@string/appwidget_configure_albumart"/> | ||
18 | <CheckBox android:id="@+id/enable_prev" | 22 | <CheckBox android:id="@+id/enable_prev" |
19 | android:layout_width="fill_parent" | 23 | android:layout_width="fill_parent" |
20 | android:layout_height="wrap_content" | 24 | android:layout_height="wrap_content" |
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 9e818319d4..c92e955edf 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | <!-- Widget configuration --> | 20 | <!-- Widget configuration --> |
21 | <string name="appwidget_configure_instructions">Please chose elements to display in widget.</string> | 21 | <string name="appwidget_configure_instructions">Please chose elements to display in widget.</string> |
22 | <string name="appwidget_configure_albumart">Cover Art</string> | ||
22 | <string name="appwidget_configure_prev">Prev Button</string> | 23 | <string name="appwidget_configure_prev">Prev Button</string> |
23 | <string name="appwidget_configure_stop">Stop Button</string> | 24 | <string name="appwidget_configure_stop">Stop Button</string> |
24 | <string name="appwidget_configure_playpause">Play/Pause Button</string> | 25 | <string name="appwidget_configure_playpause">Play/Pause Button</string> |
diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java index e8b9620280..c08e742aba 100644 --- a/android/src/org/rockbox/Helper/RunForegroundManager.java +++ b/android/src/org/rockbox/Helper/RunForegroundManager.java | |||
@@ -11,7 +11,6 @@ import android.app.NotificationManager; | |||
11 | import android.app.PendingIntent; | 11 | import android.app.PendingIntent; |
12 | import android.app.Service; | 12 | import android.app.Service; |
13 | import android.content.Intent; | 13 | import android.content.Intent; |
14 | import android.net.Uri; | ||
15 | import android.util.Log; | 14 | import android.util.Log; |
16 | import android.widget.RemoteViews; | 15 | import android.widget.RemoteViews; |
17 | 16 | ||
@@ -83,7 +82,7 @@ public class RunForegroundManager | |||
83 | api.stopForeground(); | 82 | api.stopForeground(); |
84 | } | 83 | } |
85 | 84 | ||
86 | public void updateNotification(String title, String artist, String album) | 85 | public void updateNotification(String title, String artist, String album, String albumart) |
87 | { | 86 | { |
88 | RemoteViews views = mNotification.contentView; | 87 | RemoteViews views = mNotification.contentView; |
89 | views.setTextViewText(R.id.title, title); | 88 | views.setTextViewText(R.id.title, title); |
@@ -98,6 +97,7 @@ public class RunForegroundManager | |||
98 | widgetUpdate.putExtra("title", title); | 97 | widgetUpdate.putExtra("title", title); |
99 | widgetUpdate.putExtra("artist", artist); | 98 | widgetUpdate.putExtra("artist", artist); |
100 | widgetUpdate.putExtra("album", album); | 99 | widgetUpdate.putExtra("album", album); |
100 | widgetUpdate.putExtra("albumart", albumart); | ||
101 | mCurrentService.sendBroadcast(widgetUpdate); | 101 | mCurrentService.sendBroadcast(widgetUpdate); |
102 | } | 102 | } |
103 | 103 | ||
diff --git a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java index 6ce2050780..700fc2fa1a 100644 --- a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java +++ b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java | |||
@@ -50,6 +50,7 @@ public class RockboxWidgetConfigure extends Activity | |||
50 | setResult(RESULT_CANCELED); | 50 | setResult(RESULT_CANCELED); |
51 | setContentView(R.layout.appwidget_configure); | 51 | setContentView(R.layout.appwidget_configure); |
52 | 52 | ||
53 | ((CheckBox)findViewById(R.id.enable_aa)).setChecked(true); | ||
53 | ((CheckBox)findViewById(R.id.enable_prev)).setChecked(false); | 54 | ((CheckBox)findViewById(R.id.enable_prev)).setChecked(false); |
54 | ((CheckBox)findViewById(R.id.enable_stop)).setChecked(true); | 55 | ((CheckBox)findViewById(R.id.enable_stop)).setChecked(true); |
55 | ((CheckBox)findViewById(R.id.enable_playpause)).setChecked(true); | 56 | ((CheckBox)findViewById(R.id.enable_playpause)).setChecked(true); |
@@ -73,6 +74,7 @@ public class RockboxWidgetConfigure extends Activity | |||
73 | final Context context = RockboxWidgetConfigure.this; | 74 | final Context context = RockboxWidgetConfigure.this; |
74 | 75 | ||
75 | WidgetPref state = new WidgetPref(); | 76 | WidgetPref state = new WidgetPref(); |
77 | state.enableAA = ((CheckBox)findViewById(R.id.enable_aa)).isChecked(); | ||
76 | state.enablePrev = ((CheckBox)findViewById(R.id.enable_prev)).isChecked(); | 78 | state.enablePrev = ((CheckBox)findViewById(R.id.enable_prev)).isChecked(); |
77 | state.enableStop = ((CheckBox)findViewById(R.id.enable_stop)).isChecked(); | 79 | state.enableStop = ((CheckBox)findViewById(R.id.enable_stop)).isChecked(); |
78 | state.enablePlayPause = ((CheckBox)findViewById(R.id.enable_playpause)).isChecked(); | 80 | state.enablePlayPause = ((CheckBox)findViewById(R.id.enable_playpause)).isChecked(); |
@@ -91,6 +93,7 @@ public class RockboxWidgetConfigure extends Activity | |||
91 | 93 | ||
92 | static public class WidgetPref | 94 | static public class WidgetPref |
93 | { | 95 | { |
96 | public boolean enableAA = true; | ||
94 | public boolean enablePrev = true; | 97 | public boolean enablePrev = true; |
95 | public boolean enableStop = true; | 98 | public boolean enableStop = true; |
96 | public boolean enablePlayPause = true; | 99 | public boolean enablePlayPause = true; |
@@ -100,6 +103,7 @@ public class RockboxWidgetConfigure extends Activity | |||
100 | static void saveWidgetPref(Context context, int appWidgetId, WidgetPref state) | 103 | static void saveWidgetPref(Context context, int appWidgetId, WidgetPref state) |
101 | { | 104 | { |
102 | SharedPreferences.Editor prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0).edit(); | 105 | SharedPreferences.Editor prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0).edit(); |
106 | prefs.putBoolean("albumart"+appWidgetId, state.enableAA); | ||
103 | prefs.putBoolean("prev"+appWidgetId, state.enablePrev); | 107 | prefs.putBoolean("prev"+appWidgetId, state.enablePrev); |
104 | prefs.putBoolean("stop"+appWidgetId, state.enableStop); | 108 | prefs.putBoolean("stop"+appWidgetId, state.enableStop); |
105 | prefs.putBoolean("playpause"+appWidgetId, state.enablePlayPause); | 109 | prefs.putBoolean("playpause"+appWidgetId, state.enablePlayPause); |
@@ -111,6 +115,7 @@ public class RockboxWidgetConfigure extends Activity | |||
111 | { | 115 | { |
112 | SharedPreferences prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0); | 116 | SharedPreferences prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0); |
113 | WidgetPref state = new WidgetPref(); | 117 | WidgetPref state = new WidgetPref(); |
118 | state.enableAA = prefs.getBoolean("albumart"+appWidgetId, true); | ||
114 | state.enablePrev = prefs.getBoolean("prev"+appWidgetId, true); | 119 | state.enablePrev = prefs.getBoolean("prev"+appWidgetId, true); |
115 | state.enableStop = prefs.getBoolean("stop"+appWidgetId, true); | 120 | state.enableStop = prefs.getBoolean("stop"+appWidgetId, true); |
116 | state.enablePlayPause = prefs.getBoolean("playpause"+appWidgetId, true); | 121 | state.enablePlayPause = prefs.getBoolean("playpause"+appWidgetId, true); |
diff --git a/android/src/org/rockbox/widgets/RockboxWidgetProvider.java b/android/src/org/rockbox/widgets/RockboxWidgetProvider.java index 867088f601..c6f3baf76c 100644 --- a/android/src/org/rockbox/widgets/RockboxWidgetProvider.java +++ b/android/src/org/rockbox/widgets/RockboxWidgetProvider.java | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | package org.rockbox.widgets; | 22 | package org.rockbox.widgets; |
23 | 23 | ||
24 | import java.io.File; | ||
24 | import org.rockbox.R; | 25 | import org.rockbox.R; |
25 | import org.rockbox.RockboxActivity; | 26 | import org.rockbox.RockboxActivity; |
26 | import org.rockbox.RockboxService; | 27 | import org.rockbox.RockboxService; |
@@ -108,6 +109,7 @@ public class RockboxWidgetProvider extends AppWidgetProvider | |||
108 | Intent intent = new Intent(context, RockboxActivity.class); | 109 | Intent intent = new Intent(context, RockboxActivity.class); |
109 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | 110 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); |
110 | views.setOnClickPendingIntent(R.id.infoDisplay, pendingIntent); | 111 | views.setOnClickPendingIntent(R.id.infoDisplay, pendingIntent); |
112 | views.setOnClickPendingIntent(R.id.logo, pendingIntent); | ||
111 | 113 | ||
112 | RockboxWidgetConfigure.WidgetPref state = RockboxWidgetConfigure.loadWidgetPref(context, appWidgetId); | 114 | RockboxWidgetConfigure.WidgetPref state = RockboxWidgetConfigure.loadWidgetPref(context, appWidgetId); |
113 | 115 | ||
@@ -151,6 +153,9 @@ public class RockboxWidgetProvider extends AppWidgetProvider | |||
151 | else | 153 | else |
152 | views.setViewVisibility(R.id.stop, View.GONE); | 154 | views.setViewVisibility(R.id.stop, View.GONE); |
153 | 155 | ||
156 | if (!state.enableAA) | ||
157 | views.setViewVisibility(R.id.logo, View.GONE); | ||
158 | |||
154 | if (args != null) | 159 | if (args != null) |
155 | { | 160 | { |
156 | if (args.getAction().equals("org.rockbox.TrackUpdateInfo")) | 161 | if (args.getAction().equals("org.rockbox.TrackUpdateInfo")) |
@@ -159,12 +164,18 @@ public class RockboxWidgetProvider extends AppWidgetProvider | |||
159 | CharSequence artist = args.getCharSequenceExtra("artist"); | 164 | CharSequence artist = args.getCharSequenceExtra("artist"); |
160 | CharSequence album = args.getCharSequenceExtra("album"); | 165 | CharSequence album = args.getCharSequenceExtra("album"); |
161 | views.setTextViewText(R.id.infoDisplay, title+"\n"+artist+"\n"+album); | 166 | views.setTextViewText(R.id.infoDisplay, title+"\n"+artist+"\n"+album); |
167 | CharSequence albumart = args.getCharSequenceExtra("albumart"); | ||
168 | if (albumart != null) | ||
169 | views.setImageViewUri(R.id.logo, Uri.fromFile(new File(albumart.toString()))); | ||
170 | else | ||
171 | views.setImageViewResource(R.id.logo, R.drawable.rockbox); | ||
162 | } | 172 | } |
163 | else if (args.getAction().equals("org.rockbox.TrackFinish")) | 173 | else if (args.getAction().equals("org.rockbox.TrackFinish")) |
164 | { | 174 | { |
165 | // FIXME: looks like this event is always fired earlier than | 175 | // FIXME: looks like this event is always fired earlier than |
166 | // the actual track change (a few seconds) | 176 | // the actual track change (a few seconds) |
167 | views.setTextViewText(R.id.infoDisplay, context.getString(R.string.appwidget_infoDisplay)); | 177 | views.setTextViewText(R.id.infoDisplay, context.getString(R.string.appwidget_infoDisplay)); |
178 | views.setImageViewResource(R.id.logo, R.drawable.rockbox); | ||
168 | } | 179 | } |
169 | else if (args.getAction().equals("org.rockbox.UpdateState")) | 180 | else if (args.getAction().equals("org.rockbox.UpdateState")) |
170 | { | 181 | { |
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c index 339c92acd3..bde91b039f 100644 --- a/apps/hosted/notification.c +++ b/apps/hosted/notification.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "notification.h" | 24 | #include "notification.h" |
25 | #include "appevents.h" | 25 | #include "appevents.h" |
26 | #include "metadata.h" | 26 | #include "metadata.h" |
27 | #include "albumart.h" | ||
27 | #include "misc.h" | 28 | #include "misc.h" |
28 | #include "debug.h" | 29 | #include "debug.h" |
29 | 30 | ||
@@ -33,8 +34,10 @@ extern jobject RockboxService_instance; | |||
33 | 34 | ||
34 | static jmethodID updateNotification, finishNotification; | 35 | static jmethodID updateNotification, finishNotification; |
35 | static jobject NotificationManager_instance; | 36 | static jobject NotificationManager_instance; |
36 | static jstring title, artist, album; | 37 | static jstring title, artist, album, albumart; |
37 | 38 | ||
39 | /* completely arbitrary dimensions. neded for find_albumart() */ | ||
40 | const struct dim dim = { .width = 200, .height = 200 }; | ||
38 | #define NZV(a) (a && a[0]) | 41 | #define NZV(a) (a && a[0]) |
39 | 42 | ||
40 | /* | 43 | /* |
@@ -49,6 +52,7 @@ static void track_changed_callback(void *param) | |||
49 | e->DeleteLocalRef(env_ptr, title); | 52 | e->DeleteLocalRef(env_ptr, title); |
50 | e->DeleteLocalRef(env_ptr, artist); | 53 | e->DeleteLocalRef(env_ptr, artist); |
51 | e->DeleteLocalRef(env_ptr, album); | 54 | e->DeleteLocalRef(env_ptr, album); |
55 | e->DeleteLocalRef(env_ptr, albumart); | ||
52 | 56 | ||
53 | char buf[200]; | 57 | char buf[200]; |
54 | const char * ptitle = id3->title; | 58 | const char * ptitle = id3->title; |
@@ -62,8 +66,12 @@ static void track_changed_callback(void *param) | |||
62 | artist = e->NewStringUTF(env_ptr, id3->artist ?: ""); | 66 | artist = e->NewStringUTF(env_ptr, id3->artist ?: ""); |
63 | album = e->NewStringUTF(env_ptr, id3->album ?: ""); | 67 | album = e->NewStringUTF(env_ptr, id3->album ?: ""); |
64 | 68 | ||
69 | albumart = NULL; | ||
70 | if (find_albumart(id3, buf, sizeof(buf), &dim)) | ||
71 | albumart = e->NewStringUTF(env_ptr, buf); | ||
72 | |||
65 | e->CallVoidMethod(env_ptr, NotificationManager_instance, | 73 | e->CallVoidMethod(env_ptr, NotificationManager_instance, |
66 | updateNotification, title, artist, album); | 74 | updateNotification, title, artist, album, albumart); |
67 | } | 75 | } |
68 | } | 76 | } |
69 | 77 | ||
@@ -94,6 +102,7 @@ void notification_init(void) | |||
94 | updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", | 102 | updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", |
95 | "(Ljava/lang/String;" | 103 | "(Ljava/lang/String;" |
96 | "Ljava/lang/String;" | 104 | "Ljava/lang/String;" |
105 | "Ljava/lang/String;" | ||
97 | "Ljava/lang/String;)V"); | 106 | "Ljava/lang/String;)V"); |
98 | finishNotification = e->GetMethodID(env_ptr, class, "finishNotification", | 107 | finishNotification = e->GetMethodID(env_ptr, class, "finishNotification", |
99 | "()V"); | 108 | "()V"); |