Clean ups and fixed a NPE in the widget.
This commit is contained in:
parent
df98c07592
commit
a238d6564e
2 changed files with 24 additions and 10 deletions
|
|
@ -67,15 +67,27 @@ public class MusicPlayerWidget extends AppWidgetProvider {
|
||||||
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||||
if (currentAlbumArtUri.equals(imageUri))
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
// copy() prevents the original bitmap in the memory cache from being recycled by the remote views
|
if (loadedImage != null) {
|
||||||
setAlbumArt(context, loadedImage.copy(loadedImage.getConfig(), true));
|
// 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
|
@Override
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
if (currentAlbumArtUri.equals(imageUri))
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
setAlbumArt(context, null);
|
setAlbumArt(context, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -417,24 +417,26 @@ public class MusicService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||||
if (currentAlbumArtUri.equals(imageUri)) {
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
Bitmap albumArt = loadedImage;
|
if (loadedImage != null) {
|
||||||
if (albumArt != null) {
|
|
||||||
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
||||||
// to make sure not to hand out our cache copy
|
// to make sure not to hand out our cache copy
|
||||||
Bitmap.Config config = albumArt.getConfig();
|
Bitmap.Config config = loadedImage.getConfig();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
config = Bitmap.Config.ARGB_8888;
|
config = Bitmap.Config.ARGB_8888;
|
||||||
}
|
}
|
||||||
albumArt = albumArt.copy(config, false);
|
loadedImage = loadedImage.copy(config, false);
|
||||||
updateRemoteControlClientBitmap(albumArt.copy(albumArt.getConfig(), true));
|
updateRemoteControlClientBitmap(loadedImage.copy(loadedImage.getConfig(), true));
|
||||||
|
} else {
|
||||||
|
updateRemoteControlClientBitmap(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
if (currentAlbumArtUri.equals(imageUri))
|
if (currentAlbumArtUri.equals(imageUri)) {
|
||||||
updateRemoteControlClientBitmap(null);
|
updateRemoteControlClientBitmap(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue