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

The following examples show how to use android.support.v7.graphics.Palette#getVibrantColor() . 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: ExtractedColors.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The hotseat's color is defined as follows:
 * - 12% black for super light wallpaper
 * - 18% white for super dark
 * - 25% white otherwise
 */
void updateHotseatPalette(Palette hotseatPalette) {
    int hotseatColor;
    int vibrantColor;

    if (hotseatPalette != null) {

        int extractedVibrantColor = hotseatPalette.getVibrantColor(ExtractedColors.DEFAULT_COLOR);
        if (ExtractionUtils.isSuperLight(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.12f * 255));

        } else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.18f * 255));
        } else {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.25f * 255));
        }
        setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
        setColorAtIndex(VIBRANT_INDEX, vibrantColor);
    }
}
 
Example 2
Source File: thumbSlider.java    From Android-Music-Player with MIT License 6 votes vote down vote up
public int getColor(Bitmap bm){
    int color = thumbRing.Color0;
    if(bm != null){
        Palette palette = Palette.from(bm).generate();
        int newColor = palette.getMutedColor(color);
        if(newColor == color){
            newColor = palette.getVibrantColor(color);
        }
        if(newColor == color){
            newColor = palette.getLightVibrantColor(color);
        }
        if(newColor == color){
            newColor = palette.getDarkVibrantColor(color);
        }
        color = newColor;
    }
    //Log.i("My","Color Exacted : " + color);
    return  color;
}
 
Example 3
Source File: TestFragment.java    From glide-support with The Unlicense 6 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB)
private void animateColors(Palette palette) {
	int color = palette.getVibrantColor(defaultColor);
	Swatch swatch = palette.getMutedSwatch();
	anims = new AnimatorSet();

	ValueAnimator cardBG = ValueAnimator.ofObject(new ArgbEvaluator(),
			defaultColor/* cannot retrieve card BG */, color);
	cardBG.addUpdateListener(new AnimatorUpdateListener() {
		@Override public void onAnimationUpdate(ValueAnimator animation) {
			holder.card.setCardBackgroundColor((Integer)animation.getAnimatedValue());
		}
	});
	anims.play(cardBG);
	if (swatch != null) {
		ObjectAnimator textColorBG = ofObject(holder.titleView, "backgroundColor", new ArgbEvaluator(),
				((ColorDrawable)holder.titleView.getBackground()).getColor(), swatch.getRgb());
		ObjectAnimator textColor = ofObject(holder.titleView, "textColor", new ArgbEvaluator(),
				holder.titleView.getCurrentTextColor(), swatch.getTitleTextColor());
		anims.play(textColor);
		anims.play(textColorBG);
	}
	anims.playTogether(anims.getChildAnimations());
	anims.setDuration(3000);
	anims.start();
}
 
Example 4
Source File: AlbumDetailActivity.java    From android-animations-transitions with MIT License 6 votes vote down vote up
private void colorizeFromImage(Bitmap image) {
        Palette palette = Palette.from(image).generate();

        // set panel colors
        int defaultPanelColor = 0xFF808080;
        int defaultFabColor = 0xFFEEEEEE;
        titlePanel.setBackgroundColor(palette.getDarkVibrantColor(defaultPanelColor));
        trackPanel.setBackgroundColor(palette.getLightMutedColor(defaultPanelColor));

        // set fab colors
        int[][] states = new int[][]{
                new int[]{android.R.attr.state_enabled},
                new int[]{android.R.attr.state_pressed}
        };

        int[] colors = new int[]{
                palette.getVibrantColor(defaultFabColor),
                palette.getLightVibrantColor(defaultFabColor)
        };
//        fab.setBackgroundTintList(new ColorStateList(states, colors));
    }
 
Example 5
Source File: BitmapUtility.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
public static int getPaletteColor(ImageView imageView) {
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    Bitmap bitmap = drawable.getBitmap();
    Palette palette = Palette.generate(bitmap);
    int x = Color.parseColor("#ea0101");
    return palette.getVibrantColor(x);
}
 
Example 6
Source File: AvatarManager.java    From timecat with Apache License 2.0 5 votes vote down vote up
public static int[] colorsFor(Resources res, String avatar) {

        int[] colors = new int[]{R.color.android_blue, R.color.android_blue_light};

        if (!cache.containsKey(avatar) && avatars.containsKey(avatar)) {
            Bitmap bm = BitmapFactory.decodeResource(res, avatars.get(avatar));
            if (bm != null) {
                Palette p = Palette.generate(bm);
                colors = new int[]{p.getVibrantColor(R.color.android_blue), p.getLightVibrantColor(R.color.android_blue_light)};
            }
            cache.put(avatar, colors);
        }
        return cache.get(avatar);
    }
 
Example 7
Source File: IconColorExtractor.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private static ArrayList<Integer> palette(Palette p, int defaultColor) {

        ArrayList<Integer> extractedPalette = new ArrayList<>();

        //get all palettes
        Integer lightVibrant, vibrant, darkVibrant, lightMuted, muted, darkMuted;

        lightVibrant = p.getVibrantColor(defaultColor);
        vibrant = p.getVibrantColor(defaultColor);
        darkVibrant = p.getDarkVibrantColor(defaultColor);
        lightMuted = p.getLightMutedColor(defaultColor);
        muted = p.getMutedColor(defaultColor);
        darkMuted = p.getDarkMutedColor(defaultColor);

        extractedPalette.add(lightVibrant);
        extractedPalette.add(vibrant);
        extractedPalette.add(darkVibrant);
        extractedPalette.add(lightMuted);
        extractedPalette.add(muted);
        extractedPalette.add(darkMuted);

        //add also default color, because if the next method fails we have a color anyway
        extractedPalette.add(defaultColor);

        //pass these palettes to a hashset to avoid duplicates
        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.addAll(extractedPalette);

        //add back these values to the palettes array list
        extractedPalette.clear();
        extractedPalette.addAll(hashSet);

        return extractedPalette;
    }
 
Example 8
Source File: PaletteUtils.java    From MediaNotification with Apache License 2.0 5 votes vote down vote up
@ColorInt
public static int getTextColor(Context context, Palette palette, Palette.Swatch swatch) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.getBoolean(PreferenceUtils.PREF_HIGH_CONTRAST_TEXT, false)) {
        if (ColorUtils.isColorLight(swatch.getRgb()))
            return Color.BLACK;
        else return Color.WHITE;
    } else {
        int background = swatch.getRgb();
        if (prefs.getBoolean(PreferenceUtils.PREF_INVERSE_TEXT_COLORS, true)) {
            int inverse = -1;
            if (palette != null) {
                switch (prefs.getInt(PreferenceUtils.PREF_COLOR_METHOD, PreferenceUtils.COLOR_METHOD_DOMINANT)) {
                    case PreferenceUtils.COLOR_METHOD_DOMINANT:
                        inverse = ColorUtils.isColorSaturated(background) ? palette.getMutedColor(-1) : palette.getVibrantColor(-1);
                        break;
                    case PreferenceUtils.COLOR_METHOD_VIBRANT:
                        inverse = palette.getMutedColor(-1);
                        break;
                    case PreferenceUtils.COLOR_METHOD_MUTED:
                        inverse = palette.getVibrantColor(-1);
                        break;
                }

                if (inverse != -1)
                    return ColorUtils.getReadableText(inverse, background, 150);
            }

            /*inverse = ColorUtils.getInverseColor(background);
            if (ColorUtils.getDifference(background, inverse) > 120 && ColorUtils.isColorSaturated(background))
                return ColorUtils.getReadableText(inverse, background, 150);*/
        }
        return ColorUtils.getReadableText(background, background);
    }
}
 
Example 9
Source File: thumbSlider.java    From Android-Music-Player with MIT License 5 votes vote down vote up
void loadBitmaps(){
    if(Ui.ef.MusicPlayer != null){
        musicPlayer mp = Ui.ef.MusicPlayer;
        final Bitmap bm = audioHandler.getAlubumArtBitmapById(Ui.ef.getContentResolver(),mp.handler.AID);
        if(bm != null){
            Palette palette = Palette.from(bm).generate();
            int color = thumbRing.Color0;
            int newColor = palette.getMutedColor(color);
            if(newColor == color){
                newColor = palette.getVibrantColor(color);
            }
            if(newColor == color){
                newColor = palette.getLightVibrantColor(color);
            }
            threeThumb.ring.img.maskPaint.setColor(newColor);
        }else{
            threeThumb.ring.img.maskPaint.setColor(thumbRing.Color0);
        }

        Ui.ef.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //threeThumb.setImg(bm);
                threeThumb.invalidate();
                threeThumb.ring.invalidate();
            }
        });
    }
}
 
Example 10
Source File: Screen.java    From Android-Music-Player with MIT License 5 votes vote down vote up
void loadBitmaps(){
    if(Ui.ef.MusicPlayer != null){
        musicPlayer mp = Ui.ef.MusicPlayer;
        final Bitmap bm = audioHandler.getAlubumArtBitmapById(Ui.ef.getContentResolver(),mp.handler.AID);
        if(bm != null){
            Palette palette = Palette.from(bm).generate();
            int color = thumbRing.Color0;
            int newColor = palette.getMutedColor(color);
            if(newColor == color){
                newColor = palette.getVibrantColor(color);
            }
            if(newColor == color){
                newColor = palette.getLightVibrantColor(color);
            }
            tRing.img.maskPaint.setColor(newColor);
        }else{
            tRing.img.maskPaint.setColor(thumbRing.Color0);
        }

        Ui.ef.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tRing.invalidate();
                img.setImageDrawable(null);
                img.setImageBitmap(bm);
            }
        });

    }else{
        img.setImageDrawable(null);
        img.setImageBitmap(null);
    }
}
 
Example 11
Source File: TestFragment.java    From glide-support with The Unlicense 5 votes vote down vote up
private void setColors(Palette palette) {
	int color = palette.getVibrantColor(defaultColor);
	Swatch swatch = palette.getMutedSwatch();

	holder.card.setCardBackgroundColor(color);
	if (swatch != null) {
		holder.titleView.setBackgroundColor(swatch.getRgb());
		holder.titleView.setTextColor(swatch.getTitleTextColor());
	}
}
 
Example 12
Source File: ContentActivity.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
private void applyPalette(Palette palette) {
    int colorMuted = palette.getDarkMutedColor(getResources().getColor(android.R.color.black));
    int colorLightVibrant = palette.getLightVibrantColor(getResources().getColor(android.R.color.primary_text_dark));
    int colorVibrant = palette.getVibrantColor(getResources().getColor(android.R.color.primary_text_dark));

    getWindow().setBackgroundDrawable(new ColorDrawable(colorMuted));
    textTitle.setTextColor(colorLightVibrant);
    textContent.setTextColor(colorVibrant);
}
 
Example 13
Source File: DetailActivity.java    From MaterializeYourApp with Apache License 2.0 5 votes vote down vote up
private void updateBackground(FloatingActionButton fab, Palette palette) {
    int lightVibrantColor = palette.getLightVibrantColor(getResources().getColor(android.R.color.white));
    int vibrantColor = palette.getVibrantColor(getResources().getColor(R.color.accent));

    fab.setRippleColor(lightVibrantColor);
    fab.setBackgroundTintList(ColorStateList.valueOf(vibrantColor));
}
 
Example 14
Source File: MuzeiArtworkImageLoader.java    From FORMWatchFace with Apache License 2.0 5 votes vote down vote up
private Pair<Integer, Integer> extractColors(Bitmap bitmap) {
    Palette palette = Palette.generate(bitmap, 16);
    int midColor = palette.getVibrantColor(
            palette.getDarkVibrantColor(
                    palette.getMutedColor(
                            palette.getDarkMutedColor(Color.GRAY))));
    int lightColor = palette.getLightMutedColor(
            palette.getLightVibrantColor(
                    palette.getMutedColor(Color.BLACK)));
    if (lightColor == Color.BLACK) {
        lightColor = lighten(midColor, 0.2f);
    }
    return new Pair<>(lightColor, midColor);
}
 
Example 15
Source File: PaletteFragment.java    From AndroidMaterialDesign with Apache License 2.0 4 votes vote down vote up
@Override
public void initViews(View view) {
    showTitleBack(view, "Palette");
    tvVibrant = (TextView) view.findViewById(R.id.tv_vibrant);
    tvVibrantLight = (TextView) view.findViewById(R.id.tv_vibrant_light);
    tvVibrantDark = (TextView) view.findViewById(R.id.tv_vibrant_dark);
    tvMuted = (TextView) view.findViewById(R.id.tv_muted);
    tvMutedLight = (TextView) view.findViewById(R.id.tv_muted_light);
    tvMutedDark = (TextView) view.findViewById(R.id.tv_muted_dark);


    tvMutedSwatch = (TextView) view.findViewById(R.id.tv_muted_swatch);
    tvLightMutedSwatch = (TextView) view.findViewById(R.id.tv_light_muted_swatch);
    tvDarkMutedSwatch = (TextView) view.findViewById(R.id.tv_dark_muted_swatch);

    tvVibrantSwatch = (TextView) view.findViewById(R.id.tv_vibrant_swatch);
    tvLightVibrantSwatch = (TextView) view.findViewById(R.id.tv_light_vibrant_swatch);
    tvDarkVibrantSwatch = (TextView) view.findViewById(R.id.tv_dark_vibrant_swatch);

    Palette.PaletteAsyncListener paletteListener = new Palette.PaletteAsyncListener() {
        public void onGenerated(Palette palette) {

            int defaultColor = 0x000000;
            int vibrant = palette.getVibrantColor(defaultColor);
            int vibrantLight = palette.getLightVibrantColor(defaultColor);
            int vibrantDark = palette.getDarkVibrantColor(defaultColor);
            int muted = palette.getMutedColor(defaultColor);
            int mutedLight = palette.getLightMutedColor(defaultColor);
            int mutedDark = palette.getDarkMutedColor(defaultColor);

            tvVibrant.setBackgroundColor(vibrant);
            tvVibrantLight.setBackgroundColor(vibrantLight);
            tvVibrantDark.setBackgroundColor(vibrantDark);
            tvMuted.setBackgroundColor(muted);
            tvMutedLight.setBackgroundColor(mutedLight);
            tvMutedDark.setBackgroundColor(mutedDark);

            setSwatchColor(palette.getMutedSwatch(), tvMutedSwatch);
            setSwatchColor(palette.getLightMutedSwatch(), tvLightMutedSwatch);
            setSwatchColor(palette.getDarkMutedSwatch(), tvDarkMutedSwatch);

            setSwatchColor(palette.getVibrantSwatch(), tvVibrantSwatch);
            setSwatchColor(palette.getLightVibrantSwatch(), tvLightVibrantSwatch);
            setSwatchColor(palette.getDarkVibrantSwatch(), tvDarkVibrantSwatch);

        }
    };

    Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.titanic);
    if (myBitmap != null && !myBitmap.isRecycled()) {
        Palette.from(myBitmap).generate(paletteListener);
    }
}
 
Example 16
Source File: MediaWidget.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onGenerated(@NonNull Palette palette) {
    mArtworkColor = palette.getVibrantColor(Color.WHITE);
    updatePlayPauseButtonColor(mArtworkColor);
    updateSeekBarColor(mArtworkColor);
}