Update widget play/pause icon according to state
This commit is contained in:
parent
18f1f7b8a7
commit
32ce1f7120
10
res/drawable/hidden_play.xml
Normal file
10
res/drawable/hidden_play.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_pressed="true"
|
||||
android:drawable="@drawable/play" />
|
||||
<item
|
||||
android:state_focused="true"
|
||||
android:drawable="@drawable/play" />
|
||||
<item android:drawable="@drawable/empty" />
|
||||
</selector>
|
@ -12,11 +12,18 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
<ImageButton
|
||||
android:id="@+id/play_pause"
|
||||
android:background="@drawable/hidden_play_pause"
|
||||
android:id="@+id/play"
|
||||
android:background="@drawable/hidden_play"
|
||||
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"
|
||||
|
@ -25,6 +25,7 @@ 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 {
|
||||
@ -63,7 +64,21 @@ public class OneCellWidget extends AppWidgetProvider {
|
||||
{
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.one_cell_widget);
|
||||
|
||||
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getBroadcast(context, 0, new Intent(PlaybackService.TOGGLE_PLAYBACK), 0));
|
||||
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.setOnClickPendingIntent(R.id.next, PendingIntent.getBroadcast(context, 0, new Intent(PlaybackService.NEXT_SONG), 0));
|
||||
|
||||
if (song == null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user