Skip to content

Commit

Permalink
Make Dribbble shot ripple colors consistent in grid & shot details.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Nov 11, 2015
1 parent 019ebca commit ccc223e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
19 changes: 9 additions & 10 deletions app/src/main/java/io/plaidapp/ui/DribbbleShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});

Expand Down
37 changes: 30 additions & 7 deletions app/src/main/java/io/plaidapp/util/ViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 8 additions & 23 deletions app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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));
}

}
1 change: 0 additions & 1 deletion app/src/main/res/drawable/mid_grey_ripple.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright 2015 Google Inc.
Expand Down

0 comments on commit ccc223e

Please sign in to comment.