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