use custom target for palette images with glide
This commit is contained in:
parent
8eb4f515e3
commit
b8a6241160
6 changed files with 69 additions and 30 deletions
|
|
@ -33,7 +33,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.glide.BlurTransformation;
|
||||
|
|
@ -46,7 +46,6 @@ import com.dkanada.gramophone.service.notification.PlayingNotification;
|
|||
import com.dkanada.gramophone.service.notification.PlayingNotificationImpl;
|
||||
import com.dkanada.gramophone.service.notification.PlayingNotificationImpl24;
|
||||
import com.dkanada.gramophone.service.playback.Playback;
|
||||
import com.dkanada.gramophone.util.MusicUtil;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.dkanada.gramophone.util.Util;
|
||||
import com.dkanada.gramophone.widgets.AppWidgetAlbum;
|
||||
|
|
@ -551,18 +550,24 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
request.into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {
|
||||
request.into(new CustomTarget<Bitmap>(screenSize.x, screenSize.y) {
|
||||
@Override
|
||||
public void onLoadFailed(Drawable errorDrawable) {
|
||||
super.onLoadFailed(errorDrawable);
|
||||
public void onLoadFailed(Drawable drawable) {
|
||||
super.onLoadFailed(drawable);
|
||||
mediaSession.setMetadata(metaData.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> glideAnimation) {
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> glideAnimation) {
|
||||
metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, copy(resource));
|
||||
mediaSession.setMetadata(metaData.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(Drawable drawable) {
|
||||
super.onLoadFailed(drawable);
|
||||
mediaSession.setMetadata(metaData.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ import android.text.TextUtils;
|
|||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.kabouzeid.appthemehelper.util.ColorUtil;
|
||||
|
|
@ -93,15 +94,21 @@ public class PlayingNotificationImpl extends PlayingNotification {
|
|||
target = CustomGlideRequest.Builder
|
||||
.from(service, song.primary, song.blurHash)
|
||||
.palette().build()
|
||||
.into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
.into(new CustomTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, Transition<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
public void onResourceReady(@NonNull BitmapPaletteWrapper resource, Transition<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
update(resource.getBitmap(), ThemeUtil.getColor(resource.getPalette(), Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Drawable errorDrawable) {
|
||||
super.onLoadFailed(errorDrawable);
|
||||
public void onLoadFailed(Drawable drawable) {
|
||||
super.onLoadFailed(drawable);
|
||||
update(null, Color.WHITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(Drawable drawable) {
|
||||
super.onLoadFailed(drawable);
|
||||
update(null, Color.WHITE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ import android.graphics.Color;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.media.app.NotificationCompat.MediaStyle;
|
||||
import androidx.palette.graphics.Palette;
|
||||
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.glide.CustomGlideRequest;
|
||||
|
|
@ -53,15 +54,20 @@ public class PlayingNotificationImpl24 extends PlayingNotification {
|
|||
service.runOnUiThread(() -> CustomGlideRequest.Builder
|
||||
.from(service, song.primary, song.blurHash)
|
||||
.palette().build()
|
||||
.into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
.into(new CustomTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, Transition<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
public void onResourceReady(@NonNull BitmapPaletteWrapper resource, Transition<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
Palette palette = resource.getPalette();
|
||||
update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(Color.TRANSPARENT)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Drawable errorDrawable) {
|
||||
public void onLoadFailed(Drawable drawable) {
|
||||
update(null, Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(Drawable drawable) {
|
||||
update(null, Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue