Search in sources :

Example 26 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_Trebuchet by LineageOS.

the class TaskViewTouchController method reInitAnimationController.

private void reInitAnimationController(boolean goingUp) {
    if (mCurrentAnimation != null && mCurrentAnimationIsGoingUp == goingUp) {
        // No need to init
        return;
    }
    int scrollDirections = mDetector.getScrollDirections();
    if (goingUp && ((scrollDirections & DIRECTION_POSITIVE) == 0) || !goingUp && ((scrollDirections & DIRECTION_NEGATIVE) == 0)) {
        // Trying to re-init in an unsupported direction.
        return;
    }
    if (mCurrentAnimation != null) {
        mCurrentAnimation.setPlayFraction(0);
    }
    if (mPendingAnimation != null) {
        mPendingAnimation.finish(false, Touch.SWIPE);
        mPendingAnimation = null;
    }
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    mCurrentAnimationIsGoingUp = goingUp;
    BaseDragLayer dl = mActivity.getDragLayer();
    final int secondaryLayerDimension = orientationHandler.getSecondaryDimension(dl);
    long maxDuration = 2 * secondaryLayerDimension;
    int verticalFactor = orientationHandler.getTaskDragDisplacementFactor(mIsRtl);
    int secondaryTaskDimension = orientationHandler.getSecondaryDimension(mTaskBeingDragged);
    // The interpolator controlling the most prominent visual movement. We use this to determine
    // whether we passed SUCCESS_TRANSITION_PROGRESS.
    final Interpolator currentInterpolator;
    if (goingUp) {
        currentInterpolator = Interpolators.LINEAR;
        mPendingAnimation = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged, true, /* animateTaskView */
        true, /* removeTask */
        maxDuration);
        mEndDisplacement = -secondaryTaskDimension;
    } else {
        currentInterpolator = Interpolators.ZOOM_IN;
        mPendingAnimation = mRecentsView.createTaskLaunchAnimation(mTaskBeingDragged, maxDuration, currentInterpolator);
        // Since the thumbnail is what is filling the screen, based the end displacement on it.
        View thumbnailView = mTaskBeingDragged.getThumbnail();
        mTempCords[1] = orientationHandler.getSecondaryDimension(thumbnailView);
        dl.getDescendantCoordRelativeToSelf(thumbnailView, mTempCords);
        mEndDisplacement = secondaryLayerDimension - mTempCords[1];
    }
    mEndDisplacement *= verticalFactor;
    if (mCurrentAnimation != null) {
        mCurrentAnimation.setOnCancelRunnable(null);
    }
    mCurrentAnimation = mPendingAnimation.createPlaybackController().setOnCancelRunnable(this::clearState);
    // Setting this interpolator doesn't affect the visual motion, but is used to determine
    // whether we successfully reached the target state in onDragEnd().
    mCurrentAnimation.getTarget().setInterpolator(currentInterpolator);
    onUserControlledAnimationCreated(mCurrentAnimation);
    mCurrentAnimation.getTarget().addListener(this);
    mCurrentAnimation.dispatchOnStart();
    mProgressMultiplier = 1 / mEndDisplacement;
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) Interpolator(android.view.animation.Interpolator) TaskView(com.android.quickstep.views.TaskView) View(android.view.View) RecentsView(com.android.quickstep.views.RecentsView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 27 with SUCCESS_TRANSITION_PROGRESS

use of com.android.launcher3.LauncherAnimUtils.SUCCESS_TRANSITION_PROGRESS in project android_packages_apps_Trebuchet by LineageOS.

the class AbstractStateChangeTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    boolean fling = mDetector.isFling(velocity);
    final int logAction = fling ? Touch.FLING : Touch.SWIPE;
    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 {
        float successProgress = mToState == ALL_APPS ? MIN_PROGRESS_TO_ALL_APPS : SUCCESS_TRANSITION_PROGRESS;
        targetState = (interpolatedProgress > successProgress) ? 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.dispatchOnCancelWithoutCancelRunnable();
        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;
        }
    }
    mCurrentAnimation.setEndAction(() -> onSwipeInteractionCompleted(targetState, logAction));
    ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
    anim.setFloatValues(startProgress, endProgress);
    maybeUpdateAtomicAnim(mFromState, targetState, targetState == mToState ? 1f : 0f);
    updateSwipeCompleteAnimation(anim, Math.max(duration, getRemainingAtomicDuration()), targetState, velocity, fling);
    mCurrentAnimation.dispatchOnStart();
    if (fling && targetState == LauncherState.ALL_APPS && !UNSTABLE_SPRINGS.get()) {
        mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity);
    }
    anim.start();
    mAtomicAnimAutoPlayInfo = new AutoPlayAtomicAnimationInfo(endProgress, anim.getDuration());
    maybeAutoPlayAtomicComponentsAnim();
}
Also used : LauncherState(com.android.launcher3.LauncherState) ValueAnimator(android.animation.ValueAnimator)

Example 28 with SUCCESS_TRANSITION_PROGRESS

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

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 29 with SUCCESS_TRANSITION_PROGRESS

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

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 30 with SUCCESS_TRANSITION_PROGRESS

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

the class TaskViewTouchController method onDragEnd.

@Override
public void onDragEnd(float velocity) {
    if (mOverrideVelocity != null) {
        velocity = mOverrideVelocity;
        mOverrideVelocity = null;
    }
    // Limit velocity, as very large scalar values make animations play too quickly
    float maxTaskDismissDragVelocity = mTaskBeingDragged.getResources().getDimension(R.dimen.max_task_dismiss_drag_velocity);
    velocity = Utilities.boundToRange(velocity, -maxTaskDismissDragVelocity, maxTaskDismissDragVelocity);
    boolean fling = mDetector.isFling(velocity);
    final boolean goingToEnd;
    boolean blockedFling = fling && mFlingBlockCheck.isBlocked();
    if (blockedFling) {
        fling = false;
    }
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    boolean goingUp = orientationHandler.isGoingUp(velocity, mIsRtl);
    float progress = mCurrentAnimation.getProgressFraction();
    float interpolatedProgress = mCurrentAnimation.getInterpolatedProgress();
    if (fling) {
        goingToEnd = goingUp == mCurrentAnimationIsGoingUp;
    } else {
        goingToEnd = interpolatedProgress > SUCCESS_TRANSITION_PROGRESS;
    }
    long animationDuration = BaseSwipeDetector.calculateDuration(velocity, goingToEnd ? (1 - progress) : progress);
    if (blockedFling && !goingToEnd) {
        animationDuration *= LauncherAnimUtils.blockedFlingDurationFactor(velocity);
    }
    // Due to very high or low velocity dismissals, animation durations can be inconsistently
    // long or short. Bound the duration for animation of task translations for a more
    // standardized feel.
    animationDuration = Utilities.boundToRange(animationDuration, MIN_TASK_DISMISS_ANIMATION_DURATION, MAX_TASK_DISMISS_ANIMATION_DURATION);
    mCurrentAnimation.setEndAction(this::clearState);
    mCurrentAnimation.startWithVelocity(mActivity, goingToEnd, velocity * orientationHandler.getSecondaryTranslationDirectionFactor(), mEndDisplacement, animationDuration);
    if (goingUp && goingToEnd && !mIsDismissHapticRunning) {
        VibratorWrapper.INSTANCE.get(mActivity).vibrate(TASK_DISMISS_VIBRATION_PRIMITIVE, TASK_DISMISS_VIBRATION_PRIMITIVE_SCALE, TASK_DISMISS_VIBRATION_FALLBACK);
        mIsDismissHapticRunning = true;
    }
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler)

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