public static RippleDrawable createRipple(@Nullable Palette palette, @FloatRange(from = 0f, to = 1f) float darkAlpha, @FloatRange(from = 0f, to = 1f) float lightAlpha, @ColorInt int fallbackColor, boolean bounded) { int rippleColor = fallbackColor; if (palette != null) { // 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 int getStationImageColor() { // extract color palette from station image Palette palette = Palette.from(mInputImage).generate(); // get muted and vibrant swatches Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); Palette.Swatch mutedSwatch = palette.getMutedSwatch(); if (vibrantSwatch != null) { // return vibrant color int rgb = vibrantSwatch.getRgb(); return Color.argb(255, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } else if (mutedSwatch != null) { // return muted color int rgb = mutedSwatch.getRgb(); return Color.argb(255, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } else { // default return return mContext.getResources().getColor(R.color.transistor_grey_lighter); } }
@ColorInt public int getColor(@NonNull Type type, @ColorInt int defaultColor) { final Palette.Swatch swatch; if(palette != null) { switch (type) { case TEXT: swatch = palette.getDominantSwatch(); break; case BACKGROUND: swatch = palette.getMutedSwatch(); break; default: swatch = null; break; } } else { swatch = null; } if(swatch != null) return swatch.getRgb(); else return defaultColor; } }
/** * Checks if the most populous color in the given palette is dark * <p/> * Annoyingly we have to return this Lightness 'enum' rather than a boolean as palette isn't * guaranteed to find the most populous color. */ public static @Lightness int isDark(Palette palette) { Palette.Swatch mostPopulous = getMostPopulousSwatch(palette); if (mostPopulous == null) return LIGHTNESS_UNKNOWN; return isDark(mostPopulous.getRgb()) ? IS_DARK : IS_LIGHT; }