예제 #1
0
    private int rotateColor(int color, float rad) {
      float deg = rad * 180 / 3.1415927f;
      int r = Color.red(color);
      int g = Color.green(color);
      int b = Color.blue(color);

      ColorMatrix cm = new ColorMatrix();
      ColorMatrix tmp = new ColorMatrix();

      cm.setRGB2YUV();
      tmp.setRotate(0, deg);
      cm.postConcat(tmp);
      tmp.setYUV2RGB();
      cm.postConcat(tmp);

      final float[] a = cm.getArray();

      int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
      int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
      int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);

      return Color.argb(
          Color.alpha(color), pinToByte(ir),
          pinToByte(ig), pinToByte(ib));
    }
예제 #2
0
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void animateTextColor(int targetColor) {
    if (mCurrentColorAnim != null) {
      mCurrentColorAnim.cancel();
    }

    mCurrentColorAnim = new AnimatorSet();
    mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);

    if (mSrcFilter == null) {
      mSrcFilter = new ColorMatrix();
      mDstFilter = new ColorMatrix();
      mCurrentFilter = new ColorMatrix();
    }

    DragView.setColorScale(getTextColor(), mSrcFilter);
    DragView.setColorScale(targetColor, mDstFilter);
    ValueAnimator anim1 =
        ValueAnimator.ofObject(
            new FloatArrayEvaluator(mCurrentFilter.getArray()),
            mSrcFilter.getArray(),
            mDstFilter.getArray());
    anim1.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
          }
        });

    mCurrentColorAnim.play(anim1);
    mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
    mCurrentColorAnim.start();
  }
    /** Keep all colorspace representations in sync. */
    private void updateYUVfromRGB() {
      float r = mRGB[0] / 255.0f;
      float g = mRGB[1] / 255.0f;
      float b = mRGB[2] / 255.0f;

      ColorMatrix cm = new ColorMatrix();
      cm.setRGB2YUV();
      final float[] a = cm.getArray();

      mYUV[0] = a[0] * r + a[1] * g + a[2] * b;
      mYUV[0] = pinToUnit(mYUV[0]);
      mYUV[1] = a[5] * r + a[6] * g + a[7] * b;
      mYUV[1] = pin(mYUV[1], -.5f, .5f);
      mYUV[2] = a[10] * r + a[11] * g + a[12] * b;
      mYUV[2] = pin(mYUV[2], -.5f, .5f);
    }