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.viewpagerindicator.TabMovablePageIndicator.java

private void animateScrollWithIndicator(TabView tabView) {
    int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;

    AnimatorSet as = new AnimatorSet();
    as.setDuration(300);//from  w  w w .  j a va  2s.com

    ArrayList<Animator> animations = new ArrayList<Animator>();

    // scroll
    ObjectAnimator animScrollX = ObjectAnimator.ofInt(TabMovablePageIndicator.this, "scrollX", scrollPos);
    animScrollX.setInterpolator(new AccelerateDecelerateInterpolator());
    animations.add(animScrollX);

    // indicator position
    int left = tabView.getLeft();
    //      int width = tabView.getWidth();
    int textWidth = tabView.wordWidth;
    //      int x = left + (width - textWidth) / 2 - mExtendWidth * 2;
    //      x = x < 0 ? 0 : x;

    ObjectAnimator translateXAnim = ObjectAnimator.ofFloat(mIndicator, "translationX", left);
    translateXAnim.setInterpolator(new OvershootInterpolator(0.8f));
    animations.add(translateXAnim);

    // indicator width
    ValueAnimator animWidth = ValueAnimator.ofInt(mIndicator.getLayoutParams().width,
            textWidth + mExtendWidth * 2);
    animWidth.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mIndicator.getLayoutParams();
            lp.width = (Integer) animation.getAnimatedValue();

            mIndicator.setLayoutParams(lp);
            requestLayout();
        }
    });
    animations.add(animWidth);

    as.playTogether(animations);
    as.start();
}

From source file:com.arsy.maps_library.MapRipple.java

private void startAnimation(final int numberOfRipple) {
    ValueAnimator animator = ValueAnimator.ofInt(0, (int) mDistance);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setDuration(mRippleDuration);
    animator.setEvaluator(new IntEvaluator());
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* w  w w . j  a  va  2s  . c  om*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int animated = (int) valueAnimator.getAnimatedValue();
            mGroundOverlays[numberOfRipple].setDimensions(animated);
            if (mDistance - animated <= 10) {
                if (mLatLng != mPrevLatLng) {
                    mGroundOverlays[numberOfRipple].setPosition(mLatLng);
                }
            }
        }
    });
    animator.start();
    mAnimators[numberOfRipple] = animator;
}

From source file:org.digitalcampus.oppia.activity.DownloadMediaActivity.java

private void showDownloadMediaMessage() {
    TranslateAnimation anim = new TranslateAnimation(0, 0, -200, 0);
    anim.setDuration(900);/*from  w w w. j av  a 2s  . c o  m*/
    missingMediaContainer.startAnimation(anim);

    missingMediaContainer.measure(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    ValueAnimator animator = ValueAnimator.ofInt(0, missingMediaContainer.getMeasuredHeight());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        //@Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mediaList.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            mediaList.setSelectionAfterHeaderView();
        }
    });
    animator.setStartDelay(200);
    animator.setDuration(700);
    animator.start();
}

From source file:org.digitalcampus.oppia.activity.DownloadMediaActivity.java

private void hideDownloadMediaMessage() {

    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, -200);
    anim.setDuration(900);/*  w  w w  .  j av  a 2  s.co m*/
    missingMediaContainer.startAnimation(anim);

    missingMediaContainer.measure(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    ValueAnimator animator = ValueAnimator.ofInt(missingMediaContainer.getMeasuredHeight(), 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        //@Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mediaList.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            mediaList.setSelectionAfterHeaderView();
        }
    });
    animator.setStartDelay(0);
    animator.setDuration(700);
    animator.start();

    missingMediaContainer.setVisibility(View.GONE);
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

private void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation
    // animations,
    // accounting for how the scale will affect the final position of the
    // text./*  w ww  .j ava2 s  .  co  m*/
    final float resultScale = mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale)
            * (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mFormulaEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mFormulaEditText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course
    // of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            formulaTextColor);
    textColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            /*
             * mResultEditText.setTextColor((int) valueAnimator
             * .getAnimatedValue());
             */
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(textColorAnimator,
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
            ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mResultEditText.setText(result);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Reset all of the values modified during the animation.
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.android.contacts.activities.ActionBarAdapter.java

private void animateTabHeightChange(int start, int end) {
    if (mPortraitTabs == null) {
        return;/*from   w  w  w . j a v a2  s.  co m*/
    }
    final ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            setPortraitTabHeight(value);
        }
    });
    animator.setDuration(100).start();
}

From source file:com.shalzz.attendance.activity.MainActivity.java

public void setDrawerAsUp(boolean enabled) {
    if (mDrawerLayout == null)
        return;/*from ww w  .  j  a va 2s .  c  om*/

    float start = enabled ? 0f : 1f;
    float end = enabled ? 1f : 0f;
    mDrawerLayout.setDrawerLockMode(
            enabled ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);

    ValueAnimator anim = ValueAnimator.ofFloat(start, end);
    anim.addUpdateListener(valueAnimator -> {
        float slideOffset = (Float) valueAnimator.getAnimatedValue();
        mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset);
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(300);
    anim.start();
}

From source file:com.folioreader.view.ConfigView.java

private void toggleBlackTheme() {

    int day = getResources().getColor(R.color.white);
    int night = getResources().getColor(R.color.night);
    int darkNight = getResources().getColor(R.color.dark_night);
    final int diffNightDark = night - darkNight;

    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mIsNightMode ? night : day,
            mIsNightMode ? day : night);
    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override/*from   www .j a  v  a2  s.  com*/
        public void onAnimationUpdate(ValueAnimator animator) {
            int value = (int) animator.getAnimatedValue();
            mContainer.setBackgroundColor(value);
            if (mConfigViewCallback != null) {
                mConfigViewCallback.onBackgroundUpdate(value - diffNightDark);
            }
        }
    });

    colorAnimation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mIsNightMode = !mIsNightMode;
            Config.getConfig().setNightMode(mIsNightMode);
            mConfigViewCallback.onConfigChange();
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });

    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.start();
}

From source file:cn.com.hgh.view.SlideSwitch.java

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(500);/*from  www.  j  a va 2s . c  om*/
    toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator());
    //      toDestAnim.start();
    toDestAnim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            //            frontRect_left = (Integer) animation.getAnimatedValue();
            //            alpha = (int) (255 * (float) frontRect_left / (float) max_left);
            //            invalidateView();
        }
    });
    toDestAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (toRight) {
                isOpen = true;
                if (listener != null)
                    listener.open();
                frontRect_left_begin = max_left;
            } else {
                isOpen = false;
                if (listener != null)
                    listener.close();
                frontRect_left_begin = min_left;
            }

        }
    });
}

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

private ValueAnimator createAnimator(@NonNull ShadowAnimatorImpl impl) {
    final ValueAnimator animator = new ValueAnimator();
    animator.setInterpolator(ANIM_INTERPOLATOR);
    animator.setDuration(PRESSED_ANIM_DURATION);
    animator.addListener(impl);//from  w  w  w  . j av  a2  s .  c  o  m
    animator.addUpdateListener(impl);
    animator.setFloatValues(0, 1);
    return animator;
}