Example usage for android.animation ValueAnimator ValueAnimator

List of usage examples for android.animation ValueAnimator ValueAnimator

Introduction

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

Prototype

public ValueAnimator() 

Source Link

Document

Creates a new ValueAnimator object.

Usage

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE ?
        final int viewHeight = -mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {//from ww w .j a v a2 s.c  o m
            mView.setTranslationY(viewHeight);
        }

        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        final int viewHeight = mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*from w ww .j  a  v  a2  s  . co  m*/
            mView.setTranslationY(viewHeight);
        }
        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:ticwear.design.widget.CollapsingToolbarLayout.java

private void animateScrim(int targetAlpha) {
    ensureToolbar();//  w w  w .java  2s.  c  o m
    if (mScrimAnimator == null) {
        mScrimAnimator = new ValueAnimator();
        mScrimAnimator.setDuration(SCRIM_ANIMATION_DURATION);
        mScrimAnimator
                .setInterpolator(targetAlpha > mScrimAlpha ? AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR
                        : AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR);
        mScrimAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                setScrimAlpha((int) animator.getAnimatedValue());
            }
        });
    } else if (mScrimAnimator.isRunning()) {
        mScrimAnimator.cancel();
    }

    mScrimAnimator.setIntValues(mScrimAlpha, targetAlpha);
    mScrimAnimator.start();
}

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(0, mView.getHeight());
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//from w w  w. ja  v  a 2 s. com
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE 0
        mView.setTranslationY(0);/*from   w  w w.  j  av a 2s. co  m*/
        final ValueAnimator animator = new ValueAnimator();
        //TODO CHANGE ?
        animator.setIntValues(0, -mView.getHeight());
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_out);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:acr.browser.lightning.browser.fragment.anim.HorizontalItemAnimator.java

private void clearInterpolator(View view) {
    if (mDefaultInterpolator == null) {
        mDefaultInterpolator = new ValueAnimator().getInterpolator();
    }//from  w ww  . j  a  va  2 s. c  o m
    view.animate().setInterpolator(mDefaultInterpolator);
}

From source file:android.support.v17.leanback.app.BackgroundManager.java

private BackgroundManager(Activity activity, boolean isSupportFragmentActivity) {
    mContext = activity;/*from   w  ww .j av  a 2  s .  co  m*/
    mService = BackgroundContinuityService.getInstance();
    mHeightPx = mContext.getResources().getDisplayMetrics().heightPixels;
    mWidthPx = mContext.getResources().getDisplayMetrics().widthPixels;
    mHandler = new Handler();

    Interpolator defaultInterpolator = new FastOutLinearInInterpolator();
    mAccelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.accelerate_interpolator);
    mDecelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.decelerate_interpolator);

    mAnimator = ValueAnimator.ofInt(0, FULL_ALPHA);
    mAnimator.addListener(mAnimationListener);
    mAnimator.addUpdateListener(mAnimationUpdateListener);
    mAnimator.setInterpolator(defaultInterpolator);

    mDimAnimator = new ValueAnimator();
    mDimAnimator.addUpdateListener(mDimUpdateListener);

    TypedArray ta = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    mThemeDrawableResourceId = ta.getResourceId(0, -1);
    if (mThemeDrawableResourceId < 0) {
        if (DEBUG)
            Log.v(TAG, "BackgroundManager no window background resource!");
    }
    ta.recycle();

    if (isSupportFragmentActivity) {
        createSupportFragment((FragmentActivity) activity);
    } else {
        createFragment(activity);
    }
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

private void startTransform(final int state) {
    if (mTransfrom == null) {
        return;//  w  ww. j av  a  2  s. c o  m
    }
    ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.setDuration(300);
    valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    if (state == STATE_TRANSFORM_IN) {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.startScale,
                mTransfrom.endScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.startRect.left,
                mTransfrom.endRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.startRect.top,
                mTransfrom.endRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.startRect.width,
                mTransfrom.endRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.startRect.height,
                mTransfrom.endRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 0, 255);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    } else {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.endScale,
                mTransfrom.startScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.endRect.left,
                mTransfrom.startRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.endRect.top,
                mTransfrom.startRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.endRect.width,
                mTransfrom.startRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.endRect.height,
                mTransfrom.startRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 255, 0);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    }

    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public synchronized void onAnimationUpdate(ValueAnimator animation) {
            mTransfrom.scale = (Float) animation.getAnimatedValue("scale");
            mTransfrom.rect.left = (Float) animation.getAnimatedValue("left");
            mTransfrom.rect.top = (Float) animation.getAnimatedValue("top");
            mTransfrom.rect.width = (Float) animation.getAnimatedValue("width");
            mTransfrom.rect.height = (Float) animation.getAnimatedValue("height");
            mBgAlpha = (Integer) animation.getAnimatedValue("alpha");
            invalidate();
            ((Activity) getContext()).getWindow().getDecorView().invalidate();
        }
    });
    valueAnimator.addListener(new ValueAnimator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            /*
             * ???center_cropout??center_crop?
             *  ???out???Normal???bug
             */
            // TODO ???
            if (state == STATE_TRANSFORM_IN) {
                mState = STATE_NORMAL;
            }
            if (mTransformListener != null) {
                mTransformListener.onTransformComplete(state);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }
    });
    valueAnimator.start();
}

From source file:com.hanbing.library.android.view.CustomTabLayout23.java

private void animateToTab(int newPosition) {
    if (newPosition == Tab.INVALID_POSITION) {
        return;//from   w w  w.  ja  v a 2 s. c  om
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f, true);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);

    if (startScrollX != targetScrollX) {
        if (mScrollAnimator == null) {
            mScrollAnimator = new ValueAnimator();
            mScrollAnimator.setInterpolator(new FastOutSlowInInterpolator());
            mScrollAnimator.setDuration(ANIMATION_DURATION);
            //                mScrollAnimator.setUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() {
            //                    @Override
            //                    public void onAnimationUpdate(ValueAnimatorCompat animator) {
            //                        scrollTo(animator.getAnimatedIntValue(), 0);
            //                    }
            //                });

            mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    scrollTo((Integer) animation.getAnimatedValue(), 0);
                }
            });
        }

        mScrollAnimator.setIntValues(startScrollX, targetScrollX);
        mScrollAnimator.start();
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION);
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

/**
 * Creates a new animation whose parameters come from the specified context
 * and attributes set.//  ww w. j ava  2s . c  om
 *
 * @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
 */
private static ValueAnimator loadAnimator(Context context, Resources res, Theme theme, AttributeSet attrs,
        ValueAnimator anim, float pathErrorScale, XmlPullParser parser) throws NotFoundException {
    TypedArray arrayAnimator = TypedArrayUtils.obtainAttributes(res, theme, attrs,
            AndroidResources.STYLEABLE_ANIMATOR);
    TypedArray arrayObjectAnimator = TypedArrayUtils.obtainAttributes(res, theme, attrs,
            AndroidResources.STYLEABLE_PROPERTY_ANIMATOR);

    if (anim == null) {
        anim = new ValueAnimator();
    }

    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator, pathErrorScale, parser);

    final int resID = TypedArrayUtils.getNamedResourceId(arrayAnimator, parser, "interpolator",
            AndroidResources.STYLEABLE_ANIMATOR_INTERPOLATOR, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtilsCompat.loadInterpolator(context, resID);
        anim.setInterpolator(interpolator);
    }

    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}