androidx.palette.graphics.Palette Java Examples
The following examples show how to use
androidx.palette.graphics.Palette.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PaletteTransformation.java From cathode with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap source) { if (!shouldTransform) { return source; } Palette palette = Palette.from(source).generate(); final int sourceWidth = source.getWidth(); final int sourceHeight = source.getHeight(); final Paint paint = new Paint(); paint.setColor(palette.getVibrantColor(0xFF1C1C1E)); Bitmap output = Bitmap.createBitmap(sourceWidth, sourceHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRect(new Rect(0, 0, sourceWidth, sourceHeight), paint); if (source != output) { source.recycle(); } return output; }
Example #2
Source File: PhonographColorUtil.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example #3
Source File: PaletteGeneratorTask.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
private boolean getColor() { Bitmap bitmap; try { bitmap = Picasso.get().load(Util.getAlbumArtUri(MusicPlayerRemote.getCurrentSong().albumId)).error(R.drawable.speaker2).get(); } catch (Exception e) { Context context = mWeakRefContext.get(); if(context!=null) bitmap = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.speaker2)).getBitmap(); else bitmap = null; } if(bitmap==null) return false; int color = getMostColor(bitmap); Tool.setMostCommonColor(color); Tool.setSurfaceColor(color); Palette palette = Palette.from(bitmap).generate(); return !onGeneratedPalette(palette); }
Example #4
Source File: VinylMusicPlayerColorUtil.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example #5
Source File: PlayPauseButton.java From MusicBobber with MIT License | 6 votes |
public void albumCover(Drawable newAlbumCover) { if(this.albumCover == newAlbumCover) return; this.albumCover = newAlbumCover; if(albumCover instanceof BitmapDrawable && !isNeedToFillAlbumCoverMap.containsKey(albumCover.hashCode())) { Bitmap bitmap = ((BitmapDrawable) albumCover).getBitmap(); if(bitmap != null && !bitmap.isRecycled()) { if(lastPaletteAsyncTask != null && !lastPaletteAsyncTask.isCancelled()) { lastPaletteAsyncTask.cancel(true); } lastPaletteAsyncTask = Palette.from(bitmap).generate(palette -> { int dominantColor = palette.getDominantColor(Integer.MAX_VALUE); if(dominantColor != Integer.MAX_VALUE) { Color.colorToHSV(dominantColor, hsvArray); isNeedToFillAlbumCoverMap.put(albumCover.hashCode(), hsvArray[2] > 0.65f); postInvalidate(); } }); } } postInvalidate(); }
Example #6
Source File: PaletteActivity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
private void magic(int id) { Palette.Builder builder = new Palette.Builder(BitmapFactory.decodeResource(getResources(), id)); Palette palette = builder.generate(); Optional.ofNullable(palette) .ifPresent(p -> { Palette.Swatch swatch = getSwatch(p); if (swatch != null) { mContent.setTextColor(swatch.getRgb()); mToolbarLayout.setExpandedTitleColor(Color.WHITE); mToolbarLayout.setCollapsedTitleTextColor(swatch.getTitleTextColor()); mToolbarLayout.setBackgroundColor(swatch.getRgb()); mToolbarLayout.setContentScrimColor(swatch.getRgb()); mToolbarLayout.setTitle(String.valueOf(swatch.getRgb())); fab.setBackgroundColor(swatch.getRgb()); fab.setRippleColor(swatch.getRgb()); StatusBarUtil.setColor(PaletteActivity.this, swatch.getRgb(), 0); } }); }
Example #7
Source File: MusicColorUtil.java From Music-Player with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example #8
Source File: PhonographColorUtil.java From Phonograph with GNU General Public License v3.0 | 6 votes |
@ColorInt public static int getColor(@Nullable Palette palette, int fallback) { if (palette != null) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { return palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return fallback; }
Example #9
Source File: MainActivity.java From ui with Apache License 2.0 | 6 votes |
private void dynamicToolbarColor() { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.wolf_gray); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { //a dark color a dark blue collapsingToolbarLayout.setContentScrimColor(palette.getDarkVibrantColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))); //a muted color mostly gray //collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))); //dark muted color very dark blue, almost black. // collapsingToolbarLayout.setContentScrimColor(palette.getDarkMutedColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))); //very bright color //collapsingToolbarLayout.setContentScrimColor(palette.getLightVibrantColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))); //this one doesn't seem to do anything. //collapsingToolbarLayout.setStatusBarScrimColor(palette.getDarkMutedColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark))); } }); }
Example #10
Source File: MoviesListingAdapter.java From MovieGuide with MIT License | 6 votes |
@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)); } }); }
Example #11
Source File: AlbumItemViewModel.java From Jockey with Apache License 2.0 | 6 votes |
private Palette.Swatch pickSwatch(Palette palette) { if (palette.getVibrantSwatch() != null) { return palette.getVibrantSwatch(); } if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantSwatch(); } if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantSwatch(); } if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedSwatch(); } if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedSwatch(); } return null; }
Example #12
Source File: AlbumItemViewModel.java From Jockey with Apache License 2.0 | 6 votes |
@Override public boolean onResourceReady(GlideDrawable resource, File model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (sColorMap.containsKey(model)) { Palette.Swatch swatch = sColorMap.get(model); if (isFromMemoryCache) { setSwatch(swatch); } else { animateSwatch(swatch); } } else { generateSwatch(model, resource); } return false; }
Example #13
Source File: AppSyncWorker.java From zephyr with MIT License | 5 votes |
@ColorInt private int getAppColor(@NonNull Palette palette, @ColorInt int defaultColor) { if (palette.getDarkVibrantSwatch() != null) { return palette.getDarkVibrantColor(defaultColor); } if (palette.getVibrantSwatch() != null) { return palette.getVibrantColor(defaultColor); } if (palette.getMutedSwatch() != null) { return palette.getMutedColor(defaultColor); } if (palette.getDarkMutedSwatch() != null) { return palette.getDarkMutedColor(defaultColor); } if (palette.getLightMutedSwatch() != null) { return palette.getLightMutedColor(defaultColor); } if (palette.getLightVibrantSwatch() != null) { return palette.getLightVibrantColor(defaultColor); } return defaultColor; }
Example #14
Source File: PaletteActivity.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
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 = findViewById(R.id.paletteRecycler); rvPalette.setLayoutManager(new LinearLayoutManager(this)); rvPalette.setNestedScrollingEnabled(false); paletteAdapter = new PaletteAdapter(palette.getSwatches()); rvPalette.setAdapter(paletteAdapter); }
Example #15
Source File: ColorUtil.java From HaoReader with GNU General Public License v3.0 | 5 votes |
public static Palette.Swatch getMostPopulousSwatch(Palette palette) { Palette.Swatch mostPopulous = null; if (palette != null) { for (Palette.Swatch swatch : palette.getSwatches()) { if (mostPopulous == null || swatch.getPopulation() > mostPopulous.getPopulation()) { mostPopulous = swatch; } } } return mostPopulous; }
Example #16
Source File: PaletteActivity.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
@Override public void onBindViewHolder(final PaletteActivity.PaletteAdapter.ViewHolder holder, final int position) { Palette.Swatch sw = swatches.get(position); holder.txtColor.setTextColor(sw.getTitleTextColor()); holder.txtColor.setText(String.format("#%06X", (0xFFFFFF & sw.getRgb()))); holder.itemBackground.setBackgroundColor(sw.getRgb()); }
Example #17
Source File: ExtraUtils.java From Bop with Apache License 2.0 | 5 votes |
public static int getSwatchColor(Bitmap bitmap) { Palette p = Palette.from(bitmap).generate(); Palette.Swatch vibrantSwatch = p.getVibrantSwatch(); if (vibrantSwatch != null) { return vibrantSwatch.getBodyTextColor(); } return Color.WHITE; }
Example #18
Source File: DetailActivity.java From GetApk with MIT License | 5 votes |
private void setColors(Bitmap bitmap, boolean recycle) { Palette.from(bitmap).generate(palette -> { if (recycle) { bitmap.recycle(); } if (palette != null) { Palette.Swatch swatch = palette.getDominantSwatch(); if (swatch != null) { int color = swatch.getRgb(); mToolbarLayout.setBackgroundColor(color); mToolbarLayout.setContentScrimColor(color); mToolbarLayout.setStatusBarScrimColor(color); int titleColor = swatch.getBodyTextColor(); mToolbar.setTitleTextColor(titleColor); mToolbar.setNavigationIcon(DrawableHelper.tintDrawable(this, R.drawable.ic_arrow_back_white_24dp, ColorStateList.valueOf(titleColor), null)); mToolbarLayout.setExpandedTitleColor(titleColor); mToolbarLayout.setCollapsedTitleTextColor(titleColor); mToolbar.getMenu().getItem(0).setIcon(DrawableHelper.tintDrawable(this, R.drawable.ic_export, ColorStateList.valueOf(titleColor), null)); } swatch = palette.getDarkVibrantSwatch(); if (swatch != null) { mFab.setSupportBackgroundTintList(ColorStateList.valueOf(swatch.getRgb())); mFab.setSupportImageTintList(ColorStateList.valueOf(swatch.getBodyTextColor())); } } }); }
Example #19
Source File: PaletteExtraction.java From StoryView with MIT License | 5 votes |
@Override public void onPostExecute(Palette aPalette) { super.onPostExecute(aPalette); View view = viewWeakReference.get(); if (view == null) return; GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{aPalette.getDarkVibrantColor(0), aPalette.getLightMutedColor(0)}); drawable.setCornerRadius(0f); view.setBackground(drawable); }
Example #20
Source File: CreditCardRow.java From RandomData with Apache License 2.0 | 5 votes |
@Override public void bind(CreditCardItem data) { super.bind(data); LinearLayout scrim = ((CreditcardBinding) getBinding()).scrim; int mutedColor = Palette.from(((BitmapDrawable) data.getImage()).getBitmap()).generate().getMutedColor(0); scrim.setBackgroundColor(mutedColor); }
Example #21
Source File: PaletteUtils.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public static int getMagicColor(Resources resources, int id) { Palette.Builder builder = new Palette.Builder(BitmapFactory.decodeResource(resources, id)); Palette palette = builder.generate(); return Optional.ofNullable(palette) .map(PaletteUtils::getSwatch) .map(Palette.Swatch::getRgb) .orElseGet(() -> 0); }
Example #22
Source File: PaletteUtils.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public static int getMagicColor(Bitmap bitmap) { Palette.Builder builder = new Palette.Builder(bitmap); Palette palette = builder.generate(); return Optional.ofNullable(palette) .map(PaletteUtils::getSwatch) .map(Palette.Swatch::getRgb) .orElseGet(() -> 0); }
Example #23
Source File: AlbumItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
private void animateSwatch(Palette.Swatch swatch) { if (swatch == null) { return; } animateColorValue(mBackgroundColor, swatch.getRgb()); animateColorValue(mTitleTextColor, swatch.getTitleTextColor()); animateColorValue(mArtistTextColor, swatch.getBodyTextColor()); }
Example #24
Source File: AlbumItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
private void setSwatch(Palette.Swatch swatch) { if (swatch == null) { return; } mBackgroundColor.set(swatch.getRgb()); mTitleTextColor.set(swatch.getTitleTextColor()); mArtistTextColor.set(swatch.getBodyTextColor()); }
Example #25
Source File: ImageLoader.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
public void loadWithPalettePlaceholder(String url, BitmapDrawable paletteSrcImage, @ColorInt int defaultColor, ImageView targetImageView) { Palette.from(paletteSrcImage.getBitmap()) .maximumColorCount(6) .generate(palette -> loadWithColorPlaceholder(url, palette.getDominantColor(defaultColor), targetImageView)); }
Example #26
Source File: MainActivity.java From SimplicityBrowser with MIT License | 5 votes |
public void refreshTab() { mWebView = TabManager.getCurrentTab(); mWebView.setLayoutParams(new SwipeRefreshLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipe = new RelativeLayout(this); ViewGroup group = (ViewGroup) mWebView.getParent(); if (group != null) { group.removeAllViews(); } swipe.addView(mWebView); for (int i = 0; i < root.getChildCount(); i++) { if (root.getChildAt(i) instanceof GridView) { } else { View view = root.getChildAt(i); root.removeView(view); } } root.addView(swipe); if (mWebView.getUrl() == null) { mSearchView.setText(homepage); } else { mSearchView.setText(mWebView.getUrl()); } if (mWebView.getFavicon() != null && StaticUtils.isLollipop()) { setColor(Palette.from(mWebView.getFavicon()).generate().getVibrantColor(Palette.from(mWebView.getFavicon()).generate().getMutedColor(ContextCompat.getColor(MainActivity.this, R.color.no_fav)))); }else{ setColor(ContextCompat.getColor(MainActivity.this, R.color.no_fav)); } }
Example #27
Source File: SlideFragment.java From gallery-app-android with MIT License | 5 votes |
@Override public void onGenerated(Palette palette) { hasPalette = true; target = null; int black = getResources().getColor(android.R.color.black); int white = getResources().getColor(android.R.color.white); colorDarkMuted = palette.getDarkMutedColor(black); colorVibrant = palette.getVibrantColor(white); colorLightMuted = palette.getLightMutedColor(white); applyColor(); sendPalette(); }
Example #28
Source File: SlideFragment.java From gallery-app-android with MIT License | 5 votes |
private void displayPhoto() { Picasso.get().load(Utils.imageUrl(image.photo().url())) .resize(Const.IMAGE_WIDTH, Const.IMAGE_HEIGHT) .centerCrop() .into(target = new TargetAdapter() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { SlideFragment.this.bitmap = bitmap; applyImage(); paletteTask = new Palette.Builder(bitmap) .maximumColorCount(32) .generate(SlideFragment.this); } }); }
Example #29
Source File: ThemePrefs.java From Easy_xkcd with Apache License 2.0 | 5 votes |
public boolean bitmapContainsColor(Bitmap bitmap, int comicNumber) { if(comicNumber == 1913) //https://github.com/T-Rex96/Easy_xkcd/issues/116 return true; if (comicNumber == 2018) //This one doesn't work w/o the yellow color return true; if (dontDetectColors()) return false; try { Palette palette = Palette.from(bitmap).generate(); return palette.getVibrantSwatch() != null; } catch (Exception e) { return false; } }
Example #30
Source File: AlbumItemViewModel.java From Jockey with Apache License 2.0 | 5 votes |
private void generateSwatch(File source, Drawable image) { Palette.from(ViewUtils.drawableToBitmap(image)).generate(palette -> { Palette.Swatch swatch = pickSwatch(palette); sColorMap.put(source, swatch); animateSwatch(swatch); }); }