Skip to content

Instantly share code, notes, and snippets.

@fnk0
Created October 16, 2016 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnk0/c0668a843c1cf30bd61ce8c49960d16f to your computer and use it in GitHub Desktop.
Save fnk0/c0668a843c1cf30bd61ce8c49960d16f to your computer and use it in GitHub Desktop.
Helper class to extract the necessary palette colors from the generate palette
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