summaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-10-01 20:07:57 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-10-01 20:07:57 +0000
commited15d53919fc6b9d7945230611f48b25f21caad3 (patch)
treedd534ada16dabc157ecc87dca09f1347b6e17811 /android
parent4f56b50df45cf81370c3a29bd443b91cf5fca1b0 (diff)
downloadrockbox-ed15d53919fc6b9d7945230611f48b25f21caad3.tar.gz
rockbox-ed15d53919fc6b9d7945230611f48b25f21caad3.tar.bz2
rockbox-ed15d53919fc6b9d7945230611f48b25f21caad3.zip
Android: show Album Art in notification area.
Instead of showing the small Rockbox clef logo show the Album Art if available. If no Album Art is available show the clef logo about the same size as the Album Art. - The notification area process doesn't have permissions to access the SD card. Therefore the image needs to be read and set as Bitmap instead of simply setting the Uri to it as done in the widget. - Passing a full sized image to the Notification Manager can cause issues (Rockbox UI hanging, notification not updating anymore, force closes). Scale down the image to the same size the launcher icon has to avoid this. This also makes the logo shown when no Album Art is available have the same size which looks nicer than having different sizes. Album Art images are allowed to be wider since there is enough room. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30629 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android')
-rw-r--r--android/res/layout/statusbar.xml17
-rw-r--r--android/src/org/rockbox/Helper/RunForegroundManager.java31
2 files changed, 40 insertions, 8 deletions
diff --git a/android/res/layout/statusbar.xml b/android/res/layout/statusbar.xml
index c795008225..cf49264eba 100644
--- a/android/res/layout/statusbar.xml
+++ b/android/res/layout/statusbar.xml
@@ -8,19 +8,20 @@
android:paddingBottom="0dp"
android:orientation="horizontal">
+ <ImageView android:id="@+id/artwork"
+ android:gravity="center"
+ android:padding="2dp"
+ android:scaleType="center"
+ android:adjustViewBounds="false"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent">
+ </ImageView>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
-
- <ImageView android:src="@drawable/notification_small"
- android:gravity="center"
- android:paddingTop="2dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </ImageView>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
@@ -38,7 +39,7 @@
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
- android:orientation="vertical">
+ android:orientation="horizontal">
<TextView android:id="@+id/content"
android:layout_gravity="left"
android:scrollHorizontally="true"
diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java
index fbb6040005..5384e1b595 100644
--- a/android/src/org/rockbox/Helper/RunForegroundManager.java
+++ b/android/src/org/rockbox/Helper/RunForegroundManager.java
@@ -8,6 +8,10 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.Drawable;
import android.widget.RemoteViews;
public class RunForegroundManager
@@ -20,6 +24,7 @@ public class RunForegroundManager
private IRunForeground api;
private Service mCurrentService;
private Intent mWidgetUpdate;
+ private int iconheight;
public RunForegroundManager(Service service)
{
@@ -31,6 +36,11 @@ public class RunForegroundManager
Intent intent = new Intent(service, RockboxActivity.class);
intent = intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ /* retrieve height of launcher icon. Used to scale down album art. */
+ Resources resources = service.getResources();
+ Drawable draw = resources.getDrawable(R.drawable.launcher);
+ iconheight = draw.getIntrinsicHeight();
+
mNotification = new Notification();
mNotification.tickerText = service.getString(R.string.notification);
mNotification.icon = R.drawable.notification;
@@ -87,6 +97,27 @@ public class RunForegroundManager
mNotification.tickerText = title;
else
mNotification.tickerText = title+" - "+artist;
+
+ if (albumart != null) {
+ /* The notification area doesn't have permissions to access the SD card.
+ * Push the data as Bitmap instead of Uri. Scale down to size of
+ * launcher icon -- broadcasting the unscaled image may yield in
+ * too much data, causing UI hangs of Rockbox. */
+ Bitmap b = BitmapFactory.decodeFile(albumart);
+ if(b != null) {
+ /* scale width to keep aspect ratio -- height is the constraint */
+ int scaledwidth = Math.round(iconheight*((float)b.getWidth()/b.getHeight()));
+ views.setImageViewBitmap(R.id.artwork,
+ Bitmap.createScaledBitmap(b, scaledwidth, iconheight, false));
+ }
+ else {
+ views.setImageViewResource(R.id.artwork, R.drawable.launcher);
+ }
+ }
+ else {
+ views.setImageViewResource(R.id.artwork, R.drawable.launcher);
+ }
+
mNM.notify(R.string.notification, mNotification);
mWidgetUpdate = new Intent("org.rockbox.TrackUpdateInfo");