Search in sources :

Example 16 with TimeInterpolator

use of android.animation.TimeInterpolator in project platform_frameworks_base by android.

the class ViewPropertyAnimatorRT method doStartAnimation.

private void doStartAnimation(ViewPropertyAnimator parent) {
    int size = parent.mPendingAnimations.size();
    long startDelay = parent.getStartDelay();
    long duration = parent.getDuration();
    TimeInterpolator interpolator = parent.getInterpolator();
    if (interpolator == null) {
        // Documented to be LinearInterpolator in ValueAnimator.setInterpolator
        interpolator = sLinearInterpolator;
    }
    if (!RenderNodeAnimator.isNativeInterpolator(interpolator)) {
        interpolator = new FallbackLUTInterpolator(interpolator, duration);
    }
    for (int i = 0; i < size; i++) {
        NameValuesHolder holder = parent.mPendingAnimations.get(i);
        int property = RenderNodeAnimator.mapViewPropertyToRenderProperty(holder.mNameConstant);
        final float finalValue = holder.mFromValue + holder.mDeltaValue;
        RenderNodeAnimator animator = new RenderNodeAnimator(property, finalValue);
        animator.setStartDelay(startDelay);
        animator.setDuration(duration);
        animator.setInterpolator(interpolator);
        animator.setTarget(mView);
        animator.start();
        mAnimators[property] = animator;
    }
    parent.mPendingAnimations.clear();
}
Also used : FallbackLUTInterpolator(com.android.internal.view.animation.FallbackLUTInterpolator) NameValuesHolder(android.view.ViewPropertyAnimator.NameValuesHolder) TimeInterpolator(android.animation.TimeInterpolator)

Example 17 with TimeInterpolator

use of android.animation.TimeInterpolator in project android_frameworks_base by ParanoidAndroid.

the class RecentsPanelView method animateInIconOfFirstTask.

private void animateInIconOfFirstTask() {
    if (mItemToAnimateInWhenWindowAnimationIsFinished != null && !mRecentTasksLoader.isFirstScreenful()) {
        int timeSinceWindowAnimation = (int) (System.currentTimeMillis() - mWindowAnimationStartTime);
        final int minStartDelay = 150;
        final int startDelay = Math.max(0, Math.min(minStartDelay - timeSinceWindowAnimation, minStartDelay));
        final int duration = 250;
        final ViewHolder holder = mItemToAnimateInWhenWindowAnimationIsFinished;
        final TimeInterpolator cubic = new DecelerateInterpolator(1.5f);
        FirstFrameAnimatorHelper.initializeDrawListener(holder.iconView);
        for (View v : new View[] { holder.iconView, holder.labelView, holder.calloutLine }) {
            if (v != null) {
                ViewPropertyAnimator vpa = v.animate().translationX(0).translationY(0).alpha(1f).setStartDelay(startDelay).setDuration(duration).setInterpolator(cubic);
                FirstFrameAnimatorHelper h = new FirstFrameAnimatorHelper(vpa, v);
            }
        }
        mItemToAnimateInWhenWindowAnimationIsFinished = null;
        mAnimateIconOfFirstTask = false;
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) TimeInterpolator(android.animation.TimeInterpolator) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 18 with TimeInterpolator

use of android.animation.TimeInterpolator in project android_frameworks_base by ParanoidAndroid.

the class PagedView method onFlingToDelete.

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private long mStartTime;

        private float mOffset;

        /* Anonymous inner class ctor */
        {
            mStartTime = startTime;
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION);
    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);
    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator) View(android.view.View)

Example 19 with TimeInterpolator

use of android.animation.TimeInterpolator in project android_frameworks_base by ParanoidAndroid.

the class Tweener method to.

public static Tweener to(Object object, long duration, Object... vars) {
    long delay = 0;
    AnimatorUpdateListener updateListener = null;
    AnimatorListener listener = null;
    TimeInterpolator interpolator = null;
    // Iterate through arguments and discover properties to animate
    ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
    for (int i = 0; i < vars.length; i += 2) {
        if (!(vars[i] instanceof String)) {
            throw new IllegalArgumentException("Key must be a string: " + vars[i]);
        }
        String key = (String) vars[i];
        Object value = vars[i + 1];
        if ("simultaneousTween".equals(key)) {
        // TODO
        } else if ("ease".equals(key)) {
            // TODO: multiple interpolators?
            interpolator = (TimeInterpolator) value;
        } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
            updateListener = (AnimatorUpdateListener) value;
        } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
            listener = (AnimatorListener) value;
        } else if ("delay".equals(key)) {
            delay = ((Number) value).longValue();
        } else if ("syncWith".equals(key)) {
        // TODO
        } else if (value instanceof float[]) {
            props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
        } else if (value instanceof int[]) {
            props.add(PropertyValuesHolder.ofInt(key, ((int[]) value)[0], ((int[]) value)[1]));
        } else if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            props.add(PropertyValuesHolder.ofFloat(key, floatValue));
        } else {
            throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
        }
    }
    // Re-use existing tween, if present
    Tweener tween = sTweens.get(object);
    ObjectAnimator anim = null;
    if (tween == null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
        tween = new Tweener(anim);
        sTweens.put(object, tween);
        if (DEBUG)
            Log.v(TAG, "Added new Tweener " + tween);
    } else {
        anim = sTweens.get(object).animator;
        // Cancel all animators for given object
        replace(props, object);
    }
    if (interpolator != null) {
        anim.setInterpolator(interpolator);
    }
    // Update animation with properties discovered in loop above
    anim.setStartDelay(delay);
    anim.setDuration(duration);
    if (updateListener != null) {
        // There should be only one
        anim.removeAllUpdateListeners();
        anim.addUpdateListener(updateListener);
    }
    if (listener != null) {
        // There should be only one.
        anim.removeAllListeners();
        anim.addListener(listener);
    }
    anim.addListener(mCleanupListener);
    return tween;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator) AnimatorListener(android.animation.Animator.AnimatorListener) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 20 with TimeInterpolator

use of android.animation.TimeInterpolator in project android_frameworks_base by ParanoidAndroid.

the class GlowPadView method hideTargets.

private void hideTargets(boolean animate, boolean expanded) {
    mTargetAnimations.cancel();
    // Note: these animations should complete at the same time so that we can swap out
    // the target assets asynchronously from the setTargetResources() call.
    mAnimatingTargets = animate;
    final int duration = animate ? HIDE_ANIMATION_DURATION : 0;
    final int delay = animate ? HIDE_ANIMATION_DELAY : 0;
    final float targetScale = expanded ? TARGET_SCALE_EXPANDED : TARGET_SCALE_COLLAPSED;
    final int length = mTargetDrawables.size();
    final TimeInterpolator interpolator = Ease.Cubic.easeOut;
    for (int i = 0; i < length; i++) {
        TargetDrawable target = mTargetDrawables.get(i);
        target.setState(TargetDrawable.STATE_INACTIVE);
        mTargetAnimations.add(Tweener.to(target, duration, "ease", interpolator, "alpha", 0.0f, "scaleX", targetScale, "scaleY", targetScale, "delay", delay, "onUpdate", mUpdateListener));
    }
    float ringScaleTarget = expanded ? RING_SCALE_EXPANDED : RING_SCALE_COLLAPSED;
    ringScaleTarget *= mRingScaleFactor;
    mTargetAnimations.add(Tweener.to(mOuterRing, duration, "ease", interpolator, "alpha", 0.0f, "scaleX", ringScaleTarget, "scaleY", ringScaleTarget, "delay", delay, "onUpdate", mUpdateListener, "onComplete", mTargetUpdateListener));
    mTargetAnimations.start();
}
Also used : TimeInterpolator(android.animation.TimeInterpolator)

Aggregations

TimeInterpolator (android.animation.TimeInterpolator)29 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)14 ValueAnimator (android.animation.ValueAnimator)10 ObjectAnimator (android.animation.ObjectAnimator)8 Animator (android.animation.Animator)5 Rect (android.graphics.Rect)5 View (android.view.View)5 NameValuesHolder (android.view.ViewPropertyAnimator.NameValuesHolder)5 FallbackLUTInterpolator (com.android.internal.view.animation.FallbackLUTInterpolator)5 ArrayList (java.util.ArrayList)4 AnimatorListener (android.animation.Animator.AnimatorListener)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 AnimatorSet (android.animation.AnimatorSet)3 PropertyValuesHolder (android.animation.PropertyValuesHolder)3 Resources (android.content.res.Resources)3 ViewConfiguration (android.view.ViewConfiguration)3 ViewGroup (android.view.ViewGroup)3 TargetApi (android.annotation.TargetApi)2 Transition (android.transitions.everywhere.Transition)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2