Search in sources :

Example 21 with Palette

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

the class AlbumDetailFragment method setAlbumart.

private void setAlbumart() {
    ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(albumID).toString(), albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build(), new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String imageUri, View view) {
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            loadFailed = true;
            MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(context).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
            ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
            fab.setImageDrawable(builder.build());
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            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);
                            }
                        }
                        MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setSizeDp(30);
                        if (primaryColor != -1) {
                            builder.setColor(TimberUtils.getBlackWhiteColor(primaryColor));
                            ATEUtils.setFabBackgroundTint(fab, primaryColor);
                            fab.setImageDrawable(builder.build());
                        } else {
                            if (context != null) {
                                ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
                                builder.setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
                                fab.setImageDrawable(builder.build());
                            }
                        }
                    }
                });
            } catch (Exception ignored) {
            }
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
        }
    });
}
Also used : Palette(android.support.v7.graphics.Palette) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder) Bitmap(android.graphics.Bitmap) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 22 with Palette

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

the class ArtistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    final Artist localItem = arraylist.get(i);
    itemHolder.name.setText(localItem.name);
    String albumNmber = TimberUtils.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount);
    String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
    itemHolder.albums.setText(TimberUtils.makeCombinedString(mContext, albumNmber, songCount));
    LastFmClient.getInstance(mContext).getArtistInfo(new ArtistQuery(localItem.name), new ArtistInfoListener() {

        @Override
        public void artistInfoSucess(LastfmArtist artist) {
            if (artist != null && artist.mArtwork != null) {
                if (isGrid) {
                    ImageLoader.getInstance().displayImage(artist.mArtwork.get(2).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(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 && loadedImage != null) {
                                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                                    @Override
                                    public void onGenerated(Palette palette) {
                                        int color = palette.getVibrantColor(Color.parseColor("#66000000"));
                                        itemHolder.footer.setBackgroundColor(color);
                                        Palette.Swatch swatch = palette.getVibrantSwatch();
                                        int textColor;
                                        if (swatch != null) {
                                            textColor = getOpaqueColor(swatch.getTitleTextColor());
                                        } else
                                            textColor = Color.parseColor("#ffffff");
                                        itemHolder.name.setTextColor(textColor);
                                        itemHolder.albums.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.name.setTextColor(textColorPrimary);
                                    itemHolder.albums.setTextColor(textColorPrimary);
                                }
                            }
                        }
                    });
                } else {
                    ImageLoader.getInstance().displayImage(artist.mArtwork.get(1).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build());
                }
            }
        }

        @Override
        public void artistInfoFailed() {
        }
    });
    if (TimberUtils.isLollipop())
        itemHolder.artistImage.setTransitionName("transition_artist_art" + i);
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) 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) 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) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Example 23 with Palette

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

the class MainActivity method setStatusColor.

private void setStatusColor() {
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.nav_icon);
    Palette palette = Palette.generate(bm);
    if (palette.getLightVibrantSwatch() != null) {
        mainColor = palette.getLightVibrantSwatch().getRgb();
        getWindow().setStatusBarColor(palette.getLightVibrantSwatch().getRgb());
        toolbar.setBackgroundColor(palette.getLightVibrantSwatch().getRgb());
    }
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap)

Example 24 with Palette

use of android.support.v7.graphics.Palette in project PhotoNoter by yydcdut.

the class Utils method getPaletteColor.

public static int getPaletteColor(Bitmap bitmap) {
    Palette.Builder builder = Palette.from(bitmap);
    Palette palette = builder.generate();
    Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
    if (vibrantSwatch == null) {
        Palette.Swatch lightVibrant = palette.getLightVibrantSwatch();
        if (lightVibrant == null) {
            Palette.Swatch darkVibrant = palette.getDarkVibrantSwatch();
            if (darkVibrant == null) {
                Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                if (mutedSwatch == null) {
                    Palette.Swatch lightMuted = palette.getMutedSwatch();
                    if (lightMuted == null) {
                        Palette.Swatch darkMuted = palette.getDarkMutedSwatch();
                        if (darkMuted == null) {
                            return Color.WHITE;
                        } else {
                            return darkMuted.getRgb();
                        }
                    } else {
                        return lightMuted.getRgb();
                    }
                } else {
                    return mutedSwatch.getRgb();
                }
            } else {
                return darkVibrant.getRgb();
            }
        } else {
            return lightVibrant.getRgb();
        }
    } else {
        return vibrantSwatch.getRgb();
    }
}
Also used : Palette(android.support.v7.graphics.Palette)

Example 25 with Palette

use of android.support.v7.graphics.Palette in project Shuttle by timusus.

the class PaletteBitmapTranscoder method transcode.

@Override
public Resource<PaletteBitmap> transcode(Resource<Bitmap> toTranscode) {
    Bitmap bitmap = toTranscode.get();
    Palette palette = new Palette.Builder(bitmap).generate();
    PaletteBitmap result = new PaletteBitmap(bitmap, palette);
    return new PaletteBitmapResource(result, bitmapPool);
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap)

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