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
This commit is contained in:
Dominik Riebeling 2011-10-01 20:07:57 +00:00
parent 4f56b50df4
commit ed15d53919
2 changed files with 40 additions and 8 deletions

View File

@ -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"

View File

@ -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");