More progress switching to glide.
This commit is contained in:
parent
26cf5d8e0f
commit
0146676dbc
10 changed files with 328 additions and 145 deletions
|
|
@ -12,7 +12,7 @@ import android.widget.ImageView;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.misc.CustomFragmentStatePagerAdapter;
|
||||
|
|
@ -134,7 +134,7 @@ public class AlbumCoverPagerAdapter extends CustomFragmentStatePagerAdapter {
|
|||
.transcode(new BitmapPaletteTranscoder(getActivity()), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredTarget(albumCover) {
|
||||
.into(new PhonographColoredImageViewTarget(albumCover) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
setColor(color);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import com.kabouzeid.gramophone.adapter.base.AbsMultiSelectAdapter;
|
|||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -133,7 +133,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
.into(new PhonographColoredImageViewTarget(holder.image) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
if (usePalette)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import com.kabouzeid.gramophone.adapter.base.AbsMultiSelectAdapter;
|
|||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -128,7 +128,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
.into(new PhonographColoredImageViewTarget(holder.image) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
if (usePalette)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,148 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
|
||||
import com.kabouzeid.gramophone.BuildConfig;
|
||||
import com.kabouzeid.gramophone.helper.StackBlur;
|
||||
import com.kabouzeid.gramophone.util.ImageUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class BlurTransformation extends BitmapTransformation {
|
||||
public static final float DEFAULT_BLUR_RADIUS = 5f;
|
||||
|
||||
private Context context;
|
||||
private float blurRadius;
|
||||
private int sampling;
|
||||
|
||||
private void init(Builder builder) {
|
||||
this.context = builder.context;
|
||||
this.blurRadius = builder.blurRadius;
|
||||
this.sampling = builder.sampling;
|
||||
}
|
||||
|
||||
private BlurTransformation(Builder builder) {
|
||||
super(builder.context);
|
||||
init(builder);
|
||||
}
|
||||
|
||||
private BlurTransformation(Builder builder, BitmapPool bitmapPool) {
|
||||
super(bitmapPool);
|
||||
init(builder);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Context context;
|
||||
private BitmapPool bitmapPool;
|
||||
private float blurRadius = DEFAULT_BLUR_RADIUS;
|
||||
private int sampling;
|
||||
|
||||
public Builder(@NonNull Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blurRadius The radius to use. Must be between 0 and 25. Default is 5.
|
||||
* @return the same Builder
|
||||
*/
|
||||
public Builder blurRadius(@FloatRange(from = 0.0f, to = 25.0f) float blurRadius) {
|
||||
this.blurRadius = blurRadius;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sampling The inSampleSize to use. Must be a power of 2, or 1 for no down sampling or 0 for auto detect sampling. Default is 0.
|
||||
* @return the same Builder
|
||||
*/
|
||||
public Builder sampling(int sampling) {
|
||||
this.sampling = sampling;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bitmapPool The BitmapPool to use.
|
||||
* @return the same Builder
|
||||
*/
|
||||
public Builder bitmapPool(BitmapPool bitmapPool) {
|
||||
this.bitmapPool = bitmapPool;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlurTransformation build() {
|
||||
if (bitmapPool != null) {
|
||||
return new BlurTransformation(this, bitmapPool);
|
||||
}
|
||||
return new BlurTransformation(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
|
||||
int sampling;
|
||||
if (this.sampling == 0) {
|
||||
sampling = ImageUtil.calculateInSampleSize(toTransform.getWidth(), toTransform.getHeight(), 100);
|
||||
} else {
|
||||
sampling = this.sampling;
|
||||
}
|
||||
|
||||
int width = toTransform.getWidth();
|
||||
int height = toTransform.getHeight();
|
||||
int scaledWidth = width / sampling;
|
||||
int scaledHeight = height / sampling;
|
||||
|
||||
Bitmap out = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
if (out == null) {
|
||||
out = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
Canvas canvas = new Canvas(out);
|
||||
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
|
||||
Paint paint = new Paint();
|
||||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(toTransform, 0, 0, paint);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
try {
|
||||
final RenderScript rs = RenderScript.create(context.getApplicationContext());
|
||||
final Allocation input = Allocation.createFromBitmap(rs, out, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
|
||||
final Allocation output = Allocation.createTyped(rs, input.getType());
|
||||
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
|
||||
script.setRadius(blurRadius);
|
||||
script.setInput(input);
|
||||
script.forEach(output);
|
||||
|
||||
output.copyTo(out);
|
||||
|
||||
rs.destroy();
|
||||
|
||||
return out;
|
||||
|
||||
} catch (RSRuntimeException e) {
|
||||
// on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library
|
||||
if (BuildConfig.DEBUG) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return StackBlur.blur(out, blurRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "BlurTransformation(radius=" + blurRadius + ", sampling=" + sampling + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
|
||||
public abstract class PhonographColoredImageViewTarget extends BitmapPaletteImageViewTarget {
|
||||
public PhonographColoredImageViewTarget(ImageView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
onColorReady(getDefaultBarColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
onColorReady(ColorUtil.getColor(resource.getPalette(), getDefaultBarColor()));
|
||||
}
|
||||
|
||||
private int getDefaultBarColor() {
|
||||
return ColorUtil.resolveColor(getView().getContext(), R.attr.default_bar_color);
|
||||
}
|
||||
|
||||
public abstract void onColorReady(int color);
|
||||
}
|
||||
|
|
@ -1,17 +1,32 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
|
||||
public abstract class PhonographColoredTarget extends BitmapPaletteTarget {
|
||||
public PhonographColoredTarget(ImageView view) {
|
||||
super(view);
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class PhonographColoredTarget extends SimpleTarget<BitmapPaletteWrapper> {
|
||||
private Context context;
|
||||
|
||||
public PhonographColoredTarget(Context context) {
|
||||
super();
|
||||
init(context);
|
||||
}
|
||||
|
||||
public PhonographColoredTarget(Context context, int width, int height) {
|
||||
super(width, height);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -22,12 +37,11 @@ public abstract class PhonographColoredTarget extends BitmapPaletteTarget {
|
|||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
onColorReady(ColorUtil.getColor(resource.getPalette(), getDefaultBarColor()));
|
||||
}
|
||||
|
||||
private int getDefaultBarColor() {
|
||||
return ColorUtil.resolveColor(getView().getContext(), R.attr.default_bar_color);
|
||||
return ColorUtil.resolveColor(context, R.attr.default_bar_color);
|
||||
}
|
||||
|
||||
public abstract void onColorReady(int color);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import android.widget.ImageView;
|
|||
|
||||
import com.bumptech.glide.request.target.ImageViewTarget;
|
||||
|
||||
public class BitmapPaletteTarget extends ImageViewTarget<BitmapPaletteWrapper> {
|
||||
public BitmapPaletteTarget(ImageView view) {
|
||||
public class BitmapPaletteImageViewTarget extends ImageViewTarget<BitmapPaletteWrapper> {
|
||||
public BitmapPaletteImageViewTarget(ImageView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
|
|
@ -12,30 +12,28 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageSize;
|
||||
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
|
||||
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
||||
import com.nostra13.universalimageloader.core.imageaware.NonViewAware;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
import com.nostra13.universalimageloader.core.process.BitmapProcessor;
|
||||
|
||||
public class PlayingNotificationHelper {
|
||||
|
||||
|
|
@ -56,7 +54,7 @@ public class PlayingNotificationHelper {
|
|||
private boolean isDark;
|
||||
private boolean isColored;
|
||||
|
||||
private ImageAware notificationImageAware;
|
||||
private Target<BitmapPaletteWrapper> target;
|
||||
|
||||
public PlayingNotificationHelper(@NonNull final MusicService service) {
|
||||
this.service = service;
|
||||
|
|
@ -64,7 +62,18 @@ public class PlayingNotificationHelper {
|
|||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
|
||||
notificationImageAware = new NonViewAware(new ImageSize(bigNotificationImageSize, bigNotificationImageSize), ViewScaleType.CROP);
|
||||
target = new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
setAlbumCover(null, Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
setAlbumCover(resource.getBitmap(), ColorUtil.getColor(resource.getPalette(), Color.TRANSPARENT));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void updateNotification() {
|
||||
|
|
@ -122,7 +131,7 @@ public class PlayingNotificationHelper {
|
|||
notificationLayoutBig.setOnClickPendingIntent(R.id.action_quit,
|
||||
retrievePlaybackActions(4));
|
||||
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_play_pause, getPlayPauseRes());
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_play_pause, getPlayPauseRes(isDark));
|
||||
}
|
||||
|
||||
private void setUpPlaybackActions() {
|
||||
|
|
@ -135,7 +144,7 @@ public class PlayingNotificationHelper {
|
|||
notificationLayout.setOnClickPendingIntent(R.id.action_prev,
|
||||
retrievePlaybackActions(3));
|
||||
|
||||
notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes());
|
||||
notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes(isDark));
|
||||
}
|
||||
|
||||
private PendingIntent retrievePlaybackActions(final int which) {
|
||||
|
|
@ -186,53 +195,34 @@ public class PlayingNotificationHelper {
|
|||
}
|
||||
|
||||
private void loadAlbumArt() {
|
||||
ImageLoader.getInstance().cancelDisplayTask(notificationImageAware);
|
||||
ImageLoader.getInstance().displayImage(
|
||||
MusicUtil.getSongImageLoaderString(currentSong),
|
||||
notificationImageAware,
|
||||
new DisplayImageOptions.Builder()
|
||||
.postProcessor(new BitmapProcessor() {
|
||||
@Override
|
||||
public Bitmap process(Bitmap bitmap) {
|
||||
setAlbumArt(bitmap);
|
||||
return bitmap;
|
||||
}
|
||||
}).build(),
|
||||
new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
if (loadedImage == null) {
|
||||
onLoadingFailed(imageUri, view, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
setAlbumArt(null);
|
||||
}
|
||||
});
|
||||
service.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Glide.with(service)
|
||||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(currentSong.albumId))
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(service), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setAlbumArt(@Nullable Bitmap albumArt) {
|
||||
boolean backgroundColorSet = false;
|
||||
if (albumArt != null) {
|
||||
notificationLayout.setImageViewBitmap(R.id.icon, albumArt);
|
||||
notificationLayoutBig.setImageViewBitmap(R.id.icon, albumArt);
|
||||
if (isColored) {
|
||||
int bgColor = ColorUtil.generateColor(service, albumArt);
|
||||
setBackgroundColor(bgColor);
|
||||
setNotificationTextDark(ColorUtil.useDarkTextColorOnBackground(bgColor));
|
||||
backgroundColorSet = true;
|
||||
}
|
||||
private void setAlbumCover(@Nullable Bitmap cover, int bgColor) {
|
||||
if (cover != null) {
|
||||
notificationLayout.setImageViewBitmap(R.id.icon, cover);
|
||||
notificationLayoutBig.setImageViewBitmap(R.id.icon, cover);
|
||||
} else {
|
||||
notificationLayout.setImageViewResource(R.id.icon, R.drawable.default_album_art);
|
||||
notificationLayoutBig.setImageViewResource(R.id.icon, R.drawable.default_album_art);
|
||||
}
|
||||
|
||||
if (!backgroundColorSet) {
|
||||
setBackgroundColor(Color.TRANSPARENT);
|
||||
setNotificationTextDark(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
||||
if (!isColored) {
|
||||
bgColor = Color.TRANSPARENT;
|
||||
}
|
||||
setBackgroundColor(bgColor);
|
||||
setDarkNotificationContent(bgColor == Color.TRANSPARENT ? Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP : ColorUtil.useDarkTextColorOnBackground(bgColor));
|
||||
|
||||
if (notification != null) {
|
||||
notificationManager.notify(notificationId, notification);
|
||||
|
|
@ -255,7 +245,7 @@ public class PlayingNotificationHelper {
|
|||
if (notification == null) {
|
||||
updateNotification();
|
||||
}
|
||||
int playPauseRes = getPlayPauseRes();
|
||||
int playPauseRes = getPlayPauseRes(isDark);
|
||||
if (notificationLayout != null) {
|
||||
notificationLayout.setImageViewResource(R.id.action_play_pause, playPauseRes);
|
||||
}
|
||||
|
|
@ -267,8 +257,8 @@ public class PlayingNotificationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void setNotificationTextDark(boolean setDark) {
|
||||
isDark = setDark;
|
||||
private void setDarkNotificationContent(boolean dark) {
|
||||
isDark = dark;
|
||||
|
||||
if (notificationLayout != null && notificationLayoutBig != null) {
|
||||
int darkContentColor = ContextCompat.getColor(service, R.color.primary_text_default_material_light);
|
||||
|
|
@ -276,25 +266,23 @@ public class PlayingNotificationHelper {
|
|||
int contentColor = ContextCompat.getColor(service, R.color.primary_text_default_material_dark);
|
||||
int contentSecondaryColor = ContextCompat.getColor(service, R.color.secondary_text_default_material_dark);
|
||||
|
||||
notificationLayout.setTextColor(R.id.title, setDark ? darkContentColor : contentColor);
|
||||
notificationLayout.setTextColor(R.id.text, setDark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayout.setImageViewResource(R.id.action_prev, setDark ? R.drawable.ic_skip_previous_dark_36dp : R.drawable.ic_skip_previous_white_36dp);
|
||||
notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes());
|
||||
notificationLayout.setImageViewResource(R.id.action_next, setDark ? R.drawable.ic_skip_next_dark_36dp : R.drawable.ic_skip_next_white_36dp);
|
||||
notificationLayout.setTextColor(R.id.title, dark ? darkContentColor : contentColor);
|
||||
notificationLayout.setTextColor(R.id.text, dark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayout.setImageViewResource(R.id.action_prev, dark ? R.drawable.ic_skip_previous_dark_36dp : R.drawable.ic_skip_previous_white_36dp);
|
||||
notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes(dark));
|
||||
notificationLayout.setImageViewResource(R.id.action_next, dark ? R.drawable.ic_skip_next_dark_36dp : R.drawable.ic_skip_next_white_36dp);
|
||||
|
||||
notificationLayoutBig.setTextColor(R.id.title, setDark ? darkContentColor : contentColor);
|
||||
notificationLayoutBig.setTextColor(R.id.text, setDark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayoutBig.setTextColor(R.id.text2, setDark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_prev, setDark ? R.drawable.ic_skip_previous_dark_36dp : R.drawable.ic_skip_previous_white_36dp);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_play_pause, getPlayPauseRes());
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_next, setDark ? R.drawable.ic_skip_next_dark_36dp : R.drawable.ic_skip_next_white_36dp);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_quit, setDark ? R.drawable.ic_close_dark_24dp : R.drawable.ic_close_white_24dp);
|
||||
notificationLayoutBig.setTextColor(R.id.title, dark ? darkContentColor : contentColor);
|
||||
notificationLayoutBig.setTextColor(R.id.text, dark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayoutBig.setTextColor(R.id.text2, dark ? darkContentSecondaryColor : contentSecondaryColor);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_prev, dark ? R.drawable.ic_skip_previous_dark_36dp : R.drawable.ic_skip_previous_white_36dp);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_play_pause, getPlayPauseRes(dark));
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_next, dark ? R.drawable.ic_skip_next_dark_36dp : R.drawable.ic_skip_next_white_36dp);
|
||||
notificationLayoutBig.setImageViewResource(R.id.action_quit, dark ? R.drawable.ic_close_dark_24dp : R.drawable.ic_close_white_24dp);
|
||||
}
|
||||
}
|
||||
|
||||
private int getPlayPauseRes() {
|
||||
return isPlaying ?
|
||||
(isDark ? R.drawable.ic_pause_dark_36dp : R.drawable.ic_pause_white_36dp) :
|
||||
(isDark ? R.drawable.ic_play_arrow_dark_36dp : R.drawable.ic_play_arrow_white_36dp);
|
||||
private int getPlayPauseRes(boolean dark) {
|
||||
return isPlaying ? (dark ? R.drawable.ic_pause_dark_36dp : R.drawable.ic_pause_white_36dp) : (dark ? R.drawable.ic_play_arrow_dark_36dp : R.drawable.ic_play_arrow_white_36dp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import android.content.IntentFilter;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.media.RemoteControlClient;
|
||||
|
|
@ -29,8 +31,14 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.BitmapRequestBuilder;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.appwidget.WidgetMedium;
|
||||
import com.kabouzeid.gramophone.glide.BlurTransformation;
|
||||
import com.kabouzeid.gramophone.helper.PlayingNotificationHelper;
|
||||
import com.kabouzeid.gramophone.helper.ShuffleHelper;
|
||||
import com.kabouzeid.gramophone.helper.StopWatch;
|
||||
|
|
@ -40,6 +48,7 @@ import com.kabouzeid.gramophone.provider.MusicPlaybackQueueStore;
|
|||
import com.kabouzeid.gramophone.provider.SongPlayCountStore;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -130,24 +139,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
private boolean notHandledMetaChangedForCurrentTrack;
|
||||
private boolean isServiceInUse;
|
||||
|
||||
// TODO Glide
|
||||
// private BlurProcessor blurProcessor = new BlurProcessor.Builder(this).build();
|
||||
// // we don't want to hand our bitmap to the remote control client, as it will recycle it
|
||||
// private BitmapProcessor copyProcessor = new BitmapProcessor() {
|
||||
// @Override
|
||||
// public Bitmap process(Bitmap bitmap) {
|
||||
// Bitmap.Config config = bitmap.getConfig();
|
||||
// if (config == null) {
|
||||
// config = Bitmap.Config.ARGB_8888;
|
||||
// }
|
||||
// try {
|
||||
// return bitmap.copy(config, false);
|
||||
// } catch (OutOfMemoryError e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
private Handler uiThreadHandler;
|
||||
|
||||
private static String getTrackUri(@NonNull Song song) {
|
||||
return MusicUtil.getSongUri(song.id).toString();
|
||||
|
|
@ -183,6 +175,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
queueSaveHandlerThread.start();
|
||||
queueSaveHandler = new QueueSaveHandler(this, queueSaveHandlerThread.getLooper());
|
||||
|
||||
uiThreadHandler = new Handler();
|
||||
|
||||
registerReceiversAndRemoteControlClient();
|
||||
|
||||
restoreQueueAndPosition();
|
||||
|
|
@ -450,44 +444,32 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, song.duration)
|
||||
.apply();
|
||||
if (showAlbumArt) {
|
||||
final Point screenSize = Util.getScreenSize(MusicService.this);
|
||||
final BitmapRequestBuilder request = Glide.with(MusicService.this)
|
||||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(song.albumId))
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE);
|
||||
if (blurAlbumArt) {
|
||||
request.transform(new BlurTransformation.Builder(MusicService.this).build());
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
request.into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
updateRemoteControlClientBitmap(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
|
||||
updateRemoteControlClientBitmap(copy(resource));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ImageLoader.getInstance().displayImage(
|
||||
// currentAlbumArtUri,
|
||||
// new NonViewAware(new ImageSize(screenSize.x, screenSize.y), ViewScaleType.CROP),
|
||||
// new DisplayImageOptions.Builder().postProcessor(blurAlbumArt ? blurProcessor : copyProcessor).build(),
|
||||
// new SimpleImageLoadingListener() {
|
||||
// @Override
|
||||
// public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||
// if (currentAlbumArtUri.equals(imageUri)) {
|
||||
// updateRemoteControlClientBitmap(loadedImage);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
// if (currentAlbumArtUri.equals(imageUri)) {
|
||||
// updateRemoteControlClientBitmap(null);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// NOTE THIS MIGHT NOT BE THE UI THREAD
|
||||
// Point screenSize = Util.getScreenSize(this);
|
||||
// Glide.with(this)
|
||||
// .loadFromMediaStore(MusicUtil.getAlbumArtUri(song.albumId))
|
||||
// .asBitmap()
|
||||
// // TODO transformations
|
||||
// .into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {
|
||||
// @Override
|
||||
// public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
// super.onLoadFailed(e, errorDrawable);
|
||||
// updateRemoteControlClientBitmap(null);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
|
||||
// updateRemoteControlClientBitmap(resource);
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
updateRemoteControlClientBitmap(null);
|
||||
}
|
||||
|
|
@ -501,6 +483,23 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
.apply();
|
||||
}
|
||||
|
||||
private static Bitmap copy(Bitmap bitmap) {
|
||||
Bitmap.Config config = bitmap.getConfig();
|
||||
if (config == null) {
|
||||
config = Bitmap.Config.RGB_565;
|
||||
}
|
||||
try {
|
||||
return bitmap.copy(config, false);
|
||||
} catch (OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void runOnUiThread(Runnable runnable) {
|
||||
uiThreadHandler.post(runnable);
|
||||
}
|
||||
|
||||
public Song getCurrentSong() {
|
||||
return getSongAt(getPosition());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.song.AlbumSongAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -163,7 +163,7 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
.transcode(new BitmapPaletteTranscoder(this), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredTarget(albumArtImageView) {
|
||||
.into(new PhonographColoredImageViewTarget(albumArtImageView) {
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue