Search in sources :

Example 1 with Palette

use of android.support.v7.graphics.Palette in project nmid-headline by miao1007.

the class PaletteTransformation method transform.

@Override
public Bitmap transform(Bitmap source) {
    Palette palette = Palette.generate(source);
    CACHE.put(source, palette);
    return source;
}
Also used : Palette(android.support.v7.graphics.Palette)

Example 2 with Palette

use of android.support.v7.graphics.Palette in project AntennaPod by AntennaPod.

the class CustomMRControllerDialog method fetchArt.

private Pair<Bitmap, Integer> fetchArt(@NonNull MediaDescriptionCompat description) {
    Bitmap iconBitmap = description.getIconBitmap();
    Uri iconUri = description.getIconUri();
    Bitmap art = null;
    if (iconBitmap != null) {
        art = iconBitmap;
    } else if (iconUri != null) {
        try {
            art = Glide.with(getContext().getApplicationContext()).load(iconUri.toString()).asBitmap().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Image art load failed", e);
        }
    }
    int backgroundColor = 0;
    if (art != null && art.getWidth() * 9 < art.getHeight() * 16) {
        // Portrait art requires dominant color as background color.
        Palette palette = new Palette.Builder(art).maximumColorCount(1).generate();
        backgroundColor = palette.getSwatches().isEmpty() ? 0 : palette.getSwatches().get(0).getRgb();
    }
    return new Pair<>(art, backgroundColor);
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap) Uri(android.net.Uri) Pair(android.support.v4.util.Pair)

Example 3 with Palette

use of android.support.v7.graphics.Palette in project Lightning-Browser by anthonycr.

the class BrowserActivity method changeToolbarBackground.

/**
     * Animates the color of the toolbar from one color to another. Optionally animates
     * the color of the tab background, for use when the tabs are displayed on the top
     * of the screen.
     *
     * @param favicon       the Bitmap to extract the color from
     * @param tabBackground the optional LinearLayout to color
     */
@Override
public void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
    final int defaultColor = ContextCompat.getColor(this, R.color.primary_color);
    if (mCurrentUiColor == Color.BLACK) {
        mCurrentUiColor = defaultColor;
    }
    Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {

        @Override
        public void onGenerated(Palette palette) {
            // OR with opaque black to remove transparency glitches
            int color = 0xff000000 | palette.getVibrantColor(defaultColor);
            // Lighten up the dark color if it is
            final int finalColor;
            // too dark
            if (!mShowTabsInDrawer || Utils.isColorTooDark(color)) {
                finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
            } else {
                finalColor = color;
            }
            final Window window = getWindow();
            if (!mShowTabsInDrawer) {
                window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
            }
            final int startSearchColor = getSearchBarColor(mCurrentUiColor, defaultColor);
            final int finalSearchColor = getSearchBarColor(finalColor, defaultColor);
            Animation animation = new Animation() {

                @Override
                protected void applyTransformation(float interpolatedTime, Transformation t) {
                    final int color = DrawableUtils.mixColor(interpolatedTime, mCurrentUiColor, finalColor);
                    if (mShowTabsInDrawer) {
                        mBackground.setColor(color);
                        Handlers.MAIN.post(new Runnable() {

                            @Override
                            public void run() {
                                window.setBackgroundDrawable(mBackground);
                            }
                        });
                    } else if (tabBackground != null) {
                        tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                    }
                    mCurrentUiColor = color;
                    mToolbarLayout.setBackgroundColor(color);
                    mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime, startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
                }
            };
            animation.setDuration(300);
            mToolbarLayout.startAnimation(animation);
        }
    });
}
Also used : Window(android.view.Window) Palette(android.support.v7.graphics.Palette) Transformation(android.view.animation.Transformation) ColorDrawable(android.graphics.drawable.ColorDrawable) Animation(android.view.animation.Animation)

Example 4 with Palette

use of android.support.v7.graphics.Palette in project LookLook by xinghongfei.

the class MeiziPhotoDescribeActivity method setStatusColor.

private void setStatusColor() {
    Bitmap b = convertViewToBitmap(mRelativeLayout);
    Palette palette = Palette.generate(b);
    if (palette.getLightVibrantSwatch() != null) {
        getWindow().setStatusBarColor(palette.getLightVibrantSwatch().getRgb());
    }
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap)

Example 5 with Palette

use of android.support.v7.graphics.Palette in project LeafPic by HoraApps.

the class PaletteActivity method setPalette.

public void setPalette() {
    Bitmap myBitmap = ((BitmapDrawable) paletteImg.getDrawable()).getBitmap();
    ((TextView) findViewById(R.id.palette_image_title)).setText(uri.getPath().substring(uri.getPath().lastIndexOf("/") + 1));
    ((TextView) findViewById(R.id.palette_image_caption)).setText(uri.getPath());
    palette = Palette.from(myBitmap).generate();
    rvPalette = (RecyclerView) findViewById(R.id.paletteRecycler);
    rvPalette.setLayoutManager(new LinearLayoutManager(this));
    rvPalette.setNestedScrollingEnabled(false);
    paletteAdapter = new PaletteAdapter(palette.getSwatches());
    rvPalette.setAdapter(paletteAdapter);
}
Also used : Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

Palette (android.support.v7.graphics.Palette)29 Bitmap (android.graphics.Bitmap)22 Drawable (android.graphics.drawable.Drawable)11 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)6 Context (android.content.Context)5 Intent (android.content.Intent)5 View (android.view.View)5 TextUtils (android.text.TextUtils)4 BindView (butterknife.BindView)4 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)4 BitmapPaletteWrapper (com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper)4 Song (com.kabouzeid.gramophone.model.Song)4 Bundle (android.os.Bundle)3 RecyclerView (android.support.v7.widget.RecyclerView)3 Toolbar (android.support.v7.widget.Toolbar)3 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 PendingIntent (android.app.PendingIntent)2