Search in sources :

Example 56 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener 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 57 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener 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)

Example 58 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Launcher3 by chislon.

the class DragView method crossFade.

public void crossFade(int duration) {
    ValueAnimator va = LauncherAnimUtils.ofFloat(this, 0f, 1f);
    va.setDuration(duration);
    va.setInterpolator(new DecelerateInterpolator(1.5f));
    va.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCrossFadeProgress = animation.getAnimatedFraction();
        }
    });
    va.start();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 59 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Launcher3 by chislon.

the class FolderIcon method animateFirstItem.

private void animateFirstItem(final Drawable d, int duration, final boolean reverse, final Runnable onCompleteRunnable) {
    final PreviewItemDrawingParams finalParams = computePreviewItemDrawingParams(0, null);
    final float scale0 = 1.0f;
    final float transX0 = (mAvailableSpaceInPreview - d.getIntrinsicWidth()) / 2;
    final float transY0 = (mAvailableSpaceInPreview - d.getIntrinsicHeight()) / 2 + getPaddingTop();
    mAnimParams.drawable = d;
    ValueAnimator va = LauncherAnimUtils.ofFloat(this, 0f, 1.0f);
    va.addUpdateListener(new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            float progress = (Float) animation.getAnimatedValue();
            if (reverse) {
                progress = 1 - progress;
                mPreviewBackground.setAlpha(progress);
            }
            mAnimParams.transX = transX0 + progress * (finalParams.transX - transX0);
            mAnimParams.transY = transY0 + progress * (finalParams.transY - transY0);
            mAnimParams.scale = scale0 + progress * (finalParams.scale - scale0);
            invalidate();
        }
    });
    va.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mAnimating = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimating = false;
            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }
        }
    });
    va.setDuration(duration);
    va.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 60 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Launcher3 by chislon.

the class LauncherTransitionable method hideAppsCustomizeHelper.

/**
     * Zoom the camera back into the workspace, hiding 'fromView'.
     * This is the opposite of showAppsCustomizeHelper.
     * @param animated If true, the transition will be animated.
     */
private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, final boolean springLoaded, final Runnable onCompleteRunnable) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);
        mStateAnimation.cancel();
        mStateAnimation = null;
    }
    Resources res = getResources();
    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
    final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
    final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    if (toState == Workspace.State.NORMAL) {
        int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, stagger, -1);
    } else if (toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated);
    }
    setPivotsForZoom(fromView, scaleFactor);
    showHotseat(animated);
    if (animated) {
        final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(fromView);
        scaleAnim.scaleX(scaleFactor).scaleY(scaleFactor).setDuration(duration).setInterpolator(new Workspace.ZoomInInterpolator());
        final ObjectAnimator alphaAnim = LauncherAnimUtils.ofFloat(fromView, "alpha", 1f, 0f).setDuration(fadeOutDuration);
        alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaAnim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = 1f - (Float) animation.getAnimatedValue();
                dispatchOnLauncherTransitionStep(fromView, t);
                dispatchOnLauncherTransitionStep(toView, t);
            }
        });
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        mAppsCustomizeContent.pauseScrolling();
        mStateAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                fromView.setVisibility(View.GONE);
                dispatchOnLauncherTransitionEnd(fromView, animated, true);
                dispatchOnLauncherTransitionEnd(toView, animated, true);
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
                mAppsCustomizeContent.updateCurrentPageScroll();
                mAppsCustomizeContent.resumeScrolling();
            }
        });
        mStateAnimation.playTogether(scaleAnim, alphaAnim);
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
    } else {
        fromView.setVisibility(View.GONE);
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionEnd(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        dispatchOnLauncherTransitionEnd(toView, animated, true);
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Point(android.graphics.Point) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Resources(android.content.res.Resources)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6