Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c7f2156 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Moving Workspace states into a separate file

Bug: 67678570
Change-Id: I5c63b4df29ca0f58a0223fb1919abc132576a1b6
parent 910be3c0
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.launcher3;

import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_NEXT_FRAME;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_SHORT_TIMEOUT;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;
@@ -581,7 +581,7 @@ public class Launcher extends BaseActivity
        Runnable exitSpringLoaded = new Runnable() {
            @Override
            public void run() {
                exitSpringLoadedDragMode(SPRING_LOADED_EXIT_SHORT_TIMEOUT);
                exitSpringLoadedDragMode(SPRING_LOADED_EXIT_DELAY);
            }
        };

@@ -761,7 +761,7 @@ public class Launcher extends BaseActivity
                @Override
                public void run() {
                    completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                    exitSpringLoadedDragMode(SPRING_LOADED_EXIT_SHORT_TIMEOUT);
                    exitSpringLoadedDragMode(SPRING_LOADED_EXIT_DELAY);
                }
            };
        } else if (resultCode == RESULT_CANCELED) {
@@ -1712,7 +1712,7 @@ public class Launcher extends BaseActivity
                @Override
                public void run() {
                    // Exit spring loaded mode if necessary after adding the widget
                    exitSpringLoadedDragMode(SPRING_LOADED_EXIT_SHORT_TIMEOUT);
                    exitSpringLoadedDragMode(SPRING_LOADED_EXIT_DELAY);
                }
            };
            completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
@@ -2460,11 +2460,11 @@ public class Launcher extends BaseActivity

    public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
        boolean changed = mState != State.WORKSPACE ||
                mWorkspace.getState() != Workspace.State.NORMAL;
                mWorkspace.getState() != LauncherState.NORMAL;
        if (changed || mAllAppsController.isTransitioning()) {
            mWorkspace.setVisibility(View.VISIBLE);
            mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
                    Workspace.State.NORMAL, animated, onCompleteRunnable);
                    LauncherState.NORMAL, animated, onCompleteRunnable);

            // Set focus to the AppsCustomize button
            if (mAllAppsButton != null) {
@@ -2509,7 +2509,7 @@ public class Launcher extends BaseActivity
        }
        mWorkspace.setVisibility(View.VISIBLE);
        mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
                Workspace.State.OVERVIEW, animated, postAnimRunnable);
                LauncherState.OVERVIEW, animated, postAnimRunnable);
        setState(State.WORKSPACE);

        // If animated from long press, then don't allow any of the controller in the drag
@@ -2583,7 +2583,7 @@ public class Launcher extends BaseActivity
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);

        mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
                Workspace.State.SPRING_LOADED, true /* animated */,
                LauncherState.SPRING_LOADED, true /* animated */,
                null /* onCompleteRunnable */);
        setState(State.WORKSPACE_SPRING_LOADED);
    }
@@ -2608,11 +2608,6 @@ public class Launcher extends BaseActivity
        mExitSpringLoadedModeRunnable = new Runnable() {
            @Override
            public void run() {
                // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
                //
                // Before we show workspace, hide all apps again because
                // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
                // clean up our state transition functions
                showWorkspace(true, onCompleteRunnable);
                mExitSpringLoadedModeRunnable = null;
            }
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public class LauncherAnimUtils {
    public static final int ALL_APPS_TRANSITION_MS = 320;
    public static final int OVERVIEW_TRANSITION_MS = 250;
    public static final int SPRING_LOADED_TRANSITION_MS = 150;
    public static final int SPRING_LOADED_EXIT_SHORT_TIMEOUT = 500;
    public static final int SPRING_LOADED_EXIT_DELAY = 500;
    public static final int SPRING_LOADED_EXIT_NEXT_FRAME = 0;

    static WeakHashMap<Animator, Object> sAnimators = new WeakHashMap<Animator, Object>();
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3;

import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;

import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS;
import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
import static com.android.launcher3.StateFlags.FLAG_DISABLE_ACCESSIBILITY;
import static com.android.launcher3.StateFlags.FLAG_HIDE_HOTSEAT;
import static com.android.launcher3.StateFlags.FLAG_MULTI_PAGE;
import static com.android.launcher3.StateFlags.FLAG_SHOW_SCRIM;

import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;

interface StateFlags {
    int FLAG_SHOW_SCRIM = 1 << 0;
    int FLAG_MULTI_PAGE = 1 << 1;
    int FLAG_HIDE_HOTSEAT = 1 << 2;
    int FLAG_DISABLE_ACCESSIBILITY = 1 << 3;
}

/**
 * Various states for launcher
 */
public enum LauncherState {

    NORMAL          (ContainerType.WORKSPACE, 0, 0),
    ALL_APPS        (ContainerType.ALLAPPS, ALL_APPS_TRANSITION_MS, FLAG_DISABLE_ACCESSIBILITY),
    SPRING_LOADED   (ContainerType.WORKSPACE, SPRING_LOADED_TRANSITION_MS,
            FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_DISABLE_ACCESSIBILITY),
    OVERVIEW        (ContainerType.OVERVIEW, OVERVIEW_TRANSITION_MS,
            FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT);

    public final int containerType;

    public final boolean hasMultipleVisiblePages;
    public final int workspaceAccessibilityFlag;

    // Properties related to state transition animation.
    public final boolean hasScrim;
    public final boolean hideHotseat;
    public final int transitionDuration;

    LauncherState(int containerType, int transitionDuration, int flags) {
        this.containerType = containerType;
        this.transitionDuration = transitionDuration;

        this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
        this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
        this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0;
        this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
                ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
    }
}
+11 −11
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class LauncherStateTransitionAnimation {
        cancelAnimation();

        if (!animated) {
            mLauncher.getWorkspace().setState(Workspace.State.NORMAL_HIDDEN);
            mLauncher.getWorkspace().setState(LauncherState.ALL_APPS);

            mAllAppsController.finishPullUp();
            toView.setTranslationX(0.0f);
@@ -129,7 +129,7 @@ public class LauncherStateTransitionAnimation {

        mConfig.reset();
        mAllAppsController.animateToAllApps(animation, mConfig);
        mLauncher.getWorkspace().setStateWithAnimation(Workspace.State.NORMAL_HIDDEN,
        mLauncher.getWorkspace().setStateWithAnimation(LauncherState.ALL_APPS,
                layerViews, animation, mConfig);

        Runnable startAnimRunnable = new StartAnimRunnable(animation, toView);
@@ -146,11 +146,11 @@ public class LauncherStateTransitionAnimation {
     * Starts an animation to the workspace from the current overlay view.
     */
    public void startAnimationToWorkspace(final Launcher.State fromState,
            final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
            final LauncherState fromWorkspaceState, final LauncherState toWorkspaceState,
            final boolean animated, final Runnable onCompleteRunnable) {
        if (toWorkspaceState != Workspace.State.NORMAL &&
                toWorkspaceState != Workspace.State.SPRING_LOADED &&
                toWorkspaceState != Workspace.State.OVERVIEW) {
        if (toWorkspaceState != LauncherState.NORMAL &&
                toWorkspaceState != LauncherState.SPRING_LOADED &&
                toWorkspaceState != LauncherState.OVERVIEW) {
            Log.e(TAG, "Unexpected call to startAnimationToWorkspace");
        }

@@ -166,8 +166,8 @@ public class LauncherStateTransitionAnimation {
    /**
     * Starts an animation to the workspace from the apps view.
     */
    private void startAnimationToWorkspaceFromAllApps(final Workspace.State fromWorkspaceState,
            final Workspace.State toWorkspaceState, boolean animated,
    private void startAnimationToWorkspaceFromAllApps(final LauncherState fromWorkspaceState,
            final LauncherState toWorkspaceState, boolean animated,
            final Runnable onCompleteRunnable) {
        final AllAppsContainerView fromView = mLauncher.getAppsView();
        // If for some reason our views aren't initialized, don't animate
@@ -180,7 +180,7 @@ public class LauncherStateTransitionAnimation {
        cancelAnimation();

        if (!animated) {
            if (fromWorkspaceState == Workspace.State.NORMAL_HIDDEN) {
            if (fromWorkspaceState == LauncherState.ALL_APPS) {
                mAllAppsController.finishPullDown();
            }
            fromView.setVisibility(View.GONE);
@@ -233,8 +233,8 @@ public class LauncherStateTransitionAnimation {
    /**
     * Starts an animation to the workspace from another workspace state, e.g. normal to overview.
     */
    private void startAnimationToNewWorkspaceState(final Workspace.State fromWorkspaceState,
            final Workspace.State toWorkspaceState, final boolean animated,
    private void startAnimationToNewWorkspaceState(final LauncherState fromWorkspaceState,
            final LauncherState toWorkspaceState, final boolean animated,
            final Runnable onCompleteRunnable) {
        final View fromWorkspace = mLauncher.getWorkspace();
        // Cancel the current animation
+6 −6
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;

import static com.android.launcher3.Workspace.State.NORMAL;
import static com.android.launcher3.Workspace.State.OVERVIEW;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;

/**
 * Manages the animations that play as the user pinches to/from overview mode.
@@ -141,12 +141,12 @@ public class PinchAnimationManager {
     * @param threshold One of {@link PinchThresholdManager#THRESHOLD_ONE},
     *                  {@link PinchThresholdManager#THRESHOLD_TWO}, or
     *                  {@link PinchThresholdManager#THRESHOLD_THREE}
     * @param startState {@link Workspace.State#NORMAL} or {@link Workspace.State#OVERVIEW}.
     * @param goingTowards {@link Workspace.State#NORMAL} or {@link Workspace.State#OVERVIEW}.
     * @param startState {@link LauncherState#NORMAL} or {@link LauncherState#OVERVIEW}.
     * @param goingTowards {@link LauncherState#NORMAL} or {@link LauncherState#OVERVIEW}.
     *                     Note that this doesn't have to be the opposite of startState;
     */
    public void animateThreshold(float threshold, Workspace.State startState,
            Workspace.State goingTowards) {
    public void animateThreshold(float threshold, LauncherState startState,
            LauncherState goingTowards) {
        if (threshold == PinchThresholdManager.THRESHOLD_ONE) {
            if (startState == OVERVIEW) {
                animateOverviewPanelButtons(goingTowards == OVERVIEW);
Loading