Java Code Examples for android.support.v7.graphics.Palette#Builder
The following examples show how to use
android.support.v7.graphics.Palette#Builder .
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: 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 2
Source File: CostFragment.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 { Log.d(TAG, "changeBanner: "); } } }); }
Example 3
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 4
Source File: PaletteUtils.java From AccountBook with GNU General Public License v3.0 | 5 votes |
/** * 通过 bitmap 对象获取其中的主色值。 * @param bitmap * @return */ public static int getColorRgb(Bitmap bitmap) { Palette.Builder b = new Palette.Builder(bitmap); b.maximumColorCount(1); Palette palette = b.generate(); if(palette.getSwatches().size() > 0){ Palette.Swatch swatch = palette.getSwatches().get(0); if(swatch != null){ return swatch.getRgb(); } }else{ return palette.getLightVibrantColor(UiUtils.getColor(R.color.colorAccent)); } return -1; }
Example 5
Source File: UserInfoActivity.java From nono-android with GNU General Public License v3.0 | 5 votes |
private int autoColor(Bitmap bitmap) { Palette.Builder b = Palette.from(bitmap); Palette palette = b.generate(); Palette.Swatch s0 = palette.getVibrantSwatch(); if (s0 != null) { return s0.getRgb(); }else { for(Palette.Swatch s:palette.getSwatches()){ if(s!=null){ return s.getRgb(); } } } return 0; }
Example 6
Source File: RxPalette.java From RxPalette with Apache License 2.0 | 5 votes |
/** * Returns a {@linkplain Single single} that emits a {@linkplain Palette palette} from the source {@code bitmap} */ @CheckResult @NonNull public static Single<Palette> generate(@NonNull final Palette.Builder builder) { return Single.fromCallable(new Callable<Palette>() { @Override public Palette call() throws Exception { return builder.generate(); } }); }
Example 7
Source File: RxPaletteTest.java From RxPalette with Apache License 2.0 | 5 votes |
@Test public void testNullBuilderGenerate() { TestSubscriber<Palette> testSubscriber = new TestSubscriber<>(); Palette.Builder nullBuilder = null; //noinspection ConstantConditions RxPalette.generate(nullBuilder) .test() .assertError(NullPointerException.class); }
Example 8
Source File: PaletteActivity.java From MaterialDesignDemo with MIT License | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_palette); mIvPic = (ImageView) findViewById(R.id.ivPic); mTvBody = (TextView) findViewById(R.id.tvBody); mTvTitle = (TextView) findViewById(R.id.tvTitle); mTvDarkMutedColor = (TextView) findViewById(R.id.tvDarkMutedColor); mTvLightMutedColor = (TextView) findViewById(R.id.tvLightMutedColor); mTvDarkVibrantColor = (TextView) findViewById(R.id.tvDarkVibrantColor); mTvLightVibrantColor = (TextView) findViewById(R.id.tvLightVibrantColor); mTvMutedColor = (TextView) findViewById(R.id.tvMutedColor); mTvVibrantColor = (TextView) findViewById(R.id.tvVibrantColor); BitmapDrawable drawable = (BitmapDrawable) mIvPic.getDrawable(); Bitmap bitmap = drawable.getBitmap(); Palette.Builder builder = Palette.from(bitmap); builder.maximumColorCount(32); // 构建Palette时使用的最大颜色数,默认是16,风景图推荐取值8-16,人脸图像推荐取值24-32(值越大,花费的时间越长,可选择的色彩越多) // .setRegion(0, 0, bitmap.getWidth() - 1, bitmap.getHeight()) // 设置Palette颜色分析的图像区域 // .addFilter(new Palette.Filter() { // 设置过滤器来过滤不需要的颜色(目前还不清楚怎么用,网上也找不到任何教程及代码,无从学习~) // @Override // public boolean isAllowed(int rgb, float[] hsl) { // return false; // } // }) // .clearRegion() // .clearFilters(); builder.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // 暗、柔和 int darkMutedColor = palette.getDarkMutedColor(Color.BLACK); // 亮、柔和 int lightMutedColor = palette.getLightMutedColor(Color.BLACK); // 暗、鲜艳 int darkVibrantColor = palette.getDarkVibrantColor(Color.BLACK); // 亮、鲜艳 int lightVibrantColor = palette.getLightVibrantColor(Color.BLACK); // 柔和 int mutedColor = palette.getMutedColor(Color.BLACK); // 鲜艳 int vibrantColor = palette.getVibrantColor(Color.BLACK); // 获取某种色调的样品(这里指柔和的暗色) Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch(); // 获取图片的整体颜色rgb混合值---主色调 int rgb = darkMutedSwatch.getRgb(); // 获取图片中间的文字颜色 int bodyTextColor = darkMutedSwatch.getBodyTextColor(); // 获取作为标题的颜色(有一定的和图片的对比度的颜色值) int titleTextColor = darkMutedSwatch.getTitleTextColor(); // 颜色向量 float[] hsl = darkMutedSwatch.getHsl(); // 分析该颜色在图片中所占像素值 int population = darkMutedSwatch.getPopulation(); mTvBody.setBackgroundColor(generateTransparentColor(0.2f, rgb)); mTvBody.setTextColor(bodyTextColor); mTvTitle.setBackgroundColor(generateTransparentColor(0.6f, rgb)); mTvTitle.setTextColor(titleTextColor); mTvDarkMutedColor.setBackgroundColor(darkMutedColor); mTvLightMutedColor.setBackgroundColor(lightMutedColor); mTvDarkVibrantColor.setBackgroundColor(darkVibrantColor); mTvLightVibrantColor.setBackgroundColor(lightVibrantColor); mTvMutedColor.setBackgroundColor(mutedColor); mTvVibrantColor.setBackgroundColor(vibrantColor); } }); }
Example 9
Source File: BitmapPalette.java From GlidePalette with Apache License 2.0 | 4 votes |
@NonNull Palette.Builder intercept(Palette.Builder builder);