Example usage for android.animation ValueAnimator ofFloat

List of usage examples for android.animation ValueAnimator ofFloat

Introduction

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

Prototype

public static ValueAnimator ofFloat(float... values) 

Source Link

Document

Constructs and returns a ValueAnimator that animates between float values.

Usage

From source file:Main.java

public static Animator animFlow(android.animation.ValueAnimator.AnimatorUpdateListener animatorupdatelistener) {
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] { 0.0F, 1.0F });
    valueanimator.setInterpolator(new AccelerateInterpolator());
    valueanimator.addUpdateListener(animatorupdatelistener);
    return valueanimator;
}

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

/**
 * perform opening animation for the specified node
 *
 * @param node node to be animated//from  ww  w .  j  av a 2 s  . c  o  m
 */
private void animateDrillIn(final Node<?> node) {
    final int index = activeNode.getIndex() + (activeNode.getDepth() > 1 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

            for (int i = 0; i < getChildCount(); ++i) {
                if (i < index) {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index);
                } else if (i > index) {
                    getChildAt(i).setTranslationY(headerHeight * i
                            + ((Float) animation.getAnimatedValue()) * (getHeight() - headerHeight * index));
                } else {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index); // move active item
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            updateViews(node, true);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(index + 1, getChildCount(), 0);
}

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

/**
 * perform closing animation for the specified node
 *
 * @param node node to be animated/*from  w  w  w  . j  a v  a2  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:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java

/**
 * Custom animation builder./*  w  w  w.j  a  v  a  2s . c  o  m*/
 *
 * @param update the update
 * @param values the values
 * @return the animation builder
 */
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;
}

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

/**
 * perform a fade in animation for showing node content
 *
 * @param node active node/*from   w w  w.j  a  v a  2 s .co  m*/
 */
private void fadeIn(final Node<?> node) {
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = getChildCount()
                    - (node.hasChildren() ? node.getChildCount() : 1); i < getChildCount(); ++i) {
                getChildAt(i).setAlpha(((Float) animation.getAnimatedValue()));
            }
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void setupAnimators() {
    // A zoom-in/zoom-out animator
    mZoomAnimator = ValueAnimator.ofFloat(1.f);
    mZoomAnimator.setDuration(350L);//from  w w w . j a  va2  s  .co m
    mZoomAnimator.setInterpolator(new DecelerateInterpolator());
    mZoomAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentZoom = (Float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(TimelineChartView.this);
        }
    });
    mZoomAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mInZoomOut) {
                // Swap temporary refs
                swapRefs();

                // Update the view, notify and end the animation
                Message.obtain(mUiHandler, MSG_UPDATE_COMPUTED_DATA, 1, 0).sendToTarget();
            } else {
                mState = STATE_IDLE;
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mState = STATE_IDLE;
        }

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