Search in sources :

Example 76 with StateAnimationConfig

use of com.android.launcher3.states.StateAnimationConfig in project android_packages_apps_404Launcher by P-404.

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;
    if (mMotionPauseDetector.isPaused() && noFling) {
        cancelAnimations();
        StateAnimationConfig config = new StateAnimationConfig();
        config.duration = ATOMIC_DURATION_FROM_PAUSED_TO_OVERVIEW;
        Animator overviewAnim = mLauncher.getStateManager().createAtomicAnimation(mStartState, OVERVIEW, config);
        overviewAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onAnimationToStateCompleted(OVERVIEW);
            }
        });
        overviewAnim.start();
        // Create an empty state transition so StateListeners get onStateTransitionStart().
        mLauncher.getStateManager().createAnimationToNewWorkspace(OVERVIEW, config.duration, StateAnimationConfig.SKIP_ALL_ANIMATIONS).dispatchOnStart();
        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.
        boolean passedHorizontalThreshold = mXOverviewAnim.getInterpolatedProgress() > 0.5f;
        boolean passedVerticalThreshold = mYOverviewAnim.value > 1f;
        targetState = passedHorizontalThreshold && !passedVerticalThreshold ? 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.dispatchOnStart();
    boolean flingUpToNormal = verticalFling && velocity.y < 0 && targetState == NORMAL;
    float yProgress = mYOverviewAnim.value;
    float startYProgress = Utilities.boundToRange(yProgress - velocity.y * getSingleFrameMs(mLauncher) / mYRange, 0f, mMaxYProgress);
    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;
    }
    float yDistanceToCover = Math.abs(endYProgress - startYProgress) * mYRange;
    long yDuration = (long) (yDistanceToCover / Math.max(1f, Math.abs(velocity.y)));
    ValueAnimator yOverviewAnim = mYOverviewAnim.animateToValue(startYProgress, endYProgress);
    yOverviewAnim.setDuration(yDuration);
    mYOverviewAnim.updateValue(startYProgress);
    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.
        StateAnimationConfig config = new StateAnimationConfig();
        // Update mNonOverviewAnim to do nothing so it doesn't interfere.
        config.animFlags = SKIP_ALL_ANIMATIONS;
        updateNonOverviewAnim(targetState, config);
        nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
        mNonOverviewAnim.dispatchOnStart();
        new WorkspaceRevealAnim(mLauncher, 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.getTarget().removeListener(mClearStateOnCancelListener);
            mNonOverviewAnim.dispatchOnCancel();
        }
        float startProgress = mNonOverviewAnim.getProgressFraction();
        float endProgress = canceled ? 0 : 1;
        nonOverviewAnim.setFloatValues(startProgress, endProgress);
        mNonOverviewAnim.dispatchOnStart();
    }
    if (targetState == QUICK_SWITCH) {
        // Navigating to quick switch, add scroll feedback since the first time is not
        // considered a scroll by the RecentsView.
        VibratorWrapper.INSTANCE.get(mLauncher).vibrate(RecentsView.SCROLL_VIBRATION_PRIMITIVE, RecentsView.SCROLL_VIBRATION_PRIMITIVE_SCALE, RecentsView.SCROLL_VIBRATION_FALLBACK);
    }
    nonOverviewAnim.setDuration(Math.max(xDuration, yDuration));
    mNonOverviewAnim.setEndAction(() -> onAnimationToStateCompleted(targetState));
    cancelAnimations();
    xOverviewAnim.start();
    yOverviewAnim.start();
    nonOverviewAnim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) WorkspaceRevealAnim(com.android.quickstep.util.WorkspaceRevealAnim)

Example 77 with StateAnimationConfig

use of com.android.launcher3.states.StateAnimationConfig in project android_packages_apps_404Launcher by P-404.

the class PortraitStatesTouchController method initCurrentAnimation.

@Override
protected float initCurrentAnimation() {
    float range = getShiftRange();
    long maxAccuracy = (long) (2 * range);
    float startVerticalShift = mFromState.getVerticalProgress(mLauncher) * range;
    float endVerticalShift = mToState.getVerticalProgress(mLauncher) * range;
    float totalShift = endVerticalShift - startVerticalShift;
    final StateAnimationConfig config = totalShift == 0 ? new StateAnimationConfig() : getConfigForStates(mFromState, mToState);
    config.duration = maxAccuracy;
    if (mCurrentAnimation != null) {
        mCurrentAnimation.getTarget().removeListener(mClearStateOnCancelListener);
        mCurrentAnimation.dispatchOnCancel();
    }
    mGoingBetweenStates = true;
    if (mFromState == OVERVIEW && mToState == NORMAL && mOverviewPortraitStateTouchHelper.shouldSwipeDownReturnToApp()) {
        // Reset the state manager, when changing the interaction mode
        mLauncher.getStateManager().goToState(OVERVIEW, false);
        mGoingBetweenStates = false;
        mCurrentAnimation = mOverviewPortraitStateTouchHelper.createSwipeDownToTaskAppAnimation(maxAccuracy, Interpolators.LINEAR).createPlaybackController();
        mLauncher.getStateManager().setCurrentUserControlledAnimation(mCurrentAnimation);
        RecentsView recentsView = mLauncher.getOverviewPanel();
        totalShift = LayoutUtils.getShelfTrackingDistance(mLauncher, mLauncher.getDeviceProfile(), recentsView.getPagedOrientationHandler());
    } else {
        mCurrentAnimation = mLauncher.getStateManager().createAnimationToNewWorkspace(mToState, config);
    }
    mCurrentAnimation.getTarget().addListener(mClearStateOnCancelListener);
    if (totalShift == 0) {
        totalShift = Math.signum(mFromState.ordinal - mToState.ordinal) * OverviewState.getDefaultSwipeHeight(mLauncher);
    }
    return 1 / totalShift;
}
Also used : StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) RecentsView(com.android.quickstep.views.RecentsView)

Example 78 with StateAnimationConfig

use of com.android.launcher3.states.StateAnimationConfig in project android_packages_apps_404Launcher by P-404.

the class QuickSwitchTouchController method initCurrentAnimation.

@Override
protected float initCurrentAnimation() {
    StateAnimationConfig config = new StateAnimationConfig();
    setupInterpolators(config);
    config.duration = (long) (getShiftRange() * 2);
    // Set RecentView's initial properties for coming in from the side.
    RECENTS_SCALE_PROPERTY.set(mOverviewPanel, QUICK_SWITCH.getOverviewScaleAndOffset(mLauncher)[0] * 0.85f);
    ADJACENT_PAGE_HORIZONTAL_OFFSET.set(mOverviewPanel, 1f);
    mOverviewPanel.setContentAlpha(1);
    mCurrentAnimation = mLauncher.getStateManager().createAnimationToNewWorkspace(mToState, config);
    mCurrentAnimation.getTarget().addListener(mClearStateOnCancelListener);
    mCurrentAnimation.getAnimationPlayer().addUpdateListener(valueAnimator -> updateFullscreenProgress((Float) valueAnimator.getAnimatedValue()));
    return 1 / getShiftRange();
}
Also used : StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig)

Example 79 with StateAnimationConfig

use of com.android.launcher3.states.StateAnimationConfig in project android_packages_apps_404Launcher by P-404.

the class RecentsViewStateController method setState.

@Override
public void setState(@NonNull LauncherState state) {
    super.setState(state);
    if (state.overviewUi) {
        mRecentsView.updateEmptyMessage();
        mRecentsView.resetTaskVisuals();
    }
    setAlphas(PropertySetter.NO_ANIM_PROPERTY_SETTER, new StateAnimationConfig(), state);
    mRecentsView.setFullscreenProgress(state.getOverviewFullscreenProgress());
    // In Overview, we may be layering app surfaces behind Launcher, so we need to notify
    // DepthController to prevent optimizations which might occlude the layers behind
    mLauncher.getDepthController().setHasContentBehindLauncher(state.overviewUi);
    handleSplitSelectionState(state, null);
}
Also used : StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig)

Example 80 with StateAnimationConfig

use of com.android.launcher3.states.StateAnimationConfig in project android_packages_apps_404Launcher by P-404.

the class StaggeredWorkspaceAnim method prepareToAnimate.

/**
 * Setup workspace with 0 duration to prepare for our staggered animation.
 */
private void prepareToAnimate(Launcher launcher, boolean animateOverviewScrim) {
    StateAnimationConfig config = new StateAnimationConfig();
    config.animFlags = SKIP_OVERVIEW | SKIP_DEPTH_CONTROLLER | SKIP_SCRIM;
    config.duration = 0;
    // setRecentsAttachedToAppWindow() will animate recents out.
    launcher.getStateManager().createAtomicAnimation(BACKGROUND_APP, NORMAL, config).start();
    // Stop scrolling so that it doesn't interfere with the translation offscreen.
    launcher.<RecentsView>getOverviewPanel().forceFinishScroller();
    if (animateOverviewScrim) {
        launcher.getWorkspace().getStateTransitionAnimation().setScrim(NO_ANIM_PROPERTY_SETTER, BACKGROUND_APP, config);
    }
}
Also used : StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig)

Aggregations

StateAnimationConfig (com.android.launcher3.states.StateAnimationConfig)108 PendingAnimation (com.android.launcher3.anim.PendingAnimation)26 LauncherState (com.android.launcher3.LauncherState)25 RecentsView (com.android.quickstep.views.RecentsView)24 Animator (android.animation.Animator)16 ValueAnimator (android.animation.ValueAnimator)13 Interpolator (android.view.animation.Interpolator)12 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)9 AnimatorSet (android.animation.AnimatorSet)8 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)8 AnimationSuccessListener (com.android.launcher3.anim.AnimationSuccessListener)7 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)6 BaseQuickstepLauncher (com.android.launcher3.BaseQuickstepLauncher)6 CellLayout (com.android.launcher3.CellLayout)6 Hotseat (com.android.launcher3.Hotseat)6 Workspace (com.android.launcher3.Workspace)6 DepthController (com.android.launcher3.statehandlers.DepthController)6 VISIBLE (android.view.View.VISIBLE)5 HINT_STATE (com.android.launcher3.LauncherState.HINT_STATE)5 HINT_STATE_TWO_BUTTON (com.android.launcher3.LauncherState.HINT_STATE_TWO_BUTTON)5