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(); } }); }
/** * @param anim The animator, must not be null * @param arrayAnimator Incoming typed array for Animator's attributes. * @param arrayObjectAnimator Incoming typed array for Object Animator's attributes. */ private static void parseAnimatorFromTypeArray( ValueAnimator anim, TypedArray arrayAnimator, TypedArray arrayObjectAnimator) { long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300); long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0); int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0); TypeEvaluator evaluator = null; // Must be a path animator by the time I reach here if (valueType == VALUE_TYPE_PATH) { evaluator = setupAnimatorForPath(anim, arrayAnimator); } else { throw new IllegalArgumentException("target is not a pathType target"); } anim.setDuration(duration); anim.setStartDelay(startDelay); if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) { anim.setRepeatCount(arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0)); } if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) { anim.setRepeatMode( arrayAnimator.getInt(R.styleable.Animator_android_repeatMode, ValueAnimator.RESTART)); } if (evaluator != null) { anim.setEvaluator(evaluator); } if (arrayObjectAnimator != null) { setupObjectAnimator(anim, arrayObjectAnimator); } }
/** * Setup the Animator to achieve path morphing. * * @param anim The target Animator which will be updated. * @param arrayAnimator TypedArray for the ValueAnimator. * @return the PathDataEvaluator. */ private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim, TypedArray arrayAnimator) { TypeEvaluator evaluator = null; String fromString = arrayAnimator.getString(R.styleable.Animator_vc_valueFrom); String toString = arrayAnimator.getString(R.styleable.Animator_vc_valueTo); PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString); PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString); if (nodesFrom != null) { if (nodesTo != null) { anim.setObjectValues(nodesFrom, nodesTo); if (!PathParser.canMorph(nodesFrom, nodesTo)) { throw new InflateException( arrayAnimator.getPositionDescription() + " Can't morph from " + fromString + " to " + toString); } } else { anim.setObjectValues((Object) nodesFrom); } evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom)); } else if (nodesTo != null) { anim.setObjectValues((Object) nodesTo); evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo)); } if (DBG_ANIMATOR_INFLATER && evaluator != null) { Log.v(LOG_TAG, "create a new PathDataEvaluator here"); } return evaluator; }
/** * 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 start() { setup(duration); animationSaturation.start(); animationContrast.start(); animationAlpha.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); }
/** Pause any move animation currently in progress */ public boolean pause() { if (mValueAnimator != null && mValueAnimator.isRunning() && !mIsPaused) { mValueAnimator.cancel(); mIsPaused = true; return true; } return false; }
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(); } }
private void updateZoomAnimator(float f) { if (f > mAnimatorDuration) { f = mAnimatorDuration - 1; } if (f >= 0) { for (ValueAnimator animator : mAnimators) { animator.setCurrentPlayTime((long) f); } } }
// 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(); }
/** * 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++; }
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(); }
@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(); }
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(); }
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; }
@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 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(); }
/** * If we are currently animating we stop it first before starting a new animation from the current * position */ public void cancelAnimation() { if (mValueAnimator != null) { mValueAnimator.cancel(); } mEventCurrent = null; if (mColorAnimate != null) { mPaint.setColor(mSeriesItem.getColor()); mColorAnimate = null; } }
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 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 }
private void performDismiss() { // Animate the dismissed view to zero-height and then fire the dismiss // callback. // This triggers layout on each animation frame; in the future we may // want to do something // smarter and more performant. final ViewGroup.LayoutParams lp = mView.getLayoutParams(); final int originalHeight = mView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCallback.onDismiss(mView, mToken); // Reset view presentation setAlpha(mView, 1f); ViewHelper.setTranslationX(mView, 0); // mView.setAlpha(1f); // mView.setTranslationX(0); lp.height = originalHeight; mView.setLayoutParams(lp); } }); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); mView.setLayoutParams(lp); } }); animator.start(); }
/** * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip With a * color transition animation * * @param color the final color * @param duration the transition color animation duration */ public void setColor(int color, int duration) { ValueAnimator colorAnim = ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setDuration(duration); colorAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final int animatedValue = (Integer) animation.getAnimatedValue(); int colorAlpha = colorWithAlpha(animatedValue, lastPercent); mHeader.headerBackground.setBackgroundColor(colorAlpha); mHeader.statusBackground.setBackgroundColor(colorAlpha); mHeader.toolbar.setBackgroundColor(colorAlpha); mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha); mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha); // set the new color as MaterialViewPager's color settings.color = animatedValue; } }); colorAnim.start(); }
private void createAnimation(long duration) { if (duration < defaultAnimationTime) { duration = defaultAnimationTime; } // TextView titleBarTitle = getTitleBar().getTitleView(); // PropertyValuesHolder alphaToV = PropertyValuesHolder.ofFloat("alpha", 0f, 1f); // PropertyValuesHolder alphaToG = PropertyValuesHolder.ofFloat("alpha", 1f, 0f); ValueAnimator background = ObjectAnimator.ofFloat(0, 1f).setDuration(duration); background.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { int color = getResources().getColor(R.color.uikit_white); @Override public void onAnimationUpdate(ValueAnimator animation) { Float alpha = (Float) animation.getAnimatedValue(); int a = (int) (alpha * 255); int newColor = Color.argb(a, Color.red(color), Color.green(color), Color.blue(color)); getTitleBar().setBackgroundColor(newColor); getTitleBar() .setBackDrawable( a > 253 ? R.drawable.uikit_bt_back_pressed : R.drawable.uikit_bt_back); getTitleBar() .getTitleView() .setTextColor( getResources().getColor(a > 253 ? R.color.uikit_black : R.color.uikit_white)); getTitleBar() .setShopCardImg( a > 253 ? R.drawable.uikit_ic_shop_cart_orange : R.drawable.uikit_ic_shop_cart_white); } }); mAnimators.add(background); // mAnimators.add(ObjectAnimator.ofPropertyValuesHolder(titleBarTitle, alphaToV) // .setDuration(duration)); }
/** * 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 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 protected void onDraw(Canvas canvas) { super.onDraw( canvas); // To change body of overridden methods use File | Settings | File Templates. canvas.drawRect(0, 0, mWidth, mHeight, backgroundPaint); float barWidth = (drawBoxW - (drawBoxW / 10)) / 3; float gap = drawBoxH / 30; float movement = drawBoxH / 2 * fadeAndScaleAnimator.getAnimatedFraction(); canvas.drawRect(left, top, left + barWidth, bottom, barPaint); canvas.drawRect(left + barWidth + 5, top, left + barWidth * 2, bottom, barPaint); canvas.drawRect( left + barWidth * 2 + 5, top + movement, left + barWidth * 3, bottom, barPaint); canvas.rotate(rotationAnimator.getAnimatedFraction()); }
/** * Creates a new animation whose parameters come from the specified context and attributes set. * * @param res The resources * @param attrs The set of attributes holding the animation parameters * @param anim Null if this is a ValueAnimator, otherwise this is an ObjectAnimator */ private static ValueAnimator loadAnimator( Context c, Resources res, Resources.Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws Resources.NotFoundException { TypedArray arrayAnimator = null; TypedArray arrayObjectAnimator = null; if (theme != null) { arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0); } else { arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator); } // If anim is not null, then it is an object animator. if (anim != null) { if (theme != null) { arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0); } else { arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator); } } if (anim == null) { anim = new ValueAnimator(); } parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator); final int resId = arrayAnimator.getResourceId(R.styleable.Animator_android_interpolator, 0); if (resId > 0) { anim.setInterpolator(AnimationUtils.loadInterpolator(c, resId)); } arrayAnimator.recycle(); if (arrayObjectAnimator != null) { arrayObjectAnimator.recycle(); } return anim; }