Search in sources :

Example 11 with Palette

use of android.support.v7.graphics.Palette in project Material-Movies by saulmm.

the class MovieDetailActivity method onGenerated.

@Override
public void onGenerated(Palette palette) {
    if (palette != null) {
        final Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();
        final Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
        final Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();
        final Swatch lightMutedSwatch = palette.getLightMutedSwatch();
        final Swatch vibrantSwatch = palette.getVibrantSwatch();
        final Swatch backgroundAndContentColors = (darkVibrantSwatch != null) ? darkVibrantSwatch : darkMutedSwatch;
        final Swatch titleAndFabColors = (darkVibrantSwatch != null) ? lightVibrantSwatch : lightMutedSwatch;
        setBackgroundAndFabContentColors(backgroundAndContentColors);
        setHeadersTitlColors(titleAndFabColors);
        setVibrantElements(vibrantSwatch);
    }
}
Also used : Swatch(android.support.v7.graphics.Palette.Swatch)

Example 12 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)

Example 13 with Palette

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

the class PlayerFragment method trackInfoChanged.

@Override
public void trackInfoChanged(@Nullable Song song) {
    if (song == null)
        return;
    if (isExpanded && !snowfallView.isSnowing()) {
        snowfallView.letItSnow();
    } else {
        snowfallView.removeSnow();
    }
    String totalTimeString = StringUtils.makeTimeString(this.getActivity(), song.duration / 1000);
    if (!TextUtils.isEmpty(totalTimeString)) {
        if (totalTime != null) {
            totalTime.setText(totalTimeString);
        }
    }
    if (track != null) {
        track.setText(song.name);
        track.setSelected(true);
    }
    if (album != null) {
        album.setText(String.format("%s | %s", song.artistName, song.albumName));
    }
    if (isLandscape) {
        toolbar.setTitle(song.name);
        toolbar.setSubtitle(String.format("%s | %s", song.artistName, song.albumName));
        target = Glide.with(this).load(song).diskCacheStrategy(DiskCacheStrategy.SOURCE).bitmapTransform(new BlurTransformation(getContext(), 15, 4)).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(song.name, true)).thumbnail(Glide.with(this).load(this.song).bitmapTransform(new BlurTransformation(getContext(), 15, 4))).crossFade(600).into(backgroundView);
        this.song = song;
    } else {
        backgroundView.setImageDrawable(null);
        toolbar.setTitle(null);
        toolbar.setSubtitle(null);
    }
    if (SettingsManager.getInstance().getUsePalette()) {
        // noinspection unchecked
        Glide.with(this).load(song).asBitmap().transcode(new PaletteBitmapTranscoder(getContext()), PaletteBitmap.class).override(250, 250).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<PaletteBitmap>() {

            @Override
            public void onResourceReady(PaletteBitmap resource, GlideAnimation<? super PaletteBitmap> glideAnimation) {
                if (!isAdded() || getContext() == null) {
                    return;
                }
                Palette.Swatch swatch = resource.palette.getDarkMutedSwatch();
                if (swatch != null) {
                    if (SettingsManager.getInstance().getUsePalette()) {
                        if (SettingsManager.getInstance().getUsePaletteNowPlayingOnly()) {
                            animateColors(currentColor, swatch.getRgb(), color -> invalidateColors(color));
                        } else {
                            // Set Aesthetic colors globally, based on the current Palette swatch
                            disposables.add(Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(integer -> animateColors(integer, swatch.getRgb(), color -> {
                                if (getContext() != null && isAdded()) {
                                    Aesthetic aesthetic = Aesthetic.get(getContext()).colorPrimary(color).colorStatusBarAuto();
                                    if (SettingsManager.getInstance().getTintNavBar()) {
                                        aesthetic = aesthetic.colorNavigationBar(color);
                                    }
                                    aesthetic.apply();
                                }
                            })));
                        }
                    }
                } else {
                    // Failed to generate the dark muted swatch, fall back to the primary theme colour.
                    Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
                }
            }

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
            }
        });
    }
}
Also used : PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) ImageView(android.widget.ImageView) SeekBarStopChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStopChangeEvent) FavoriteActionBarView(com.simplecity.amp_library.ui.views.FavoriteActionBarView) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) RepeatingImageButton(com.simplecity.amp_library.ui.views.RepeatingImageButton) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) ShuffleButton(com.simplecity.amp_library.ui.views.ShuffleButton) Unbinder(butterknife.Unbinder) Log(android.util.Log) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) LogUtils(com.simplecity.amp_library.utils.LogUtils) PlayPauseView(com.simplecity.amp_library.ui.views.PlayPauseView) SeekBarProgressChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarProgressChangeEvent) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) SnowfallView(com.simplecity.amp_library.ui.views.SnowfallView) SeekBarStartChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStartChangeEvent) Util(com.afollestad.aesthetic.Util) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SuppressLint(android.annotation.SuppressLint) SeekBarChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarChangeEvent) Flowable(io.reactivex.Flowable) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) UnsafeConsumer(com.simplecity.amp_library.rx.UnsafeConsumer) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) BackpressureStrategy(io.reactivex.BackpressureStrategy) LayoutInflater(android.view.LayoutInflater) Target(com.bumptech.glide.request.target.Target) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) TextUtils(android.text.TextUtils) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap) Glide(com.bumptech.glide.Glide) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Toolbar(android.support.v7.widget.Toolbar) MusicService(com.simplecity.amp_library.playback.MusicService) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) RepeatButton(com.simplecity.amp_library.ui.views.RepeatButton) Collections(java.util.Collections) RxSeekBar(com.jakewharton.rxbinding2.widget.RxSeekBar) ValueAnimator(android.animation.ValueAnimator) RxSharedPreferences(com.f2prateek.rx.preferences2.RxSharedPreferences) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Aesthetic(com.afollestad.aesthetic.Aesthetic) Drawable(android.graphics.drawable.Drawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap)

Example 14 with Palette

use of android.support.v7.graphics.Palette in project kickmaterial by byoutline.

the class ProjectDetailsActivity method loadProjectPhoto.

private void loadProjectPhoto() {
    Bitmap bitmap = picassoCache.getPlaceholder(project.getBigPhotoUrl());
    boolean bigPhotoMustBeFetched = bitmap == null;
    if (bigPhotoMustBeFetched) {
        bitmap = picassoCache.getPlaceholder(project.getPhotoUrl());
        boolean placeholderAlreadyFetched = bitmap != null;
        if (placeholderAlreadyFetched) {
            binding.projectPhotoIv.setImageBitmap(bitmap);
        }
    }
    // Make sure that transition starts soon even if image is not ready.
    binding.projectPhotoIv.postDelayed(this::supportStartPostponedEnterTransition, MAX_TRANSITION_DELAY);
    Picasso.with(this).load(project.getBigPhotoUrl()).resize(imageWidth, imageHeight).onlyScaleDown().centerCrop().transform(PaletteAndAplaTransformation.instance()).into(binding.projectPhotoIv, new Callback() {

        @Override
        public void onSuccess() {
            // Ew!
            Bitmap bitmap = ((BitmapDrawable) binding.projectPhotoIv.getDrawable()).getBitmap();
            Palette palette = PaletteAndAplaTransformation.getPalette(bitmap);
            binding.detailsContainer.setBackgroundColor(palette.getDarkVibrantColor(Color.BLACK));
            supportStartPostponedEnterTransition();
        }

        @Override
        public void onError() {
            supportStartPostponedEnterTransition();
        }
    });
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap) SharedElementCallback(android.support.v4.app.SharedElementCallback) Callback(com.squareup.picasso.Callback)

Example 15 with Palette

use of android.support.v7.graphics.Palette in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, final int i) {
    final Playlist localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.name);
    itemHolder.songcount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
    itemHolder.subtitle1.setVisibility(View.GONE);
    itemHolder.divider.setVisibility(View.GONE);
    PlaylistSongLoader.getSongsInPlaylist(mContext, localItem.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {

        @Override
        public void call(List<Song> playlistsongs) {
            String uri = "";
            long firstAlbumID = -1;
            if (playlistsongs.size() != 0) {
                firstAlbumID = playlistsongs.get(0).albumId;
                uri = ListenerUtil.getAlbumArtUri(firstAlbumID).toString();
            }
            itemHolder.playlistArt.setTag(R.string.playlistArt, firstAlbumID);
            Glide.with(itemHolder.itemView.getContext()).load(uri).asBitmap().placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    if (isGrid) {
                        itemHolder.footer.setBackgroundColor(ATEUtil.getThemeAlbumDefaultPaletteColor(mContext));
                    }
                    itemHolder.playlistArt.setImageDrawable(ATEUtil.getDefaultAlbumDrawable(mContext));
                    itemHolder.title.setTextColor(ATEUtil.getThemeTextColorPrimary(mContext));
                    itemHolder.songcount.setTextColor(ATEUtil.getThemeTextColorSecondly(mContext));
                    itemHolder.popupMenu.setColorFilter(mContext.getResources().getColor(R.color.background_floating_material_dark));
                }

                @Override
                public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    if (isGrid) {
                        new Palette.Builder(resource).generate(new Palette.PaletteAsyncListener() {

                            @Override
                            public void onGenerated(Palette palette) {
                                Palette.Swatch swatch = ColorUtil.getMostPopulousSwatch(palette);
                                if (swatch != null) {
                                    int color = swatch.getRgb();
                                    itemHolder.footer.setBackgroundColor(color);
                                    int detailColor = swatch.getTitleTextColor();
                                    itemHolder.playlistArt.setImageBitmap(resource);
                                    itemHolder.title.setTextColor(ColorUtil.getOpaqueColor(detailColor));
                                    itemHolder.songcount.setTextColor(detailColor);
                                    itemHolder.popupMenu.setColorFilter(detailColor);
                                }
                            }
                        });
                    } else {
                        itemHolder.playlistArt.setImageBitmap(resource);
                    }
                }
            });
        }
    });
    if (ListenerUtil.isLollipop())
        itemHolder.playlistArt.setTransitionName("transition_album_art" + i);
    setOnPopupMenuListener(itemHolder, i);
}
Also used : Palette(android.support.v7.graphics.Palette) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Playlist(io.hefuyi.listener.mvp.model.Playlist) Song(io.hefuyi.listener.mvp.model.Song) Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) List(java.util.List)

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