Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

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

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

@Override
public boolean onDoubleTap(MotionEvent event) {
    if (!mIsZoomPanSupported) {
        return false;
    }//from w  ww.j ava  2s  .  c o m
    mZoomIn = !mZoomIn;
    float scale = 1.0f;
    final float x = event.getX();
    final float y = event.getY();
    if (mZoomIn) {
        scale = mMasterImage.getMaxScaleFactor();
    }
    if (scale != mMasterImage.getScaleFactor()) {
        if (mAnimatorScale != null) {
            mAnimatorScale.cancel();
        }
        mAnimatorScale = ValueAnimator.ofFloat(mMasterImage.getScaleFactor(), scale);
        float translateX = (getWidth() / 2 - x);
        float translateY = (getHeight() / 2 - y);
        Point translation = mMasterImage.getTranslation();
        int startTranslateX = translation.x;
        int startTranslateY = translation.y;
        if (scale != 1.0f) {
            translation.x = (int) (mOriginalTranslation.x + translateX);
            translation.y = (int) (mOriginalTranslation.y + translateY);
        } else {
            translation.x = 0;
            translation.y = 0;
        }
        constrainTranslation(translation, scale);
        startAnimTranslation(startTranslateX, translation.x, startTranslateY, translation.y,
                mAnimationZoomDelay);
        mAnimatorScale.setDuration(mAnimationZoomDelay);
        mAnimatorScale.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mMasterImage.setScaleFactor((Float) animation.getAnimatedValue());
                invalidate();
            }
        });
        mAnimatorScale.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                applyTranslationConstraints();
                invalidate();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        mAnimatorScale.start();
    }
    return true;
}

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

/**
 * @param h ???//  w  w  w  .j  a v  a2s . c  o  m
 */
public void startWaveAnimation(float h) {
    h = Math.min(h, MAX_WAVE_HEIGHT) * mWidth;
    mWaveReverseAnimator = ValueAnimator.ofFloat(h, 0.f);
    mWaveReverseAnimator.setDuration(WAVE_ANIMATOR_DURATION);
    mWaveReverseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float h = (Float) valueAnimator.getAnimatedValue();
            mWavePath.moveTo(0, 0);
            mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f);
            mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f);
            mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0);
            postInvalidate();
        }
    });
    mWaveReverseAnimator.setInterpolator(new BounceInterpolator());
    mWaveReverseAnimator.start();
}

From source file:bottombar.BottomBarTab.java

private void animateColors(int previousColor, int color) {
    ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(previousColor, color);
    anim.setEvaluator(new ArgbEvaluator());
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*  www.java2 s.c  o m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setColors((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim.setDuration(150);
    anim.start();
}

From source file:jp.co.recruit_lifestyle.android.widget.WaveView.java

public void startDropAnimation() {

    mDisappearCircleAnimator = ValueAnimator.ofFloat(1.f, 1.f);
    mDisappearCircleAnimator.setDuration(1);
    mDisappearCircleAnimator.start();//from  ww  w .j a  v  a 2  s .c o  m

    mDropCircleAnimator = ValueAnimator.ofFloat(500 * (mWidth / 1440.f), mMaxDropHeight);
    mDropCircleAnimator.setDuration(DROP_CIRCLE_ANIMATOR_DURATION);
    mDropCircleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentCircleCenterY = (Float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(WaveView.this);
        }
    });
    mDropCircleAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    mDropCircleAnimator.start();

    mDropVertexAnimator = ValueAnimator.ofFloat(0.f, mMaxDropHeight - mDropCircleRadius);
    mDropVertexAnimator.setDuration(DROP_VERTEX_ANIMATION_DURATION);
    mDropVertexAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropVertexAnimator.start();

    mDropBounceVerticalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceVerticalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceVerticalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceVerticalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceVerticalAnimator.setStartDelay(DROP_VERTEX_ANIMATION_DURATION);
    mDropBounceVerticalAnimator.start();

    mDropBounceHorizontalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceHorizontalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceHorizontalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceHorizontalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceHorizontalAnimator
            .setStartDelay((long) (DROP_VERTEX_ANIMATION_DURATION + DROP_BOUNCE_ANIMATOR_DURATION * 0.25));
    mDropBounceHorizontalAnimator.start();
}

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

/**
 * perform opening animation for the specified node
 *
 * @param node node to be animated// www.  j ava  2s  .  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:io.github.sin3hz.fastjumper.FastJumperDecoration.java

private void setupAnimators() {
    mThumbShowHideAnimator = ValueAnimator.ofFloat();
    mThumbShowHideAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  ww  .ja  v a 2 s  . co m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            setThumbLeftOffset(value);
        }
    });
    mThumbShowHideAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mThumbOffset == 1f) {
                setStateInternal(STATE_GONE);
            }
        }
    });
    mLabelExpandAnimator = ValueAnimator.ofFloat();
    mLabelExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            setLabelOffset(value);
        }
    });
    mLabelExpandAnimator.addListener(new AnimatorListenerAdapter() {

    });
    mLabelShowHideAnimator = ValueAnimator.ofFloat();
    mLabelShowHideAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            setLabelAlpha(value);
        }
    });
    mLabelShowHideAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mLabelAlpha == 0) {
                mLabelVisible = false;
            }
            mLabelHiding = false;
        }
    });
}

From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

private void startAnimTranslation(int fromX, int toX, int fromY, int toY, int delay) {
    if (fromX == toX && fromY == toY) {
        return;/* w ww. j  a v  a 2s . co m*/
    }
    if (mAnimatorTranslateX != null) {
        mAnimatorTranslateX.cancel();
    }
    if (mAnimatorTranslateY != null) {
        mAnimatorTranslateY.cancel();
    }
    mAnimatorTranslateX = ValueAnimator.ofInt(fromX, toX);
    mAnimatorTranslateY = ValueAnimator.ofInt(fromY, toY);
    mAnimatorTranslateX.setDuration(delay);
    mAnimatorTranslateY.setDuration(delay);
    mAnimatorTranslateX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Point translation = mMasterImage.getTranslation();
            translation.x = (Integer) animation.getAnimatedValue();
            mMasterImage.setTranslation(translation);
            invalidate();
        }
    });
    mAnimatorTranslateY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Point translation = mMasterImage.getTranslation();
            translation.y = (Integer) animation.getAnimatedValue();
            mMasterImage.setTranslation(translation);
            invalidate();
        }
    });
    mAnimatorTranslateX.start();
    mAnimatorTranslateY.start();
}

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

public void startDropAnimation() {
    // show dropBubble again
    mDisappearCircleAnimator = ValueAnimator.ofFloat(1.f, 1.f);
    mDisappearCircleAnimator.setDuration(1);
    mDisappearCircleAnimator.start();//from ww w . j  a v a2 s  .c  o m

    mDropCircleAnimator = ValueAnimator.ofFloat(500 * (mWidth / 1440.f), mMaxDropHeight);
    mDropCircleAnimator.setDuration(DROP_CIRCLE_ANIMATOR_DURATION);
    mDropCircleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentCircleCenterY = (float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(WaveView.this);
        }
    });
    mDropCircleAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    mDropCircleAnimator.start();

    mDropVertexAnimator = ValueAnimator.ofFloat(0.f, mMaxDropHeight - mDropCircleRadius);
    mDropVertexAnimator.setDuration(DROP_VERTEX_ANIMATION_DURATION);
    mDropVertexAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropVertexAnimator.start();

    mDropBounceVerticalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceVerticalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceVerticalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceVerticalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceVerticalAnimator.setStartDelay(DROP_VERTEX_ANIMATION_DURATION);
    mDropBounceVerticalAnimator.start();

    mDropBounceHorizontalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceHorizontalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceHorizontalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceHorizontalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceHorizontalAnimator
            .setStartDelay((long) (DROP_VERTEX_ANIMATION_DURATION + DROP_BOUNCE_ANIMATOR_DURATION * 0.25));
    mDropBounceHorizontalAnimator.start();
}

From source file:feifei.project.view.widget.WaveView.java

public void startDropAnimation() {
    // show dropBubble again
    mDisappearCircleAnimator = ValueAnimator.ofFloat(1.f, 1.f);
    mDisappearCircleAnimator.setDuration(1);
    mDisappearCircleAnimator.start();//from   ww  w . j  ava 2  s. c o  m

    //todo ?
    mDropCircleAnimator = ValueAnimator.ofFloat(500 * (mWidth / 1440.f), mMaxDropHeight - 20);
    mDropCircleAnimator.setDuration(DROP_CIRCLE_ANIMATOR_DURATION);
    mDropCircleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentCircleCenterY = (float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(WaveView.this);
        }
    });
    mDropCircleAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    mDropCircleAnimator.start();

    mDropVertexAnimator = ValueAnimator.ofFloat(0.f, mMaxDropHeight - mDropCircleRadius);
    mDropVertexAnimator.setDuration(DROP_VERTEX_ANIMATION_DURATION);
    mDropVertexAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropVertexAnimator.start();

    mDropBounceVerticalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceVerticalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceVerticalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceVerticalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceVerticalAnimator.setStartDelay(DROP_VERTEX_ANIMATION_DURATION);
    mDropBounceVerticalAnimator.start();

    mDropBounceHorizontalAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mDropBounceHorizontalAnimator.setDuration(DROP_BOUNCE_ANIMATOR_DURATION);
    mDropBounceHorizontalAnimator.addUpdateListener(mAnimatorUpdateListener);
    mDropBounceHorizontalAnimator.setInterpolator(new DropBounceInterpolator());
    mDropBounceHorizontalAnimator
            .setStartDelay((long) (DROP_VERTEX_ANIMATION_DURATION + DROP_BOUNCE_ANIMATOR_DURATION * 0.25));
    mDropBounceHorizontalAnimator.start();
}

From source file:com.jsibbold.zoomage.ZoomageView.java

/**
 * Animate the matrix back to its original position after the user stopped interacting with it.
 *//* ww  w  .  ja  v a2 s .c o m*/
private void animateToStartMatrix() {

    final Matrix beginMatrix = new Matrix(getImageMatrix());
    beginMatrix.getValues(mValues);

    //difference in current and original values
    final float xsdiff = startValues[Matrix.MSCALE_X] - mValues[Matrix.MSCALE_X];
    final float ysdiff = startValues[Matrix.MSCALE_Y] - mValues[Matrix.MSCALE_Y];
    final float xtdiff = startValues[Matrix.MTRANS_X] - mValues[Matrix.MTRANS_X];
    final float ytdiff = startValues[Matrix.MTRANS_Y] - mValues[Matrix.MTRANS_Y];

    ValueAnimator anim = ValueAnimator.ofFloat(0, 1f);
    anim.addUpdateListener(new AnimatorUpdateListener() {

        final Matrix activeMatrix = new Matrix(getImageMatrix());
        final float[] values = new float[9];

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = (Float) animation.getAnimatedValue();
            activeMatrix.set(beginMatrix);
            activeMatrix.getValues(values);
            values[Matrix.MTRANS_X] = values[Matrix.MTRANS_X] + xtdiff * val;
            values[Matrix.MTRANS_Y] = values[Matrix.MTRANS_Y] + ytdiff * val;
            values[Matrix.MSCALE_X] = values[Matrix.MSCALE_X] + xsdiff * val;
            values[Matrix.MSCALE_Y] = values[Matrix.MSCALE_Y] + ysdiff * val;
            activeMatrix.setValues(values);
            setImageMatrix(activeMatrix);
        }
    });
    anim.setDuration(RESET_DURATION);
    anim.start();
}