private void setup(int duration) { // region saturation animationSaturation = ValueAnimator.ofFloat(0.2f, 1f); animationSaturation.setDuration(duration); animationSaturation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { saturation = animation.getAnimatedFraction(); } }); // endregion // region contrast animationContrast = ValueAnimator.ofFloat(0, 1f); animationContrast.setDuration(duration * 3 / 4); animationContrast.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ColorMatrix colorMatrix = setContrast(animation.getAnimatedFraction()); colorMatrix.setSaturation(saturation); ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); drawable.setColorFilter(colorFilter); } }); // endregion // region alpha animationAlpha = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1f); animationAlpha.setDuration(duration / 2); // endregion }
@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<Animator>(); ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.6f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat = (Float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(-1); rotateAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees = (Float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim.start(); animators.add(scaleAnim); animators.add(rotateAnim); return animators; }
@Override public void createAnimation() { float startX = getWidth() / 6; float startY = getWidth() / 6; for (int i = 0; i < 2; i++) { final int index = i; ValueAnimator translateXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, startX, getWidth() - startX, startX); if (i == 1) { translateXAnim = ValueAnimator.ofFloat( getWidth() - startX, startX, getWidth() - startX, startX, getWidth() - startX); } ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY); if (i == 1) { translateYAnim = ValueAnimator.ofFloat( getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY); } translateXAnim.setDuration(2000); translateXAnim.setInterpolator(new LinearInterpolator()); translateXAnim.setRepeatCount(-1); translateXAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateX[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); translateXAnim.start(); translateYAnim.setDuration(2000); translateYAnim.setInterpolator(new LinearInterpolator()); translateYAnim.setRepeatCount(-1); translateYAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateY[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); translateYAnim.start(); } }
@Override public List<Animator> createAnimation() { List<Animator> animators = new ArrayList<Animator>(); int[] durations = {960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190}; int[] delays = {360, 400, 680, 410, 710, -150, -120, 10, 320}; for (int i = 0; i < 9; i++) { final int index = i; ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 168, 255); alphaAnim.setDuration(durations[i]); alphaAnim.setRepeatCount(-1); alphaAnim.setStartDelay(delays[i]); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphas[index] = (Integer) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); animators.add(alphaAnim); } return animators; }
public void start() { initpaints(); fadeAndScaleAnimator.setInterpolator(new OvershootInterpolator(1.15f)); fadeAndScaleAnimator.start(); fadeAndScaleAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { invalidate(); if (animation.getAnimatedFraction() > .8f && !hasfired) { hasfired = true; rotationAnimator.start(); } } }); rotationAnimator.setInterpolator(new DecelerateInterpolator()); rotationAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { invalidate(); } }); }
/** * Perform dismiss action * * @param dismissView View * @param dismissPosition Position of list */ protected void performDismiss( final View dismissView, final int dismissPosition, boolean doPendingDismiss) { final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime); if (doPendingDismiss) { animator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --dismissAnimationRefCount; if (dismissAnimationRefCount == 0) { removePendingDismisses(originalHeight); } } }); } animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
public void duang() { mStatus = Status.STATUS_DOWN; ValueAnimator valueAnimator = ValueAnimator.ofInt(mMaxArcHeight, 0); valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mArcHeight = (int) animation.getAnimatedValue(); invalidate(); } }); valueAnimator.addListener( new SimpleAnimationListener() { @Override public void onAnimationEnd(Animator animation) { if (mAnimationListener != null) { mAnimationListener.onEnd(); } } }); valueAnimator.setDuration(500); valueAnimator.setInterpolator(new OvershootInterpolator(5f)); valueAnimator.start(); }
public void show() { mStatus = Status.STATUS_SMOOTH_UP; if (mAnimationListener != null) { mAnimationListener.onStart(); this.postDelayed( new Runnable() { @Override public void run() { mAnimationListener.onContentShow(); } }, 600); } ValueAnimator valueAnimator = ValueAnimator.ofInt(0, mMaxArcHeight); valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); mArcHeight = value; if (value == mMaxArcHeight) { duang(); } invalidate(); } }); valueAnimator.setDuration(800); valueAnimator.setInterpolator(new AccelerateInterpolator()); valueAnimator.start(); }
private void createAnimation() { Context appContext = AnimationLoading.this; if (animation == null) { ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.loadAnimator(appContext, R.animator.object_animator); anim.addUpdateListener(this); anim.setTarget(balls.get(0)); ValueAnimator fader = (ValueAnimator) AnimatorInflater.loadAnimator(appContext, R.animator.animator); fader.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { balls.get(1).setAlpha((Float) animation.getAnimatedValue()); } }); AnimatorSet seq = (AnimatorSet) AnimatorInflater.loadAnimator(appContext, R.animator.animator_set); seq.setTarget(balls.get(2)); ObjectAnimator colorizer = (ObjectAnimator) AnimatorInflater.loadAnimator(appContext, R.animator.color_animator); colorizer.setTarget(balls.get(3)); animation = new AnimatorSet(); ((AnimatorSet) animation).playTogether(anim, fader, seq, colorizer); } }
private void hideCard(int which) { if (isAnimating) return; List<Animator> animators = new ArrayList<>(mChildCount); final View displayingCard = getChildAt(which); int t = (int) (getMeasuredHeight() - (mChildCount - which) * mTitleBarHeightNoDisplay); ValueAnimator displayAnimator = ValueAnimator.ofFloat(ViewHelper.getY(displayingCard), t).setDuration(mDuration); displayAnimator.setTarget(displayingCard); final int finalT = t; displayAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float value = (float) valueAnimator.getAnimatedValue(); ViewHelper.setY(displayingCard, value); if (mDarkFrameLayout != null && isFade && value < finalT) { mDarkFrameLayout.fade((int) ((1 - value / finalT) * DarkFrameLayout.MAX_ALPHA)); } } }); animators.add(displayAnimator); for (int i = 0; i < mChildCount; i++) { if (i == 0 && isExistBackground) continue; if (i != which) { t = (int) (getMeasuredHeight() - (mChildCount - i) * mTitleBarHeightNoDisplay); animators.add( ObjectAnimator.ofFloat(getChildAt(i), "y", ViewHelper.getY(getChildAt(i)), t)); } } AnimatorSet set = new AnimatorSet(); set.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { isAnimating = true; } @Override public void onAnimationEnd(Animator animator) { isAnimating = false; isDisplaying = false; } @Override public void onAnimationCancel(Animator animator) { isAnimating = false; isDisplaying = false; } @Override public void onAnimationRepeat(Animator animator) {} }); set.setInterpolator(mCloseAnimatorInterpolator); set.playTogether(animators); set.start(); mDisplayingCard = -1; if (mOnDisplayOrHideListener != null) mOnDisplayOrHideListener.onHide(isExistBackground ? (which - 1) : which); }
public void animateSubjectOut(final SubjectCard materia) { final List<View> toBeAnimated = new ArrayList<View>(); boolean after = false; for (SubjectCard mtr : mSubjectCards) { if (after) toBeAnimated.add(mtr); if (mtr == materia) after = true; } toBeAnimated.add(mAddButton); final int numberToBeAnimated = toBeAnimated.size(); int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(), materiaHeight = materia.getHeight(); final int initScroll = mScrollView.getScrollY(), scrollBy = ((maxScroll < initScroll + materiaHeight) ? Math.max(maxScroll - materiaHeight, 0) : initScroll) - initScroll; ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight); listAnimator.setInterpolator(new DecelerateInterpolator(3.2f)); listAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); for (int i = 0; i < numberToBeAnimated; i++) ViewHelper.setTranslationY(toBeAnimated.get(i), value); ViewHelper.setScrollY( mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction())); } }); listAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mSubjectCards.remove(materia); mSubjectsLayout.removeView(materia); mSqlHelper.remove(materia.getData().getSqlID()); updateTotal(); mScrollView.setVerticalScrollBarEnabled(true); mScrollView.setOnTouchListener(null); for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0); } }); listAnimator.setDuration(700); mScrollView.setVerticalScrollBarEnabled(false); mScrollView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); // disable user scrolling during the animation if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0); listAnimator.setStartDelay(500); listAnimator.start(); }
private void performRemovalIfNecessary() { if (mCurrentRemovedView != null && mCurrentRemovedView.getParent() != null) { ValueAnimator animator = ValueAnimator.ofInt(mCurrentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION); animator.addListener(new RemoveViewAnimatorListenerAdapter(mCurrentRemovedView)); animator.addUpdateListener(new RemoveViewAnimatorUpdateListener(mCurrentRemovedView)); animator.start(); mActiveAnimators.put(mCurrentRemovedView, animator); clearCurrentRemovedView(); } }
@Override public void executeAnim(final View target, final int animType) { if (ExpandableStickyListHeadersListView.ANIMATION_EXPAND == animType && target.getVisibility() == View.VISIBLE) { return; } if (ExpandableStickyListHeadersListView.ANIMATION_COLLAPSE == animType && target.getVisibility() != View.VISIBLE) { return; } if (mOriginalViewHeightPool.get(target) == null) { mOriginalViewHeightPool.put(target, target.getHeight()); } final int viewHeight = mOriginalViewHeightPool.get(target); float animStartY = animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND ? 0f : viewHeight; float animEndY = animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND ? viewHeight : 0f; final ViewGroup.LayoutParams lp = target.getLayoutParams(); ValueAnimator animator = ValueAnimator.ofFloat(animStartY, animEndY); animator.setDuration(200); target.setVisibility(View.VISIBLE); animator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) {} @Override public void onAnimationEnd(Animator animator) { if (animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND) { target.setVisibility(View.VISIBLE); } else { target.setVisibility(View.GONE); } target.getLayoutParams().height = viewHeight; } @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = ((Float) valueAnimator.getAnimatedValue()).intValue(); target.setLayoutParams(lp); target.requestLayout(); } }); animator.start(); }
@Override public void createAnimation() { ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat1 = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator scaleAnim2 = ValueAnimator.ofFloat(1, 0.6f, 1); scaleAnim2.setDuration(1000); scaleAnim2.setRepeatCount(-1); scaleAnim2.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat2 = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim2.start(); ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(-1); rotateAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees = (float) animation.getAnimatedValue(); postInvalidate(); } }); rotateAnim.start(); }
// TODO sync public void animateDismiss(final int pos) { final int actionPos = pos - mListView.getFirstVisiblePosition() + mListView.getHeaderViewsCount(); final View view = mListView.getChildAt(actionPos); final ViewGroup.LayoutParams lp = view.getLayoutParams(); final int originWidth = view.getWidth(); final int originHeight = view.getHeight(); Animator translationXAnim = ObjectAnimator.ofFloat(view, "x", 0, -originWidth); Animator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 1, 0); ValueAnimator layoutParamYAnim = ValueAnimator.ofInt(originHeight, 0); layoutParamYAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator anim) { lp.height = (Integer) anim.getAnimatedValue(); view.setLayoutParams(lp); } }); AnimatorSet animSet = new AnimatorSet(); animSet.setDuration(1000); animSet.setTarget(view); animSet.setInterpolator(new AccelerateInterpolator()); animSet.playTogether(translationXAnim, alphaAnim, layoutParamYAnim); layoutParamYAnim.setStartDelay(200); animSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator arg0) {} @Override public void onAnimationRepeat(Animator arg0) {} @Override public void onAnimationCancel(Animator arg0) {} @Override public void onAnimationEnd(Animator arg0) { // 还原 View 的状态 lp.height = originHeight; view.setLayoutParams(lp); ViewHelper.setX(view, 0); ViewHelper.setAlpha(view, 1); mAdapter.getData().remove(pos); mAdapter.notifyDataSetChanged(); } }); animSet.start(); }
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } mCallback.onDismiss(mListView, dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation setAlpha(pendingDismiss.view, 1f); setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingDismisses.clear(); } } }); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
public void animateColorPercent(float percent, int duration) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(lastPercent, percent); valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { setColorPercent((float) animation.getAnimatedValue()); } }); valueAnimator.setDuration(duration); valueAnimator.start(); }
/** * Animates the dismissed list item to zero-height and fires the dismiss callback when all * dismissed list item animations have completed. * * @param view the dismissed {@link View}. */ protected void performDismiss(View view, DeleteItemWrapper position) { mDismissedViews.add(view); mDismissedPositions.add(position); ValueAnimator animator = ValueAnimator.ofInt(view.getHeight(), 1).setDuration(mDismissAnimationTime); animator.addUpdateListener(new DismissAnimatorUpdateListener(view)); animator.addListener(new DismissAnimatorListener()); animator.start(); mActiveDismissCount++; }
@Override public boolean onTouchEvent(MotionEvent event) { boolean hit = event.getY() > content.getTop() && getParent() != null; if (tapOutsideToDismiss && !hit) { hide(); return false; } if (hit && swipeToDismiss) { if (event.getAction() == MotionEvent.ACTION_DOWN) { swipe = 0; handler.removeCallbacks(hideRunnable); if (animator != null) { animator.cancel(); animator = null; swipe = ViewHelper.getTranslationX(content); } super.onTouchEvent(event); return true; } else if ((event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) && animator == null) { animator = ObjectAnimator.ofFloat(swipe, 0); animator.setDuration(200); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float s = (Float) animation.getAnimatedValue(); ViewHelper.setTranslationX(content, s); ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(s) / content.getWidth())); postInvalidate(); } }); animator.start(); animator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { animator.cancel(); animator = null; if (duration != INFINITE) handler.postDelayed(hideRunnable, duration); } }); super.onTouchEvent(event); return true; } } return super.onTouchEvent(event); }
/** 开始绘制动画 */ private void startAnim(int value) { ValueAnimator valueAnimator = ObjectAnimator.ofInt(value); valueAnimator.setDuration(1000); valueAnimator.setInterpolator(new LinearInterpolator()); valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mDegress = Integer.valueOf(valueAnimator.getAnimatedValue().toString()); invalidate(); } }); valueAnimator.start(); }
/** * Animate change of color * * @param event Event to process */ public void startAnimateColorChange(@NonNull final DecoEvent event) { cancelAnimation(); event.notifyStartListener(); mVisible = true; mDrawMode = event.getEventType(); mPercentComplete = 0f; final boolean changeColors = event.isColorSet(); if (changeColors) { mColorAnimate = new ColorAnimate(mSeriesItem.getColor(), event.getColor()); mSeriesItem.setColor(event.getColor()); } else { Log.w(TAG, "Must set new color to start CHANGE_COLOR event"); return; } final float maxValue = 1.0f; mValueAnimator = ValueAnimator.ofFloat(0, maxValue); mValueAnimator.setDuration(event.getEffectDuration()); if (event.getInterpolator() != null) { mValueAnimator.setInterpolator(event.getInterpolator()); } else { mValueAnimator.setInterpolator(new LinearInterpolator()); } mValueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mPercentComplete = Float.valueOf(valueAnimator.getAnimatedValue().toString()); for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) { seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete); } } }); mValueAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { event.notifyEndListener(); } }); mValueAnimator.start(); }
@Override public void createAnimation() { long[] delays = new long[] {0, 200, 400}; for (int i = 0; i < 3; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1); scaleAnim.setInterpolator(new LinearInterpolator()); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.setStartDelay(delays[i]); scaleAnim.start(); ValueAnimator alphaAnim = ValueAnimator.ofInt(0, 255); scaleAnim.setInterpolator(new LinearInterpolator()); alphaAnim.setDuration(1000); alphaAnim.setRepeatCount(-1); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphaInts[index] = (int) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.setStartDelay(delays[i]); alphaAnim.start(); } }
@Override public void createAnimation() { int[] durations = {720, 1020, 1280, 1420, 1450, 1180, 870, 1450, 1060}; int[] delays = {-60, 250, -170, 480, 310, 30, 460, 780, 450}; for (int i = 0; i < 9; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.5f, 1); scaleAnim.setDuration(durations[i]); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 210, 122, 255); alphaAnim.setDuration(durations[i]); alphaAnim.setRepeatCount(-1); alphaAnim.setStartDelay(delays[i]); alphaAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphas[index] = (int) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); } }
/** * Execute an Animation effect by starting the Value Animator * * @param event Event to process effect * @throws IllegalStateException No effect set in event */ public void startAnimateEffect(@NonNull final DecoEvent event) throws IllegalStateException { if (event.getEffectType() == null) { throw new IllegalStateException("Unable to execute null effect type"); } // All effects run from 0.0 .. 1.0f in duration final float maxValue = 1.0f; cancelAnimation(); event.notifyStartListener(); mVisible = true; mDrawMode = event.getEventType(); mEffect = new DecoDrawEffect(event.getEffectType(), mPaint, event.getDisplayText()); mEffect.setRotationCount(event.getEffectRotations()); mPercentComplete = 0f; mValueAnimator = ValueAnimator.ofFloat(0, maxValue); mValueAnimator.setDuration(event.getEffectDuration()); Interpolator interpolator = (event.getInterpolator() != null) ? event.getInterpolator() : new LinearInterpolator(); mValueAnimator.setInterpolator(interpolator); mValueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mPercentComplete = Float.valueOf(valueAnimator.getAnimatedValue().toString()); for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) { seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete); } } }); mValueAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { event.notifyEndListener(); mDrawMode = DecoEvent.EventType.EVENT_MOVE; mVisible = mEffect.postExecuteVisibility(); mEffect = null; } }); mValueAnimator.start(); }
public AnimationBuilder custom(final AnimationListener.Update update, float... values) { for (final View view : views) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(getValues(values)); if (update != null) valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { //noinspection unchecked update.update(view, (Float) animation.getAnimatedValue()); } }); add(valueAnimator); } return this; }
private void handleActionUp() { if (isOutOfRange) { // When user drag it back, we should call onReset(). if (GeometryUtil.getDistanceBetween2Points(mDragCenter, mInitCenter) < resetDistance) { if (mListener != null) mListener.onReset(isOutOfRange); return; } // Otherwise disappeared(); } else { // 手指抬起时,弹回动画 mAnim = ValueAnimator.ofFloat(1.0f); mAnim.setInterpolator(new OvershootInterpolator(4.0f)); final PointF startPoint = new PointF(mDragCenter.x, mDragCenter.y); final PointF endPoint = new PointF(mStickCenter.x, mStickCenter.y); mAnim.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); PointF pointByPercent = GeometryUtil.getPointByPercent(startPoint, endPoint, fraction); updateDragCenter((float) pointByPercent.x, (float) pointByPercent.y); } }); mAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (mListener != null) mListener.onReset(isOutOfRange); } }); if (GeometryUtil.getDistanceBetween2Points(startPoint, endPoint) < 10) { mAnim.setDuration(10); } else { mAnim.setDuration(500); } mAnim.start(); } }
private void startSendingAnimation(final RevealView.RevealAnimationListener listener) { final int width = mFab.getLeft(); final int height = mFab.getTop(); ValueAnimator valueAnimator = new ValueAnimator(); valueAnimator.setDuration(Const.DURATION / 2); valueAnimator.setObjectValues(new PointF(0, 0)); valueAnimator.setInterpolator(new DecelerateInterpolator()); valueAnimator.setEvaluator( new TypeEvaluator<PointF>() { @Override public PointF evaluate(float fraction, PointF startValue, PointF endValue) { PointF point = new PointF(); point.x = (width) * (1 - fraction / 2); point.y = (height) - 0.85f * (height) * (fraction / 2) * (fraction / 2); return point; } }); valueAnimator.start(); valueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { PointF point = (PointF) animation.getAnimatedValue(); mFab.setX(point.x); mFab.setY(point.y); } }); valueAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mRevealView.reveal( (int) mFab.getX() + mFab.getWidth() / 2, (int) mFab.getY() + mFab.getHeight() / 2, getThemeColor(), Const.RADIUS, Const.DURATION, listener); } }); }
public void show(final View view) { pushedView = view; if (this.getParent() != null) return; synchronized (Snackbar.class) { if (!next.contains(this)) next.add(this); if (next.indexOf(this) == 0) { View decor = ((Activity) getContext()).getWindow().getDecorView(); ((ViewGroup) decor.findViewById(android.R.id.content)) .addView( this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); ViewHelper.setAlpha(content, 0); AnimUtils.flyIn(content, null); if (view != null) { ValueAnimator animator = ValueAnimator.ofFloat(0, -1); animator.setDuration(200); animator.setInterpolator(new DecelerateInterpolator()); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams(); Log.e( "snackbar " + Snackbar.this.hashCode(), "" + ((content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue())); ViewHelper.setTranslationY( view, (content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue()); if (pushedView.getParent() != null) ((View) pushedView.getParent()).postInvalidate(); } }); animator.start(); } if (duration != INFINITE) handler.postDelayed(hideRunnable, duration); } } }
/** * Kick off an animation to hide or show the arc. This results in an animation where both the * width of the line used for the arc and the transparency of the arc is altered over the duration * provided * * @param event Event to process * @param showArc True to show the arc, false to hide */ public void startAnimateHideShow(@NonNull final DecoEvent event, final boolean showArc) { cancelAnimation(); event.notifyStartListener(); mDrawMode = event.getEventType(); mPercentComplete = showArc ? 1.0f : 0f; mVisible = true; final float maxValue = 1.0f; mValueAnimator = ValueAnimator.ofFloat(0, maxValue); mValueAnimator.setDuration(event.getEffectDuration()); mValueAnimator.setInterpolator(new LinearInterpolator()); mValueAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float current = Float.valueOf(valueAnimator.getAnimatedValue().toString()); mPercentComplete = showArc ? (maxValue - current) : current; for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) { seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete); } } }); mValueAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (event.getEventType() != DecoEvent.EventType.EVENT_EFFECT) { event.notifyEndListener(); } } }); mValueAnimator.start(); }
@Override public void createAnimation() { int[] delays = new int[] {120, 240, 360}; for (int i = 0; i < 3; i++) { final int index = i; ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1); scaleAnim.setDuration(750); scaleAnim.setRepeatCount(-1); // 循环 scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // 每次值value值变化的时候 重设对应 位置圆的scale值 scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); // 通知重绘 } }); scaleAnim.start(); } }