@NonNull public static ObjectAnimator ofArgb(@Nullable Object target, @NonNull String propertyName, int... values) { return ObjectAnimator.ofArgb(target, propertyName, values); }
@NonNull public static <T> ObjectAnimator ofArgb(@Nullable T target, @NonNull Property<T, Integer> property, int... values) { return ObjectAnimator.ofArgb(target, property, values); }
static ObjectAnimator createArgbAnimator(View view, String propertyName, int startColor, int endColor) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return ObjectAnimator.ofObject(view, propertyName, new TypeEvaluator() { @Override public Object evaluate(float fraction, Object startValue, Object endValue) { int startInt = (Integer) startValue; int startA = (startInt >> 24) & 0xff; int startR = (startInt >> 16) & 0xff; int startG = (startInt >> 8) & 0xff; int startB = startInt & 0xff; int endInt = (Integer) endValue; int endA = (endInt >> 24) & 0xff; int endR = (endInt >> 16) & 0xff; int endG = (endInt >> 8) & 0xff; int endB = endInt & 0xff; return (startA + (int)(fraction * (endA - startA))) << 24 | (startR + (int)(fraction * (endR - startR))) << 16 | (startG + (int)(fraction * (endG - startG))) << 8 | (startB + (int)(fraction * (endB - startB))); } }, startColor, endColor); } else { return ObjectAnimator.ofArgb(view, propertyName, startColor, endColor); } }
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
endValues.view.setBackground(background); final Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor); final Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius);
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);
/** * ObjectAnimator usage * * @param b * @return */ public ObjectAnimator getObjectAnimator(boolean b) { if (b) { ObjectAnimator bgColorAnimator = ObjectAnimator.ofArgb(mPuppet, "backgroundColor", 0xff009688, 0xff795548); bgColorAnimator.setRepeatCount(1); bgColorAnimator.setDuration(3000); bgColorAnimator.setRepeatMode(ValueAnimator.REVERSE); bgColorAnimator.setStartDelay(0); return bgColorAnimator; } else { ObjectAnimator rotationXAnimator = ObjectAnimator.ofFloat(mPuppet, "rotationX", 0f, 360f); rotationXAnimator.setRepeatCount(1); rotationXAnimator.setDuration(3000); rotationXAnimator.setRepeatMode(ValueAnimator.REVERSE); return rotationXAnimator; } }
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius);
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void startBackGround(int centerX,int centerY) { AnimatorSet showScrim = new AnimatorSet(); showScrim.playTogether( ViewAnimationUtils.createCircularReveal( scrim, centerX, centerY, 0, (float) Math.hypot(display.getWidth(), display.getHeight())), ObjectAnimator.ofArgb( scrim, "backgroundColor", Color.GRAY, getActivity().getResources().getColor(R.color.gray_1), getActivity().getResources().getColor(R.color.transWhite))); showScrim.setDuration(1000L); showScrim.setInterpolator(linearOutSlowInInterpolator); showScrim.start(); }
endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius);
@Override public void prepareStateChange(State toState, AnimatorSet targetAnim) { int finalAlpha = getAlphaForState(toState); if (targetAnim == null) { mBgPaint.setAlpha(finalAlpha); invalidate(); } else { ObjectAnimator anim = ObjectAnimator.ofArgb(mBgPaint, "alpha", finalAlpha); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { invalidate(); } }); targetAnim.play(anim); } }
@Override public void prepareStateChange(State toState, AnimatorSet targetAnim) { int finalAlpha = getAlphaForState(toState); if (targetAnim == null) { mBgPaint.setAlpha(finalAlpha); invalidate(); } else { ObjectAnimator anim = ObjectAnimator.ofArgb(mBgPaint, "alpha", finalAlpha); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { invalidate(); } }); targetAnim.play(anim); } }
/** * ObjectAnimator usage * * @param b * @return */ public ObjectAnimator getObjectAnimator(boolean b) { if (b) { ObjectAnimator bgColorAnimator = ObjectAnimator.ofArgb(mPuppet, "backgroundColor", 0xff009688, 0xff795548); bgColorAnimator.setRepeatCount(1); bgColorAnimator.setDuration(3000); bgColorAnimator.setRepeatMode(ValueAnimator.REVERSE); bgColorAnimator.setStartDelay(0); return bgColorAnimator; } else { ObjectAnimator rotationXAnimator = ObjectAnimator.ofFloat(mPuppet, "rotationX", 0f, 360f); rotationXAnimator.setRepeatCount(1); rotationXAnimator.setDuration(3000); rotationXAnimator.setRepeatMode(ValueAnimator.REVERSE); return rotationXAnimator; } }
private void hideFilterContainer() { AnimatorSet hideConfirmation = new AnimatorSet(); hideConfirmation.playTogether( ViewAnimationUtils.createCircularReveal(confirmSaveContainer, confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2, confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2), ObjectAnimator.ofArgb(resultsScrim, Utils.BACKGROUND_COLOR, Color.TRANSPARENT)); hideConfirmation.setDuration(150L); hideConfirmation.setInterpolator(AnimUtils.getFastOutSlowInInterpolator (getActivity())); hideConfirmation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { confirmSaveContainer.setVisibility(View.GONE); resultsScrim.setVisibility(View.GONE); fab.setVisibility(View.VISIBLE); FabAnimationUtils.scaleIn(fab); } }); hideConfirmation.start(); }
@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(); }
@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(); }
@Override public AnimatorSet onIndicatorPress(IndicatorView view, IndicatorView.IndicatorHolder target) { int terminalColor = indicator2.getIndicatorColor(); int centerColor = Color.RED; int centerColor2 = Color.BLUE; ValueAnimator animator = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { animator = ObjectAnimator.ofArgb(target, "color", terminalColor, centerColor, centerColor2, terminalColor); } else { animator = ObjectAnimator.ofInt(target, "color", terminalColor, centerColor, centerColor2, terminalColor); animator.setEvaluator(new ArgbEvaluator()); } int terminalSize = indicator2.getIndicatorPixeSize(); int centerSize = indicator2.getIndicatorPixeSize() * 2; ValueAnimator animatorH = ObjectAnimator.ofInt(target, "height", terminalSize, centerSize, terminalSize); ValueAnimator animatorW = ObjectAnimator.ofInt(target, "width", terminalSize, centerSize, terminalSize); AnimatorSet set = new AnimatorSet(); set.play(animator).with(animatorH).with(animatorW); set.setDuration(1000); //播放时为700 return set; } });
@Override public AnimatorSet onIndicatorSwitch(IndicatorView view, IndicatorView.IndicatorHolder target) { int terminalColor = indicator4.getIndicatorColor(); int centerColor = indicator4.getDotColor(); ValueAnimator colorAnim = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { colorAnim = ObjectAnimator.ofArgb(target, "color", terminalColor, centerColor, terminalColor); } else { colorAnim = ObjectAnimator.ofInt(target, "color", terminalColor, centerColor, terminalColor); colorAnim.setEvaluator(new ArgbEvaluator()); } int terminalSize = indicator4.getIndicatorPixeSize(); int centerSize = indicator4.getIndicatorPixeSize() * 3 / 2; ValueAnimator animatorH = ObjectAnimator.ofInt(target, "height", terminalSize, centerSize, terminalSize); ValueAnimator animatorW = ObjectAnimator.ofInt(target, "width", terminalSize, centerSize, terminalSize); AnimatorSet set = new AnimatorSet(); set.play(colorAnim).with(animatorH).with(animatorW); set.setDuration(500); return set; } });