Java Code Examples for android.support.v7.graphics.Palette#getMutedSwatch()
The following examples show how to use
android.support.v7.graphics.Palette#getMutedSwatch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorUtil.java From music_player with Open Software License 3.0 | 6 votes |
public static int getColor(Drawable drawable) { Palette palette = Palette.from(drawableToBitmap(drawable)).generate(); if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else { return Color.parseColor("#009688"); } }
Example 2
Source File: TestFragment.java From glide-support with The Unlicense | 6 votes |
@TargetApi(VERSION_CODES.HONEYCOMB) private void animateColors(Palette palette) { int color = palette.getVibrantColor(defaultColor); Swatch swatch = palette.getMutedSwatch(); anims = new AnimatorSet(); ValueAnimator cardBG = ValueAnimator.ofObject(new ArgbEvaluator(), defaultColor/* cannot retrieve card BG */, color); cardBG.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { holder.card.setCardBackgroundColor((Integer)animation.getAnimatedValue()); } }); anims.play(cardBG); if (swatch != null) { ObjectAnimator textColorBG = ofObject(holder.titleView, "backgroundColor", new ArgbEvaluator(), ((ColorDrawable)holder.titleView.getBackground()).getColor(), swatch.getRgb()); ObjectAnimator textColor = ofObject(holder.titleView, "textColor", new ArgbEvaluator(), holder.titleView.getCurrentTextColor(), swatch.getTitleTextColor()); anims.play(textColor); anims.play(textColorBG); } anims.playTogether(anims.getChildAnimations()); anims.setDuration(3000); anims.start(); }
Example 3
Source File: ColorUtil.java From APlayer with GNU General Public License v3.0 | 6 votes |
public static Palette.Swatch getSwatch(Palette palette) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()); } } return new Palette.Swatch(Color.GRAY, 100); }
Example 4
Source File: ColorUtil.java From APlayer with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example 5
Source File: RetroMusicColorUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
public static int[] getMultipleColor(Palette palette) { int[] colors = new int[2]; if (palette != null) { if (palette.getVibrantSwatch() != null) { colors[0] = palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { colors[1] = palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { colors[0] = palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { colors[1] = palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { colors[0] = palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { colors[1] = palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { colors[0] = Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return colors; }
Example 6
Source File: RetroMusicColorUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example 7
Source File: PhonographColorUtil.java From Orin with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example 8
Source File: PaletteUtils.java From MediaNotification with Apache License 2.0 | 6 votes |
private static Palette.Swatch getBestPaletteSwatchFrom(Palette palette) { if (palette != null) { if (palette.getVibrantSwatch() != null) return palette.getVibrantSwatch(); else if (palette.getMutedSwatch() != null) return palette.getMutedSwatch(); else if (palette.getDarkVibrantSwatch() != null) return palette.getDarkVibrantSwatch(); else if (palette.getDarkMutedSwatch() != null) return palette.getDarkMutedSwatch(); else if (palette.getLightVibrantSwatch() != null) return palette.getLightVibrantSwatch(); else if (palette.getLightMutedSwatch() != null) return palette.getLightMutedSwatch(); else if (!palette.getSwatches().isEmpty()) return getBestPaletteSwatchFrom(palette.getSwatches()); } return null; }
Example 9
Source File: ColorUtil.java From music_player with Open Software License 3.0 | 6 votes |
public static int getColor(Bitmap bitmap) { Palette palette = Palette.from(bitmap).generate(); if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else { return Color.parseColor("#009688"); } }
Example 10
Source File: ViewUtils.java From Protein with Apache License 2.0 | 5 votes |
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; 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); }
Example 11
Source File: ViewUtils.java From materialup with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) 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); }
Example 12
Source File: PaletteUtils.java From MediaNotification with Apache License 2.0 | 5 votes |
public static Palette.Swatch getSwatch(Context context, Palette palette) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (palette == null) return new Palette.Swatch(prefs.getInt(PreferenceUtils.PREF_CUSTOM_COLOR, Color.WHITE), 1); Palette.Swatch swatch = null; switch (prefs.getInt(PreferenceUtils.PREF_COLOR_METHOD, PreferenceUtils.COLOR_METHOD_DOMINANT)) { case PreferenceUtils.COLOR_METHOD_DOMINANT: swatch = palette.getDominantSwatch(); break; case PreferenceUtils.COLOR_METHOD_PRIMARY: swatch = getBestPaletteSwatchFrom(palette); break; case PreferenceUtils.COLOR_METHOD_VIBRANT: swatch = palette.getVibrantSwatch(); break; case PreferenceUtils.COLOR_METHOD_MUTED: swatch = palette.getMutedSwatch(); break; } if (swatch == null) swatch = new Palette.Swatch(prefs.getInt(PreferenceUtils.PREF_CUSTOM_COLOR, Color.WHITE), 1); return swatch; }
Example 13
Source File: TestFragment.java From glide-support with The Unlicense | 5 votes |
private void setColors(Palette palette) { int color = palette.getVibrantColor(defaultColor); Swatch swatch = palette.getMutedSwatch(); holder.card.setCardBackgroundColor(color); if (swatch != null) { holder.titleView.setBackgroundColor(swatch.getRgb()); holder.titleView.setTextColor(swatch.getTitleTextColor()); } }
Example 14
Source File: ViewUtils.java From android-proguards with Apache License 2.0 | 5 votes |
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; 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); }
Example 15
Source File: ShotFragment.java From droidddle with Apache License 2.0 | 5 votes |
private void updateShotPalette(Palette palette) { mDensity = getResources().getDisplayMetrics().density; int index = 0; Palette.Swatch swatch = palette.getDarkMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getDarkVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getLightMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getLightVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } }
Example 16
Source File: ColorUtils.java From Musicoco with Apache License 2.0 | 4 votes |
/** * 获得图片中出现最多的颜色 * 0 活力颜色<br> * 1 对应字体颜色<br> * 2 亮的活力颜色<br> * 3 对应字体颜色<br> * 4 暗的活力颜色<br> * 5 对应字体颜色<br> * 6 柔和颜色<br> * 7 对应字体颜色<br> * 8 亮的柔和颜色<br> * 9 对应字体颜色<br> * 10 暗的柔和颜色<br> * 11 对应字体颜色<br> */ public static void get12ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int defaultTextColor, int[] colors) { if (colors.length != 12) return; Palette palette; palette = new Palette.Builder(bitmap).generate(); Palette.Swatch swatch; int color; int tColor; if ((swatch = palette.getVibrantSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[0] = color; colors[1] = tColor; if ((swatch = palette.getLightVibrantSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[2] = color; colors[3] = tColor; if ((swatch = palette.getDarkVibrantSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[4] = color; colors[5] = tColor; if ((swatch = palette.getMutedSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[6] = color; colors[7] = tColor; if ((swatch = palette.getLightMutedSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[8] = color; colors[9] = tColor; if ((swatch = palette.getDarkMutedSwatch()) != null) { color = swatch.getRgb(); tColor = swatch.getTitleTextColor(); } else { color = defaultColor; tColor = defaultTextColor; } colors[10] = color; colors[11] = tColor; }
Example 17
Source File: ColorUtils.java From Musicoco with Apache License 2.0 | 4 votes |
/** * 获得图片中出现最多的颜色 * 0 活力颜色<br> * 1 亮的活力颜色<br> * 2 暗的活力颜色<br> * 3 柔和颜色<br> * 4 亮的柔和颜色<br> * 5 暗的柔和颜色<br> */ public static void get6ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int[] colors) { if (colors.length != 6) return; Palette palette; palette = new Palette.Builder(bitmap).generate(); Palette.Swatch swatch; int color; if ((swatch = palette.getVibrantSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[0] = color; if ((swatch = palette.getLightVibrantSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[1] = color; if ((swatch = palette.getDarkVibrantSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[2] = color; if ((swatch = palette.getMutedSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[3] = color; if ((swatch = palette.getLightMutedSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[4] = color; if ((swatch = palette.getDarkMutedSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[5] = color; }
Example 18
Source File: MainActivity.java From TutosAndroidFrance with MIT License | 4 votes |
public void appliquerPalette(Palette palette) { { //je récupère le swatch Vibrant Palette.Swatch vibrant = palette.getVibrantSwatch(); if (vibrant != null) { //il se peut que la palette ne génère pas tous les swatch //j'utilise getRgb() en tant que couleurs de fond te ma textView textVibrant.setBackgroundColor(vibrant.getRgb()); //getBodyTextColor() est prévu pour être affiché dessus une vue en background getRgb() textVibrant.setTextColor(vibrant.getBodyTextColor()); } } { Palette.Swatch vibrantDark = palette.getDarkVibrantSwatch(); if (vibrantDark != null) { textVibrantDark.setBackgroundColor(vibrantDark.getRgb()); textVibrantDark.setTextColor(vibrantDark.getBodyTextColor()); } } { Palette.Swatch vibrantLight = palette.getLightVibrantSwatch(); if (vibrantLight != null) { textVibrantLight.setBackgroundColor(vibrantLight.getRgb()); textVibrantLight.setTextColor(vibrantLight.getBodyTextColor()); } } { Palette.Swatch muted = palette.getMutedSwatch(); if (muted != null) { textMuted.setBackgroundColor(muted.getRgb()); textMuted.setTextColor(muted.getBodyTextColor()); } } { Palette.Swatch mutedDark = palette.getDarkMutedSwatch(); if (mutedDark != null) { textMutedDark.setBackgroundColor(mutedDark.getRgb()); textMutedDark.setTextColor(mutedDark.getBodyTextColor()); } } { Palette.Swatch lightMuted = palette.getLightMutedSwatch(); if (lightMuted != null) { textMutedLight.setBackgroundColor(lightMuted.getRgb()); textMutedLight.setTextColor(lightMuted.getBodyTextColor()); } } }