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

The following examples show how to use android.support.v7.graphics.Palette#getMutedColor() . 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: 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 2
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 3
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 4
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 5
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 6
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);
    }
}