コード例 #1
0
 public static boolean isLightColor(Bitmap bitmap) {
   Palette palette = Palette.from(bitmap).generate();
   if (palette.getSwatches().size() > 0) {
     return isLightColor(palette);
   }
   return isLightColor(palette);
 }
コード例 #2
0
ファイル: Utils.java プロジェクト: yezi34880/Meizi
  public static int getPaletteColor(Bitmap bitmap) {
    int color = -12417291;
    Palette p = Palette.from(bitmap).generate();
    Palette.Swatch vibrant = p.getVibrantSwatch();
    Palette.Swatch vibrantdark = p.getDarkVibrantSwatch();
    Palette.Swatch vibrantlight = p.getLightVibrantSwatch();
    Palette.Swatch Muted = p.getMutedSwatch();
    Palette.Swatch Muteddark = p.getDarkMutedSwatch();
    Palette.Swatch Mutedlight = p.getLightMutedSwatch();

    if (vibrant != null) {
      color = vibrant.getRgb();
    } else if (vibrantdark != null) {
      color = vibrantdark.getRgb();
    } else if (vibrantlight != null) {
      color = vibrantlight.getRgb();
    } else if (Muted != null) {
      color = Muted.getRgb();
    } else if (Muteddark != null) {
      color = Muteddark.getRgb();
    } else if (Mutedlight != null) {
      color = Mutedlight.getRgb();
    }
    return color;
  }
コード例 #3
0
 @Override
 public boolean onResourceReady(
     Bitmap resource,
     String model,
     Target<Bitmap> target,
     boolean isFromMemoryCache,
     boolean isFirstResource) {
   Palette.Builder builder = Palette.from(resource);
   builder.generate(
       new Palette.PaletteAsyncListener() {
         @Override
         public void onGenerated(Palette palette) {
           Palette.Swatch swatch = palette.getVibrantSwatch();
           if (swatch != null) {
             mToolbarLayout.setBackgroundColor(swatch.getRgb());
             mToolbarLayout.setContentScrimColor(swatch.getRgb());
             mToolbarLayout.setCollapsedTitleTextColor(swatch.getTitleTextColor());
             mToolbarLayout.setStatusBarScrimColor(deeper(swatch.getRgb()));
             if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
               Window window = mActivity.getWindow();
               window.setStatusBarColor(deeper(swatch.getRgb()));
               window.setNavigationBarColor(deeper(swatch.getRgb()));
             }
           }
         }
       });
   return false;
 }
コード例 #4
0
ファイル: PaletteActivity.java プロジェクト: xfmax/Lollipop
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
      Uri uri = data.getData();
      ContentResolver cr = getContentResolver();
      try {
        Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
        image.setImageBitmap(bitmap);
        Palette palette = Palette.from(bitmap).generate();
        Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
        if (vibrantSwatch != null) {
          cardViews[0].setCardBackgroundColor(vibrantSwatch.getRgb());
        } else {
          cardViews[0].setCardBackgroundColor(Color.WHITE);
        }
        Palette.Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();
        if (darkVibrantSwatch != null) {
          cardViews[1].setCardBackgroundColor(darkVibrantSwatch.getRgb());
        } else {
          cardViews[1].setCardBackgroundColor(Color.WHITE);
        }
        Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();
        if (lightVibrantSwatch != null) {
          cardViews[2].setCardBackgroundColor(lightVibrantSwatch.getRgb());
        } else {
          cardViews[2].setCardBackgroundColor(Color.WHITE);
        }
        Palette.Swatch mutedSwatch = palette.getMutedSwatch();
        if (mutedSwatch != null) {
          cardViews[3].setCardBackgroundColor(mutedSwatch.getRgb());
        } else {
          cardViews[3].setCardBackgroundColor(Color.WHITE);
        }
        Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
        if (darkMutedSwatch != null) {
          cardViews[4].setCardBackgroundColor(darkMutedSwatch.getRgb());
        } else {
          cardViews[4].setCardBackgroundColor(Color.WHITE);
        }
        Palette.Swatch lightMutedSwatch = palette.getLightMutedSwatch();
        if (lightMutedSwatch != null) {
          cardViews[5].setCardBackgroundColor(lightMutedSwatch.getRgb());
        } else {
          cardViews[5].setCardBackgroundColor(Color.WHITE);
        }

      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #5
0
 public static int getColorFromIcon(Drawable icon, final Context context) {
   Palette palette = Palette.from(Utils.drawableToBitmap(icon)).generate();
   int resultColor = getBetterColor(palette.getVibrantColor(0));
   if (resultColor == 0) {
     resultColor = getBetterColor(palette.getMutedColor(0));
   }
   if (resultColor == 0) {
     resultColor =
         ContextCompat.getColor(
             context,
             ThemeUtils.darkTheme ? R.color.dark_theme_accent : R.color.light_theme_accent);
   }
   return resultColor;
 }
コード例 #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.girl);

    girl_show = (ImageView) findViewById(R.id.iv_girl_show);

    girl_show.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            girl_show.setImageBitmap(blurBitmap(bitmap, i));
            if (i < 25) i = i + 2;
          }
        });

    cardView = (CardView) findViewById(R.id.card);
    cardView1 = (CardView) findViewById(R.id.card1);

    tv = (TextView) findViewById(R.id.name);
    girl = (TextView) findViewById(R.id.tv_girl);

    Palette.Builder palette = Palette.from(bitmap);

    palette.generate(
        new Palette.PaletteAsyncListener() {
          @Override
          public void onGenerated(Palette palette) {
            tv.setTextColor(palette.getVibrantColor(Color.WHITE));
            cardView.setCardBackgroundColor(palette.getLightVibrantColor(Color.RED));
          }
        });

    applyBlur();
  }
コード例 #7
0
  @Nullable
  @Override
  protected Object run() throws InterruptedException {
    try {
      Bitmap bmp = BitmapFactory.decodeFile(artPath);
      Palette.from(bmp)
          .generate(
              new Palette.PaletteAsyncListener() {
                @Override
                public void onGenerated(final Palette palette) {
                  Integer colorTo =
                      palette.getVibrantColor(
                          palette.getDarkVibrantColor(
                              palette.getDarkMutedColor(
                                  palette.getMutedColor(
                                      ContextCompat.getColor(context, R.color.colorPrimary)))));
                  onColorFetched(colorTo);
                  colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
                  colorAnimation.setDuration(2000);
                  colorAnimation.addUpdateListener(
                      new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                          detailHolder.setBackgroundColor((Integer) animator.getAnimatedValue());
                        }
                      });
                  colorAnimation.start();
                }
              });
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      noBitmap = true;
    }
    return null;
  }
コード例 #8
0
 public static Palette.Swatch getProminentSwatch(Bitmap bitmap) {
   Palette palette = Palette.from(bitmap).generate();
   return getProminentSwatch(palette);
 }