android.support.v7.graphics.Palette Java Examples
The following examples show how to use
android.support.v7.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: ShotActivity.java From tribbble with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shot); ButterKnife.bind(this); overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_to_left); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); mShot = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_SHOT)); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); (mShot.isAnimated() ? mGifImageLoader : mStaticImageLoader).load(bitmap -> Palette.from(bitmap).maximumColorCount(8) .generate(palette -> mShotDetailsView.bind(palette.getSwatches()))); load(); }
Example #2
Source File: ColorUtil.java From music_player with Open Software License 3.0 | 6 votes |
public static int getColor(Drawable drawable) { Palette palette = Palette.from(drawableToBitmap(drawable)).generate(); 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 { return Color.parseColor("#009688"); } }
Example #3
Source File: BlogDetailDelegate.java From CoreModule with Apache License 2.0 | 6 votes |
private Transformation getTransformation(final String t) { return new Transformation() { @Override public Bitmap transform(Bitmap b) { Palette.from(b).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(final Palette palette) { int defaultColor = rootView.getResources().getColor (android.R.color.white); int titleColor = palette.getLightVibrantColor (defaultColor); CollapsingToolbarLayout collapsingToolbar = get(R.id .collapsing_toolbar); collapsingToolbar.setExpandedTitleColor(titleColor); } }); return b; } @Override public String key() { return t; } }; }
Example #4
Source File: PlayerPresenter.java From YAAB with GNU General Public License v3.0 | 6 votes |
private void fetchColors(Bitmap img) { Palette.from(img).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); Palette.Swatch mutedSwatch = palette.getMutedSwatch(); int bodyText = 0, titleText = 0, background = 0, dominantColor = palette.getDominantColor(context.getResources().getColor(R.color.colorAccent)); if (vibrantSwatch != null && view != null) { background = vibrantSwatch.getRgb(); bodyText = vibrantSwatch.getBodyTextColor(); titleText = vibrantSwatch.getTitleTextColor(); } else if (mutedSwatch != null && view != null) { background = mutedSwatch.getRgb(); bodyText = mutedSwatch.getBodyTextColor(); titleText = mutedSwatch.getTitleTextColor(); } if (bodyText == 0 || view == null) return; bodyTextAnimator(bodyText); titleTextAnimator(titleText); backgroundAnimator(background); view.onDominantColorLoad(dominantColor); } }); }
Example #5
Source File: ExtractedColors.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
/** * The hotseat's color is defined as follows: * - 12% black for super light wallpaper * - 18% white for super dark * - 25% white otherwise */ void updateHotseatPalette(Palette hotseatPalette) { int hotseatColor; int vibrantColor; if (hotseatPalette != null) { int extractedVibrantColor = hotseatPalette.getVibrantColor(ExtractedColors.DEFAULT_COLOR); if (ExtractionUtils.isSuperLight(hotseatPalette)) { hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255)); vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.12f * 255)); } else if (ExtractionUtils.isSuperDark(hotseatPalette)) { hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255)); vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.18f * 255)); } else { hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255)); vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.25f * 255)); } setColorAtIndex(HOTSEAT_INDEX, hotseatColor); setColorAtIndex(VIBRANT_INDEX, vibrantColor); } }
Example #6
Source File: thumbSlider.java From Android-Music-Player with MIT License | 6 votes |
public int getColor(Bitmap bm){ int color = thumbRing.Color0; if(bm != null){ Palette palette = Palette.from(bm).generate(); int newColor = palette.getMutedColor(color); if(newColor == color){ newColor = palette.getVibrantColor(color); } if(newColor == color){ newColor = palette.getLightVibrantColor(color); } if(newColor == color){ newColor = palette.getDarkVibrantColor(color); } color = newColor; } //Log.i("My","Color Exacted : " + color); return color; }
Example #7
Source File: AbstractDetailActivity.java From google-io-2014-compat with Apache License 2.0 | 6 votes |
public void applyPalette(Palette palette) { Resources res = getResources(); container.setBackgroundColor(palette.getDarkMutedColor(res.getColor(R.color.default_dark_muted))); TextView titleView = (TextView) findViewById(R.id.title); titleView.setTextColor(palette.getVibrantColor(res.getColor(R.color.default_vibrant))); TextView descriptionView = (TextView) findViewById(R.id.description); descriptionView.setTextColor(palette.getLightVibrantColor(res.getColor(R.color.default_light_vibrant))); colorButton(R.id.info_button, palette.getDarkMutedColor(res.getColor(R.color.default_dark_muted)), palette.getDarkVibrantColor(res.getColor(R.color.default_dark_vibrant))); colorButton(R.id.star_button, palette.getMutedColor(res.getColor(R.color.default_muted)), palette.getVibrantColor(res.getColor(R.color.default_vibrant))); AnimatedPathView star = (AnimatedPathView) findViewById(R.id.star_container); star.setFillColor(palette.getVibrantColor(R.color.default_vibrant)); star.setStrokeColor(palette.getLightVibrantColor(res.getColor(R.color.default_light_vibrant))); }
Example #8
Source File: PaletteUtils.java From MediaNotification with Apache License 2.0 | 6 votes |
private static Palette.Swatch getBestPaletteSwatchFrom(Palette palette) { if (palette != null) { if (palette.getVibrantSwatch() != null) return palette.getVibrantSwatch(); else if (palette.getMutedSwatch() != null) return palette.getMutedSwatch(); else if (palette.getDarkVibrantSwatch() != null) return palette.getDarkVibrantSwatch(); else if (palette.getDarkMutedSwatch() != null) return palette.getDarkMutedSwatch(); else if (palette.getLightVibrantSwatch() != null) return palette.getLightVibrantSwatch(); else if (palette.getLightMutedSwatch() != null) return palette.getLightMutedSwatch(); else if (!palette.getSwatches().isEmpty()) return getBestPaletteSwatchFrom(palette.getSwatches()); } return null; }
Example #9
Source File: EyepetizerDetailActivity.java From Ency with Apache License 2.0 | 6 votes |
/** * 使用Palette改变状态颜色 */ private void initPalette() { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bg_video); Palette.Builder builder = Palette.from(bitmap); builder.generate(); // 提取颜色 builder.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(@NonNull Palette palette) { // 柔和的颜色 Palette.Swatch muted = palette.getMutedSwatch(); if (Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); // 很明显,这两货是新API才有的。 window.setStatusBarColor(ColorUtil.colorBurn(muted.getRgb())); window.setNavigationBarColor(ColorUtil.colorBurn(muted.getRgb())); } } }); }
Example #10
Source File: MovieDetailsFragment.java From udacity-p1-p2-popular-movies with MIT License | 6 votes |
@Override protected void onSuccess(Palette palette) { Activity activity = getActivity(); if (activity == null) { return; } if (palette != null && palette.getVibrantSwatch() != null) { Palette.Swatch vibrant = palette.getVibrantSwatch(); mPrimaryColor = vibrant.getRgb(); mPrimaryDarkColor = AppUtil.multiplyColor(mPrimaryColor, 0.8f); mTitleTextColor = vibrant.getTitleTextColor(); } else { mPrimaryColor = ContextCompat.getColor(activity, R.color.colorPrimary); mPrimaryDarkColor = ContextCompat.getColor(activity, R.color.colorPrimaryDark); mTitleTextColor = ContextCompat.getColor(activity, android.R.color.white); } AppUtil.setColorTheme(activity, mToolbar, mPrimaryColor, mPrimaryDarkColor, mTitleTextColor, true); if (activity instanceof PaletteCallback) { PaletteCallback callback = (PaletteCallback) activity; callback.setPalette(mPrimaryColor, mPrimaryDarkColor, mTitleTextColor); } }
Example #11
Source File: RetroMusicColorUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
public static int[] getMultipleColor(Palette palette) { int[] colors = new int[2]; if (palette != null) { if (palette.getVibrantSwatch() != null) { colors[0] = palette.getVibrantSwatch().getRgb(); } else if (palette.getMutedSwatch() != null) { colors[1] = palette.getMutedSwatch().getRgb(); } else if (palette.getDarkVibrantSwatch() != null) { colors[0] = palette.getDarkVibrantSwatch().getRgb(); } else if (palette.getDarkMutedSwatch() != null) { colors[1] = palette.getDarkMutedSwatch().getRgb(); } else if (palette.getLightVibrantSwatch() != null) { colors[0] = palette.getLightVibrantSwatch().getRgb(); } else if (palette.getLightMutedSwatch() != null) { colors[1] = palette.getLightMutedSwatch().getRgb(); } else if (!palette.getSwatches().isEmpty()) { colors[0] = Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb(); } } return colors; }
Example #12
Source File: EarnFragment.java From Ucount with GNU General Public License v3.0 | 6 votes |
public void changeBanner(IOItem tmpItem) { Bitmap bm = BitmapFactory.decodeResource(getResources(), tmpItem.getSrcId()); Palette.Builder pb = new Palette.Builder(bm); pb.maximumColorCount(1); itemImage.setImageResource(tmpItem.getSrcId()); itemTitle.setText(tmpItem.getName()); itemImage.setTag(1); // 保留图片资源属性,1表示收入 itemTitle.setTag(tmpItem.getSrcName()); // 保留图片资源名称作为标签,方便以后调用 // 获取图片颜色并改变上方banner的背景色 pb.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getSwatches().get(0); if (swatch != null) { itemLayout.setBackgroundColor(swatch.getRgb()); } else { } } }); }
Example #13
Source File: AlbumDetailActivity.java From android-animations-transitions with MIT License | 6 votes |
private void colorizeFromImage(Bitmap image) { Palette palette = Palette.from(image).generate(); // set panel colors int defaultPanelColor = 0xFF808080; int defaultFabColor = 0xFFEEEEEE; titlePanel.setBackgroundColor(palette.getDarkVibrantColor(defaultPanelColor)); trackPanel.setBackgroundColor(palette.getLightMutedColor(defaultPanelColor)); // set fab colors int[][] states = new int[][]{ new int[]{android.R.attr.state_enabled}, new int[]{android.R.attr.state_pressed} }; int[] colors = new int[]{ palette.getVibrantColor(defaultFabColor), palette.getLightVibrantColor(defaultFabColor) }; // fab.setBackgroundTintList(new ColorStateList(states, colors)); }
Example #14
Source File: ColorUtil.java From APlayer 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 #15
Source File: RecyclerAdapterFav.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 6 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { byte[] posterImage = itemsModels.get(position).getPosterImage(); holder.image.setImageBitmap(BitmapUtility.getImage(posterImage)); holder.title.setText(itemsModels.get(position).getName()); holder.genre.setText(itemsModels.get(position).getGenre()); //int vibrant = BitmapUtility.getPaletteColor(holder.image); //holder.linearLayout.setBackgroundColor(vibrant); BitmapDrawable drawable = (BitmapDrawable) holder.image.getDrawable(); Bitmap bitmap = drawable.getBitmap(); Palette palette = Palette.generate(bitmap); int defaultColor = 0xFF333333; int color = palette.getDarkMutedColor(defaultColor); holder.linearLayout.setBackgroundColor(color); }
Example #16
Source File: ColorUtils.java From Musicoco with Apache License 2.0 | 6 votes |
/** * 获得图片中出现最多的颜色 * 0 亮的活力颜色 * 1 亮的柔和颜色 */ public static void get2ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int[] colors) { if (colors.length != 2) return; Palette palette; palette = new Palette.Builder(bitmap).generate(); Palette.Swatch swatch; int color; if ((swatch = palette.getLightVibrantSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[0] = color; if ((swatch = palette.getLightMutedSwatch()) != null) color = swatch.getRgb(); else color = defaultColor; colors[1] = color; }
Example #17
Source File: PaletteManager.java From COCOFramework with Apache License 2.0 | 6 votes |
public void updatePalette(Picasso picasso, String url, final ImageView imageView, final TextView textView, final View block) { final String key = url; picasso.load(url).into(imageView, new com.squareup.picasso.Callback() { @Override public void onSuccess() { Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); getPalette(key, bitmap, new PaletteManager.Callback() { @Override public void onPaletteReady(Palette.Swatch palette) { if (palette != null) { if (block != null) block.setBackgroundColor(palette.getRgb()); if (textView != null) textView.setTextColor(palette.getTitleTextColor()); } } }); } @Override public void onError() { } }); }
Example #18
Source File: MovieDetailActivity.java From Material-Movies with Apache License 2.0 | 6 votes |
@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); } }
Example #19
Source File: ShotFragment.java From droidddle with Apache License 2.0 | 5 votes |
private void updateShotPalette(Palette palette) { mDensity = getResources().getDisplayMetrics().density; int index = 0; Palette.Swatch swatch = palette.getDarkMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getDarkVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getLightMutedSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } swatch = palette.getLightVibrantSwatch(); if (swatch != null) { setPaletteColor(index, swatch); index++; } }
Example #20
Source File: PaletteLoader.java From narrate-android with Apache License 2.0 | 5 votes |
@Override public boolean handleMessage(Message message) { switch (message.what) { case MSG_RENDER_PALETTE: Pair<Bitmap, PaletteTarget> pair = (Pair<Bitmap, PaletteTarget>) message.obj; if (pair != null && !pair.first.isRecycled()) { Palette palette = Palette.generate(pair.first); colorSchemeCache.put(pair.second.getPath(), palette); Message uiMessage = uiHandler.obtainMessage(); uiMessage.what = MSG_DISPLAY_PALETTE; uiMessage.obj = new Pair<Palette, PaletteTarget>(palette, pair.second); uiMessage.arg1 = FALSE; uiHandler.sendMessage(uiMessage); } break; case MSG_DISPLAY_PALETTE: Pair<Palette, PaletteTarget> pairDisplay = (Pair<Palette, PaletteTarget>) message.obj; boolean fromCache = message.arg1 == TRUE; applyColorToView(pairDisplay.second, pairDisplay.first, fromCache); break; } return false; }
Example #21
Source File: DetailActivity.java From MaterializeYourApp with Apache License 2.0 | 5 votes |
@SuppressWarnings("ConstantConditions") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initActivityTransitions(); setContentView(R.layout.activity_detail); ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), EXTRA_IMAGE); supportPostponeEnterTransition(); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); String itemTitle = getIntent().getStringExtra(EXTRA_TITLE); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setTitle(itemTitle); collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent)); final ImageView image = (ImageView) findViewById(R.id.image); Picasso.with(this).load(getIntent().getStringExtra(EXTRA_IMAGE)).into(image, new Callback() { @Override public void onSuccess() { Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap(); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { applyPalette(palette); } }); } @Override public void onError() { } }); TextView title = (TextView) findViewById(R.id.title); title.setText(itemTitle); }
Example #22
Source File: InfoRecyclerViewAdapter.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
private void retrieveColors(final Uri uri) { if (uri == null) { return; } int[] imageDimens = Util .getImageDimensions(itemView.getContext(), uri); RequestOptions options = new RequestOptions() .skipMemoryCache(true) .override((int) (imageDimens[0] * 0.1f), (int) (imageDimens[1] * 0.1f)) .diskCacheStrategy(DiskCacheStrategy.NONE); Glide.with(itemView.getContext()) .asBitmap() .load(uri) .apply(options) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(@NonNull final Bitmap bitmap, com.bumptech.glide.request .transition.Transition<? super Bitmap> transition) { // Do something with bitmap here. Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(@NonNull Palette palette) { p = palette; setColors(null); } }); } }); }
Example #23
Source File: Util.java From Ouroboros with GNU General Public License v3.0 | 5 votes |
public static void setSwatch(final View view, ImageViewBitmapInfo result){ if (result.getBitmapInfo() != null){ Palette.from(result.getBitmapInfo().bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getMutedSwatch(); if (swatch != null) { view.setBackgroundColor(swatch.getRgb()); } } }); } }
Example #24
Source File: DetailActivity.java From RxAndroidBootstrap with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); mActionBarSize = getActionBarSize(); mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height); image = (ImageView) findViewById(R.id.image); ViewCompat.setTransitionName(image, EXTRA_IMAGE); collapsingToolbar.setTitle(getIntent().getStringExtra(EXTRA_TITLE)); bitmapImageViewTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { Palette.generateAsync(bitmap, DetailActivity.this); image.setImageBitmap(bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { //place your code here } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { //place your code here } }; Picasso.with(this).load(getIntent().getStringExtra(EXTRA_IMAGE)).into(bitmapImageViewTarget); }
Example #25
Source File: SwatchAdapter.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
public void sortSwatches() { sort(new Comparator<Palette.Swatch>() { @Override public int compare( Palette.Swatch lhs, Palette.Swatch rhs ) { return rhs.getPopulation() - lhs.getPopulation(); } }); }
Example #26
Source File: ColorUtils.java From Protein with Apache License 2.0 | 5 votes |
/** * Checks if the most populous color in the given palette is dark * <p/> * Annoyingly we have to return this Lightness 'enum' rather than a boolean as palette isn't * guaranteed to find the most populous color. */ public static @Lightness int isDark(Palette palette) { Palette.Swatch mostPopulous = getMostPopulousSwatch(palette); if (mostPopulous == null) return LIGHTNESS_UNKNOWN; return isDark(mostPopulous.getHsl()) ? IS_DARK : IS_LIGHT; }
Example #27
Source File: MainActivity.java From music-player with MIT License | 5 votes |
public void setStatusBar(Palette palette){ Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Palette.Swatch vibrant = palette.getDominantSwatch(); if (vibrant != null) { window.setStatusBarColor(vibrant.getRgb()); } } }
Example #28
Source File: ColorUtils.java From materialup with Apache License 2.0 | 5 votes |
/** * Determines if a given bitmap is dark. This extracts a palette inline so should not be called * with a large image!! If palette fails then check the color of the specified pixel */ public static boolean isDark(@NonNull Bitmap bitmap, int backupPixelX, int backupPixelY) { // first try palette with a small color quant size Palette palette = Palette.from(bitmap).maximumColorCount(3).generate(); if (palette != null && palette.getSwatches().size() > 0) { return isDark(palette) == IS_DARK; } else { // if palette failed, then check the color of the specified pixel return isDark(bitmap.getPixel(backupPixelX, backupPixelY)); } }
Example #29
Source File: NavigationActivity.java From android with Apache License 2.0 | 5 votes |
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { headerViewHolder.imgClubLogo.setImageBitmap(bitmap); Palette.from(bitmap).generate(palette -> { int[] colors = { palette.getDarkVibrantColor(DEFAULT_DARK_VIBRANT_COLOR), palette.getLightVibrantColor(DEFAULT_LIGHT_VIBRANT_COLOR) }; ColorUtilsKt.setLinearBackgroundGradient(colors, headerViewHolder.navHeaderLayout); }); }
Example #30
Source File: MainActivity.java From RxPalette with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(final ImageHolder holder, int position) { Image image = images.get(position); Glide.with(holder.imageView.getContext()) .load(image.link) .crossFade() .centerCrop() .listener(new BitmapListener() { @Override public void onBitmapReady(Bitmap bitmap) { RxPalette.generate(bitmap) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Palette>() { @Override public void accept(Palette palette) { Palette.Swatch swatch = palette.getVibrantSwatch() != null ? palette.getVibrantSwatch() : palette.getMutedSwatch(); holder.textView.setTextColor(swatch != null ? swatch.getTitleTextColor() : Color.BLACK); holder.textView.setBackgroundColor(swatch != null ? swatch.getRgb() : Color.WHITE); } }); } }) .into(holder.imageView); }