Search in sources :

Example 11 with TimeInterpolator

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

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 12 with TimeInterpolator

use of android.animation.TimeInterpolator in project assertj-android by square.

the class ViewPropertyAnimatorAssert method hasInterpolator.

@TargetApi(JELLY_BEAN_MR2)
public ViewPropertyAnimatorAssert hasInterpolator(TimeInterpolator interpolator) {
    isNotNull();
    TimeInterpolator actualInterpolator = actual.getInterpolator();
    // 
    assertThat(actualInterpolator).overridingErrorMessage("Expected interpolator <%s> but was <%s>.", interpolator, // 
    actualInterpolator).isEqualTo(interpolator);
    return this;
}
Also used : TimeInterpolator(android.animation.TimeInterpolator) TargetApi(android.annotation.TargetApi)

Example 13 with TimeInterpolator

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

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 14 with TimeInterpolator

use of android.animation.TimeInterpolator in project Launcher3 by chislon.

the class DeleteDropTarget method onFlingToDelete.

public void onFlingToDelete(final DragObject d, int x, int y, PointF vel) {
    final boolean isAllApps = d.dragSource instanceof AppsCustomizePagedView;
    // Don't highlight the icon as it's animating
    d.dragView.setColor(0);
    d.dragView.updateInitialScaleToCurrentScale();
    // Don't highlight the target if we are flinging from AllApps
    if (isAllApps) {
        resetHoverColor();
    }
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        // Defer animating out the drop target if we are animating to it
        mSearchDropTargetBar.deferOnDragEnd();
        mSearchDropTargetBar.finishAnimations();
    }
    final ViewConfiguration config = ViewConfiguration.get(mLauncher);
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final int duration = FLING_DELETE_ANIMATION_DURATION;
    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 float mOffset = 0f;

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - startTime) / duration);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    AnimatorUpdateListener updateCb = null;
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        updateCb = createFlingToTrashAnimatorListener(dragLayer, d, vel, config);
    } else if (mFlingDeleteMode == MODE_FLING_DELETE_ALONG_VECTOR) {
        updateCb = createFlingAlongVectorAnimatorListener(dragLayer, d, vel, startTime, duration, config);
    }
    deferCompleteDropIfUninstalling(d);
    Runnable onAnimationEndRunnable = new Runnable() {

        @Override
        public void run() {
            // itself, otherwise, complete the drop to initiate the deletion process
            if (!isAllApps) {
                mLauncher.exitSpringLoadedDragMode();
                completeDrop(d);
            }
            mLauncher.getDragController().onDeferredEndFling(d);
        }
    };
    dragLayer.animateView(d.dragView, updateCb, duration, tInterpolator, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator)

Example 15 with TimeInterpolator

use of android.animation.TimeInterpolator in project Launcher3 by chislon.

the class DeleteDropTarget method createFlingToTrashAnimatorListener.

/**
     * Creates an animation from the current drag view to the delete trash icon.
     */
private AnimatorUpdateListener createFlingToTrashAnimatorListener(final DragLayer dragLayer, DragObject d, PointF vel, ViewConfiguration config) {
    final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    // Calculate how far along the velocity vector we should put the intermediate point on
    // the bezier curve
    float velocity = Math.abs(vel.length());
    float vp = Math.min(1f, velocity / (config.getScaledMaximumFlingVelocity() / 2f));
    int offsetY = (int) (-from.top * vp);
    int offsetX = (int) (offsetY / (vel.y / vel.x));
    // intermediate t/l
    final float y2 = from.top + offsetY;
    final float x2 = from.left + offsetX;
    // drag view t/l
    final float x1 = from.left;
    final float y1 = from.top;
    // delete target t/l
    final float x3 = to.left;
    final float y3 = to.top;
    final TimeInterpolator scaleAlphaInterpolator = new TimeInterpolator() {

        @Override
        public float getInterpolation(float t) {
            return t * t * t * t * t * t * t * t;
        }
    };
    return new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final DragView dragView = (DragView) dragLayer.getAnimatedView();
            float t = ((Float) animation.getAnimatedValue()).floatValue();
            float tp = scaleAlphaInterpolator.getInterpolation(t);
            float initialScale = dragView.getInitialScale();
            float finalAlpha = 0.5f;
            float scale = dragView.getScaleX();
            float x1o = ((1f - scale) * dragView.getMeasuredWidth()) / 2f;
            float y1o = ((1f - scale) * dragView.getMeasuredHeight()) / 2f;
            float x = (1f - t) * (1f - t) * (x1 - x1o) + 2 * (1f - t) * t * (x2 - x1o) + (t * t) * x3;
            float y = (1f - t) * (1f - t) * (y1 - y1o) + 2 * (1f - t) * t * (y2 - x1o) + (t * t) * y3;
            dragView.setTranslationX(x);
            dragView.setTranslationY(y);
            dragView.setScaleX(initialScale * (1f - tp));
            dragView.setScaleY(initialScale * (1f - tp));
            dragView.setAlpha(finalAlpha + (1f - finalAlpha) * (1f - tp));
        }
    };
}
Also used : Rect(android.graphics.Rect) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) 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