Set a foreground image instead of background image in the widget

This has proper scaling and can be set in RemoteViews. Curiously, it requires
that the transparent placeholder be the same size as the icon---the image size
doesn't seem to be updated when the drawable state changes
This commit is contained in:
Christopher Eby 2010-03-20 15:24:16 -05:00
parent 5fde2d3b82
commit cc953001b8
3 changed files with 7 additions and 26 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 122 B

View File

@ -12,21 +12,16 @@
android:layout_width="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/play"
android:background="@drawable/hidden_play"
android:id="@+id/play_pause"
android:src="@drawable/hidden_play"
android:background="#0000"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1" />
<ImageButton
android:id="@+id/pause"
android:background="@drawable/hidden_pause"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:visibility="gone" />
<ImageButton
android:id="@+id/next"
android:background="@drawable/hidden_next"
android:src="@drawable/hidden_next"
android:background="#0000"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1" />

View File

@ -25,7 +25,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;
public class OneCellWidget extends AppWidgetProvider {
@ -64,21 +63,8 @@ public class OneCellWidget extends AppWidgetProvider {
{
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.one_cell_widget);
int toggle;
// Unfortunately we have to have two views since we can not call
// setBackgroundResource from RemoteViews
if (playing) {
toggle = R.id.pause;
views.setViewVisibility(R.id.play, View.GONE);
views.setViewVisibility(R.id.pause, View.VISIBLE);
} else {
toggle = R.id.play;
views.setViewVisibility(R.id.pause, View.GONE);
views.setViewVisibility(R.id.play, View.VISIBLE);
}
views.setOnClickPendingIntent(toggle, PendingIntent.getBroadcast(context, 0, new Intent(PlaybackService.TOGGLE_PLAYBACK), 0));
views.setImageViewResource(R.id.play_pause, playing ? R.drawable.hidden_pause : R.drawable.hidden_play);
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getBroadcast(context, 0, new Intent(PlaybackService.TOGGLE_PLAYBACK), 0));
views.setOnClickPendingIntent(R.id.next, PendingIntent.getBroadcast(context, 0, new Intent(PlaybackService.NEXT_SONG), 0));
if (song == null) {