Search in sources :

Example 16 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class NavBarToHomeTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    boolean fling = mSwipeDetector.isFling(velocity);
    float progress = mCurrentAnimation.getProgressFraction();
    float interpolatedProgress = PULLBACK_INTERPOLATOR.getInterpolation(progress);
    boolean success = interpolatedProgress >= SUCCESS_TRANSITION_PROGRESS || (velocity < 0 && fling);
    if (success) {
        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            RecentsView recentsView = mLauncher.getOverviewPanel();
            recentsView.switchToScreenshot(null, () -> recentsView.finishRecentsAnimation(true, /* toRecents */
            null));
        }
        if (mStartState.overviewUi) {
            new OverviewToHomeAnim(mLauncher, () -> onSwipeInteractionCompleted(mEndState)).animateWithVelocity(velocity);
        } else {
            mLauncher.getStateManager().goToState(mEndState, true, forSuccessCallback(() -> onSwipeInteractionCompleted(mEndState)));
        }
        if (mStartState != mEndState) {
            logHomeGesture();
        }
        AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(mLauncher);
        if (topOpenView != null) {
            AbstractFloatingView.closeAllOpenViews(mLauncher);
        // TODO: add to WW log
        }
        TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
    } else {
        // Quickly return to the state we came from (we didn't move far).
        ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
        anim.setFloatValues(progress, 0);
        anim.addListener(forSuccessCallback(() -> onSwipeInteractionCompleted(mStartState)));
        anim.setDuration(80).start();
    }
}
Also used : RecentsView(com.android.quickstep.views.RecentsView) OverviewToHomeAnim(com.android.quickstep.util.OverviewToHomeAnim) ValueAnimator(android.animation.ValueAnimator) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 17 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class AbstractStateChangeTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    if (mCurrentAnimation == null) {
        // canceled us will handle a new state transition to clean up.
        return;
    }
    boolean fling = mDetector.isFling(velocity);
    boolean blockedFling = fling && mFlingBlockCheck.isBlocked();
    if (blockedFling) {
        fling = false;
    }
    final LauncherState targetState;
    final float progress = mCurrentAnimation.getProgressFraction();
    final float progressVelocity = velocity * mProgressMultiplier;
    final float interpolatedProgress = mCurrentAnimation.getInterpolatedProgress();
    if (fling) {
        targetState = Float.compare(Math.signum(velocity), Math.signum(mProgressMultiplier)) == 0 ? mToState : mFromState;
    // snap to top or bottom using the release velocity
    } else {
        targetState = (interpolatedProgress > SUCCESS_TRANSITION_PROGRESS) ? mToState : mFromState;
    }
    final float endProgress;
    final float startProgress;
    final long duration;
    // Increase the duration if we prevented the fling, as we are going against a high velocity.
    final int durationMultiplier = blockedFling && targetState == mFromState ? LauncherAnimUtils.blockedFlingDurationFactor(velocity) : 1;
    if (targetState == mToState) {
        endProgress = 1;
        if (progress >= 1) {
            duration = 0;
            startProgress = 1;
        } else {
            startProgress = Utilities.boundToRange(progress + progressVelocity * getSingleFrameMs(mLauncher), 0f, 1f);
            duration = BaseSwipeDetector.calculateDuration(velocity, endProgress - Math.max(progress, 0)) * durationMultiplier;
        }
    } else {
        // Let the state manager know that the animation didn't go to the target state,
        // but don't cancel ourselves (we already clean up when the animation completes).
        mCurrentAnimation.getTarget().removeListener(mClearStateOnCancelListener);
        mCurrentAnimation.dispatchOnCancel();
        endProgress = 0;
        if (progress <= 0) {
            duration = 0;
            startProgress = 0;
        } else {
            startProgress = Utilities.boundToRange(progress + progressVelocity * getSingleFrameMs(mLauncher), 0f, 1f);
            duration = BaseSwipeDetector.calculateDuration(velocity, Math.min(progress, 1) - endProgress) * durationMultiplier;
        }
    }
    if (targetState != mStartState) {
        logReachedState(targetState);
    }
    mCurrentAnimation.setEndAction(() -> onSwipeInteractionCompleted(targetState));
    ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
    anim.setFloatValues(startProgress, endProgress);
    updateSwipeCompleteAnimation(anim, duration, targetState, velocity, fling);
    mCurrentAnimation.dispatchOnStart();
    if (targetState == LauncherState.ALL_APPS) {
        if (mAllAppsOvershootStarted) {
            mLauncher.getAppsView().onRelease();
            mAllAppsOvershootStarted = false;
        } else {
            mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity, progress);
        }
    }
    anim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) ValueAnimator(android.animation.ValueAnimator)

Example 18 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_404Launcher by P-404.

the class NavBarToHomeTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    boolean fling = mSwipeDetector.isFling(velocity);
    float progress = mCurrentAnimation.getProgressFraction();
    float interpolatedProgress = PULLBACK_INTERPOLATOR.getInterpolation(progress);
    boolean success = interpolatedProgress >= SUCCESS_TRANSITION_PROGRESS || (velocity < 0 && fling);
    if (success) {
        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            RecentsView recentsView = mLauncher.getOverviewPanel();
            recentsView.switchToScreenshot(null, () -> recentsView.finishRecentsAnimation(true, /* toRecents */
            null));
        }
        if (mStartState.overviewUi) {
            new OverviewToHomeAnim(mLauncher, () -> onSwipeInteractionCompleted(mEndState)).animateWithVelocity(velocity);
        } else {
            mLauncher.getStateManager().goToState(mEndState, true, forSuccessCallback(() -> onSwipeInteractionCompleted(mEndState)));
        }
        if (mStartState != mEndState) {
            logHomeGesture();
        }
        AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(mLauncher);
        if (topOpenView != null) {
            AbstractFloatingView.closeAllOpenViews(mLauncher);
        // TODO: add to WW log
        }
        TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);
    } else {
        // Quickly return to the state we came from (we didn't move far).
        ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
        anim.setFloatValues(progress, 0);
        anim.addListener(forSuccessCallback(() -> onSwipeInteractionCompleted(mStartState)));
        anim.setDuration(80).start();
    }
}
Also used : RecentsView(com.android.quickstep.views.RecentsView) OverviewToHomeAnim(com.android.quickstep.util.OverviewToHomeAnim) ValueAnimator(android.animation.ValueAnimator) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 19 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_404Launcher by P-404.

the class RecentsView method createTaskLaunchAnimation.

public PendingAnimation createTaskLaunchAnimation(TaskView tv, long duration, Interpolator interpolator) {
    if (FeatureFlags.IS_STUDIO_BUILD && mPendingAnimation != null) {
        throw new IllegalStateException("Another pending animation is still running");
    }
    int count = getTaskViewCount();
    if (count == 0) {
        return new PendingAnimation(duration);
    }
    // When swiping down from overview to tasks, ensures the snapped page's scroll maintain
    // invariant between quick switch and overview, to ensure a smooth animation transition.
    updateGridProperties();
    updateScrollSynchronously();
    int targetSysUiFlags = tv.getThumbnail().getSysUiStatusNavFlags();
    final boolean[] passedOverviewThreshold = new boolean[] { false };
    ValueAnimator progressAnim = ValueAnimator.ofFloat(0, 1);
    progressAnim.addUpdateListener(animator -> {
        // tasks' flags
        if (animator.getAnimatedFraction() > UPDATE_SYSUI_FLAGS_THRESHOLD) {
            mActivity.getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, targetSysUiFlags);
        } else {
            mActivity.getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
        }
        // Passing the threshold from taskview to fullscreen app will vibrate
        final boolean passed = animator.getAnimatedFraction() >= SUCCESS_TRANSITION_PROGRESS;
        if (passed != passedOverviewThreshold[0]) {
            passedOverviewThreshold[0] = passed;
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        }
    });
    AnimatorSet anim = createAdjacentPageAnimForTaskLaunch(tv);
    DepthController depthController = getDepthController();
    if (depthController != null) {
        ObjectAnimator depthAnimator = ObjectAnimator.ofFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(mActivity));
        anim.play(depthAnimator);
    }
    anim.play(progressAnim);
    anim.setInterpolator(interpolator);
    mPendingAnimation = new PendingAnimation(duration);
    mPendingAnimation.add(anim);
    if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
        runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTaskViewSimulator().addOverviewToAppAnim(mPendingAnimation, interpolator));
        mPendingAnimation.addOnFrameCallback(this::redrawLiveTile);
    }
    mPendingAnimation.addEndListener(isSuccess -> {
        if (isSuccess) {
            if (tv.getTaskIds()[1] != -1) {
                // TODO(b/194414938): make this part of the animations instead.
                TaskViewUtils.setSplitAuxiliarySurfacesShown(mRemoteTargetHandles[0].getTransformParams().getTargetSet().nonApps, true, /*shown*/
                false);
            }
            if (ENABLE_QUICKSTEP_LIVE_TILE.get() && tv.isRunningTask()) {
                finishRecentsAnimation(false, /* toRecents */
                null);
                onTaskLaunchAnimationEnd(true);
            } else {
                tv.launchTask(this::onTaskLaunchAnimationEnd);
            }
            Task task = tv.getTask();
            if (task != null) {
                mActivity.getStatsLogManager().logger().withItemInfo(tv.getItemInfo()).log(LAUNCHER_TASK_LAUNCH_SWIPE_DOWN);
            }
        } else {
            onTaskLaunchAnimationEnd(false);
        }
        mPendingAnimation = null;
    });
    return mPendingAnimation;
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Task(com.android.systemui.shared.recents.model.Task) GroupTask(com.android.quickstep.util.GroupTask) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) DepthController(com.android.launcher3.statehandlers.DepthController) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Example 20 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_404Launcher by P-404.

the class AbstractStateChangeTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    if (mCurrentAnimation == null) {
        // canceled us will handle a new state transition to clean up.
        return;
    }
    boolean fling = mDetector.isFling(velocity);
    boolean blockedFling = fling && mFlingBlockCheck.isBlocked();
    if (blockedFling) {
        fling = false;
    }
    final LauncherState targetState;
    final float progress = mCurrentAnimation.getProgressFraction();
    final float progressVelocity = velocity * mProgressMultiplier;
    final float interpolatedProgress = mCurrentAnimation.getInterpolatedProgress();
    if (fling) {
        targetState = Float.compare(Math.signum(velocity), Math.signum(mProgressMultiplier)) == 0 ? mToState : mFromState;
    // snap to top or bottom using the release velocity
    } else {
        targetState = (interpolatedProgress > SUCCESS_TRANSITION_PROGRESS) ? mToState : mFromState;
    }
    final float endProgress;
    final float startProgress;
    final long duration;
    // Increase the duration if we prevented the fling, as we are going against a high velocity.
    final int durationMultiplier = blockedFling && targetState == mFromState ? LauncherAnimUtils.blockedFlingDurationFactor(velocity) : 1;
    if (targetState == mToState) {
        endProgress = 1;
        if (progress >= 1) {
            duration = 0;
            startProgress = 1;
        } else {
            startProgress = Utilities.boundToRange(progress + progressVelocity * getSingleFrameMs(mLauncher), 0f, 1f);
            duration = BaseSwipeDetector.calculateDuration(velocity, endProgress - Math.max(progress, 0)) * durationMultiplier;
        }
    } else {
        // Let the state manager know that the animation didn't go to the target state,
        // but don't cancel ourselves (we already clean up when the animation completes).
        mCurrentAnimation.getTarget().removeListener(mClearStateOnCancelListener);
        mCurrentAnimation.dispatchOnCancel();
        endProgress = 0;
        if (progress <= 0) {
            duration = 0;
            startProgress = 0;
        } else {
            startProgress = Utilities.boundToRange(progress + progressVelocity * getSingleFrameMs(mLauncher), 0f, 1f);
            duration = BaseSwipeDetector.calculateDuration(velocity, Math.min(progress, 1) - endProgress) * durationMultiplier;
        }
    }
    if (targetState != mStartState) {
        logReachedState(targetState);
    }
    mCurrentAnimation.setEndAction(() -> onSwipeInteractionCompleted(targetState));
    ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
    anim.setFloatValues(startProgress, endProgress);
    updateSwipeCompleteAnimation(anim, duration, targetState, velocity, fling);
    mCurrentAnimation.dispatchOnStart();
    if (targetState == LauncherState.ALL_APPS) {
        if (mAllAppsOvershootStarted) {
            mLauncher.getAppsView().onRelease();
            mAllAppsOvershootStarted = false;
        } else {
            mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity, progress);
        }
    }
    anim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) ValueAnimator(android.animation.ValueAnimator)

Aggregations

ValueAnimator (android.animation.ValueAnimator)21 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)13 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)13 RecentsView (com.android.quickstep.views.RecentsView)12 PendingAnimation (com.android.launcher3.anim.PendingAnimation)11 LauncherState (com.android.launcher3.LauncherState)9 ObjectAnimator (android.animation.ObjectAnimator)8 View (android.view.View)8 AnimatorSet (android.animation.AnimatorSet)7 Point (android.graphics.Point)7 TextPaint (android.text.TextPaint)7 Interpolator (android.view.animation.Interpolator)7 Task (com.android.systemui.shared.recents.model.Task)7 DepthController (com.android.launcher3.statehandlers.DepthController)6 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)6 OverviewToHomeAnim (com.android.quickstep.util.OverviewToHomeAnim)6 TaskView (com.android.quickstep.views.TaskView)6 LayoutTransition (android.animation.LayoutTransition)2 TransitionListener (android.animation.LayoutTransition.TransitionListener)2 TargetApi (android.annotation.TargetApi)2