Search in sources :

Example 21 with AnimatorSetBuilder

use of com.android.launcher3.anim.AnimatorSetBuilder in project Neo-Launcher by NeoApplications.

the class FlingAndHoldTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    if (mMotionPauseDetector.isPaused() && handlingOverviewAnim()) {
        if (mPeekAnim != null) {
            mPeekAnim.cancel();
        }
        AnimatorSetBuilder builder = new AnimatorSetBuilder();
        builder.setInterpolator(ANIM_VERTICAL_PROGRESS, OVERSHOOT_1_2);
        if ((OVERVIEW.getVisibleElements(mLauncher) & HOTSEAT_ICONS) != 0) {
            builder.setInterpolator(ANIM_HOTSEAT_SCALE, OVERSHOOT_1_2);
            builder.setInterpolator(ANIM_HOTSEAT_TRANSLATE, OVERSHOOT_1_2);
        }
        AnimatorSet overviewAnim = mLauncher.getStateManager().createAtomicAnimation(NORMAL, OVERVIEW, builder, ANIM_ALL, ATOMIC_DURATION);
        overviewAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onSwipeInteractionCompleted(OVERVIEW, Touch.SWIPE);
            }
        });
        overviewAnim.start();
    } else if (mGoingHome && Float.compare(Math.signum(velocity), Math.signum(mProgressMultiplier)) == 0) {
        mAnimatingToHome = true;
        AnimatorSetBuilder builder = new AnimatorSetBuilder();
        AnimatorSet homeAnim = mLauncher.getStateManager().createAtomicAnimation(NORMAL, NORMAL, builder, ANIM_ALL, ATOMIC_DURATION);
        homeAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onSwipeInteractionCompleted(NORMAL, Touch.SWIPE);
                mAnimatingToHome = false;
            }
        });
        homeAnim.start();
        mLauncher.getWorkspace().snapToPage(0);
    } else if (!mAnimatingToHome) {
        super.onDragEnd(velocity);
    }
    mMotionPauseDetector.clear();
}
Also used : AnimatorSetBuilder(com.android.launcher3.anim.AnimatorSetBuilder) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet)

Example 22 with AnimatorSetBuilder

use of com.android.launcher3.anim.AnimatorSetBuilder in project Neo-Launcher by NeoApplications.

the class NoButtonQuickSwitchTouchController method onDragEnd.

@Override
public void onDragEnd(PointF velocity) {
    boolean horizontalFling = mSwipeDetector.isFling(velocity.x);
    boolean verticalFling = mSwipeDetector.isFling(velocity.y);
    boolean noFling = !horizontalFling && !verticalFling;
    int logAction = noFling ? Touch.SWIPE : Touch.FLING;
    if (mMotionPauseDetector.isPaused() && noFling) {
        cancelAnimations();
        Animator overviewAnim = mLauncher.getAppTransitionManager().createStateElementAnimation(INDEX_PAUSE_TO_OVERVIEW_ANIM);
        overviewAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onAnimationToStateCompleted(OVERVIEW, logAction);
            }
        });
        overviewAnim.start();
        return;
    }
    final LauncherState targetState;
    if (horizontalFling && verticalFling) {
        if (velocity.x < 0) {
            // Flinging left and up or down both go back home.
            targetState = NORMAL;
        } else {
            if (velocity.y > 0) {
                // Flinging right and down goes to quick switch.
                targetState = QUICK_SWITCH;
            } else {
                // Flinging up and right could go either home or to quick switch.
                // Determine the target based on the higher velocity.
                targetState = Math.abs(velocity.x) > Math.abs(velocity.y) ? QUICK_SWITCH : NORMAL;
            }
        }
    } else if (horizontalFling) {
        targetState = velocity.x > 0 ? QUICK_SWITCH : NORMAL;
    } else if (verticalFling) {
        targetState = velocity.y > 0 ? QUICK_SWITCH : NORMAL;
    } else {
        // If user isn't flinging, just snap to the closest state based on x progress.
        boolean passedHorizontalThreshold = mXOverviewAnim.getInterpolatedProgress() > 0.5f;
        targetState = passedHorizontalThreshold ? QUICK_SWITCH : NORMAL;
    }
    // Animate the various components to the target state.
    float xProgress = mXOverviewAnim.getProgressFraction();
    float startXProgress = Utilities.boundToRange(xProgress + velocity.x * getSingleFrameMs(mLauncher) / mXRange, 0f, 1f);
    final float endXProgress = targetState == NORMAL ? 0 : 1;
    long xDuration = BaseSwipeDetector.calculateDuration(velocity.x, Math.abs(endXProgress - startXProgress));
    ValueAnimator xOverviewAnim = mXOverviewAnim.getAnimationPlayer();
    xOverviewAnim.setFloatValues(startXProgress, endXProgress);
    xOverviewAnim.setDuration(xDuration).setInterpolator(scrollInterpolatorForVelocity(velocity.x));
    mXOverviewAnim.dispatchOnStartWithVelocity(endXProgress, velocity.x);
    boolean flingUpToNormal = verticalFling && velocity.y < 0 && targetState == NORMAL;
    float yProgress = mYOverviewAnim.getProgressFraction();
    float startYProgress = Utilities.boundToRange(yProgress - velocity.y * getSingleFrameMs(mLauncher) / mYRange, 0f, 1f);
    final float endYProgress;
    if (flingUpToNormal) {
        endYProgress = 1;
    } else if (targetState == NORMAL) {
        // Keep overview at its current scale/translationY as it slides off the screen.
        endYProgress = startYProgress;
    } else {
        endYProgress = 0;
    }
    long yDuration = BaseSwipeDetector.calculateDuration(velocity.y, Math.abs(endYProgress - startYProgress));
    ValueAnimator yOverviewAnim = mYOverviewAnim.getAnimationPlayer();
    yOverviewAnim.setFloatValues(startYProgress, endYProgress);
    yOverviewAnim.setDuration(yDuration);
    mYOverviewAnim.dispatchOnStartWithVelocity(endYProgress, velocity.y);
    ValueAnimator nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
    if (flingUpToNormal && !mIsHomeScreenVisible) {
        // We are flinging to home while workspace is invisible, run the same staggered
        // animation as from an app.
        // Update mNonOverviewAnim to do nothing so it doesn't interfere.
        updateNonOverviewAnim(targetState, new AnimatorSetBuilder(), 0);
        nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
        new StaggeredWorkspaceAnim(mLauncher, velocity.y, false).start();
    } else {
        boolean canceled = targetState == NORMAL;
        if (canceled) {
            // Let the state manager know that the animation didn't go to the target state,
            // but don't clean up yet (we already clean up when the animation completes).
            mNonOverviewAnim.dispatchOnCancelWithoutCancelRunnable();
        }
        float startProgress = mNonOverviewAnim.getProgressFraction();
        float endProgress = canceled ? 0 : 1;
        nonOverviewAnim.setFloatValues(startProgress, endProgress);
        mNonOverviewAnim.dispatchOnStartWithVelocity(endProgress, horizontalFling ? velocity.x : velocity.y);
    }
    nonOverviewAnim.setDuration(Math.max(xDuration, yDuration));
    mNonOverviewAnim.setEndAction(() -> onAnimationToStateCompleted(targetState, logAction));
    cancelAnimations();
    xOverviewAnim.start();
    yOverviewAnim.start();
    nonOverviewAnim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorSetBuilder(com.android.launcher3.anim.AnimatorSetBuilder) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) StaggeredWorkspaceAnim(com.android.quickstep.util.StaggeredWorkspaceAnim) ValueAnimator(android.animation.ValueAnimator)

Aggregations

AnimatorSetBuilder (com.android.launcher3.anim.AnimatorSetBuilder)16 Animator (android.animation.Animator)7 AnimatorSet (android.animation.AnimatorSet)4 Interpolator (android.view.animation.Interpolator)4 PropertySetter (com.android.launcher3.anim.PropertySetter)4 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)3 AnimationConfig (com.android.launcher3.LauncherStateManager.AnimationConfig)3 RecentsView (com.android.quickstep.views.RecentsView)3 LauncherState (com.android.launcher3.LauncherState)2 ScaleAndTranslation (com.android.launcher3.LauncherState.ScaleAndTranslation)2 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)2 SpringObjectAnimator (com.android.launcher3.anim.SpringObjectAnimator)2 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)1 PageAlphaProvider (com.android.launcher3.LauncherState.PageAlphaProvider)1 LauncherStateManager (com.android.launcher3.LauncherStateManager)1 AnimationSuccessListener (com.android.launcher3.anim.AnimationSuccessListener)1 DragLayer (com.android.launcher3.dragndrop.DragLayer)1 OverviewScrim (com.android.launcher3.graphics.OverviewScrim)1