Created
October 16, 2016 21:15
-
-
Save fnk0/c0668a843c1cf30bd61ce8c49960d16f to your computer and use it in GitHub Desktop.
Helper class to extract the necessary palette colors from the generate palette
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PaletteUtils { | |
public static PaletteColors getPaletteColors(Palette palette) { | |
PaletteColors colors = new PaletteColors(); | |
//figuring out toolbar palette color in order of preference | |
if (palette.getDarkVibrantSwatch() != null) { | |
colors.setToolbarBackgroundColor(palette.getDarkVibrantSwatch().getRgb()); | |
colors.setTextColor(palette.getDarkVibrantSwatch().getBodyTextColor()); | |
colors.setTitleColor(palette.getDarkVibrantSwatch().getTitleTextColor()); | |
} else if (palette.getDarkMutedSwatch() != null) { | |
colors.setToolbarBackgroundColor(palette.getDarkMutedSwatch().getRgb()); | |
colors.setTextColor(palette.getDarkMutedSwatch().getBodyTextColor()); | |
colors.setTitleColor(palette.getDarkMutedSwatch().getTitleTextColor()); | |
} else if (palette.getVibrantSwatch() != null) { | |
colors.setToolbarBackgroundColor(palette.getVibrantSwatch().getRgb()); | |
colors.setTextColor(palette.getVibrantSwatch().getBodyTextColor()); | |
colors.setTitleColor(palette.getVibrantSwatch().getTitleTextColor()); | |
} | |
//set the status bar color to be a darker version of the toolbar background Color; | |
if (colors.getToolbarBackgroundColor() != 0) { | |
float[] hsv = new float[3]; | |
int color = colors.getToolbarBackgroundColor(); | |
Color.colorToHSV(color, hsv); | |
hsv[2] *= 0.8f; // value component | |
colors.setStatusBarColor(Color.HSVToColor(hsv)); | |
} | |
return colors; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment