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
This commit is contained in:
Thomas Martitz 2011-02-27 20:47:44 +00:00
parent 952d82b7bd
commit 883ff8507e
9 changed files with 49 additions and 9 deletions

View file

@ -8,10 +8,12 @@
android:background="@drawable/appwidget_background">
<!-- style="@style/appwidget_background"-->
<ImageView android:id="@+id/logo"
<ImageButton android:id="@+id/logo"
android:layout_marginTop="5dp"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_height="80dp"
android:scaleType="centerInside"
android:background="@drawable/appwidget_infodisplay_background"
android:src="@drawable/rockbox" />
<Button android:id="@+id/infoDisplay"
style="@style/appwidget_infodisplay"

View file

@ -8,10 +8,12 @@
android:background="@drawable/appwidget_background">
<!-- style="@style/appwidget_background"-->
<ImageView android:id="@+id/logo"
<ImageButton android:id="@+id/logo"
android:layout_marginTop="15dp"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_height="130dp"
android:scaleType="centerInside"
android:background="@drawable/appwidget_infodisplay_background"
android:src="@drawable/rockbox" />
<Button android:id="@+id/infoDisplay"
style="@style/appwidget_infodisplay"

View file

@ -8,6 +8,12 @@
android:background="@drawable/appwidget_background">
<!-- style="@style/appwidget_background"-->
<ImageButton android:id="@+id/logo"
android:layout_width="68dp"
android:layout_height="fill_parent"
android:scaleType="centerInside"
android:background="@drawable/appwidget_infodisplay_background"
android:src="@drawable/rockbox" />
<Button android:id="@+id/infoDisplay"
style="@style/appwidget_infodisplay"
android:layout_height="fill_parent"

View file

@ -15,6 +15,10 @@
android:layout_height="wrap_content"
android:text="@string/appwidget_configure_instructions"/>
<CheckBox android:id="@+id/enable_aa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/appwidget_configure_albumart"/>
<CheckBox android:id="@+id/enable_prev"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View file

@ -19,6 +19,7 @@
<!-- Widget configuration -->
<string name="appwidget_configure_instructions">Please chose elements to display in widget.</string>
<string name="appwidget_configure_albumart">Cover Art</string>
<string name="appwidget_configure_prev">Prev Button</string>
<string name="appwidget_configure_stop">Stop Button</string>
<string name="appwidget_configure_playpause">Play/Pause Button</string>

View file

@ -11,7 +11,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
@ -83,7 +82,7 @@ public class RunForegroundManager
api.stopForeground();
}
public void updateNotification(String title, String artist, String album)
public void updateNotification(String title, String artist, String album, String albumart)
{
RemoteViews views = mNotification.contentView;
views.setTextViewText(R.id.title, title);
@ -98,6 +97,7 @@ public class RunForegroundManager
widgetUpdate.putExtra("title", title);
widgetUpdate.putExtra("artist", artist);
widgetUpdate.putExtra("album", album);
widgetUpdate.putExtra("albumart", albumart);
mCurrentService.sendBroadcast(widgetUpdate);
}

View file

@ -50,6 +50,7 @@ public class RockboxWidgetConfigure extends Activity
setResult(RESULT_CANCELED);
setContentView(R.layout.appwidget_configure);
((CheckBox)findViewById(R.id.enable_aa)).setChecked(true);
((CheckBox)findViewById(R.id.enable_prev)).setChecked(false);
((CheckBox)findViewById(R.id.enable_stop)).setChecked(true);
((CheckBox)findViewById(R.id.enable_playpause)).setChecked(true);
@ -73,6 +74,7 @@ public class RockboxWidgetConfigure extends Activity
final Context context = RockboxWidgetConfigure.this;
WidgetPref state = new WidgetPref();
state.enableAA = ((CheckBox)findViewById(R.id.enable_aa)).isChecked();
state.enablePrev = ((CheckBox)findViewById(R.id.enable_prev)).isChecked();
state.enableStop = ((CheckBox)findViewById(R.id.enable_stop)).isChecked();
state.enablePlayPause = ((CheckBox)findViewById(R.id.enable_playpause)).isChecked();
@ -91,6 +93,7 @@ public class RockboxWidgetConfigure extends Activity
static public class WidgetPref
{
public boolean enableAA = true;
public boolean enablePrev = true;
public boolean enableStop = true;
public boolean enablePlayPause = true;
@ -100,6 +103,7 @@ public class RockboxWidgetConfigure extends Activity
static void saveWidgetPref(Context context, int appWidgetId, WidgetPref state)
{
SharedPreferences.Editor prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0).edit();
prefs.putBoolean("albumart"+appWidgetId, state.enableAA);
prefs.putBoolean("prev"+appWidgetId, state.enablePrev);
prefs.putBoolean("stop"+appWidgetId, state.enableStop);
prefs.putBoolean("playpause"+appWidgetId, state.enablePlayPause);
@ -111,6 +115,7 @@ public class RockboxWidgetConfigure extends Activity
{
SharedPreferences prefs = context.getSharedPreferences("org.rockbox.RockboxWidgetConfigure", 0);
WidgetPref state = new WidgetPref();
state.enableAA = prefs.getBoolean("albumart"+appWidgetId, true);
state.enablePrev = prefs.getBoolean("prev"+appWidgetId, true);
state.enableStop = prefs.getBoolean("stop"+appWidgetId, true);
state.enablePlayPause = prefs.getBoolean("playpause"+appWidgetId, true);

View file

@ -21,6 +21,7 @@
package org.rockbox.widgets;
import java.io.File;
import org.rockbox.R;
import org.rockbox.RockboxActivity;
import org.rockbox.RockboxService;
@ -108,6 +109,7 @@ public class RockboxWidgetProvider extends AppWidgetProvider
Intent intent = new Intent(context, RockboxActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.infoDisplay, pendingIntent);
views.setOnClickPendingIntent(R.id.logo, pendingIntent);
RockboxWidgetConfigure.WidgetPref state = RockboxWidgetConfigure.loadWidgetPref(context, appWidgetId);
@ -151,6 +153,9 @@ public class RockboxWidgetProvider extends AppWidgetProvider
else
views.setViewVisibility(R.id.stop, View.GONE);
if (!state.enableAA)
views.setViewVisibility(R.id.logo, View.GONE);
if (args != null)
{
if (args.getAction().equals("org.rockbox.TrackUpdateInfo"))
@ -159,12 +164,18 @@ public class RockboxWidgetProvider extends AppWidgetProvider
CharSequence artist = args.getCharSequenceExtra("artist");
CharSequence album = args.getCharSequenceExtra("album");
views.setTextViewText(R.id.infoDisplay, title+"\n"+artist+"\n"+album);
CharSequence albumart = args.getCharSequenceExtra("albumart");
if (albumart != null)
views.setImageViewUri(R.id.logo, Uri.fromFile(new File(albumart.toString())));
else
views.setImageViewResource(R.id.logo, R.drawable.rockbox);
}
else if (args.getAction().equals("org.rockbox.TrackFinish"))
{
// FIXME: looks like this event is always fired earlier than
// the actual track change (a few seconds)
views.setTextViewText(R.id.infoDisplay, context.getString(R.string.appwidget_infoDisplay));
views.setImageViewResource(R.id.logo, R.drawable.rockbox);
}
else if (args.getAction().equals("org.rockbox.UpdateState"))
{

View file

@ -24,6 +24,7 @@
#include "notification.h"
#include "appevents.h"
#include "metadata.h"
#include "albumart.h"
#include "misc.h"
#include "debug.h"
@ -33,8 +34,10 @@ extern jobject RockboxService_instance;
static jmethodID updateNotification, finishNotification;
static jobject NotificationManager_instance;
static jstring title, artist, album;
static jstring title, artist, album, albumart;
/* completely arbitrary dimensions. neded for find_albumart() */
const struct dim dim = { .width = 200, .height = 200 };
#define NZV(a) (a && a[0])
/*
@ -49,6 +52,7 @@ static void track_changed_callback(void *param)
e->DeleteLocalRef(env_ptr, title);
e->DeleteLocalRef(env_ptr, artist);
e->DeleteLocalRef(env_ptr, album);
e->DeleteLocalRef(env_ptr, albumart);
char buf[200];
const char * ptitle = id3->title;
@ -62,8 +66,12 @@ static void track_changed_callback(void *param)
artist = e->NewStringUTF(env_ptr, id3->artist ?: "");
album = e->NewStringUTF(env_ptr, id3->album ?: "");
albumart = NULL;
if (find_albumart(id3, buf, sizeof(buf), &dim))
albumart = e->NewStringUTF(env_ptr, buf);
e->CallVoidMethod(env_ptr, NotificationManager_instance,
updateNotification, title, artist, album);
updateNotification, title, artist, album, albumart);
}
}
@ -94,6 +102,7 @@ void notification_init(void)
updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",
"(Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;)V");
finishNotification = e->GetMethodID(env_ptr, class, "finishNotification",
"()V");