Search in sources :

Example 1 with LauncherState

use of com.android.launcher3.LauncherState in project android_packages_apps_Launcher3 by crdroidandroid.

the class WorkspaceStateTransitionAnimation method applyChildState.

private void applyChildState(LauncherState state, CellLayout cl, int childIndex, PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter, StateAnimationConfig config) {
    float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
    float springLoadedProgress = (state instanceof SpringLoadedState) ? 1.0f : 0f;
    propertySetter.setFloat(cl, CellLayout.SPRING_LOADED_PROGRESS, springLoadedProgress, ZOOM_OUT);
    Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE, pageAlphaProvider.interpolator);
    propertySetter.setFloat(cl.getShortcutsAndWidgets(), VIEW_ALPHA, pageAlpha, fadeInterpolator);
}
Also used : SpringLoadedState(com.android.launcher3.states.SpringLoadedState) Interpolator(android.view.animation.Interpolator)

Example 2 with LauncherState

use of com.android.launcher3.LauncherState in project android_packages_apps_Launcher3 by crdroidandroid.

the class WorkspaceStateTransitionAnimation method setWorkspaceProperty.

/**
 * Starts a transition animation for the workspace.
 */
private void setWorkspaceProperty(LauncherState state, PropertySetter propertySetter, StateAnimationConfig config) {
    ScaleAndTranslation scaleAndTranslation = state.getWorkspaceScaleAndTranslation(mLauncher);
    ScaleAndTranslation hotseatScaleAndTranslation = state.getHotseatScaleAndTranslation(mLauncher);
    mNewScale = scaleAndTranslation.scale;
    PageAlphaProvider pageAlphaProvider = state.getWorkspacePageAlphaProvider(mLauncher);
    final int childCount = mWorkspace.getChildCount();
    for (int i = 0; i < childCount; i++) {
        applyChildState(state, (CellLayout) mWorkspace.getChildAt(i), i, pageAlphaProvider, propertySetter, config);
    }
    int elements = state.getVisibleElements(mLauncher);
    Interpolator fadeInterpolator = config.getInterpolator(ANIM_WORKSPACE_FADE, pageAlphaProvider.interpolator);
    Hotseat hotseat = mWorkspace.getHotseat();
    Interpolator scaleInterpolator = config.getInterpolator(ANIM_WORKSPACE_SCALE, ZOOM_OUT);
    LauncherState fromState = mLauncher.getStateManager().getState();
    boolean shouldSpring = propertySetter instanceof PendingAnimation && fromState == HINT_STATE && state == NORMAL;
    if (shouldSpring) {
        ((PendingAnimation) propertySetter).add(getSpringScaleAnimator(mLauncher, mWorkspace, mNewScale));
    } else {
        propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, scaleInterpolator);
    }
    mWorkspace.setPivotToScaleWithSelf(hotseat);
    float hotseatScale = hotseatScaleAndTranslation.scale;
    if (shouldSpring) {
        PendingAnimation pa = (PendingAnimation) propertySetter;
        pa.add(getSpringScaleAnimator(mLauncher, hotseat, hotseatScale));
    } else {
        Interpolator hotseatScaleInterpolator = config.getInterpolator(ANIM_HOTSEAT_SCALE, scaleInterpolator);
        propertySetter.setFloat(hotseat, SCALE_PROPERTY, hotseatScale, hotseatScaleInterpolator);
    }
    float hotseatIconsAlpha = (elements & HOTSEAT_ICONS) != 0 ? 1 : 0;
    propertySetter.setViewAlpha(hotseat, hotseatIconsAlpha, fadeInterpolator);
    float workspacePageIndicatorAlpha = (elements & WORKSPACE_PAGE_INDICATOR) != 0 ? 1 : 0;
    propertySetter.setViewAlpha(mLauncher.getWorkspace().getPageIndicator(), workspacePageIndicatorAlpha, fadeInterpolator);
    Interpolator translationInterpolator = config.getInterpolator(ANIM_WORKSPACE_TRANSLATE, ZOOM_OUT);
    propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_X, scaleAndTranslation.translationX, translationInterpolator);
    propertySetter.setFloat(mWorkspace, VIEW_TRANSLATE_Y, scaleAndTranslation.translationY, translationInterpolator);
    Interpolator hotseatTranslationInterpolator = config.getInterpolator(ANIM_HOTSEAT_TRANSLATE, translationInterpolator);
    propertySetter.setFloat(hotseat, VIEW_TRANSLATE_Y, hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
    propertySetter.setFloat(mWorkspace.getPageIndicator(), VIEW_TRANSLATE_Y, hotseatScaleAndTranslation.translationY, hotseatTranslationInterpolator);
    if (!config.hasAnimationFlag(SKIP_SCRIM)) {
        setScrim(propertySetter, state, config);
    }
}
Also used : ScaleAndTranslation(com.android.launcher3.LauncherState.ScaleAndTranslation) PendingAnimation(com.android.launcher3.anim.PendingAnimation) PageAlphaProvider(com.android.launcher3.LauncherState.PageAlphaProvider) Interpolator(android.view.animation.Interpolator)

Example 3 with LauncherState

use of com.android.launcher3.LauncherState in project android_packages_apps_Launcher3 by crdroidandroid.

the class NoButtonNavbarToOverviewTouchController method goToOverviewOrHomeOnDragEnd.

private void goToOverviewOrHomeOnDragEnd(float velocity) {
    boolean goToHomeInsteadOfOverview = !mMotionPauseDetector.isPaused();
    if (goToHomeInsteadOfOverview) {
        new OverviewToHomeAnim(mLauncher, () -> onSwipeInteractionCompleted(NORMAL)).animateWithVelocity(velocity);
    }
    if (mReachedOverview) {
        float distanceDp = dpiFromPx(Math.max(Math.abs(mRecentsView.getTranslationX()), Math.abs(mRecentsView.getTranslationY())));
        long duration = (long) Math.max(TRANSLATION_ANIM_MIN_DURATION_MS, distanceDp / TRANSLATION_ANIM_VELOCITY_DP_PER_MS);
        mRecentsView.animate().translationX(0).translationY(0).setInterpolator(ACCEL_DEACCEL).setDuration(duration).withEndAction(goToHomeInsteadOfOverview ? null : this::maybeSwipeInteractionToOverviewComplete);
        if (!goToHomeInsteadOfOverview) {
            // Return to normal properties for the overview state.
            StateAnimationConfig config = new StateAnimationConfig();
            config.duration = duration;
            LauncherState state = mLauncher.getStateManager().getState();
            mLauncher.getStateManager().createAtomicAnimation(state, state, config).start();
        }
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) OverviewToHomeAnim(com.android.quickstep.util.OverviewToHomeAnim)

Example 4 with LauncherState

use of com.android.launcher3.LauncherState in project android_packages_apps_Launcher3 by crdroidandroid.

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();
        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();
        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();
    }
    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 5 with LauncherState

use of com.android.launcher3.LauncherState in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherTaskbarUIController method createAnimToLauncher.

/**
 * Create Taskbar animation when going from an app to Launcher.
 * @param toState If known, the state we will end up in when reaching Launcher.
 */
public Animator createAnimToLauncher(@Nullable LauncherState toState, long duration) {
    PendingAnimation anim = new PendingAnimation(duration);
    anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(0, duration));
    if (toState != null) {
        mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
    }
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mIsAnimatingToLauncher = true;
            mTaskbarView.setHolesAllowedInLayout(true);
            mTaskbarView.updateHotseatItemsVisibility();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsAnimatingToLauncher = false;
            setTaskbarViewVisible(false);
        }
    });
    return anim.buildAnim();
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Animator(android.animation.Animator) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Aggregations

LauncherState (com.android.launcher3.LauncherState)14 StateAnimationConfig (com.android.launcher3.states.StateAnimationConfig)8 Animator (android.animation.Animator)4 PendingAnimation (com.android.launcher3.anim.PendingAnimation)4 ValueAnimator (android.animation.ValueAnimator)3 RecentsView (com.android.quickstep.views.RecentsView)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 AnimatorSet (android.animation.AnimatorSet)2 Interpolator (android.view.animation.Interpolator)2 PendingRequestArgs (com.android.launcher3.util.PendingRequestArgs)2 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 Parcelable (android.os.Parcelable)1 FloatProperty (android.util.FloatProperty)1 View (android.view.View)1 VISIBLE (android.view.View.VISIBLE)1 ImageView (android.widget.ImageView)1 Nullable (androidx.annotation.Nullable)1 BaseQuickstepLauncher (com.android.launcher3.BaseQuickstepLauncher)1 CellLayout (com.android.launcher3.CellLayout)1 DeviceProfile (com.android.launcher3.DeviceProfile)1