diff --git a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java index 280b19a1e..c04ce1acb 100644 --- a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java +++ b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java @@ -409,16 +409,15 @@ public void onAnimationUpdate(ValueAnimator animation) { .generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { - Palette.Swatch vibrant = palette.getVibrantSwatch(); - if (vibrant != null) { - // color the ripple on the image spacer (default is grey) - shotSpacer.setBackground(ViewUtils.createMaskedRipple(vibrant - .getRgb(), 0.25f)); - // slightly more opaque ripple on the pinned image to compensate - // for the scrim - imageView.setForeground(ViewUtils.createRipple(vibrant.getRgb(), - 0.3f)); - } + // color the ripple on the image spacer (default is grey) + shotSpacer.setBackground(ViewUtils.createRipple(palette, 0.25f, 0.5f, + ContextCompat.getColor(DribbbleShot.this, R.color.mid_grey), + true)); + // slightly more opaque ripple on the pinned image to compensate + // for the scrim + imageView.setForeground(ViewUtils.createRipple(palette, 0.3f, 0.6f, + ContextCompat.getColor(DribbbleShot.this, R.color.mid_grey), + true)); } }); diff --git a/app/src/main/java/io/plaidapp/util/ViewUtils.java b/app/src/main/java/io/plaidapp/util/ViewUtils.java index f34129d7a..c838b5fcb 100644 --- a/app/src/main/java/io/plaidapp/util/ViewUtils.java +++ b/app/src/main/java/io/plaidapp/util/ViewUtils.java @@ -26,6 +26,7 @@ import android.support.annotation.ColorInt; import android.support.annotation.FloatRange; import android.support.annotation.NonNull; +import android.support.v7.graphics.Palette; import android.text.TextPaint; import android.util.DisplayMetrics; import android.util.Property; @@ -53,16 +54,38 @@ public static int getActionBarSize(Context context) { } public static RippleDrawable createRipple(@ColorInt int color, - @FloatRange(from = 0f, to = 1f) float alpha) { + @FloatRange(from = 0f, to = 1f) float alpha, + boolean bounded) { color = ColorUtils.modifyAlpha(color, alpha); - return new RippleDrawable(ColorStateList.valueOf(color), null, null); + return new RippleDrawable(ColorStateList.valueOf(color), null, + bounded ? new ColorDrawable(Color.WHITE) : null); } - public static RippleDrawable createMaskedRipple(@ColorInt int color, - @FloatRange(from = 0f, to = 1f) float alpha) { - color = ColorUtils.modifyAlpha(color, alpha); - return new RippleDrawable(ColorStateList.valueOf(color), null, new ColorDrawable - (0xffffffff)); + public static RippleDrawable createRipple(@NonNull Palette palette, + @FloatRange(from = 0f, to = 1f) float darkAlpha, + @FloatRange(from = 0f, to = 1f) float lightAlpha, + @ColorInt int fallbackColor, + boolean bounded) { + int rippleColor = fallbackColor; + // try the named swatches in preference order + if (palette.getVibrantSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha); + } else if (palette.getLightVibrantSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), + lightAlpha); + } else if (palette.getDarkVibrantSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), + darkAlpha); + } else if (palette.getMutedSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha); + } else if (palette.getLightMutedSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(), + lightAlpha); + } else if (palette.getDarkMutedSwatch() != null) { + rippleColor = ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha); + } + return new RippleDrawable(ColorStateList.valueOf(rippleColor), null, + bounded ? new ColorDrawable(Color.WHITE) : null); } public static void setLightStatusBar(@NonNull View view) { diff --git a/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java b/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java index 8deeb71bc..f88792b32 100644 --- a/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java +++ b/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java @@ -17,7 +17,6 @@ package io.plaidapp.util.glide; import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v7.graphics.Palette; @@ -33,10 +32,11 @@ import io.plaidapp.util.ViewUtils; /** - * + * A Glide {@see ViewTarget} for {@link BadgedFourThreeImageView}s. It applies a badge for animated + * images, can prevent GIFs from auto-playing & applies a palette generated ripple. */ -public class DribbbleTarget extends GlideDrawableImageViewTarget implements Palette - .PaletteAsyncListener { +public class DribbbleTarget extends GlideDrawableImageViewTarget implements + Palette.PaletteAsyncListener { private boolean playGifs; @@ -94,24 +94,9 @@ public void onStop() { @Override public void onGenerated(Palette palette) { - Drawable ripple = null; - // try the named swatches in preference order - if (palette.getVibrantSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getVibrantSwatch().getRgb(), 0.25f); - } else if (palette.getLightVibrantSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getLightVibrantSwatch().getRgb(), 0.5f); - } else if (palette.getDarkVibrantSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getDarkVibrantSwatch().getRgb(), 0.25f); - } else if (palette.getMutedSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getMutedSwatch().getRgb(), 0.25f); - } else if (palette.getLightMutedSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getLightMutedSwatch().getRgb(), 0.5f); - } else if (palette.getDarkMutedSwatch() != null) { - ripple = ViewUtils.createRipple(palette.getDarkMutedSwatch().getRgb(), 0.25f); - } else { - // no swatches found, fall back to grey :( - ripple = getView().getContext().getDrawable(R.drawable.mid_grey_ripple); - } - ((BadgedFourThreeImageView) getView()).setForeground(ripple); + ((BadgedFourThreeImageView) getView()).setForeground( + ViewUtils.createRipple(palette, 0.25f, 0.5f, + ContextCompat.getColor(getView().getContext(), R.color.mid_grey), true)); } + } diff --git a/app/src/main/res/drawable/mid_grey_ripple.xml b/app/src/main/res/drawable/mid_grey_ripple.xml index f80db08a0..ff2a4b65e 100644 --- a/app/src/main/res/drawable/mid_grey_ripple.xml +++ b/app/src/main/res/drawable/mid_grey_ripple.xml @@ -1,5 +1,4 @@ -