Beispiel #1
0
    private void applyColors(Palette.Swatch swatch) {
      if (swatch != null) {
        mMovieItemFooter.setBackgroundColor(swatch.getRgb());
        mMovieItemTitle.setTextColor(swatch.getBodyTextColor());

        mFavoriteButton.setColorFilter(swatch.getBodyTextColor(), PorterDuff.Mode.MULTIPLY);
      }
    }
Beispiel #2
0
  @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();
  }
  @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));
  }
  protected int getSwatchColor(@NonNull Palette palette, @Nullable Palette.Swatch swatch) {

    swatch = ensureSwatchIsNotNull(palette, swatch);

    switch (getColorType()) {
      case BACKGROUND:
        return swatch.getRgb();

      case TEXT_BODY:
        return swatch.getBodyTextColor();

      case TEXT_TITLE:
        return swatch.getTitleTextColor();
    }

    return Color.GRAY;
  }
Beispiel #5
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();
      }
    }
  }
Beispiel #6
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;
  }