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:org.chromium.chrome.browser.widget.animation.FocusAnimator.java

private void startAnimator(final Runnable callback) {
    // Don't animate anything if the number of children changed.
    if (mInitialNumberOfChildren != mLayout.getChildCount()) {
        finishAnimation(callback);// w  w w.  ja v a  2  s  .c  om
        return;
    }

    // Don't animate if children are already all in the correct places.
    boolean isAnimationNecessary = false;
    ArrayList<Integer> finalChildTops = calculateChildTops();
    for (int i = 0; i < finalChildTops.size() && !isAnimationNecessary; i++) {
        isAnimationNecessary |= finalChildTops.get(i).compareTo(mInitialTops.get(i)) != 0;
    }
    if (!isAnimationNecessary) {
        finishAnimation(callback);
        return;
    }

    // Animate each child moving and changing size to match their final locations.
    ArrayList<Animator> animators = new ArrayList<Animator>();
    ValueAnimator childAnimator = ValueAnimator.ofFloat(0f, 1f);
    animators.add(childAnimator);
    for (int i = 0; i < mLayout.getChildCount(); i++) {
        // The child is already where it should be.
        if (mInitialTops.get(i).compareTo(finalChildTops.get(i)) == 0
                && mInitialTops.get(i + 1).compareTo(finalChildTops.get(i + 1)) == 0) {
            continue;
        }

        final View child = mLayout.getChildAt(i);
        final int translationDifference = mInitialTops.get(i) - finalChildTops.get(i);
        final int oldHeight = mInitialTops.get(i + 1) - mInitialTops.get(i);
        final int newHeight = finalChildTops.get(i + 1) - finalChildTops.get(i);

        // Translate the child to its new place while changing where its bottom is drawn to
        // animate the child changing height without causing another layout.
        childAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float progress = (Float) animation.getAnimatedValue();
                child.setTranslationY(translationDifference * (1f - progress));

                if (oldHeight != newHeight) {
                    float animatedHeight = oldHeight * (1f - progress) + newHeight * progress;
                    child.setBottom(child.getTop() + (int) animatedHeight);
                }
            }
        });

        // Explicitly place the child in its final position in the end.
        childAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                child.setTranslationY(0);
                child.setBottom(child.getTop() + newHeight);
            }
        });
    }

    // Animate the height of the container itself changing.
    int oldContainerHeight = mInitialTops.get(mInitialTops.size() - 1);
    int newContainerHeight = finalChildTops.get(finalChildTops.size() - 1);
    ValueAnimator layoutAnimator = ValueAnimator.ofInt(oldContainerHeight, newContainerHeight);
    layoutAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mLayout.setBottom(((Integer) animation.getAnimatedValue()));
            requestChildFocus();
        }
    });
    animators.add(layoutAnimator);

    // Set up and kick off the animation.
    AnimatorSet animator = new AnimatorSet();
    animator.setDuration(ANIMATION_LENGTH_MS);
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.playTogether(animators);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            finishAnimation(callback);

            // Request a layout to put everything in the right final place.
            mLayout.requestLayout();
        }
    });
    animator.start();
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

private ValueAnimator createCircleAnimator() {
    final float maxDimen = Math.max(getWidth(), getHeight()) * 0.8F;
    final ValueAnimator animator = ValueAnimator.ofFloat(0F, maxDimen);
    animator.setDuration(CIRCLE_ANIMATION_DURATION_MILLIS);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* w w  w.  jav  a  2  s.c om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            circleRadius = (Float) animation.getAnimatedValue();
            invalidate();
        }
    });

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

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            drawingPressAnimation = false;
            invalidate();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    return animator;
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

private void continueAnimation(float horzOffset, int width) {
    ValueAnimator animator = ValueAnimator.ofFloat(horzOffset, width);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.setDuration((long) (150 * Math.abs(width - horzOffset) / width));
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from w  w w . ja  v  a 2s. c  om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            updateSlideOffset(value);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (mSlideListener != null) {
                mSlideListener.onSlideFinished();
            }
        }
    });

    animator.start();
}

From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissTouchListener.java

private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss
    // callback./*from  w w  w  .jav a  2 s.  c o  m*/
    // This triggers layout on each animation frame; in the future we may
    // want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallback.onDismiss(mView, mToken);
            // Reset view presentation
            setAlpha(mView, 1f);
            setTranslationX(mView, 0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}

From source file:com.wytiger.common.widget.SlideSwitch.java

private void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(500);/*from   ww  w. j  a v  a  2 s .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.example.google.maps.dataviz.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mMap == null) {
        return true;
    }/*from w  w  w .  ja  v  a  2s .c  o  m*/

    switch (item.getItemId()) {
    // Rotate the camera 360 deg.
    case R.id.action_rotate:
        if (mAnimator != null && mAnimator.isRunning()) {
            mAnimator.cancel();
        } else {
            mAnimator = ValueAnimator.ofFloat(0, 360);
            mAnimator.setDuration(3000);
            mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float bearing = (Float) animation.getAnimatedValue();
                    CameraPosition pos = CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing)
                            .build();
                    mMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
                }
            });
            mAnimator.start();
        }

        return true;

    // Chance the camera perspective.
    case R.id.action_perspective:
        CameraPosition currentPosition = mMap.getCameraPosition();
        CameraPosition newPosition;
        if (currentPosition.zoom == CAMERA_OBLIQUE_ZOOM && currentPosition.tilt == CAMERA_OBLIQUE_TILT) {
            newPosition = new CameraPosition.Builder().tilt(0).zoom(mInitZoom).bearing(0).target(mInitPosition)
                    .build();
        } else {
            newPosition = new CameraPosition.Builder().tilt(CAMERA_OBLIQUE_TILT).zoom(CAMERA_OBLIQUE_ZOOM)
                    .bearing(currentPosition.bearing).target(currentPosition.target).build();
        }
        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(newPosition));

        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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//from   www.j ava2s  .  co  m
        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:se.frikod.payday.DailyBudgetFragment.java

@TargetApi(11)
private void renderBudgetAnimated() {
    ValueAnimator animation = ValueAnimator.ofFloat((float) currentBudget, (float) budget.dailyBudget);
    animation.setDuration(500);//from ww  w.  ja  v a2s . c  o m

    animation.addUpdateListener(new AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator a) {
            renderBudget((Float) a.getAnimatedValue());
        }
    });

    animation.start();

}

From source file:cn.refactor.ultraindicator.lib.UltraIndicatorView.java

/**
 * start checked animation/*from  w w  w. j a va2 s.  co  m*/
 */
private void startCheckedAnim() {
    if (mValueAnimator != null && mValueAnimator.isRunning()) {
        return;
    }
    mValueAnimator = ValueAnimator.ofFloat(1.0f, 1.2f, 1.0f);
    mValueAnimator.setDuration(mAnimDuration);
    mValueAnimator.setInterpolator(new DecelerateInterpolator());
    mValueAnimator.setRepeatCount(0);
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float animatedValue = (float) animation.getAnimatedValue();
            mCheckedRunningRadius = animatedValue * mRadius;
            invalidate();
        }
    });
    mValueAnimator.start();
}

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

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(duration);/*from   w w  w.  j a v  a  2 s .  co  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;
            }
        }
    });
}