Search in sources :

Example 6 with Palette

use of android.support.v7.graphics.Palette in project Timber by naman14.

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    Album localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.title);
    itemHolder.artist.setText(localItem.artistName);
    ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.id).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build(), new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            if (isGrid) {
                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        Palette.Swatch swatch = palette.getVibrantSwatch();
                        if (swatch != null) {
                            int color = swatch.getRgb();
                            itemHolder.footer.setBackgroundColor(color);
                            int textColor = TimberUtils.getBlackWhiteColor(swatch.getTitleTextColor());
                            itemHolder.title.setTextColor(textColor);
                            itemHolder.artist.setTextColor(textColor);
                        } else {
                            Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                            if (mutedSwatch != null) {
                                int color = mutedSwatch.getRgb();
                                itemHolder.footer.setBackgroundColor(color);
                                int textColor = TimberUtils.getBlackWhiteColor(mutedSwatch.getTitleTextColor());
                                itemHolder.title.setTextColor(textColor);
                                itemHolder.artist.setTextColor(textColor);
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            if (isGrid) {
                itemHolder.footer.setBackgroundColor(0);
                if (mContext != null) {
                    int textColorPrimary = Config.textColorPrimary(mContext, Helpers.getATEKey(mContext));
                    itemHolder.title.setTextColor(textColorPrimary);
                    itemHolder.artist.setTextColor(textColorPrimary);
                }
            }
        }
    });
    if (TimberUtils.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Palette(android.support.v7.graphics.Palette) Album(com.naman14.timber.models.Album) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Example 7 with Palette

use of android.support.v7.graphics.Palette in project Timber by naman14.

the class PlaylistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    final Playlist localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.name);
    String s = getAlbumArtUri(i, localItem.id);
    itemHolder.albumArt.setTag(firstAlbumID);
    ImageLoader.getInstance().displayImage(s, itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build(), new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            if (isGrid) {
                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        Palette.Swatch swatch = palette.getVibrantSwatch();
                        if (swatch != null) {
                            int color = swatch.getRgb();
                            itemHolder.footer.setBackgroundColor(color);
                            int textColor = TimberUtils.getBlackWhiteColor(swatch.getTitleTextColor());
                            itemHolder.title.setTextColor(textColor);
                            itemHolder.artist.setTextColor(textColor);
                        } else {
                            Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                            if (mutedSwatch != null) {
                                int color = mutedSwatch.getRgb();
                                itemHolder.footer.setBackgroundColor(color);
                                int textColor = TimberUtils.getBlackWhiteColor(mutedSwatch.getTitleTextColor());
                                itemHolder.title.setTextColor(textColor);
                                itemHolder.artist.setTextColor(textColor);
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            if (isGrid) {
                itemHolder.footer.setBackgroundColor(0);
                if (mContext != null) {
                    int textColorPrimary = Config.textColorPrimary(mContext, Helpers.getATEKey(mContext));
                    itemHolder.title.setTextColor(textColorPrimary);
                    itemHolder.artist.setTextColor(textColorPrimary);
                }
            }
        }
    });
    itemHolder.artist.setText(" " + String.valueOf(songCountInt) + " " + mContext.getString(R.string.songs));
    if (TimberUtils.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Palette(android.support.v7.graphics.Palette) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Playlist(com.naman14.timber.models.Playlist) Bitmap(android.graphics.Bitmap) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 8 with Palette

use of android.support.v7.graphics.Palette in project Timber by naman14.

the class ArtistDetailFragment method setUpArtistDetails.

private void setUpArtistDetails() {
    final Artist artist = ArtistLoader.getArtist(getActivity(), artistID);
    collapsingToolbarLayout.setTitle(artist.name);
    LastFmClient.getInstance(getActivity()).getArtistInfo(new ArtistQuery(artist.name), new ArtistInfoListener() {

        @Override
        public void artistInfoSucess(final LastfmArtist artist) {
            if (artist != null) {
                ImageLoader.getInstance().displayImage(artist.mArtwork.get(4).mUrl, artistArt, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).build(), new SimpleImageLoadingListener() {

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        largeImageLoaded = true;
                        try {
                            new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                                @Override
                                public void onGenerated(Palette palette) {
                                    Palette.Swatch swatch = palette.getVibrantSwatch();
                                    if (swatch != null) {
                                        primaryColor = swatch.getRgb();
                                        collapsingToolbarLayout.setContentScrimColor(primaryColor);
                                        if (getActivity() != null)
                                            ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
                                    } else {
                                        Palette.Swatch swatchMuted = palette.getMutedSwatch();
                                        if (swatchMuted != null) {
                                            primaryColor = swatchMuted.getRgb();
                                            collapsingToolbarLayout.setContentScrimColor(primaryColor);
                                            if (getActivity() != null)
                                                ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
                                        }
                                    }
                                }
                            });
                        } catch (Exception ignored) {
                        }
                    }
                });
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        setBlurredPlaceholder(artist);
                    }
                }, 100);
            }
        }

        @Override
        public void artistInfoFailed() {
        }
    });
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) Palette(android.support.v7.graphics.Palette) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)

Example 9 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 10 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)

Aggregations

Palette (android.support.v7.graphics.Palette)22 Bitmap (android.graphics.Bitmap)17 ImageView (android.widget.ImageView)9 View (android.view.View)8 TextView (android.widget.TextView)8 RecyclerView (android.support.v7.widget.RecyclerView)5 Drawable (android.graphics.drawable.Drawable)4 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)4 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)4 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)3 BindView (butterknife.BindView)2 Callback (com.squareup.picasso.Callback)2 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Color (android.graphics.Color)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Uri (android.net.Uri)1