introduce MEDIUM cover size

Turns out that widget image views may run out of heap space if we use the large cover everywhere, oops.
Since having the full cover everywhere indeed doesn't make sense, we introduce a MEDIUM size for use in widgets and other remote views.
This commit is contained in:
Adrian Ulrich 2021-04-04 14:32:01 +02:00
parent 68f1337cc1
commit 8c6a4cd4c7
12 changed files with 26 additions and 12 deletions

View File

@ -24,7 +24,7 @@ THE SOFTWARE.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.blinkenlights.android.vanilla"
android:versionName="1.0.92"
android:versionCode="10921"
android:versionCode="10922"
android:installLocation="auto">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

View File

@ -53,7 +53,11 @@ public class CoverCache {
*/
public final static int SIZE_SMALL = (int)(44 * METRICS.density);
/**
* Returned size of large (cover view) album covers
* Cover to use in remote views with a medium size.
*/
public final static int SIZE_MEDIUM = (int)(240 * METRICS.density);
/**
* Cover to use in the highest quality possible (full cover view).
*/
public final static int SIZE_LARGE = (METRICS.heightPixels > METRICS.widthPixels ? METRICS.widthPixels : METRICS.heightPixels);
/**

View File

@ -227,7 +227,7 @@ public final class CoverView extends View implements Handler.Callback {
*/
private Bitmap generateBitmap(Song song) {
int style = mCoverStyle;
Bitmap cover = song == null ? null : song.getCover(mContext);
Bitmap cover = song == null ? null : song.getLargeCover(mContext);
if (cover == null && style != CoverBitmap.STYLE_OVERLAPPING_BOX) {
cover = CoverBitmap.generateDefaultCover(mContext, getWidth(), getHeight());

View File

@ -111,7 +111,7 @@ public class FourLongWidget extends AppWidgetProvider {
views.setTextViewText(R.id.title, song.title);
views.setTextViewText(R.id.artist, song.artist);
views.setTextViewText(R.id.album, song.album);
Bitmap cover = song.getCover(context);
Bitmap cover = song.getMediumCover(context);
if (cover == null) {
views.setImageViewResource(R.id.cover, R.drawable.fallback_cover_large);
} else {

View File

@ -109,7 +109,7 @@ public class FourSquareWidget extends AppWidgetProvider {
views.setViewVisibility(R.id.buttons, View.VISIBLE);
views.setTextViewText(R.id.title, song.title);
views.setTextViewText(R.id.artist, song.artist);
cover = song.getCover(context);
cover = song.getMediumCover(context);
playResource = playing ? R.drawable.hidden_pause : R.drawable.hidden_play;
nextResource = R.drawable.hidden_next;
}

View File

@ -114,7 +114,7 @@ public class FourWhiteWidget extends AppWidgetProvider {
views.setViewVisibility(R.id.title, View.VISIBLE);
views.setTextViewText(R.id.title, song.title);
views.setTextViewText(R.id.artist, song.artist);
Bitmap cover = song.getCover(context);
Bitmap cover = song.getMediumCover(context);
if (cover == null) {
views.setViewVisibility(R.id.cover, View.INVISIBLE);
} else {

View File

@ -114,7 +114,7 @@ public class MediaSessionTracker {
.build();
if (song != null) {
final Bitmap cover = song.getCover(mContext);
final Bitmap cover = song.getMediumCover(mContext);
MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artist)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.album)

View File

@ -118,7 +118,7 @@ public class OneCellWidget extends AppWidgetProvider {
views.setInt(R.id.title, "setText", R.string.app_name);
} else {
views.setTextViewText(R.id.title, song.title);
cover = song.getCover(context);
cover = song.getMediumCover(context);
}
if (cover == null) {

View File

@ -2119,7 +2119,7 @@ public final class PlaybackService extends Service
public Notification createNotification(Song song, int state, int mode)
{
final boolean playing = (state & FLAG_PLAYING) != 0;
final Bitmap cover = song.getCover(this);
final Bitmap cover = song.getMediumCover(this);
ComponentName service = new ComponentName(this, PlaybackService.class);

View File

@ -138,7 +138,7 @@ public class RemoteControlImplICS implements RemoteControl.Client {
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, artist_album);
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.title);
Bitmap bitmap = song.getCover(mContext);
Bitmap bitmap = song.getMediumCover(mContext);
if (bitmap != null && mShowCover == 1 && (isPlaying || keepPaused)) {
// Create a copy of the cover art, since RemoteControlClient likes
// to recycle what we give it.

View File

@ -232,10 +232,20 @@ public class Song implements Comparable<Song> {
* @param context A context to use.
* @return The album art or null if no album art could be found
*/
public Bitmap getCover(Context context) {
public Bitmap getLargeCover(Context context) {
return getCoverInternal(context, CoverCache.SIZE_LARGE);
}
/**
* Query the medium album art for this song.
*
* @param context A context to use.
* @return The album art or null if no album art could be found
*/
public Bitmap getMediumCover(Context context) {
return getCoverInternal(context, CoverCache.SIZE_MEDIUM);
}
/**
* Query the small album art for this song.
*

View File

@ -105,7 +105,7 @@ public class WidgetD extends AppWidgetProvider {
views.setViewVisibility(R.id.buttons, View.VISIBLE);
views.setTextViewText(R.id.title, song.title);
views.setTextViewText(R.id.artist, song.artist);
cover = song.getCover(context);
cover = song.getMediumCover(context);
}
if (cover == null) {