Clean ups and fixed a NPE in the widget.

This commit is contained in:
Karim Abou Zeid 2015-07-05 15:22:30 +02:00
commit a238d6564e
2 changed files with 24 additions and 10 deletions

View file

@ -67,15 +67,27 @@ public class MusicPlayerWidget extends AppWidgetProvider {
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (currentAlbumArtUri.equals(imageUri))
// copy() prevents the original bitmap in the memory cache from being recycled by the remote views
setAlbumArt(context, loadedImage.copy(loadedImage.getConfig(), true));
if (currentAlbumArtUri.equals(imageUri)) {
if (loadedImage != null) {
// The RemoteViews might wants to recycle the bitmaps thrown at it, so we need
// to make sure not to hand out our cache copy
Bitmap.Config config = loadedImage.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}
loadedImage = loadedImage.copy(config, false);
setAlbumArt(context, loadedImage.copy(loadedImage.getConfig(), true));
} else {
setAlbumArt(context, null);
}
}
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
if (currentAlbumArtUri.equals(imageUri))
if (currentAlbumArtUri.equals(imageUri)) {
setAlbumArt(context, null);
}
}
});
}

View file

@ -417,24 +417,26 @@ public class MusicService extends Service {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (currentAlbumArtUri.equals(imageUri)) {
Bitmap albumArt = loadedImage;
if (albumArt != null) {
if (loadedImage != null) {
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
// to make sure not to hand out our cache copy
Bitmap.Config config = albumArt.getConfig();
Bitmap.Config config = loadedImage.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}
albumArt = albumArt.copy(config, false);
updateRemoteControlClientBitmap(albumArt.copy(albumArt.getConfig(), true));
loadedImage = loadedImage.copy(config, false);
updateRemoteControlClientBitmap(loadedImage.copy(loadedImage.getConfig(), true));
} else {
updateRemoteControlClientBitmap(null);
}
}
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
if (currentAlbumArtUri.equals(imageUri))
if (currentAlbumArtUri.equals(imageUri)) {
updateRemoteControlClientBitmap(null);
}
}
});
} else {