Java Code Examples for android.support.v7.graphics.Palette#Swatch

The following examples show how to use android.support.v7.graphics.Palette#Swatch . 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: DetailActivity.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
@Override
public void onGenerated(Palette palette) {
    try {
        if (palette != null) {
            final Palette.Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();
            final Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
            final Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();
            final Palette.Swatch lightMutedSwatch = palette.getLightMutedSwatch();
            final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();

            final Palette.Swatch backgroundAndContentColors = (darkVibrantSwatch != null)
                    ? darkVibrantSwatch : darkMutedSwatch;

            final Palette.Swatch titleAndFabColors = (darkVibrantSwatch != null)
                    ? lightVibrantSwatch : lightMutedSwatch;

            mToolBarColor = backgroundAndContentColors.getRgb();
            bodyTextview.setBackgroundColor(backgroundAndContentColors.getRgb());
            titleTextView.setTextColor(titleAndFabColors.getRgb());
        }
    } catch (Exception e) {
        cleanErrorHandler.logExpception(e);
    }
}
 
Example 2
Source File: MovieDetailsFragment.java    From udacity-p1-p2-popular-movies with MIT License 6 votes vote down vote up
@Override
protected void onSuccess(Palette palette) {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }
    if (palette != null && palette.getVibrantSwatch() != null) {
        Palette.Swatch vibrant = palette.getVibrantSwatch();
        mPrimaryColor = vibrant.getRgb();
        mPrimaryDarkColor = AppUtil.multiplyColor(mPrimaryColor, 0.8f);
        mTitleTextColor = vibrant.getTitleTextColor();
    } else {
        mPrimaryColor = ContextCompat.getColor(activity, R.color.colorPrimary);
        mPrimaryDarkColor = ContextCompat.getColor(activity, R.color.colorPrimaryDark);
        mTitleTextColor = ContextCompat.getColor(activity, android.R.color.white);
    }
    AppUtil.setColorTheme(activity, mToolbar, mPrimaryColor, mPrimaryDarkColor,
            mTitleTextColor, true);

    if (activity instanceof PaletteCallback) {
        PaletteCallback callback = (PaletteCallback) activity;
        callback.setPalette(mPrimaryColor, mPrimaryDarkColor, mTitleTextColor);
    }
}
 
Example 3
Source File: ColorUtil.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
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: ColorUtils.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
/**
 * 获得图片中出现最多的颜色
 * 0 亮的活力颜色
 * 1 亮的柔和颜色
 */
public static void get2ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int[] colors) {

    if (colors.length != 2)
        return;

    Palette palette;
    palette = new Palette.Builder(bitmap).generate();

    Palette.Swatch swatch;
    int color;

    if ((swatch = palette.getLightVibrantSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[0] = color;

    if ((swatch = palette.getLightMutedSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[1] = color;

}
 
Example 5
Source File: DetailActivity.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
@Override
public void onGenerated(Palette palette) {
    try {
        if (palette != null) {
            final Palette.Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();
            final Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
            final Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();
            final Palette.Swatch lightMutedSwatch = palette.getLightMutedSwatch();
            final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();

            final Palette.Swatch backgroundAndContentColors = (darkVibrantSwatch != null)
                    ? darkVibrantSwatch : darkMutedSwatch;

            final Palette.Swatch titleAndFabColors = (darkVibrantSwatch != null)
                    ? lightVibrantSwatch : lightMutedSwatch;

            toolbar.setBackgroundColor(backgroundAndContentColors.getRgb());
            //   bodyTextview.setBackgroundColor(backgroundAndContentColors.getRgb());
            titleTextView.setTextColor(titleAndFabColors.getRgb());
        }
    } catch (Exception e) {

    }
}
 
Example 6
Source File: BitmapPalette.java    From PicassoPalette with Apache License 2.0 5 votes vote down vote up
protected static int getColor(Palette.Swatch swatch, @Swatch.PaletteSwatch int paletteSwatch) {
    if (swatch != null) {
        switch (paletteSwatch) {
            case Swatch.RGB:
                return swatch.getRgb();
            case Swatch.TITLE_TEXT_COLOR:
                return swatch.getTitleTextColor();
            case Swatch.BODY_TEXT_COLOR:
                return swatch.getBodyTextColor();
        }
    } else {
        Log.e(TAG, "error while generating Palette, null palette returned");
    }
    return 0;
}
 
Example 7
Source File: ShotDetail.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
private void applyPalette(Palette palette) {
    if (palette == null || v == null)
        return;
    Palette.Swatch item = palette.getDarkMutedSwatch();
    if (item == null)
        return;
    v.setBackgroundColor(item.getRgb());
    mDescription.setTextColor(item.getBodyTextColor());
}
 
Example 8
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 9
Source File: ColorBurn.java    From Glass with MIT License 5 votes vote down vote up
public static int colorBurn(Palette.Swatch swatch) {
    if(null == swatch) {
        return Color.parseColor("#3F51B5");
    } else {
        int rgb = swatch.getRgb();
        int alpha = rgb >> 24;
        int red = rgb >> 16 & 0xFF;
        int green = rgb >> 8 & 0xFF;
        int blue = rgb & 0xFF;
        red = (int) Math.floor(red * (1 - 0.1));
        green = (int) Math.floor(green * (1 - 0.1));
        blue = (int) Math.floor(blue * (1 - 0.1));
        return Color.argb(alpha, red, green, blue);
    }
}
 
Example 10
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
public void setViewSwatch( TextView view, Palette.Swatch swatch ) {
    if( swatch != null ) {
        view.setTextColor( swatch.getTitleTextColor() );
        view.setBackgroundColor( swatch.getRgb() );
        view.setVisibility( View.VISIBLE );
    } else {
        view.setVisibility( View.GONE );
    }
}
 
Example 11
Source File: ShotFragment.java    From droidddle with Apache License 2.0 5 votes vote down vote up
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 12
Source File: BitmapPalette.java    From GlidePalette with Apache License 2.0 5 votes vote down vote up
protected static int getColor(Palette.Swatch swatch, @Swatch int paletteSwatch) {
    if (swatch != null) {
        switch (paletteSwatch) {
            case Swatch.RGB:
                return swatch.getRgb();
            case Swatch.TITLE_TEXT_COLOR:
                return swatch.getTitleTextColor();
            case Swatch.BODY_TEXT_COLOR:
                return swatch.getBodyTextColor();
        }
    } else {
        Log.e(TAG, "error while generating Palette, null palette returned");
    }
    return 0;
}
 
Example 13
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
/**
 * 获得图片中出现最多的颜色<br>
 * 0 亮的活力颜色<br>
 * 1 亮的活力颜色 对应适合的字体颜色<br>
 * 2 亮的柔和颜色<br>
 * 3 亮的柔和颜色 对应适合的字体颜色<br>
 */
public static void get4LightColorWithTextFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int defaultTextColor, int[] colors) {

    if (colors.length != 4)
        return;

    Palette palette;
    palette = new Palette.Builder(bitmap).generate();

    Palette.Swatch swatch;
    int color = defaultColor;
    int textColor = defaultTextColor;

    if ((swatch = palette.getLightVibrantSwatch()) != null) {
        color = swatch.getRgb();
        textColor = swatch.getTitleTextColor();
    }
    colors[0] = color;
    colors[1] = textColor;

    color = defaultColor;
    textColor = defaultTextColor;

    if ((swatch = palette.getLightMutedSwatch()) != null) {
        color = swatch.getRgb();
        textColor = swatch.getTitleTextColor();
    }
    colors[2] = color;
    colors[3] = textColor;

}
 
Example 14
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
/**
 * 获得图片中出现最多的颜色<br>
 * 0 暗的活力颜色<br>
 * 1 暗的活力颜色 对应适合的字体颜色<br>
 * 2 暗的柔和颜色<br>
 * 3 暗的柔和颜色 对应适合的字体颜色<br>
 */
public static void get4DarkColorWithTextFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int defaultTextColor, int[] colors) {

    if (colors.length != 4)
        return;

    Palette palette;
    palette = new Palette.Builder(bitmap).generate();

    Palette.Swatch swatch;
    int color = defaultColor;
    int textColor = defaultTextColor;

    if ((swatch = palette.getDarkVibrantSwatch()) != null) {
        color = swatch.getRgb();
        textColor = swatch.getTitleTextColor();
    }
    colors[0] = color;
    colors[1] = textColor;

    color = defaultColor;
    textColor = defaultTextColor;

    if ((swatch = palette.getDarkMutedSwatch()) != null) {
        color = swatch.getRgb();
        textColor = swatch.getTitleTextColor();
    }
    colors[2] = color;
    colors[3] = textColor;

}
 
Example 15
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 16
Source File: PaletteSwatchAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public PaletteSwatchAssert(Palette.Swatch actual) {
  super(actual, PaletteSwatchAssert.class);
}
 
Example 17
Source File: MainActivity.java    From TutosAndroidFrance with MIT License 4 votes vote down vote up
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());
            }
        }
    }
 
Example 18
Source File: RetroMusicColorUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int compare(Palette.Swatch lhs, Palette.Swatch rhs) {
    return lhs.getPopulation() - rhs.getPopulation();
}
 
Example 19
Source File: ColorUtils.java    From android-proguards with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the most populous color in the given palette is dark
 * <p/>
 * Annoyingly we have to return this Lightness 'enum' rather than a boolean as palette isn't
 * guaranteed to find the most populous color.
 */
public static @Lightness int isDark(Palette palette) {
    Palette.Swatch mostPopulous = getMostPopulousSwatch(palette);
    if (mostPopulous == null) return LIGHTNESS_UNKNOWN;
    return isDark(mostPopulous.getHsl()) ? IS_DARK : IS_LIGHT;
}
 
Example 20
Source File: PaletteManager.java    From COCOFramework with Apache License 2.0 votes vote down vote up
void onPaletteReady(Palette.Swatch palette);