Search in sources :

Example 1 with GestureEndTarget

use of com.android.quickstep.GestureState.GestureEndTarget in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbsSwipeUpHandler method handleNormalGestureEnd.

@UiThread
private void handleNormalGestureEnd(float endVelocity, boolean isFling, PointF velocity, boolean isCancel) {
    long duration = MAX_SWIPE_DURATION;
    float currentShift = mCurrentShift.value;
    final GestureEndTarget endTarget = calculateEndTarget(velocity, endVelocity, isFling, isCancel);
    // Set the state, but don't notify until the animation completes
    mGestureState.setEndTarget(endTarget, false);
    float endShift = endTarget.isLauncher ? 1 : 0;
    final float startShift;
    if (!isFling) {
        long expectedDuration = Math.abs(Math.round((endShift - currentShift) * MAX_SWIPE_DURATION * SWIPE_DURATION_MULTIPLIER));
        duration = Math.min(MAX_SWIPE_DURATION, expectedDuration);
        startShift = currentShift;
    } else {
        startShift = Utilities.boundToRange(currentShift - velocity.y * getSingleFrameMs(mContext) / mTransitionDragLength, 0, mDragLengthFactor);
        if (mTransitionDragLength > 0) {
            float distanceToTravel = (endShift - currentShift) * mTransitionDragLength;
            // we want the page's snap velocity to approximately match the velocity at
            // which the user flings, so we scale the duration by a value near to the
            // derivative of the scroll interpolator at zero, ie. 2.
            long baseDuration = Math.round(Math.abs(distanceToTravel / velocity.y));
            duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration);
        }
    }
    Interpolator interpolator;
    S state = mActivityInterface.stateFromGestureEndTarget(endTarget);
    if (state.displayOverviewTasksAsGrid(mDp)) {
        interpolator = ACCEL_DEACCEL;
    } else if (endTarget == RECENTS) {
        interpolator = OVERSHOOT_1_2;
    } else {
        interpolator = DEACCEL;
    }
    if (endTarget.isLauncher) {
        mInputConsumerProxy.enable();
    }
    if (endTarget == HOME) {
        duration = HOME_DURATION;
        // Early detach the nav bar once the endTarget is determined as HOME
        if (mRecentsAnimationController != null) {
            mRecentsAnimationController.detachNavigationBarFromApp(true);
        }
    } else if (endTarget == RECENTS) {
        if (mRecentsView != null) {
            int nearestPage = mRecentsView.getDestinationPage();
            boolean isScrolling = false;
            // Update page scroll before snapping to page to make sure we snapped to the
            // position calculated with target gesture in mind.
            mRecentsView.updateScrollSynchronously();
            if (mRecentsView.getNextPage() != nearestPage) {
                // We shouldn't really scroll to the next page when swiping up to recents.
                // Only allow settling on the next page if it's nearest to the center.
                mRecentsView.snapToPage(nearestPage, Math.toIntExact(duration));
                isScrolling = true;
            }
            if (mRecentsView.getScroller().getDuration() > MAX_SWIPE_DURATION) {
                mRecentsView.snapToPage(mRecentsView.getNextPage(), (int) MAX_SWIPE_DURATION);
                isScrolling = true;
            }
            if (!mGestureState.isHandlingAtomicEvent() || isScrolling) {
                duration = Math.max(duration, mRecentsView.getScroller().getDuration());
            }
        }
    }
    // or resumeLastTask().
    if (mRecentsView != null) {
        mRecentsView.setOnPageTransitionEndCallback(() -> mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED));
    } else {
        mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED);
    }
    animateToProgress(startShift, endShift, duration, interpolator, endTarget, velocity);
}
Also used : DEBUG_STATES(com.android.quickstep.MultiStateCallback.DEBUG_STATES) RECENTS(com.android.quickstep.GestureState.GestureEndTarget.RECENTS) CLOSE_SYSTEM_WINDOWS_REASON_RECENTS(com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS) STATE_HANDLER_INVISIBILITY_FLAGS(com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS) Interpolator(android.view.animation.Interpolator) GestureEndTarget(com.android.quickstep.GestureState.GestureEndTarget) UiThread(androidx.annotation.UiThread)

Example 2 with GestureEndTarget

use of com.android.quickstep.GestureState.GestureEndTarget in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbsSwipeUpHandler method onSettledOnEndTarget.

private void onSettledOnEndTarget() {
    // Fast-finish the attaching animation if it's still running.
    maybeUpdateRecentsAttachedState(false);
    final GestureEndTarget endTarget = mGestureState.getEndTarget();
    if (endTarget != NEW_TASK) {
        InteractionJankMonitorWrapper.cancel(InteractionJankMonitorWrapper.CUJ_QUICK_SWITCH);
    }
    if (endTarget != HOME) {
        InteractionJankMonitorWrapper.cancel(InteractionJankMonitorWrapper.CUJ_APP_CLOSE_TO_HOME);
    }
    switch(endTarget) {
        case HOME:
            mStateCallback.setState(STATE_SCALED_CONTROLLER_HOME | STATE_CAPTURE_SCREENSHOT);
            // Notify swipe-to-home (recents animation) is finished
            SystemUiProxy.INSTANCE.get(mContext).notifySwipeToHomeFinished();
            break;
        case RECENTS:
            mStateCallback.setState(STATE_SCALED_CONTROLLER_RECENTS | STATE_CAPTURE_SCREENSHOT | STATE_SCREENSHOT_VIEW_SHOWN);
            break;
        case NEW_TASK:
            mStateCallback.setState(STATE_START_NEW_TASK | STATE_CAPTURE_SCREENSHOT);
            break;
        case LAST_TASK:
            mStateCallback.setState(STATE_RESUME_LAST_TASK);
            break;
    }
    ActiveGestureLog.INSTANCE.addLog("onSettledOnEndTarget " + endTarget);
}
Also used : GestureEndTarget(com.android.quickstep.GestureState.GestureEndTarget)

Example 3 with GestureEndTarget

use of com.android.quickstep.GestureState.GestureEndTarget in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbsSwipeUpHandler method calculateEndTarget.

private GestureEndTarget calculateEndTarget(PointF velocity, float endVelocity, boolean isFling, boolean isCancel) {
    if (mGestureState.isHandlingAtomicEvent()) {
        // Button mode, this is only used to go to recents
        return RECENTS;
    }
    final GestureEndTarget endTarget;
    final boolean goingToNewTask;
    if (mRecentsView != null) {
        if (!hasTargets()) {
            // If there are no running tasks, then we can assume that this is a continuation of
            // the last gesture, but after the recents animation has finished
            goingToNewTask = true;
        } else {
            final int runningTaskIndex = mRecentsView.getRunningTaskIndex();
            final int taskToLaunch = mRecentsView.getNextPage();
            goingToNewTask = runningTaskIndex >= 0 && taskToLaunch != runningTaskIndex;
        }
    } else {
        goingToNewTask = false;
    }
    final boolean reachedOverviewThreshold = mCurrentShift.value >= MIN_PROGRESS_FOR_OVERVIEW;
    if (!isFling) {
        if (isCancel) {
            endTarget = LAST_TASK;
        } else if (mDeviceState.isFullyGesturalNavMode()) {
            if (mIsMotionPaused) {
                endTarget = RECENTS;
            } else if (goingToNewTask) {
                endTarget = NEW_TASK;
            } else {
                endTarget = !reachedOverviewThreshold ? LAST_TASK : HOME;
            }
        } else {
            endTarget = reachedOverviewThreshold && mGestureStarted ? RECENTS : goingToNewTask ? NEW_TASK : LAST_TASK;
        }
    } else {
        // If swiping at a diagonal, base end target on the faster velocity.
        boolean isSwipeUp = endVelocity < 0;
        boolean willGoToNewTaskOnSwipeUp = goingToNewTask && Math.abs(velocity.x) > Math.abs(endVelocity);
        if (mDeviceState.isFullyGesturalNavMode() && isSwipeUp && !willGoToNewTaskOnSwipeUp) {
            endTarget = HOME;
        } else if (mDeviceState.isFullyGesturalNavMode() && isSwipeUp) {
            // If swiping at a diagonal, base end target on the faster velocity.
            endTarget = NEW_TASK;
        } else if (isSwipeUp) {
            endTarget = !reachedOverviewThreshold && willGoToNewTaskOnSwipeUp ? NEW_TASK : RECENTS;
        } else {
            endTarget = goingToNewTask ? NEW_TASK : LAST_TASK;
        }
    }
    if (mDeviceState.isOverviewDisabled() && (endTarget == RECENTS || endTarget == LAST_TASK)) {
        return LAST_TASK;
    }
    return endTarget;
}
Also used : GestureEndTarget(com.android.quickstep.GestureState.GestureEndTarget)

Aggregations

GestureEndTarget (com.android.quickstep.GestureState.GestureEndTarget)3 Interpolator (android.view.animation.Interpolator)1 UiThread (androidx.annotation.UiThread)1 STATE_HANDLER_INVISIBILITY_FLAGS (com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS)1 RECENTS (com.android.quickstep.GestureState.GestureEndTarget.RECENTS)1 DEBUG_STATES (com.android.quickstep.MultiStateCallback.DEBUG_STATES)1 CLOSE_SYSTEM_WINDOWS_REASON_RECENTS (com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS)1