Fix widget

This commit is contained in:
Joshua Bahnsen 2013-02-22 19:59:40 -07:00
parent 4c7c0ebf90
commit 8d4bf5d4b0
3 changed files with 141 additions and 141 deletions

View File

@ -1,99 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:orientation="horizontal"
a:background="@drawable/appwidget_bg">
<ImageView
a:id="@+id/appwidget_coverart"
a:layout_height="fill_parent"
a:layout_width="81dip"
a:scaleType="fitXY"
a:src="@drawable/appwidget_art_default"
a:clickable="true"
a:focusable="true"
a:background="@drawable/list_selector_holo_dark"/>
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:background="@drawable/appwidget_bg"
a:orientation="horizontal" >
<LinearLayout
a:id="@+id/linearLayout1"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical" >
<LinearLayout
a:id="@+id/appwidget_top"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
<ImageView
a:id="@+id/appwidget_coverart"
a:layout_width="81dip"
a:layout_height="fill_parent"
a:background="@drawable/list_selector_holo_dark"
a:clickable="true"
a:focusable="true"
a:orientation="vertical" >
<TextView
a:id="@+id/title"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="20dip"
a:minHeight="16sp"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="16sp"
a:textStyle="bold" />
<TextView
a:id="@+id/artist"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="10dip"
a:minHeight="12sp"
a:paddingBottom="2dip"
a:paddingLeft="5dip"
a:singleLine="true"
a:textColor="@color/cyan"
a:textSize="12sp" />
</LinearLayout>
a:scaleType="fitXY"
a:src="@drawable/appwidget_art_default" />
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:layout_marginTop="3dp"
a:orientation="horizontal" >
a:id="@+id/linearLayout1"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical" >
<ImageButton
a:id="@+id/control_previous"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
<LinearLayout
a:id="@+id/appwidget_top"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_previous" />
a:clickable="true"
a:focusable="true"
a:orientation="vertical" >
<ImageButton
a:id="@+id/control_play"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_play" />
<TextView
a:id="@+id/title"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="20dip"
a:minHeight="16sp"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="16sp"
a:textStyle="bold" />
<ImageButton
a:id="@+id/control_next"
a:layout_width="0dip"
<TextView
a:id="@+id/artist"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="10dip"
a:minHeight="12sp"
a:paddingBottom="2dip"
a:paddingLeft="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="12sp" />
</LinearLayout>
<LinearLayout
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_next" />
a:layout_marginTop="3dp"
a:orientation="horizontal" >
<ImageButton
a:id="@+id/control_previous"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_previous" />
<ImageButton
a:id="@+id/control_play"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_play" />
<ImageButton
a:id="@+id/control_next"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_next" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -44,6 +44,7 @@ import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
import net.sourceforge.subsonic.androidapp.domain.PlayerState;
import net.sourceforge.subsonic.androidapp.domain.RepeatMode;
import net.sourceforge.subsonic.androidapp.provider.SubsonicAppWidgetProvider4x1;
import net.sourceforge.subsonic.androidapp.receiver.MediaButtonIntentReceiver;
import net.sourceforge.subsonic.androidapp.util.CancellableTask;
import net.sourceforge.subsonic.androidapp.util.LRUCache;
@ -435,7 +436,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
setRemoteControl();
if (Util.isNotificationEnabled(this) && currentPlaying != null && showNotification) {
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED);
if (currentPlaying != null && showNotification) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else {
Util.hidePlayingNotification(this, this, handler);
@ -684,15 +688,14 @@ public class DownloadServiceImpl extends Service implements DownloadService {
setRemoteControl();
if (Util.isNotificationEnabled(this)) {
if (show) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else if (hide) {
Util.hidePlayingNotification(this, this, handler);
}
} else {
Util.hidePlayingNotification(this, this, handler);
}
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED);
if (show) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else if (hide) {
Util.hidePlayingNotification(this, this, handler);
}
if (playerState == STARTED) {
scrobbler.scrobble(this, currentPlaying, false);

View File

@ -592,52 +592,53 @@ public class Util extends DownloadActivity {
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song, final Notification notification, PlayerState playerState) {
if (currentSong != song) {
currentSong = song;
// Use the same text for the ticker and the expanded notification
String title = song.getTitle();
String text = song.getArtist();
String album = song.getAlbum();
// Set the album art.
try {
int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
if (bitmap == null) {
// set default album art
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
} else {
notification.contentView.setImageViewBitmap(R.id.notification_image, bitmap);
}
} catch (Exception x) {
Log.w(TAG, "Failed to get notification cover art", x);
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
}
if (Util.isNotificationEnabled(context)) {
if (currentSong != song) {
currentSong = song;
// set the text for the notifications
notification.contentView.setTextViewText(R.id.trackname, title);
notification.contentView.setTextViewText(R.id.artist, text);
notification.contentView.setTextViewText(R.id.album, album);
}
if (playerState == PlayerState.PAUSED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
}
else if (playerState == PlayerState.STARTED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause);
// Use the same text for the ticker and the expanded
// notification
String title = song.getTitle();
String text = song.getArtist();
String album = song.getAlbum();
// Set the album art.
try {
int size = context.getResources()
.getDrawable(R.drawable.unknown_album)
.getIntrinsicHeight();
Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
if (bitmap == null) {
// set default album art
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
} else {
notification.contentView.setImageViewBitmap(R.id.notification_image, bitmap);
}
} catch (Exception x) {
Log.w(TAG, "Failed to get notification cover art", x);
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
}
// set the text for the notifications
notification.contentView.setTextViewText(R.id.trackname, title);
notification.contentView.setTextViewText(R.id.artist, text);
notification.contentView.setTextViewText(R.id.album, album);
}
if (playerState == PlayerState.PAUSED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
} else if (playerState == PlayerState.STARTED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause);
}
// Send the notification and put the service in the foreground.
handler.post(new Runnable() {
@Override
public void run() {
startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
}
});
}
// Send the notification and put the service in the foreground.
handler.post(new Runnable() {
@Override
public void run() {
startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
}
});
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, true);
}
public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
@ -651,9 +652,6 @@ public class Util extends DownloadActivity {
stopForeground(downloadService, true);
}
});
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, false);
}
public static void sleepQuietly(long millis) {