Ejemplo n.º 1
0
 private void setAnimatorValue(boolean checked) {
   if (checked) {
     mCurProperty.mCircleColor = mCheckedPaintColor;
     mCurProperty.mSweepAngle = 360;
   } else {
     mCurProperty.mCircleColor = mUnCheckedPaintColor;
     mCurProperty.mSweepAngle = 0;
   }
   invalidate();
 }
Ejemplo n.º 2
0
    @Override
    public AnimatorProperty evaluate(
        float fraction, AnimatorProperty startValue, AnimatorProperty endValue) {
      // Values
      mProperty.mSweepAngle =
          (int)
              (startValue.mSweepAngle + (endValue.mSweepAngle - startValue.mSweepAngle) * fraction);

      // Color
      int startA = (startValue.mCircleColor >> 24) & 0xff;
      int startR = (startValue.mCircleColor >> 16) & 0xff;
      int startG = (startValue.mCircleColor >> 8) & 0xff;
      int startB = startValue.mCircleColor & 0xff;

      int endA = (endValue.mCircleColor >> 24) & 0xff;
      int endR = (endValue.mCircleColor >> 16) & 0xff;
      int endG = (endValue.mCircleColor >> 8) & 0xff;
      int endB = endValue.mCircleColor & 0xff;

      mProperty.mCircleColor =
          (startA + (int) (fraction * (endA - startA))) << 24
              | (startR + (int) (fraction * (endR - startR))) << 16
              | (startG + (int) (fraction * (endG - startG))) << 8
              | (startB + (int) (fraction * (endB - startB)));

      return mProperty;
    }
Ejemplo n.º 3
0
  /**
   * =============================================================================================
   * The Animate
   * =============================================================================================
   */
  private void animateCheckedState(boolean newCheckedState) {
    AnimatorProperty property = new AnimatorProperty();
    if (newCheckedState) {
      property.mSweepAngle = 360;
      property.mCircleColor = mCheckedPaintColor;
    } else {
      property.mSweepAngle = 0;
      property.mCircleColor = mUnCheckedPaintColor;
    }

    if (mAnimator == null) {
      mAnimator =
          ObjectAnimator.ofObject(this, ANIM_VALUE, new AnimatorEvaluator(mCurProperty), property);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        mAnimator.setAutoCancel(true);
      mAnimator.setDuration(ANIMATION_DURATION);
      mAnimator.setInterpolator(ANIMATION_INTERPOLATOR);
    } else {
      mAnimator.cancel();
      mAnimator.setObjectValues(property);
    }
    mAnimator.start();
  }