コード例 #1
0
  public static RippleDrawable createRipple(
      Palette palette,
      @FloatRange(from = 0f, to = 1f) float darkAlpha,
      @FloatRange(from = 0f, to = 1f) float lightAlpha,
      @ColorInt int fallbackColor,
      boolean bounded) {
    int rippleColor = fallbackColor;
    // try the named swatches in preference order
    if (palette != null) {
      if (palette.getVibrantSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
      } else if (palette.getLightVibrantSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), lightAlpha);
      } else if (palette.getDarkVibrantSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), darkAlpha);
      } else if (palette.getMutedSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
      } else if (palette.getLightMutedSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(), lightAlpha);
      } else if (palette.getDarkMutedSwatch() != null) {
        rippleColor = ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
      }
    }

    return new RippleDrawable(
        ColorStateList.valueOf(rippleColor), null, bounded ? new ColorDrawable(Color.WHITE) : null);
  }
コード例 #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
ファイル: PlayerSeekbar.java プロジェクト: HKMOpen/SoundWaves
  @Override
  public void onPaletteFound(Palette argChangedPalette) {
    Palette.Swatch swatch = argChangedPalette.getVibrantSwatch();
    if (swatch == null) return;

    int color = swatch.getRgb(); // .getTitleTextColor();
    ColorDrawable dc = new ColorDrawable(color);
    dc.setAlpha(100);
    // setProgressDrawable(dc);
    // setBackgroundColor(color);
    invalidate();
  }
コード例 #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
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_color_pallete);
    Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.ic_checkbox_checked);
    Palette palette = Palette.generate(img);
    Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    float[] vibrant = vibrantSwatch.getHsl();
    toolbar.setBackgroundColor(Color.HSVToColor(vibrant));
  }
コード例 #6
0
  private static List<Palette.Swatch> getSwatchesList(Palette palette) {
    List<Palette.Swatch> swatches = new ArrayList<>();

    Palette.Swatch vib = palette.getVibrantSwatch();
    Palette.Swatch vibLight = palette.getLightVibrantSwatch();
    Palette.Swatch vibDark = palette.getDarkVibrantSwatch();

    Palette.Swatch muted = palette.getMutedSwatch();
    Palette.Swatch mutedLight = palette.getLightMutedSwatch();
    Palette.Swatch mutedDark = palette.getDarkMutedSwatch();

    swatches.add(vib);
    swatches.add(vibLight);
    swatches.add(vibDark);
    swatches.add(muted);
    swatches.add(mutedLight);
    swatches.add(mutedDark);

    return swatches;
  }