Example usage for android.animation ValueAnimator addUpdateListener

List of usage examples for android.animation ValueAnimator addUpdateListener

Introduction

In this page you can find the example usage for android.animation ValueAnimator addUpdateListener.

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Reset refresh state/*from   w  w w .  j av a2  s.  c  om*/
 * @param headerViewHeight
 */
private void resetHeaderView(int headerViewHeight) {
    headerView.stopAnimation();
    headerView.setStartEndTrim(0, 0.75f);
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            headerView.setLayoutParams(lp);
            moveTargetView(lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            resetRefreshState();

        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Reset loadmore state/*  w  w w  .  jav  a 2 s. com*/
 * @param headerViewHeight
 */
private void resetFootView(int headerViewHeight) {
    footerView.stopAnimation();
    footerView.setStartEndTrim(0.5f, 1.25f);
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) footerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            footerView.setLayoutParams(lp);
            moveTargetView(-lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            resetLoadmoreState();

        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start Refresh//  www.  j  a v a 2 s  . co  m
 * @param headerViewHeight
 */
private void startRefresh(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, refreshViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            headerView.setLayoutParams(lp);
            moveTargetView(lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            headerView.startAnimation();
            //TODO updateLoadText
            if (onRefreshListener != null) {
                onRefreshListener.onRefresh();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start loadmore//from w w  w  .  ja v a  2 s .  com
 * @param headerViewHeight
 */
private void startLoadmore(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, loadingViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) footerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            footerView.setLayoutParams(lp);
            moveTargetView(-lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            footerView.startAnimation();
            //TODO updateLoadText
            if (onLoadingListener != null) {
                onLoadingListener.onLoading();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void animateToArrow(boolean toArrow) {
    int start, stop;
    if (toArrow) {
        start = 0;/*from w w w . j  a va2s . c o m*/
        stop = 1;
    } else {
        start = 1;
        stop = 0;
    }
    ValueAnimator anim = ValueAnimator.ofFloat(start, stop);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            toggle.onDrawerSlide(drawer, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(300);
    anim.start();
}

From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java

public void fadeInSignal(final int colorTo, final ValueAnimator.AnimatorUpdateListener updateListener) {
    final int colorFrom = DEFAULT_BACKGROUND_COLOR;
    final ValueAnimator colorAnimation = getValueAnimator(colorTo, colorFrom);
    colorAnimation.setDuration(DEFAULT_DURATION_ENTER); // milliseconds
    colorAnimation.addUpdateListener(updateListener);
    colorAnimation.addListener(new Animator.AnimatorListener() {
        @Override/*  w  ww . j a v a  2s . c  o  m*/
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            final ValueAnimator colorAnimation = getValueAnimator(colorFrom, colorTo);
            colorAnimation.setDuration(DEFAULT_DURATION_EXIT); // milliseconds
            colorAnimation.addUpdateListener(updateListener);
            colorAnimation.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    colorAnimation.start();
}

From source file:com.gu.swiperefresh.ProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final ValueAnimator animator = ObjectAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  ww  . j a  v a 2 s.c o  m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float interpolatedTime = Float.valueOf(animation.getAnimatedValue().toString());
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    });
    animator.setRepeatCount(Animation.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setInterpolator(LINEAR_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

        }

        @Override
        public void onAnimationStart(Animator animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animator;
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

private void onDropPhase() {
    mWaveView.animationDropCircle();//  w w w .  ja v a2s  .c  om

    ValueAnimator animator = ValueAnimator.ofFloat(0, 0);
    animator.setDuration(500);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mCircleView.setTranslationY(mWaveView.getCurrentCircleCenterY() + mCircleView.getHeight() / 2.f);
        }
    });
    animator.start();
    setRefreshing(true, true);
    mIsBeingDropped = true;
    setEventPhase(EVENT_PHASE.DROPPING);
    setEnabled(false);
}

From source file:com.android.settings.widget.DotsPageIndicator.java

private ValueAnimator createJoiningAnimator(final int leftJoiningDot, final long startDelay) {
    // animate the joining fraction for the given dot
    ValueAnimator joining = ValueAnimator.ofFloat(0f, 1.0f);
    joining.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* w w w.  j  a  va2 s .c o  m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setJoiningFraction(leftJoiningDot, valueAnimator.getAnimatedFraction());
        }
    });
    joining.setDuration(animHalfDuration);
    joining.setStartDelay(startDelay);
    joining.setInterpolator(interpolator);
    return joining;
}

From source file:com.quanliren.quan_one.pull.swipe.SwipeRefreshLayout.java

private ValueAnimator startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }/*from  ww w  .ja  va  2 s  . c  om*/
    ValueAnimator alpha = new ObjectAnimator().ofFloat(0f, 1f);
    alpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha)
                    * Float.valueOf(animation.getAnimatedValue().toString()))));
        }
    });
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    alpha.start();
    return alpha;
}