Java Code Examples for android.support.v7.graphics.Palette#getDominantSwatch()

The following examples show how to use android.support.v7.graphics.Palette#getDominantSwatch() . 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: PaletteUtils.java    From MediaNotification with Apache License 2.0 5 votes vote down vote up
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 2
Source File: MainActivity.java    From music-player with MIT License 5 votes vote down vote up
public void setStatusBar(Palette palette){
    Window window = getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Palette.Swatch vibrant = palette.getDominantSwatch();
        if (vibrant != null) {
            window.setStatusBarColor(vibrant.getRgb());
        }

    }
}
 
Example 3
Source File: PlaylistFragment.java    From Melophile with Apache License 2.0 5 votes vote down vote up
private void applyPalette(Palette palette) {
  Palette.Swatch swatch = palette.getDarkVibrantSwatch();
  if (swatch == null) swatch = palette.getDominantSwatch();
  if (swatch != null) {
    toggle.setBackgroundTintList(ColorStateList.valueOf(swatch.getRgb()));
  }
}
 
Example 4
Source File: Utils.java    From AndroidAppShortcuts with Apache License 2.0 5 votes vote down vote up
/**
 * Get dominant color of bitmap
 * @param bitmap Bitmap
 * @return int
 */
public static int getDominantColor(Bitmap bitmap){
    Palette palette = Palette.from(bitmap).generate();
    Palette.Swatch dominantSwatch = palette.getDominantSwatch();
    if(dominantSwatch != null){
        return dominantSwatch.getRgb();
    }
    return 0;
}