Search in sources :

Example 1 with Palette

use of androidx.palette.graphics.Palette in project MovieGuide by esoxjem.

the class MoviesListingAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.itemView.setOnClickListener(holder);
    holder.movie = movies.get(position);
    holder.name.setText(holder.movie.getTitle());
    RequestOptions options = new RequestOptions().centerCrop().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).priority(Priority.HIGH);
    Glide.with(context).asBitmap().load(Api.getPosterPath(holder.movie.getPosterPath())).apply(options).into(new BitmapImageViewTarget(holder.poster) {

        @Override
        public void onResourceReady(Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
            super.onResourceReady(bitmap, transition);
            Palette.from(bitmap).generate(palette -> setBackgroundColor(palette, holder));
        }
    });
}
Also used : Context(android.content.Context) Api(com.esoxjem.movieguide.Api) RequestOptions(com.bumptech.glide.request.RequestOptions) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Glide(com.bumptech.glide.Glide) Priority(com.bumptech.glide.Priority) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) R(com.esoxjem.movieguide.R) Palette(androidx.palette.graphics.Palette) Movie(com.esoxjem.movieguide.Movie) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 2 with Palette

use of androidx.palette.graphics.Palette in project Timber by naman14.

the class ArtistDetailFragment method setUpArtistDetails.

private void setUpArtistDetails() {
    final Artist artist = ArtistLoader.getArtist(getActivity(), artistID);
    List<Song> songList = ArtistSongLoader.getSongsForArtist(getActivity(), artistID);
    mAdapter = new ArtistSongAdapter(getActivity(), songList, 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(androidx.palette.graphics.Palette) Handler(android.os.Handler) ArtistSongAdapter(com.naman14.timber.adapters.ArtistSongAdapter) 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) Song(com.naman14.timber.models.Song) Bitmap(android.graphics.Bitmap) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)

Example 3 with Palette

use of androidx.palette.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).showImageOnLoading(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(androidx.palette.graphics.Palette) Album(com.naman14.timber.models.Album) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Example 4 with Palette

use of androidx.palette.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) + " - " + TimberUtils.makeShortTimeString(mContext, totalRuntime));
    if (TimberUtils.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Palette(androidx.palette.graphics.Palette) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.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 5 with Palette

use of androidx.palette.graphics.Palette in project AntennaPod by AntennaPod.

the class PaletteBitmapTranscoder method transcode.

@Nullable
@Override
public Resource<PaletteBitmap> transcode(@NonNull Resource<Bitmap> toTranscode, @NonNull Options options) {
    Bitmap bitmap = toTranscode.get();
    Palette palette = null;
    if (UserPreferences.shouldShowSubscriptionTitle()) {
        palette = new Palette.Builder(bitmap).generate();
    }
    PaletteBitmap result = new PaletteBitmap(bitmap, palette);
    return new PaletteBitmapResource(result);
}
Also used : Palette(androidx.palette.graphics.Palette) Bitmap(android.graphics.Bitmap) Nullable(androidx.annotation.Nullable)

Aggregations

Bitmap (android.graphics.Bitmap)7 Palette (androidx.palette.graphics.Palette)7 View (android.view.View)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)4 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)4 Nullable (androidx.annotation.Nullable)2 ArtistInfoListener (com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)2 ArtistQuery (com.naman14.timber.lastfmapi.models.ArtistQuery)2 LastfmArtist (com.naman14.timber.lastfmapi.models.LastfmArtist)2 Artist (com.naman14.timber.models.Artist)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 Context (android.content.Context)1 Handler (android.os.Handler)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1