Java源码示例:android.support.v7.graphics.Palette

示例1
@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();
}
 
示例2
@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);
    }
}
 
示例3
@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);

}
 
示例4
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() {

        }
    });

}
 
示例5
/**
 * 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);
    }
}
 
示例6
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);
        }
    });

}
 
示例7
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");
    }
}
 
示例8
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;
        }
    };
}
 
示例9
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;
}
 
示例10
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 {

            }
        }
    });

}
 
示例11
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));
    }
 
示例12
/**
 * 获得图片中出现最多的颜色
 * 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;

}
 
示例13
@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;
}
 
示例14
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)));
}
 
示例15
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;
}
 
示例16
/**
 * 使用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()));
            }
        }
    });
}
 
示例17
@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);
    }
}
 
示例18
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;
}
 
示例19
@Override
public void setThemeColor(@Nullable Palette palette) {
    if (palette != null) {
        int colorPrimary = App.getInstance().getResources().getColor(R.color.colorPrimary);
        // 把从调色板上获取的主题色保存在内存中
        ThemeManage.INSTANCE.setColorPrimary(palette.getDarkVibrantColor(colorPrimary));
        // 设置 AppBarLayout 的背景色
        mHomeView.setAppBarLayoutColor(ThemeManage.INSTANCE.getColorPrimary());
        // 设置 FabButton 的背景色
        mHomeView.setFabButtonColor(ThemeManage.INSTANCE.getColorPrimary());
        // 停止 FabButton 加载中动画
        mHomeView.enableFabButton();
        mHomeView.stopBannerLoadingAnim();
    }
}
 
示例20
public static int[] colorsFor(Resources res, String avatar) {

        int[] colors = new int[]{R.color.android_blue, R.color.android_blue_light};

        if (!cache.containsKey(avatar) && avatars.containsKey(avatar)) {
            Bitmap bm = BitmapFactory.decodeResource(res, avatars.get(avatar));
            if (bm != null) {
                Palette p = Palette.generate(bm);
                colors = new int[]{p.getVibrantColor(R.color.android_blue), p.getLightVibrantColor(R.color.android_blue_light)};
            }
            cache.put(avatar, colors);
        }
        return cache.get(avatar);
    }
 
示例21
@TargetApi(Build.VERSION_CODES.N)
private Palette getHotseatPalette() {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    if (AndroidVersion.isAtLeastNougat) {
        try (ParcelFileDescriptor fd = wallpaperManager
                .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
            BitmapRegionDecoder decoder = BitmapRegionDecoder
                    .newInstance(fd.getFileDescriptor(), false);
            int height = decoder.getHeight();
            Rect decodeRegion = new Rect(0, (int) (height * (1f - HOTSEAT_FRACTION)),
                    decoder.getWidth(), height);
            Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
            decoder.recycle();
            if (bitmap != null) {
                return Palette.from(bitmap).clearFilters().generate();
            }
        } catch (IOException | NullPointerException e) {
            e.printStackTrace();
        }
    }

    Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
    return Palette.from(wallpaper)
            .setRegion(0, (int) (wallpaper.getHeight() * (1f - HOTSEAT_FRACTION)),
                    wallpaper.getWidth(), wallpaper.getHeight())
            .clearFilters()
            .generate();
}
 
示例22
@TargetApi(Build.VERSION_CODES.N)
private Palette getStatusBarPalette() {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    int statusBarHeight = getResources()
            .getDimensionPixelSize(R.dimen.status_bar_height);

    if (AndroidVersion.isAtLeastNougat) {
        try (ParcelFileDescriptor fd = wallpaperManager
                .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
            BitmapRegionDecoder decoder = BitmapRegionDecoder
                    .newInstance(fd.getFileDescriptor(), false);
            Rect decodeRegion = new Rect(0, 0,
                    decoder.getWidth(), statusBarHeight);
            Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
            decoder.recycle();
            if (bitmap != null) {
                return Palette.from(bitmap).clearFilters().generate();
            }
        } catch (IOException | NullPointerException e) {
            e.printStackTrace();
        }
    }

    Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
    return Palette.from(wallpaper)
            .setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
            .clearFilters()
            .generate();
}
 
示例23
/**
 * Given a color, returns true if that color is legible on
 * the given wallpaper color swatches, else returns false.
 */
private static boolean isLegibleOnWallpaper(int color, List<Palette.Swatch> wallpaperSwatches) {
    int legiblePopulation = 0;
    int illegiblePopulation = 0;
    for (Palette.Swatch swatch : wallpaperSwatches) {
        if (isLegible(color, swatch.getRgb())) {
            legiblePopulation += swatch.getPopulation();
        } else {
            illegiblePopulation += swatch.getPopulation();
        }
    }
    return legiblePopulation > illegiblePopulation;
}
 
示例24
private static ArrayList<Integer> palette(Palette p, int defaultColor) {

        ArrayList<Integer> extractedPalette = new ArrayList<>();

        //get all palettes
        Integer lightVibrant, vibrant, darkVibrant, lightMuted, muted, darkMuted;

        lightVibrant = p.getVibrantColor(defaultColor);
        vibrant = p.getVibrantColor(defaultColor);
        darkVibrant = p.getDarkVibrantColor(defaultColor);
        lightMuted = p.getLightMutedColor(defaultColor);
        muted = p.getMutedColor(defaultColor);
        darkMuted = p.getDarkMutedColor(defaultColor);

        extractedPalette.add(lightVibrant);
        extractedPalette.add(vibrant);
        extractedPalette.add(darkVibrant);
        extractedPalette.add(lightMuted);
        extractedPalette.add(muted);
        extractedPalette.add(darkMuted);

        //add also default color, because if the next method fails we have a color anyway
        extractedPalette.add(defaultColor);

        //pass these palettes to a hashset to avoid duplicates
        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.addAll(extractedPalette);

        //add back these values to the palettes array list
        extractedPalette.clear();
        extractedPalette.addAll(hashSet);

        return extractedPalette;
    }
 
示例25
@Override public Resource<Palette> decode(InputStream source, int width, int height) throws IOException {
	try {
		ObjectInputStream stream = new ObjectInputStream(source);
		PaletteSerializer palette = (PaletteSerializer)stream.readObject();
		Log.d("PALETTE", "Palette loaded");
		return new SimpleResource<>(palette.getPalette());
	} catch (Exception e) {
		Log.w("PALETTE", "Cannot deserialize", e);
		throw new IOException("Cannot read palette", e);
	}
}
 
示例26
@Override
protected Palette doInBackground(Void... params) {
    Palette palette = MizuuApplication.getPalette(getPaletteKey());

    if (palette == null) {
        try {
            palette = Palette.generate(mPicasso.load(getImage()).get());
        } catch (IOException e) {}
    }

    return palette;
}
 
示例27
private void changeUIColors(Bitmap bitmap) {
    Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
        public void onGenerated(Palette palette) {
            int defaultColor = 0xFF333333;
            int darkMutedColor = palette.getDarkMutedColor(defaultColor);
            metaBar.setBackgroundColor(darkMutedColor);
            if (mCollapsingToolbarLayout != null) {
                mCollapsingToolbarLayout.setContentScrimColor(darkMutedColor);
                mCollapsingToolbarLayout.setStatusBarScrimColor(darkMutedColor);
            }
        }
    });
}
 
示例28
@Override
public void run() {
    if (bitmap != null && !bitmap.isRecycled()) {
        Palette colorScheme = Palette.generate(bitmap);
        colorSchemeCache.put(paletteTarget.getPath(), colorScheme);

        PalettePresenter palettePresenter = new PalettePresenter(
                paletteTarget,
                colorScheme,
                false
        );
        uiHandler.post(palettePresenter);
    }
}
 
示例29
private static Palette.Swatch getBestPaletteSwatchFrom(List<Palette.Swatch> swatches) {
    if (swatches == null) return null;
    return Collections.max(swatches, new Comparator<Palette.Swatch>() {
        @Override
        public int compare(Palette.Swatch opt1, Palette.Swatch opt2) {
            int a = opt1 == null ? 0 : opt1.getPopulation();
            int b = opt2 == null ? 0 : opt2.getPopulation();
            return a - b;
        }
    });
}
 
示例30
public void paletteToolbar(){
    //collapsingToolbar.setcon
    imageLoader.displayImage(user.getAvatar_url(), backDrop, option, new AnimateFirstDisplayListener() {
        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            super.onLoadingComplete(imageUri, view, loadedImage);

            Palette.generateAsync(loadedImage, 24, new Palette.PaletteAsyncListener() {
                @Override
                public void onGenerated(Palette palette) {

                    Palette.Swatch vibrant = palette.getVibrantSwatch();
                    Palette.Swatch darkVibrant = palette.getDarkVibrantSwatch();
                    Palette.Swatch lightVibrant = palette.getLightVibrantSwatch();
                    Palette.Swatch muted = palette.getMutedSwatch();
                    Palette.Swatch darkMuted = palette.getDarkMutedSwatch();
                    Palette.Swatch lightMuted = palette.getLightMutedSwatch();
                    Palette.Swatch swatch = vibrant;
                    swatch = (swatch == null) ? muted : swatch;
                    swatch = (swatch == null) ? darkVibrant : swatch;
                    swatch = (swatch == null) ? darkMuted : swatch;
                    swatch = (swatch == null) ? lightVibrant : swatch;
                    swatch = (swatch == null) ? lightMuted : swatch;
                    collapsingToolbar.setContentScrim(new ColorDrawable(swatch.getRgb()));
                }
            });
        }
    });
}