Java Code Examples for androidx.palette.graphics.Palette#getMutedSwatch()
The following examples show how to use
androidx.palette.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: MusicColorUtil.java From Music-Player 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 2
Source File: PhonographColorUtil.java From MusicPlayer 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 3
Source File: VinylMusicPlayerColorUtil.java From VinylMusicPlayer 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 4
Source File: PhonographColorUtil.java From Phonograph 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: AppSyncWorker.java From zephyr with MIT License | 5 votes |
@ColorInt private int getAppColor(@NonNull Palette palette, @ColorInt int defaultColor) { if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantColor(defaultColor); } if (palette.getVibrantSwatch() != null) { return palette.getVibrantColor(defaultColor); } if (palette.getMutedSwatch() != null) { return palette.getMutedColor(defaultColor); } if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedColor(defaultColor); } if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedColor(defaultColor); } if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantColor(defaultColor); } return defaultColor; }
Example 6
Source File: ChannelActivity.java From Twire with GNU General Public License v3.0 | 4 votes |
private Target<Bitmap> getLightThemeTarget() { return new CustomTarget<Bitmap>() { @Override public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) { streamerImage.setImageBitmap(bitmap); Palette palette = Palette.from(bitmap).generate(); int defaultColor = Service.getColorAttribute(R.attr.colorPrimary, R.color.primary, getBaseContext()); int defaultDarkColor = Service.getColorAttribute(R.attr.colorPrimaryDark, R.color.primaryDark, getBaseContext()); int vibrant = palette.getVibrantColor(defaultColor); int vibrantDark = palette.getDarkVibrantColor(defaultColor); int vibrantLight = palette.getLightVibrantColor(defaultColor); int muted = palette.getMutedColor(defaultColor); int mutedDark = palette.getDarkMutedColor(defaultColor); Palette.Swatch swatch; if (vibrant != defaultColor) { swatch = palette.getVibrantSwatch(); } else if (vibrantDark != defaultColor) { swatch = palette.getDarkVibrantSwatch(); } else if (vibrantLight != defaultColor) { swatch = palette.getLightVibrantSwatch(); } else if (muted != defaultColor) { swatch = palette.getMutedSwatch(); } else if (mutedDark != defaultColor) { swatch = palette.getDarkMutedSwatch(); } else { swatch = palette.getLightMutedSwatch(); } if (swatch != null) { float[] swatchValues = swatch.getHsl(); float[] newSwatch = {swatchValues[0], (float) 0.85, (float) 0.85}; float[] newSwatchComposite = {(swatchValues[0] + 180) % 360, newSwatch[1], newSwatch[2]}; float[] newSwatchDark = {newSwatch[0], newSwatch[1], (float) 0.6}; int newColorDark = Color.HSVToColor(newSwatchDark); int newColor = Color.HSVToColor(newSwatch); int compositeNewColor = Color.HSVToColor(newSwatchComposite); int primaryColor = Service.getBackgroundColorFromView(toolbar, defaultColor); int primaryColorDark = Service.getBackgroundColorFromView(mTabs, defaultDarkColor); Service.animateBackgroundColorChange(toolbar, newColor, primaryColor, COLOR_FADE_DURATION); Service.animateBackgroundColorChange(additionalToolbar, newColor, primaryColor, COLOR_FADE_DURATION); Service.animateBackgroundColorChange(mTabs, newColorDark, primaryColorDark, COLOR_FADE_DURATION); mFab.setBackgroundTintList(ColorStateList.valueOf(compositeNewColor)); mTabs.setSelectedTabIndicatorColor(compositeNewColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(newColorDark); } } } @Override public void onLoadCleared(@Nullable Drawable placeholder) { } }; }
Example 7
Source File: PaletteGeneratorTask.java From MusicPlayer with GNU General Public License v3.0 | 4 votes |
private boolean onGeneratedPalette(@NonNull Palette p) { int[] palette = new int[6]; // access palette colors here Palette.Swatch psVibrant = p.getVibrantSwatch(); Palette.Swatch psVibrantLight = p.getLightVibrantSwatch(); Palette.Swatch psVibrantDark = p.getDarkVibrantSwatch(); Palette.Swatch psMuted = p.getMutedSwatch(); Palette.Swatch psMutedLight = p.getLightMutedSwatch(); Palette.Swatch psMutedDark = p.getDarkMutedSwatch(); for (int i = 0; i < 6; i++) palette[i] = 0; if (psVibrant != null) { palette[0] = psVibrant.getRgb(); } if (psVibrantLight != null) { palette[1] = psVibrantLight.getRgb(); } if (psVibrantDark != null) { palette[2] = psVibrantDark.getRgb(); } if (psMuted != null) { palette[3] = psMuted.getRgb(); } if (psMutedLight != null) { palette[4] = psMutedLight.getRgb(); } if (psMutedDark != null) { palette[5] = psMutedDark.getRgb(); } float[] hsv = new float[3]; Color.colorToHSV(Tool.getMostCommonColor(), hsv); // Log.d(hsv[0] + "|" + hsv[1] + "|" + hsv[2], "ColorMe"); float alpha_7basic = hsv[1]; final int color1,color2; float alpha1,alpha2; if(alpha_7basic<0.5f) // Đủ đậm thì màu mostCommon sẽ là màu song name, màu basic là màu artist { color1= Tool.getMostCommonColor(); alpha1 =1; color2 = Tool.getBaseColor(); alpha2 =alpha_7basic; } else // ngược lại thì màu basic sẽ là màu song name { int tempColor1 = getBestColorFromPalette(palette); if(tempColor1==0) color1 = Tool.getBaseColor(); else color1 = tempColor1; alpha1 = 1; color2 =Color.WHITE; alpha2 = 0.7f; } Context context = mWeakRefContext.get(); if(context!=null&&!mCanceled) { Intent intent = new Intent(PALETTE_ACTION); intent.putExtra(RESULT, true); intent.putExtra(COLOR_ONE, color1); intent.putExtra(COLOR_TWO, color2); intent.putExtra(ALPHA_ONE, alpha1); intent.putExtra(ALPHA_TWO, alpha2); context.sendBroadcast(intent); } else return false; return true; }
Example 8
Source File: ChannelActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 4 votes |
private Target getLightThemeTarget() { return new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { streamerImage.setImageBitmap(bitmap); Palette palette = Palette.from(bitmap).generate(); int defaultColor = Service.getColorAttribute(R.attr.colorPrimary, R.color.primary, getBaseContext()); int defaultDarkColor = Service.getColorAttribute(R.attr.colorPrimaryDark, R.color.primaryDark, getBaseContext()); int vibrant = palette.getVibrantColor(defaultColor); int vibrantDark = palette.getDarkVibrantColor(defaultColor); int vibrantLight = palette.getLightVibrantColor(defaultColor); int muted = palette.getMutedColor(defaultColor); int mutedDark = palette.getDarkMutedColor(defaultColor); int mutedLight = palette.getLightMutedColor(defaultColor); Palette.Swatch swatch = null; if (vibrant != defaultColor) { swatch = palette.getVibrantSwatch(); } else if (vibrantDark != defaultColor) { swatch = palette.getDarkVibrantSwatch(); } else if (vibrantLight != defaultColor){ swatch = palette.getLightVibrantSwatch(); } else if (muted != defaultColor) { swatch = palette.getMutedSwatch(); } else if (mutedDark != defaultColor) { swatch = palette.getDarkMutedSwatch(); } else { swatch = palette.getLightMutedSwatch(); } if (swatch != null) { float[] swatchValues = swatch.getHsl(); float[] newSwatch = {swatchValues[0], (float) 0.85, (float) 0.85}; float[] newSwatchComposite = {(swatchValues[0] + 180) % 360, newSwatch[1], newSwatch[2]}; float[] newSwatchDark = {newSwatch[0], newSwatch[1], (float) 0.6}; int newColorDark = Color.HSVToColor(newSwatchDark); int newColor = Color.HSVToColor(newSwatch); int compositeNewColor = Color.HSVToColor(newSwatchComposite); int primaryColor = Service.getBackgroundColorFromView(toolbar, defaultColor); int primaryColorDark = Service.getBackgroundColorFromView(mTabs, defaultDarkColor); Service.animateBackgroundColorChange(toolbar, newColor, primaryColor, COLOR_FADE_DURATION); Service.animateBackgroundColorChange(additionalToolbar, newColor, primaryColor, COLOR_FADE_DURATION); Service.animateBackgroundColorChange(mTabs, newColorDark, primaryColorDark, COLOR_FADE_DURATION); mFab.setBackgroundTintList(ColorStateList.valueOf(compositeNewColor)); mTabs.setSelectedTabIndicatorColor(compositeNewColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(newColorDark); } } } @Override public void onBitmapFailed(Drawable errorDrawable) {} @Override public void onPrepareLoad(Drawable placeHolderDrawable) {} }; }
Example 9
Source File: PaletteUtils.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
@Nullable private static Palette.Swatch getSwatchInternal(final Palette pPalette, @SwatchStyle final int... pSwatchStyle) { for (final int style : pSwatchStyle) { switch (style) { case SwatchStyle.Vibrant: if (pPalette.getVibrantSwatch() != null) { return pPalette.getVibrantSwatch(); } else { break; } case SwatchStyle.LightVibrant: if (pPalette.getLightVibrantSwatch() != null) { return pPalette.getLightVibrantSwatch(); } else { break; } case SwatchStyle.DarkVibrant: if (pPalette.getDarkVibrantSwatch() != null) { return pPalette.getDarkVibrantSwatch(); } else { break; } case SwatchStyle.Muted: if (pPalette.getMutedSwatch() != null) { return pPalette.getMutedSwatch(); } else { break; } case SwatchStyle.LightMuted: if (pPalette.getLightMutedSwatch() != null) { return pPalette.getLightMutedSwatch(); } else { break; } case SwatchStyle.DarkMuted: if (pPalette.getDarkMutedSwatch() != null) { return pPalette.getDarkMutedSwatch(); } else { break; } default: break; } } return DEFAULT_SWATCH; }