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:net.margaritov.preference.colorpicker.ColorPickerDialog.java

private ValueAnimator createAlphaAnimator(int start, int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.setDuration(500);/*w  w w. j a v  a2 s  .c o m*/
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            float currentAlpha = value / 100f;
            mActionBarMain.setAlpha(1f - currentAlpha);
            mActionBarEditHex.setAlpha(currentAlpha);
            mDivider.setAlpha(currentAlpha);
        }
    });
    if (mHideEditHexBar) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mActionBarMain.setVisibility(View.VISIBLE);
                ViewCompat.jumpDrawablesToCurrentState(mActionBarMain);
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mActionBarEditHex.setVisibility(View.GONE);
                mDivider.setVisibility(View.GONE);
            }
        });
    } else {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mActionBarEditHex.setVisibility(View.VISIBLE);
                ViewCompat.jumpDrawablesToCurrentState(mActionBarEditHex);
                mDivider.setVisibility(View.VISIBLE);
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mActionBarMain.setVisibility(View.GONE);
            }
        });
    }
    return animator;
}

From source file:com.telenav.nodeflow.NodeFlowLayout.java

/**
 * perform closing animation for the specified node
 *
 * @param node node to be animated//w  w  w  . j  av a 2 s .c o m
 */
private void animateDrillOut(final Node<?> node) {
    final Node<?> parent = node.getParent();
    if (parent.getDepth() > 0)
        addView(_getHeaderView(node.getParent()), 0);//add parent
    if (nodeChangeListener != null && node.getParent().getDepth() > 0)
        nodeChangeListener.onParentNodeOpening(getChildAt(0), node.getParent());
    for (int i = 0; i < node.getParent().getChildCount(); ++i) {
        if (i != node.getIndex())
            addView(_getHeaderView(node.getParent().getChildAt(i)), i + (parent.getDepth() > 0 ? 1 : 0));
    }

    final int newIndex = node.getIndex() + (parent.getDepth() > 0 ? 1 : 0);
    final int aux = parent.getChildCount() + (parent.getDepth() > 0 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = 0; i < aux; ++i) {
                if (i < newIndex) {
                    getChildAt(i).setTranslationY(headerHeight * (-newIndex + i)
                            + headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                } else if (i > newIndex) {
                    getChildAt(i)
                            .setTranslationY((getHeight() + headerHeight * (i - (newIndex + 1))) - ((getHeight()
                                    - (node.getIndex() + 1 + (parent.getDepth() > 0 ? 1 : 0)) * headerHeight)
                                    * ((Float) animation.getAnimatedValue())));
                } else {
                    getChildAt(newIndex)
                            .setTranslationY(headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            activeNode = parent;
            updateViews(node, false);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(newIndex + 1, aux, 1);
}

From source file:org.xbmc.kore.ui.generic.NavigationDrawerFragment.java

/**
 * Animates the drawerToggle from the hamburger to an arrow or vice versa
 * @param toArrow True, hamburger to arrow, false arrow to hamburger
 *///from   w w w.  j av a 2 s  .  co m
public void animateDrawerToggle(final boolean toArrow) {
    float start = toArrow ? 0.0f : 1.0f, end = 1.0f - start;

    ValueAnimator anim = ValueAnimator.ofFloat(start, end);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(500);
    anim.start();
}

From source file:com.telenav.nodeflow.NodeFlowLayout.java

/**
 * perform alpha animation associated with closing or opening a node
 *
 * @param startIndex start index of child views to be animated
 * @param endIndex   end index of child views to be animated
 * @param destAlpha  final alpha of child views to be animated
 *//* w  ww  . j  ava  2  s . com*/
private void animateDrillAlpha(final int startIndex, final int endIndex, final int destAlpha) {
    ValueAnimator animator = ValueAnimator.ofFloat(1 - destAlpha, destAlpha);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = startIndex; i < endIndex; ++i) {
                getChildAt(i).setAlpha(((Float) animation.getAnimatedValue()));
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            for (int i = startIndex; i < getChildCount(); ++i) {
                getChildAt(i).setAlpha(1 - destAlpha);
            }
        }
    });
    animator.setDuration(duration);
    if (destAlpha == 1)
        animator.setInterpolator(new AccelerateInterpolator());
    else
        animator.setInterpolator(new DecelerateInterpolator(2));
    animator.start();
}

From source file:com.waz.zclient.pages.main.conversation.views.row.footer.FooterViewController.java

public ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setDuration(250);//from  ww  w. jav  a 2 s.co  m
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams == null) {
                // needed for tests
                return;
            }
            layoutParams.height = (Integer) valueAnimator.getAnimatedValue();
            view.setLayoutParams(layoutParams);
        }
    });
    return animator;
}

From source file:com.dean.phonesafe.ui.SlideSwitch.java

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(500);//from  w  w  w  .  ja  v a  2s  .  c  o m
    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.advaitaworld.widgets.SlidingTabLayout.java

private void updateTitleColors(int prevSelectedPosition, int newSelectedPosition) {
    if (mSelectedTabColor == 0 && mDefaultTabColor == 0) {
        return;/*from  w  ww  .  j a v a2 s.  c o m*/
    }
    View tabViewPrev = mTabStrip.getChildAt(prevSelectedPosition);
    View tabViewNew = mTabStrip.getChildAt(newSelectedPosition);
    final TextView tabTitlePrev = getTabTitleView(tabViewPrev);
    final TextView tabTitleNew = getTabTitleView(tabViewNew);

    ArgbEvaluator evaluator = new ArgbEvaluator();
    ValueAnimator anim1 = new ValueAnimator();
    anim1.setIntValues(mDefaultTabColor, mSelectedTabColor);
    anim1.setEvaluator(evaluator);
    anim1.setDuration(300);
    anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tabTitleNew.setTextColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    ValueAnimator anim2 = new ValueAnimator();
    anim2.setIntValues(mSelectedTabColor, mDefaultTabColor);
    anim2.setEvaluator(evaluator);
    anim2.setDuration(300);
    anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tabTitlePrev.setTextColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim1.start();
    anim2.start();
}

From source file:com.mishiranu.dashchan.util.DrawerToggle.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void setDrawerIndicatorMode(int mode) {
    if (this.mode != mode) {
        this.mode = mode;
        ActionBar actionBar = activity.getActionBar();
        if (mode == MODE_DISABLED) {
            if (C.API_JELLY_BEAN_MR2) {
                actionBar.setHomeAsUpIndicator(null);
            }//from w w w.j  av  a2 s  . c  o  m
            actionBar.setDisplayHomeAsUpEnabled(false);
        } else {
            actionBar.setDisplayHomeAsUpEnabled(true);
            if (C.API_LOLLIPOP) {
                activity.getActionBar().setHomeAsUpIndicator(arrowDrawable);
                boolean open = drawerLayout.isDrawerOpen(Gravity.START) && arrowDrawable.position == 1f;
                if (!open) {
                    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
                    animator.setDuration(DRAWER_CLOSE_DURATION);
                    animator.addUpdateListener(new StateArrowAnimatorListener(mode == MODE_DRAWER));
                    animator.start();
                }
            } else {
                setActionBarUpIndicatorObsolete(mode == MODE_DRAWER ? slideDrawable : homeAsUpIndicator);
            }
        }
    }
}

From source file:com.audionote.widget.SlideSwitch.java

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(200);/*w w  w  . jav  a 2 s.c  o m*/
    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.sociablue.nanodegree_p1.MovieListFragment.java

private void initializeFab(View rootView) {
    final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container);
    final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar);
    final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar);
    Fab.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override/*w w w  .ja  v a2s .c  o  m*/
        public void onClick(View v) {

            //Menu Button Icon Animation
            //Setting up necessary variables
            long animationDuration = 500;
            float containerHeight = buttonContainer.getHeight();
            float containerCenterY = containerHeight / 2;
            float containerCenterX = buttonContainer.getWidth() / 2;
            float topBarCenter = topBar.getTop() + topBar.getHeight() / 2;
            float widthOfBar = topBar.getWidth();
            float heightOfBar = topBar.getHeight();
            final float distanceBetweenBars = (containerCenterY - topBarCenter);

            /**
             *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties
             *and objects at the same time. Also, will try to break intialization into smaller functions.
             */

            //Setting up animations of hamburger bars and rotation

            /**
             * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar.
             * Y Translation is 1/2 the height of the hamburger bar minus the distance.
             * Subtracting the distance from the height because the distance between bars is
             * calculated of the exact center of the button.
             * With out the subtraction the bar would translate slightly below the middle bar.
             */
            float yTranslation = heightOfBar / 2 - distanceBetweenBars;
            float xTranslation = widthOfBar / 2 + heightOfBar / 2;
            TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars);
            topBarTranslationAnim.setDuration((long) (animationDuration * 0.8));
            topBarTranslationAnim.setFillAfter(true);

            //Animation for bottom hamburger bar. Translates and Rotates to create 'X'
            AnimationSet bottomBarAnimation = new AnimationSet(true);
            bottomBarAnimation.setFillAfter(true);

            //Rotate to create cross. (The cross becomes the X after the button rotation completes"
            RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f,
                    Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
            bottomBarRotationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarRotationAnimation);

            //Translate to correct X alignment
            TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE,
                    -yTranslation);
            bottomBarTranslationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarTranslationAnimation);

            //Button Specific Animations
            //Rotate Button Container
            RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            containerRotationAnimation.setDuration(animationDuration);
            containerRotationAnimation.setFillAfter(true);

            //Animate change of button color between Active and Disabled colors that have been
            //defined in color.xml
            int activeColor = getResources().getColor(R.color.active_button);
            int disabledColor = getResources().getColor(R.color.disabled_button);

            //Need to use ValueAnimator because property animator does not support BackgroundTint
            ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor);
            buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue()));
                }
            });
            buttonColorAnimation.setDuration(animationDuration);

            //Start all the animations
            topBar.startAnimation(topBarTranslationAnim);
            bottomBar.startAnimation(bottomBarAnimation);
            buttonContainer.startAnimation(containerRotationAnimation);
            buttonColorAnimation.start();

            //Toogle mMenu open and closed
            if (mMenu.isOpen()) {
                //If mMenu is open, do the reverse of the animation
                containerRotationAnimation
                        .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator()));
                mMenu.close();
            } else {
                bottomBarAnimation.setInterpolator(new AccelerateInterpolator());
                mMenu.open();
            }
        }
    });
}