Search in sources :

Example 16 with Palette

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

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, final int i) {
    Album localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.title);
    itemHolder.artist.setText(localItem.artistName);
    itemHolder.songcount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
    Glide.with(itemHolder.itemView.getContext()).load(ListenerUtil.getAlbumArtUri(localItem.id).toString()).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(new SimpleTarget<Bitmap>() {

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            if (isGrid) {
                itemHolder.footer.setBackgroundColor(ATEUtil.getThemeAlbumDefaultPaletteColor(mContext));
            }
            itemHolder.albumArt.setImageDrawable(ATEUtil.getDefaultAlbumDrawable(mContext));
            itemHolder.title.setTextColor(ATEUtil.getThemeTextColorPrimary(mContext));
            itemHolder.artist.setTextColor(ATEUtil.getThemeTextColorSecondly(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.albumArt.setImageBitmap(resource);
                            itemHolder.title.setTextColor(ColorUtil.getOpaqueColor(detailColor));
                            itemHolder.artist.setTextColor(detailColor);
                            itemHolder.songcount.setTextColor(detailColor);
                            itemHolder.popupMenu.setColorFilter(detailColor);
                        }
                    }
                });
            } else {
                itemHolder.albumArt.setImageBitmap(resource);
            }
        }
    });
    if (ListenerUtil.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
    setOnPopupMenuListener(itemHolder, i);
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) Album(io.hefuyi.listener.mvp.model.Album)

Example 17 with Palette

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

the class PaletteAndAplaTransformation method transform.

@Override
public Bitmap transform(Bitmap source) {
    // Calculate palette from original bitmap.
    Palette palette = Palette.from(source).generate();
    // Add apla overlay to bitmap.
    Bitmap result = aplaTransformation.transform(source);
    // Cache palette with result as a key, since ImageView will have result bitmap set
    // (as opposed to source which at this point is recycled).
    CACHE.put(result, palette);
    return result;
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap)

Example 18 with Palette

use of android.support.v7.graphics.Palette in project google-io-2014 by romainguy.

the class DetailActivity method colorize.

private void colorize(Bitmap photo) {
    Palette palette = Palette.generate(photo);
    applyPalette(palette);
}
Also used : Palette(android.support.v7.graphics.Palette)

Example 19 with Palette

use of android.support.v7.graphics.Palette in project SeriesGuide by UweTrottmann.

the class MovieDetailsFragment method populateMovieViews.

private void populateMovieViews() {
    /**
         * Get everything from TMDb. Also get additional rating from trakt.
         */
    final Ratings traktRatings = movieDetails.traktRatings();
    final Movie tmdbMovie = movieDetails.tmdbMovie();
    final boolean inCollection = movieDetails.inCollection;
    final boolean inWatchlist = movieDetails.inWatchlist;
    final boolean isWatched = movieDetails.isWatched;
    final int rating = movieDetails.userRating;
    textViewMovieTitle.setText(tmdbMovie.title);
    getActivity().setTitle(tmdbMovie.title);
    textViewMovieDescription.setText(tmdbMovie.overview);
    // release date and runtime: "July 17, 2009 | 95 min"
    StringBuilder releaseAndRuntime = new StringBuilder();
    if (tmdbMovie.release_date != null) {
        releaseAndRuntime.append(TimeTools.formatToLocalDate(getContext(), tmdbMovie.release_date));
        releaseAndRuntime.append(" | ");
    }
    releaseAndRuntime.append(getString(R.string.runtime_minutes, String.valueOf(tmdbMovie.runtime)));
    textViewMovieDate.setText(releaseAndRuntime.toString());
    // check-in button
    final String title = tmdbMovie.title;
    buttonMovieCheckIn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // display a check-in dialog
            MovieCheckInDialogFragment f = MovieCheckInDialogFragment.newInstance(tmdbId, title);
            f.show(getFragmentManager(), "checkin-dialog");
            Utils.trackAction(getActivity(), TAG, "Check-In");
        }
    });
    CheatSheet.setup(buttonMovieCheckIn);
    // hide check-in if not connected to trakt or hexagon is enabled
    boolean isConnectedToTrakt = TraktCredentials.get(getActivity()).hasCredentials();
    boolean displayCheckIn = isConnectedToTrakt && !HexagonSettings.isEnabled(getActivity());
    buttonMovieCheckIn.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    dividerMovieButtons.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    // watched button (only supported when connected to trakt)
    if (isConnectedToTrakt) {
        buttonMovieWatched.setText(isWatched ? R.string.action_unwatched : R.string.action_watched);
        CheatSheet.setup(buttonMovieWatched, isWatched ? R.string.action_unwatched : R.string.action_watched);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieWatched, 0, isWatched ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatched) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatch), 0, 0);
        buttonMovieWatched.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isWatched) {
                    MovieTools.unwatchedMovie(SgApp.from(getActivity()), tmdbId);
                    Utils.trackAction(getActivity(), TAG, "Unwatched movie");
                } else {
                    MovieTools.watchedMovie(SgApp.from(getActivity()), tmdbId);
                    Utils.trackAction(getActivity(), TAG, "Watched movie");
                }
            }
        });
        buttonMovieWatched.setVisibility(View.VISIBLE);
    } else {
        buttonMovieWatched.setVisibility(View.GONE);
    }
    // collected button
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieCollected, 0, inCollection ? R.drawable.ic_collected : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect), 0, 0);
    buttonMovieCollected.setText(inCollection ? R.string.action_collection_remove : R.string.action_collection_add);
    CheatSheet.setup(buttonMovieCollected, inCollection ? R.string.action_collection_remove : R.string.action_collection_add);
    buttonMovieCollected.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (inCollection) {
                MovieTools.removeFromCollection(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Uncollected movie");
            } else {
                MovieTools.addToCollection(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Collected movie");
            }
        }
    });
    // watchlist button
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieWatchlisted, 0, inWatchlist ? R.drawable.ic_listed : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableList), 0, 0);
    buttonMovieWatchlisted.setText(inWatchlist ? R.string.watchlist_remove : R.string.watchlist_add);
    CheatSheet.setup(buttonMovieWatchlisted, inWatchlist ? R.string.watchlist_remove : R.string.watchlist_add);
    buttonMovieWatchlisted.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (inWatchlist) {
                MovieTools.removeFromWatchlist(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Unwatchlist movie");
            } else {
                MovieTools.addToWatchlist(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Watchlist movie");
            }
        }
    });
    // show button bar
    containerMovieButtons.setVisibility(View.VISIBLE);
    // language button
    LanguageTools.LanguageData languageData = LanguageTools.getMovieLanguageData(getContext());
    if (languageData != null) {
        currentLanguageIndex = languageData.languageIndex;
        buttonMovieLanguage.setText(languageData.languageString);
    } else {
        buttonMovieLanguage.setText(null);
    }
    buttonMovieLanguage.setVisibility(View.VISIBLE);
    // ratings
    textViewRatingsTmdbValue.setText(TraktTools.buildRatingString(tmdbMovie.vote_average));
    textViewRatingsTmdbVotes.setText(TraktTools.buildRatingVotesString(getActivity(), tmdbMovie.vote_count));
    if (traktRatings != null) {
        textViewRatingsTraktVotes.setText(TraktTools.buildRatingVotesString(getActivity(), traktRatings.votes));
        textViewRatingsTraktValue.setText(TraktTools.buildRatingString(traktRatings.rating));
    }
    // if movie is not in database, can't handle user ratings
    if (!inCollection && !inWatchlist && !isWatched) {
        textViewRatingsTraktUserLabel.setVisibility(View.GONE);
        textViewRatingsTraktUser.setVisibility(View.GONE);
        containerRatings.setClickable(false);
        // cheat sheet
        containerRatings.setLongClickable(false);
    } else {
        textViewRatingsTraktUserLabel.setVisibility(View.VISIBLE);
        textViewRatingsTraktUser.setVisibility(View.VISIBLE);
        textViewRatingsTraktUser.setText(TraktTools.buildUserRatingString(getActivity(), rating));
        containerRatings.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                rateMovie();
            }
        });
        CheatSheet.setup(containerRatings, R.string.action_rate);
    }
    containerRatings.setVisibility(View.VISIBLE);
    // genres
    textViewMovieGenresLabel.setVisibility(View.VISIBLE);
    Utils.setValueOrPlaceholder(textViewMovieGenres, TmdbTools.buildGenresString(tmdbMovie.genres));
    // trakt comments link
    buttonMovieComments.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), TraktCommentsActivity.class);
            i.putExtras(TraktCommentsActivity.createInitBundleMovie(title, tmdbId));
            Utils.startActivityWithAnimation(getActivity(), i, v);
            Utils.trackAction(v.getContext(), TAG, "Comments");
        }
    });
    buttonMovieComments.setVisibility(View.VISIBLE);
    // load poster, cache on external storage
    if (TextUtils.isEmpty(tmdbMovie.poster_path)) {
        frameLayoutMoviePoster.setClickable(false);
        frameLayoutMoviePoster.setFocusable(false);
    } else {
        final String smallImageUrl = TmdbSettings.getImageBaseUrl(getActivity()) + TmdbSettings.POSTER_SIZE_SPEC_W342 + tmdbMovie.poster_path;
        ServiceUtils.loadWithPicasso(getActivity(), smallImageUrl).into(imageViewMoviePoster, new Callback.EmptyCallback() {

            @Override
            public void onSuccess() {
                Bitmap bitmap = ((BitmapDrawable) imageViewMoviePoster.getDrawable()).getBitmap();
                paletteAsyncTask = Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        int color = palette.getVibrantColor(Color.WHITE);
                        color = ColorUtils.setAlphaComponent(color, 50);
                        rootLayoutMovie.setBackgroundColor(color);
                    }
                });
            }
        });
        // click listener for high resolution poster
        frameLayoutMoviePoster.setFocusable(true);
        frameLayoutMoviePoster.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                String largeImageUrl = TmdbSettings.getImageBaseUrl(getActivity()) + TmdbSettings.POSTER_SIZE_SPEC_ORIGINAL + tmdbMovie.poster_path;
                Intent intent = new Intent(getActivity(), FullscreenImageActivity.class);
                intent.putExtra(FullscreenImageActivity.EXTRA_PREVIEW_IMAGE, smallImageUrl);
                intent.putExtra(FullscreenImageActivity.EXTRA_IMAGE, largeImageUrl);
                Utils.startActivityWithAnimation(getActivity(), intent, view);
            }
        });
    }
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) Palette(android.support.v7.graphics.Palette) MovieCheckInDialogFragment(com.battlelancer.seriesguide.ui.dialogs.MovieCheckInDialogFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) LanguageTools(com.battlelancer.seriesguide.util.LanguageTools) Ratings(com.uwetrottmann.trakt5.entities.Ratings) Bitmap(android.graphics.Bitmap) Callback(com.squareup.picasso.Callback) OnClickListener(android.view.View.OnClickListener)

Example 20 with Palette

use of android.support.v7.graphics.Palette in project qksms by moezbhatti.

the class ThemeManager method showColorPicker.

private static void showColorPicker(QKActivity context, View.OnClickListener saveListener) {
    final QKDialog dialog = new QKDialog();
    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_color_picker, null, false);
    ColorPickerViewHolder holder = new ColorPickerViewHolder(view);
    holder.mTab1.setBackgroundDrawable(getRippleBackground());
    holder.mTab2.setBackgroundDrawable(getRippleBackground());
    holder.mTab1.setOnClickListener(v -> holder.mPager.setCurrentItem(0));
    holder.mTab2.setOnClickListener(v -> holder.mPager.setCurrentItem(1));
    ColorPickerPagerAdapter adapter = new ColorPickerPagerAdapter(context);
    holder.mPager.setAdapter(adapter);
    holder.mPager.setOffscreenPageLimit(1);
    holder.mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            holder.mTab1.setTextColor(position == 0 ? getColor() : getTextOnBackgroundPrimary());
            holder.mTab2.setTextColor(position == 1 ? getColor() : getTextOnBackgroundPrimary());
        }
    });
    int swatchColor = getSwatchColor(getColor());
    holder.mPalette.init(19, 4, color -> {
        holder.mPalette.init(getSwatch(color).length, 4, color2 -> {
            setActiveColor(color2);
            saveListener.onClick(null);
            dialog.dismiss();
        });
        holder.mPalette.drawPalette(getSwatch(color), getColor());
    });
    holder.mPalette.drawPalette(PALETTE, swatchColor);
    if (swatchColor == getColor()) {
        // If the current theme was set from the RGB picker, show that page instead
        holder.mPager.setCurrentItem(1);
    }
    SeekBar.OnSeekBarChangeListener seekListener = new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int color = getColor();
            color = Color.rgb(seekBar == holder.mRed ? progress : Color.red(color), seekBar == holder.mGreen ? progress : Color.green(color), seekBar == holder.mBlue ? progress : Color.blue(color));
            if (seekBar == holder.mRed)
                holder.mRedValue.setText(String.valueOf(progress));
            if (seekBar == holder.mGreen)
                holder.mGreenValue.setText(String.valueOf(progress));
            if (seekBar == holder.mBlue)
                holder.mBlueValue.setText(String.valueOf(progress));
            setActiveColor(color);
            String colorString = Integer.toHexString(color);
            holder.mHex.setTextChangedListenerEnabled(false);
            holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0));
            holder.mHex.setTextChangedListenerEnabled(true);
            holder.mError.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    };
    Drawable thumbRed = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
    Drawable thumbGreen = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
    Drawable thumbBlue = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
    LiveViewManager.registerView(QKPreference.THEME, holder.mPreview, key -> {
        holder.mPreview.setBackgroundColor(getColor());
        holder.mRed.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
        holder.mGreen.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
        holder.mBlue.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
        if (holder.mPager.getCurrentItem() == 0) {
            holder.mTab1.setTextColor(getColor());
        } else {
            holder.mTab2.setTextColor(getColor());
        }
    });
    LiveViewManager.registerView(QKPreference.BACKGROUND, holder.mHex, key -> {
        holder.mHex.getBackground().setColorFilter(0x22888888, PorterDuff.Mode.MULTIPLY);
        holder.mError.setColorFilter(getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP);
    });
    holder.mRed.setThumb(thumbRed);
    holder.mRed.setOnSeekBarChangeListener(seekListener);
    holder.mGreen.setThumb(thumbGreen);
    holder.mGreen.setOnSeekBarChangeListener(seekListener);
    holder.mBlue.setThumb(thumbBlue);
    holder.mBlue.setOnSeekBarChangeListener(seekListener);
    holder.mRed.setProgress(Color.red(getColor()));
    holder.mGreen.setProgress(Color.green(getColor()));
    holder.mBlue.setProgress(Color.blue(getColor()));
    String colorString = Integer.toHexString(getColor());
    holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0));
    holder.mHex.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            holder.mHex.clearFocus();
            KeyboardUtils.hide(mContext, holder.mHex);
        }
        return false;
    });
    holder.mHex.setTextChangedListener(s -> {
        if (s.length() == 6) {
            int color = Color.parseColor("#" + s.toString());
            holder.mError.setVisibility(View.INVISIBLE);
            if (color != getColor()) {
                holder.mRed.setProgress(Color.red(color));
                holder.mGreen.setProgress(Color.green(color));
                holder.mBlue.setProgress(Color.blue(color));
            }
        } else {
            holder.mError.setVisibility(View.VISIBLE);
        }
    });
    dialog.setContext(context).setCustomView(view).setNegativeButton(R.string.cancel, v -> setActiveColor(getThemeColor())).setPositiveButton(R.string.save, saveListener).show();
}
Also used : SeekBar(android.widget.SeekBar) Drawable(android.graphics.drawable.Drawable) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ViewPager(android.support.v4.view.ViewPager) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ColorPickerPagerAdapter(com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter)

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