/** * Applys a spin animation to the Chart. * * @param durationmillis * @param fromangle * @param toangle */ @SuppressLint("NewApi") public void spin(int durationmillis, float fromangle, float toangle, Easing.EasingOption easing) { if (android.os.Build.VERSION.SDK_INT < 11) return; setRotationAngle(fromangle); ObjectAnimator spinAnimator = ObjectAnimator.ofFloat(this, "rotationAngle", fromangle, toangle); spinAnimator.setDuration(durationmillis); spinAnimator.setInterpolator(Easing.getEasingFunctionFromOption(easing)); spinAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { postInvalidate(); } }); spinAnimator.start(); }
private void animateFilterTo(float[] targetFilter) { float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter; mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length); if (mFilterAnimator != null) { mFilterAnimator.cancel(); } mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter), oldFilter, targetFilter); mFilterAnimator.setDuration(COLOR_CHANGE_DURATION); mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter)); invalidate(); } }); mFilterAnimator.start(); }
public void animateShift(final int shiftX, final int shiftY) { if (mAnim.isStarted()) { return; } mAnimatedShiftX = shiftX; mAnimatedShiftY = shiftY; applyTranslation(); mAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = 1 - animation.getAnimatedFraction(); mAnimatedShiftX = (int) (fraction * shiftX); mAnimatedShiftY = (int) (fraction * shiftY); applyTranslation(); } }); }
public ValueAnimator createHotseatAlphaAnimator(float finalValue) { if (Float.compare(finalValue, mHotseatAlpha[HOTSEAT_STATE_ALPHA_INDEX]) == 0) { // Return a dummy animator to avoid null checks. return ValueAnimator.ofFloat(0, 0); } else { ValueAnimator animator = ValueAnimator .ofFloat(mHotseatAlpha[HOTSEAT_STATE_ALPHA_INDEX], finalValue); animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float value = (Float) valueAnimator.getAnimatedValue(); setHotseatAlphaAtIndex(value, HOTSEAT_STATE_ALPHA_INDEX); } }); AccessibilityManager am = (AccessibilityManager) mLauncher.getSystemService(Context.ACCESSIBILITY_SERVICE); final boolean accessibilityEnabled = am.isEnabled(); animator.addUpdateListener( new AlphaUpdateListener(mLauncher.getHotseat(), accessibilityEnabled)); animator.addUpdateListener( new AlphaUpdateListener(mPageIndicator, accessibilityEnabled)); return animator; } }
private void snapChild(final View animView, final float targetLeft, float velocity) { final boolean canBeDismissed = mCallback.canChildBeDismissed(animView); AnimatorUpdateListener updateListener = new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed); } }; Animator anim = getViewTranslationAnimator(animView, targetLeft, updateListener); if (anim == null) { return; } int duration = SNAP_ANIM_LEN; anim.setDuration(duration); anim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animator) { mSnappingChild = false; updateSwipeProgressFromOffset(animView, canBeDismissed); mCallback.onChildSnappedBack(animView, targetLeft); } }); prepareSnapBackAnimation(animView, anim); mSnappingChild = true; anim.start(); }
void animateShadeOpen() { this.phone.performHapticFeedback(3, 2); updateText(this.explanation, R.string.oob_pullout_shade_all_the_way, 0, null); final float dimIncrement = this.dimValue / ((float) this.shadeHeight); float currentHeight = (float) this.shade.getHeight(); ValueAnimator va = ValueAnimator.ofInt(new int[]{(int) currentHeight, this.shadeHeight}); va.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { Integer height = (Integer) animation.getAnimatedValue(); LayoutParams layoutParams = OOBTutorialActivity.this.shade.getLayoutParams(); layoutParams.height = height.intValue(); OOBTutorialActivity.this.shade.setLayoutParams(layoutParams); OOBTutorialActivity.this.dim.setAlpha(height.floatValue() * dimIncrement); OOBTutorialActivity.this.shade.requestLayout(); } }); va.start(); }
void animateShadeClose() { this.phone.performHapticFeedback(3, 2); updateText(this.explanation, R.string.oob_pullout_shade_all_the_way, 0, null); final float dimIncrement = this.dimValue / ((float) this.shadeHeight); float currentHeight = (float) this.shade.getHeight(); ValueAnimator va = ValueAnimator.ofInt(new int[]{(int) currentHeight, 0}); va.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { Integer height = (Integer) animation.getAnimatedValue(); LayoutParams layoutParams = OOBTutorialActivity.this.shade.getLayoutParams(); layoutParams.height = height.intValue(); OOBTutorialActivity.this.shade.setLayoutParams(layoutParams); OOBTutorialActivity.this.dim.setAlpha(height.floatValue() * dimIncrement); OOBTutorialActivity.this.shade.requestLayout(); } }); va.start(); }
@Override public AnimatorUpdateListener onLoadingFinish(int footerHeight, Interpolator interpolator, int duration) { if (mScrollableView != null) { if (mScrollableView instanceof RecyclerView) ((RecyclerView) mScrollableView).smoothScrollBy(0, footerHeight, interpolator); else if (mScrollableView instanceof ScrollView) ((ScrollView) mScrollableView).smoothScrollBy(0, footerHeight); else if (mScrollableView instanceof AbsListView) ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration); else { try { Method method = mScrollableView.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class); method.invoke(mScrollableView, 0, footerHeight); } catch (Exception e) { int scrollX = mScrollableView.getScrollX(); int scrollY = mScrollableView.getScrollY(); return animation -> mScrollableView.scrollTo(scrollX, scrollY + (int) animation.getAnimatedValue()); } } return null; } return null; }
@Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (mSheetAnimator != null) mSheetAnimator.cancel(); mRequestView.removeOnLayoutChangeListener(this); mContainerHeightDifference = (bottom - top) - (oldBottom - oldTop); ValueAnimator containerAnimator = ValueAnimator.ofFloat(1f, 0f); containerAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float alpha = (Float) animation.getAnimatedValue(); update(alpha); } }); mSheetAnimator = containerAnimator; mSheetAnimator.setDuration(DIALOG_ENTER_ANIMATION_MS); mSheetAnimator.setInterpolator(new LinearOutSlowInInterpolator()); mSheetAnimator.addListener(this); mSheetAnimator.start(); }
private void doTabPageIndicatorAnimator(int start, int end) { this.mTabPIValueAnimator = ValueAnimator.ofInt(new int[]{start, end}); this.mTabPIValueAnimator.addUpdateListener(new AnimatorUpdateListener(this) { final /* synthetic */ MyDownloadActivity this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public void onAnimationUpdate(ValueAnimator animation) { int value = ((Integer) animation.getAnimatedValue()).intValue(); LayoutParams layoutParams = this.this$0.mIndicator.getLayoutParams(); layoutParams.height = value; this.this$0.mIndicator.setLayoutParams(layoutParams); } }); this.mTabPIValueAnimator.start(); }
private void smoothScrollTo(int desX, int desY, AnimatorListener listener) { ObjectAnimator xTranslate = ObjectAnimator.ofInt(this, "scrollX", desX); ObjectAnimator yTranslate = ObjectAnimator.ofInt(this, "scrollY", desY); yTranslate.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (mHeaderStatusChangedListener != null) mHeaderStatusChangedListener.onHeaderOffsetChanged((int) (mScrollOffsetHeight * animation.getAnimatedFraction()), animation.getAnimatedFraction()); } }); AnimatorSet animators = new AnimatorSet(); animators.setDuration(240L); animators.playTogether(xTranslate, yTranslate); if (listener != null) animators.addListener(listener); animators.start(); }
private void startCheckedAnim() { ValueAnimator animator = new ValueAnimator(); final float hookMaxValue = (this.mHookSize + this.mEndLeftHookOffset) - this .mBaseLeftHookOffset; final float circleMaxFraction = this.mHookSize / hookMaxValue; final float circleMaxValue = 360.0f / circleMaxFraction; animator.setFloatValues(new float[]{0.0f, 1.0f}); animator.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); AnimCheckBox.this.mHookOffset = hookMaxValue * fraction; if (fraction <= circleMaxFraction) { AnimCheckBox.this.mSweepAngle = (float) ((int) ((circleMaxFraction - fraction) * circleMaxValue)); } else { AnimCheckBox.this.mSweepAngle = 0.0f; } AnimCheckBox.this.mInnerCircleAlpha = (int) (255.0f * fraction); AnimCheckBox.this.invalidate(); } }); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(500).start(); }
private void startUnCheckedAnim() { ValueAnimator animator = new ValueAnimator(); final float hookMaxValue = (this.mHookSize + this.mEndLeftHookOffset) - this .mBaseLeftHookOffset; final float circleMinFraction = (this.mEndLeftHookOffset - this.mBaseLeftHookOffset) / hookMaxValue; final float circleMaxValue = 360.0f / (1.0f - circleMinFraction); animator.setFloatValues(new float[]{0.0f, 1.0f}); animator.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { float circleFraction = animation.getAnimatedFraction(); float fraction = 1.0f - circleFraction; AnimCheckBox.this.mHookOffset = hookMaxValue * fraction; if (circleFraction >= circleMinFraction) { AnimCheckBox.this.mSweepAngle = (float) ((int) ((circleFraction - circleMinFraction) * circleMaxValue)); } else { AnimCheckBox.this.mSweepAngle = 0.0f; } AnimCheckBox.this.mInnerCircleAlpha = (int) (255.0f * fraction); AnimCheckBox.this.invalidate(); } }); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(500).start(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void animateFilterTo(float[] targetFilter) { float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter; mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length); if (mFilterAnimator != null) { mFilterAnimator.cancel(); } mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter), oldFilter, targetFilter); mFilterAnimator.setDuration(COLOR_CHANGE_DURATION); mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter)); invalidate(); } }); mFilterAnimator.start(); }
@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 AnimatorUpdateListener scrollContentWhenFinished(final int spinner) { if (mScrollableView != null && spinner != 0) { if ((spinner < 0 && canScrollDown(mScrollableView)) || (spinner > 0 && canScrollUp(mScrollableView))) { return new AnimatorUpdateListener() { int lastValue = spinner; @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); try { if (mScrollableView instanceof AbsListView) { scrollListBy((AbsListView) mScrollableView, value - lastValue); } else { mScrollableView.scrollBy(0, value - lastValue); } } catch (Throwable ignored) { //根据用户反馈,此处可能会有BUG } lastValue = value; } }; } } return null; }
@TargetApi(VERSION_CODES.HONEYCOMB) private void animateColors(Palette palette) { int color = palette.getVibrantColor(defaultColor); Swatch swatch = palette.getMutedSwatch(); anims = new AnimatorSet(); ValueAnimator cardBG = ValueAnimator.ofObject(new ArgbEvaluator(), defaultColor/* cannot retrieve card BG */, color); cardBG.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { holder.card.setCardBackgroundColor((Integer)animation.getAnimatedValue()); } }); anims.play(cardBG); if (swatch != null) { ObjectAnimator textColorBG = ofObject(holder.titleView, "backgroundColor", new ArgbEvaluator(), ((ColorDrawable)holder.titleView.getBackground()).getColor(), swatch.getRgb()); ObjectAnimator textColor = ofObject(holder.titleView, "textColor", new ArgbEvaluator(), holder.titleView.getCurrentTextColor(), swatch.getTitleTextColor()); anims.play(textColor); anims.play(textColorBG); } anims.playTogether(anims.getChildAnimations()); anims.setDuration(3000); anims.start(); }
private void animateMatrixIndex(final int index, final float to) { ValueAnimator animator = ValueAnimator.ofFloat(matrixValues[index], to); animator.addUpdateListener(new AnimatorUpdateListener() { final float[] values = new float[9]; Matrix current = new Matrix(); @Override public void onAnimationUpdate(ValueAnimator animation) { current.set(getImageMatrix()); current.getValues(values); values[index] = (Float) animation.getAnimatedValue(); current.setValues(values); setImageMatrix(current); } }); animator.setDuration(RESET_DURATION); animator.start(); }
@TargetApi(14) public final Animator createScaleAnimator(final View paramView, float paramFloat1, float paramFloat2, long paramLong) { ValueAnimator localValueAnimator = ValueAnimator.ofFloat(new float[] { paramFloat1, paramFloat2 }); localValueAnimator.setDuration(paramLong); if (Build.VERSION.SDK_INT >= 21) { localValueAnimator.setInterpolator(PlayInterpolators.fastOutSlowIn(paramView.getContext())); } for (;;) { localValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public final void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator) { float f = ((Float)paramAnonymousValueAnimator.getAnimatedValue()).floatValue(); paramView.setScaleX(f); paramView.setScaleY(f); } }); return localValueAnimator; localValueAnimator.setInterpolator(new FastOutSlowInInterpolator()); } }
/** * 自由落体 * * @param view */ public void verticalRun(View view) { ValueAnimator animator = ValueAnimator.ofFloat(0, mScreenHeight - mBlueBall.getHeight()); //animator.setTarget(mBlueBall); animator.setDuration(1000).start(); animator.setInterpolator(new BounceInterpolator()); animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mBlueBall.setTranslationY((Float) animation.getAnimatedValue()); } }); }
public void rotateyAnimRun(final View view) { //ObjectAnimator.ofFloat(view, "rotationX", 0,180L).setDuration(1000).start(); //自定义一个属性实现多个动画的叠加 ObjectAnimator anim = ObjectAnimator// .ofFloat(view, "zhy", 1.0F, 0.2F)// .setDuration(500);// anim.start(); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float cVal = (Float) animation.getAnimatedValue(); Log.e("cVal", cVal+""); view.setAlpha(cVal); view.setScaleX(cVal); view.setScaleY(cVal); } }); }
private void prepareAnimator(final boolean expand) { if (mAnimator != null) { mAnimator.cancel(); } mAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final Float fraction = (Float) animation.getAnimatedValue(); setMargins(fraction); } }); mAnimator.setDuration(ANIMATION_DURATION); mAnimator.start(); }