예제 #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
 @Override
 public void onNext(PaletteResponse paletteResponse) {
   if (artwork != null) {
     Palette p = paletteResponse.palette;
     int color = p.getDarkVibrantColor(getResources().getColor(R.color.transparent_black));
     color = ThemeUtils.setColorAlpha(color, 0x66);
     PorterDuffColorFilter cf = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
     artwork.setColorFilter(cf);
   }
 }
예제 #3
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));
  }
예제 #4
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;
  }
예제 #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;
 }
 @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;
 }
예제 #7
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();
      }
    }
  }
예제 #8
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();
  }
예제 #9
0
    @Override
    public void onBindViewHolder(final ItemViewHolder viewHolder, final IItem item) {

      viewHolder.vTitle.setText(item.getTitle());
      viewHolder.vDesc.setText(item.getDesc());

      int bal = item.getBalls();
      if (bal == -1) viewHolder.vBalls.setText(R.string.not_defined);
      else viewHolder.vBalls.setText(String.valueOf(bal));
      viewHolder.vStatus.setText(item.getStatus().toString());
      viewHolder.itemView.setTag(item.getId());
      viewHolder.vDate.setText(item.getStringDate());

      viewHolder.vUserSet.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              showPopupMenu(view, item.getId());
            }
          });

      try {

        viewHolder.vImage.post(
            new Runnable() {
              @Override
              public void run() {
                viewHolder.vImage.setImageBitmap(item.getBitmapInView(viewHolder.vImage));
              }
            });

        Palette.generateAsync(
            item.getBitmap(),
            new Palette.PaletteAsyncListener() {
              public void onGenerated(Palette palette) {

                //  int bgColor = palette.getMutedColor(ContextCompat.getColor(mContext,
                // R.color.colorPrimary));
                //  viewHolder.vDesc.setBackgroundColor(bgColor);

              }
            });
      } catch (Exception a) {
        viewHolder.vImage.setScaleType(ImageView.ScaleType.CENTER);
        viewHolder.vImage.setImageDrawable(
            new IconicsDrawable(getActivity())
                .icon(GoogleMaterial.Icon.gmd_error)
                .color(getResources().getColor(R.color.md_red_500))
                .sizeDpX(40)
                .sizeDpY(40));
      }
    }
 private void setSwipeRefreshLayoutSchemeColors() {
   Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
   Palette.generateAsync(
       bitmap,
       new Palette.PaletteAsyncListener() {
         @Override
         public void onGenerated(Palette palette) {
           Palette.Swatch swatch1 = palette.getVibrantSwatch();
           Palette.Swatch swatch2 = palette.getLightVibrantSwatch();
           Palette.Swatch swatch3 = palette.getDarkVibrantSwatch();
           mSwipeRefreshLayout.setColorSchemeColors(swatch1.getRgb(), swatch2.getRgb());
         }
       });
 }
예제 #11
0
  /**
   * A function that ensures a non-null {@link android.support.v7.graphics.Palette.Swatch} is
   * returned, whether from the {@link Palette} or a new based on Color.GRAY.
   *
   * @param palette The desired {@link Palette}
   * @param nullableSwatch The {@link Palette.Swatch} that could be null.
   * @return A non-null {@link Palette.Swatch} from the {@link Palette}, or a new {@link
   *     Palette.Swatch} based on Color.GRAY.
   */
  @NonNull
  public Palette.Swatch ensureSwatchIsNotNull(
      @NonNull Palette palette, @Nullable Palette.Swatch nullableSwatch) {

    if (nullableSwatch != null) {
      return nullableSwatch;
    }
    // nullableSwatch was null, fall back to a swatch that isn't null.
    for (Palette.Swatch swatch : palette.getSwatches()) {
      if (swatch != null) {
        return swatch;
      }
    }

    return new Palette.Swatch(Color.GRAY, 1);
  }
예제 #12
0
  // 3
  @Override
  public void onBindViewHolder(final ViewHolder holder, final int position) {
    final Place place = new PlaceData().placeList().get(position);
    holder.placeName.setText(place.name);
    Picasso.with(mContext).load(place.getImageResourceId(mContext)).into(holder.placeImage);
    Bitmap photo =
        BitmapFactory.decodeResource(mContext.getResources(), place.getImageResourceId(mContext));

    Palette.generateAsync(
        photo,
        new Palette.PaletteAsyncListener() {
          public void onGenerated(Palette palette) {
            int bgColor =
                palette.getMutedColor(mContext.getResources().getColor(android.R.color.black));
            holder.placeNameHolder.setBackgroundColor(bgColor);
          }
        });
  }
예제 #13
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();
  }
예제 #14
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;
  }
예제 #15
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;
  }
예제 #16
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);
  }
예제 #17
0
 // # Transformation Contract
 @Override
 public final Bitmap transform(Bitmap source) {
   final Palette palette = Palette.generate(source);
   CACHE.put(source, palette);
   return source;
 }
예제 #18
0
 public static Palette.Swatch getProminentSwatch(Bitmap bitmap) {
   Palette palette = Palette.from(bitmap).generate();
   return getProminentSwatch(palette);
 }
예제 #19
0
 private void colorize(Bitmap photo) {
   mPalette = Palette.generate(photo);
   applyPalette();
 }
예제 #20
0
 private void applyPalette() {
   mTitleHolder.setBackgroundColor(mPalette.getMutedColor(defaultColorForRipple));
 }
예제 #21
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_contact_view, container, false);

    // Use this to indicate the ratio
    /*Display display = getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    int width = point.x;
    int height = point.y;

    // This indicate ratio based on Material design
    RelativeLayout headerSection = (RelativeLayout) v.findViewById(R.id.contact_view_header);

    // We are using LinearLayout is because in activity_contact_view the root layout is LinearLayout
    // and this layout contains contact_view_header
    headerSection.setLayoutParams(new LinearLayout.LayoutParams(width, (int) (width * (9.0 / 16.0))));*/

    mContact = ContactList.getInstance().get(mPosition);

    mContactName = (TextView) v.findViewById(R.id.contact_name);

    Toolbar toolbar = (Toolbar) v.findViewById(R.id.contact_view_toolbar);
    //  setSupportActionBar(toolbar);

    // To catch the click on the menu item edit (icon)
    toolbar.setOnMenuItemClickListener(
        new Toolbar.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.contact_view_edit) {
              getContrat().selectedEditPosition(mPosition);
              // Before we use Intent here so fragment was couple with activity
              /* Intent intent = new Intent(getActivity(), ContactEditActivity.class);
              intent.putExtra(ContactEditActivity.EXTRA, mPosition);
              startActivity(intent);*/
              Log.d(TAG, "Edit is clicked");
            }

            return false;
          }
        });

    toolbar.inflateMenu(R.menu.menu_contact_view);

    ListView listView = (ListView) v.findViewById(R.id.contact_view_fields);
    mAdapter = new FieldsAdapter(mContact);
    listView.setAdapter(mAdapter);

    // To use this palette we have to add an external library
    // compile "com.android.support:palette-v7:21.0.+"  in build.gradle (Module:app)

    // Palette takes an image, analyzes it and finds the prominent colors.
    // To do this we need a bitmap which is an object that holds image data.
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.parrots);
    Palette palette = Palette.generate(bitmap);

    // With our Palette now created, we can get a color from it and use that to change the color of
    // our icons.
    mColor = palette.getDarkVibrantSwatch().getRgb();

    updateUI();
    return v;
  }
    @Override
    public void onCreate(SurfaceHolder holder) {
      if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onCreate");
      }
      super.onCreate(holder);

      setWatchFaceStyle(
          new WatchFaceStyle.Builder(SweepWatchFaceService.this)
              .setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
              .setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
              .setShowSystemUiTime(false)
              .build());

      mBackgroundPaint = new Paint();
      mBackgroundPaint.setColor(Color.BLACK);
      mBackgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bg);

      /* Set defaults for colors */
      mWatchHandColor = Color.WHITE;
      mWatchHandHighlightColor = Color.RED;
      mWatchHandShadowColor = Color.BLACK;

      mHourPaint = new Paint();
      mHourPaint.setColor(mWatchHandColor);
      mHourPaint.setStrokeWidth(HOUR_STROKE_WIDTH);
      mHourPaint.setAntiAlias(true);
      mHourPaint.setStrokeCap(Paint.Cap.ROUND);
      mHourPaint.setShadowLayer(SHADOW_RADIUS, 0, 0, mWatchHandShadowColor);

      mMinutePaint = new Paint();
      mMinutePaint.setColor(mWatchHandColor);
      mMinutePaint.setStrokeWidth(MINUTE_STROKE_WIDTH);
      mMinutePaint.setAntiAlias(true);
      mMinutePaint.setStrokeCap(Paint.Cap.ROUND);
      mMinutePaint.setShadowLayer(SHADOW_RADIUS, 0, 0, mWatchHandShadowColor);

      mSecondPaint = new Paint();
      mSecondPaint.setColor(mWatchHandHighlightColor);
      mSecondPaint.setStrokeWidth(SECOND_TICK_STROKE_WIDTH);
      mSecondPaint.setAntiAlias(true);
      mSecondPaint.setStrokeCap(Paint.Cap.ROUND);
      mSecondPaint.setShadowLayer(SHADOW_RADIUS, 0, 0, mWatchHandShadowColor);

      mTickAndCirclePaint = new Paint();
      mTickAndCirclePaint.setColor(mWatchHandColor);
      mTickAndCirclePaint.setStrokeWidth(SECOND_TICK_STROKE_WIDTH);
      mTickAndCirclePaint.setAntiAlias(true);
      mTickAndCirclePaint.setStyle(Paint.Style.STROKE);
      mTickAndCirclePaint.setShadowLayer(SHADOW_RADIUS, 0, 0, mWatchHandShadowColor);

      /* Extract colors from background image to improve watchface style. */
      Palette.generateAsync(
          mBackgroundBitmap,
          new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
              if (palette != null) {
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                  Log.d(TAG, "Palette: " + palette);
                }

                mWatchHandHighlightColor = palette.getVibrantColor(Color.RED);
                mWatchHandColor = palette.getLightVibrantColor(Color.WHITE);
                mWatchHandShadowColor = palette.getDarkMutedColor(Color.BLACK);
                updateWatchHandStyle();
              }
            }
          });

      mCalendar = Calendar.getInstance();
    }