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

Commit f9403d92 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing state definition from Launcher

State is only maintained is workspace and is used for all the UI

Bug: 67678570
Change-Id: Ie3cce5a1f4ada3913d0480f7918c27460dacbd34
parent 4c7f2156
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.launcher3.accessibility.FolderAccessibilityHelper;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.util.CellAndSpan;
@@ -342,7 +341,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
        // the home screen mode, however, once in overview mode stylus button press should be
        // enabled to allow rearranging the different home screens. So check what mode
        // the workspace is in, and only perform stylus button presses while in overview mode.
        if (mLauncher.mWorkspace.isInOverviewMode()
        if (mLauncher.isInState(LauncherState.OVERVIEW)
                && mStylusEventHelper.onMotionEvent(ev)) {
            return true;
        }
+42 −84
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.OvershootInterpolator;
@@ -186,11 +185,6 @@ public class Launcher extends BaseActivity
     */
    protected static final int REQUEST_LAST = 100;

    private static final int SOFT_INPUT_MODE_DEFAULT =
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
    private static final int SOFT_INPUT_MODE_ALL_APPS =
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

    // The Intent extra that defines whether to ignore the launch animation
    static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
            "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
@@ -208,10 +202,6 @@ public class Launcher extends BaseActivity

    static final String APPS_VIEW_SHOWN = "launcher.apps_view_shown";

    /** The different states that Launcher can be in. */
    enum State { WORKSPACE, WORKSPACE_SPRING_LOADED, APPS}

    @Thunk State mState = State.WORKSPACE;
    @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;

    private boolean mIsSafeModeEnabled;
@@ -601,7 +591,7 @@ public class Launcher extends BaseActivity
            }
            return;
        } else if (requestCode == REQUEST_PICK_WALLPAPER) {
            if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
            if (resultCode == RESULT_OK && isInState(LauncherState.OVERVIEW)) {
                // User could have free-scrolled between pages before picking a wallpaper; make sure
                // we move to the closest one now.
                mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
@@ -1001,8 +991,7 @@ public class Launcher extends BaseActivity
                AbstractFloatingView.closeAllOpenViews(this);

                // Show the overview mode if we are on the workspace
                if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
                        !mWorkspace.isSwitchingState()) {
                if (isInState(LauncherState.NORMAL) && !mWorkspace.isSwitchingState()) {
                    mOverviewPanel.requestFocus();
                    showOverviewMode(true, true /* requestButtonFocus */);
                }
@@ -1023,6 +1012,10 @@ public class Launcher extends BaseActivity
        Selection.setSelection(mDefaultKeySsb, 0);
    }

    public boolean isInState(LauncherState state) {
        return mWorkspace.getState() == state;
    }

    /**
     * Restores the previous state, if it exists.
     *
@@ -1033,12 +1026,15 @@ public class Launcher extends BaseActivity
            return;
        }

        int stateOrdinal = savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal());
        State[] stateValues = State.values();
        State state = (stateOrdinal >= 0 && stateOrdinal < stateValues.length)
                ? stateValues[stateOrdinal] : State.WORKSPACE;
        if (state == State.APPS) {
        int stateOrdinal = savedState.getInt(RUNTIME_STATE, LauncherState.NORMAL.ordinal());
        LauncherState[] stateValues = LauncherState.values();
        LauncherState state = stateValues[stateOrdinal];
        if (!state.doNotRestore) {
            if (state == LauncherState.ALL_APPS) {
                showAppsView(false /* animated */);
            } else {
                // TODO: Add logic for other states
            }
        }

        PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS);
@@ -1419,8 +1415,8 @@ public class Launcher extends BaseActivity
                != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        // Check this condition before handling isActionMain, as this will get reset.
        boolean shouldMoveToDefaultScreen = alreadyOnHome &&
                mState == State.WORKSPACE && AbstractFloatingView.getTopOpenView(this) == null;
        boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(LauncherState.NORMAL)
                && AbstractFloatingView.getTopOpenView(this) == null;

        boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
        if (isActionMain) {
@@ -1499,7 +1495,7 @@ public class Launcher extends BaseActivity
            outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());

        }
        outState.putInt(RUNTIME_STATE, mState.ordinal());
        outState.putInt(RUNTIME_STATE, mWorkspace.getState().ordinal());


        AbstractFloatingView widgets = AbstractFloatingView
@@ -1893,10 +1889,10 @@ public class Launcher extends BaseActivity
        AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
        if (topView != null) {
            topView.onBackPressed();
        } else if (isAppsViewVisible()) {
        } else if (isInState(LauncherState.ALL_APPS)) {
            ued.logActionCommand(Action.Command.BACK, ContainerType.ALLAPPS);
            showWorkspace(true);
        } else if (mWorkspace.isInOverviewMode()) {
        } else if (isInState(LauncherState.OVERVIEW)) {
            ued.logActionCommand(Action.Command.BACK, ContainerType.OVERVIEW);
            showWorkspace(true);
        } else {
@@ -1922,7 +1918,7 @@ public class Launcher extends BaseActivity
        }

        if (v instanceof Workspace) {
            if (mWorkspace.isInOverviewMode()) {
            if (isInState(LauncherState.OVERVIEW)) {
                getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH,
                        LauncherLogProto.Action.Direction.NONE,
                        LauncherLogProto.ContainerType.OVERVIEW, mWorkspace.getCurrentPage());
@@ -1932,7 +1928,7 @@ public class Launcher extends BaseActivity
        }

        if (v instanceof CellLayout) {
            if (mWorkspace.isInOverviewMode()) {
            if (isInState(LauncherState.OVERVIEW)) {
                int page = mWorkspace.indexOfChild(v);
                getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH,
                        LauncherLogProto.Action.Direction.NONE,
@@ -2010,7 +2006,7 @@ public class Launcher extends BaseActivity
     */
    protected void onClickAllAppsButton(View v) {
        if (LOGD) Log.d(TAG, "onClickAllAppsButton");
        if (!isAppsViewVisible()) {
        if (!isInState(LauncherState.ALL_APPS)) {
            getUserEventDispatcher().logActionOnControl(Action.Touch.TAP,
                    ControlType.ALL_APPS_BUTTON);
            showAppsView(true /* animated */);
@@ -2340,13 +2336,13 @@ public class Launcher extends BaseActivity
    public boolean onLongClick(View v) {
        if (!isDraggingEnabled()) return false;
        if (isWorkspaceLocked()) return false;
        if (mState != State.WORKSPACE) return false;
        if (!isInState(LauncherState.NORMAL)) return false;

        boolean ignoreLongPressToOverview =
                mDeviceProfile.shouldIgnoreLongPressToOverview(mLastDispatchTouchEventX);

        if (v instanceof Workspace) {
            if (!mWorkspace.isInOverviewMode()) {
            if (!isInState(LauncherState.OVERVIEW)) {
                if (!mWorkspace.isTouchActive() && !ignoreLongPressToOverview) {
                    getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,
                            Action.Direction.NONE, ContainerType.WORKSPACE,
@@ -2377,7 +2373,7 @@ public class Launcher extends BaseActivity
        if (!mDragController.isDragging()) {
            if (itemUnderLongClick == null) {
                // User long pressed on empty space
                if (mWorkspace.isInOverviewMode()) {
                if (isInState(LauncherState.OVERVIEW)) {
                    mWorkspace.startReordering(v);
                    getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,
                            Action.Direction.NONE, ContainerType.OVERVIEW);
@@ -2427,17 +2423,6 @@ public class Launcher extends BaseActivity
        }
    }

    /**
     * For overridden classes.
     */
    public boolean isAllAppsVisible() {
        return isAppsViewVisible();
    }

    public boolean isAppsViewVisible() {
        return mState == State.APPS;
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
@@ -2459,11 +2444,10 @@ public class Launcher extends BaseActivity
    }

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

            // Set focus to the AppsCustomize button
@@ -2472,9 +2456,6 @@ public class Launcher extends BaseActivity
            }
        }

        // Change the state *after* we've called all the transition code
        setState(State.WORKSPACE);

        if (changed) {
            // Send an accessibility event to announce the context change
            getWindow().getDecorView()
@@ -2508,32 +2489,14 @@ public class Launcher extends BaseActivity
            };
        }
        mWorkspace.setVisibility(View.VISIBLE);
        mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
        mStateTransitionAnimation.startAnimationToWorkspace(
                LauncherState.OVERVIEW, animated, postAnimRunnable);
        setState(State.WORKSPACE);

        // If animated from long press, then don't allow any of the controller in the drag
        // layer to intercept any remaining touch.
        mWorkspace.requestDisallowInterceptTouchEvent(animated);
    }

    private void setState(State state) {
        this.mState = state;
        updateSoftInputMode();
    }

    private void updateSoftInputMode() {
        if (FeatureFlags.LAUNCHER3_UPDATE_SOFT_INPUT_MODE) {
            final int mode;
            if (isAppsViewVisible()) {
                mode = SOFT_INPUT_MODE_ALL_APPS;
            } else {
                mode = SOFT_INPUT_MODE_DEFAULT;
            }
            getWindow().setSoftInputMode(mode);
        }
    }

    /**
     * Shows the apps view.
     *
@@ -2544,8 +2507,8 @@ public class Launcher extends BaseActivity
    public boolean showAppsView(boolean animated) {
        markAppsViewShown();

        if (!(mState == State.WORKSPACE ||
                (mState == State.APPS && mAllAppsController.isTransitioning()))) {
        if (!(isInState(LauncherState.NORMAL) ||
                (isInState(LauncherState.ALL_APPS) && mAllAppsController.isTransitioning()))) {
            return false;
        }

@@ -2558,7 +2521,6 @@ public class Launcher extends BaseActivity
        mStateTransitionAnimation.startAnimationToAllApps(animated);

        // Change the state *after* we've called all the transition code
        setState(State.APPS);
        AbstractFloatingView.closeAllOpenViews(this);

        // Send an accessibility event to announce the context change
@@ -2568,8 +2530,9 @@ public class Launcher extends BaseActivity
    }

    public void enterSpringLoadedDragMode() {
        if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
        if (isStateSpringLoaded()) {
        if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s",
                mWorkspace.getState().name()));
        if (isInState(LauncherState.SPRING_LOADED)) {
            return;
        }

@@ -2582,10 +2545,9 @@ public class Launcher extends BaseActivity
        // in spring loaded mode
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);

        mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
        mStateTransitionAnimation.startAnimationToWorkspace(
                LauncherState.SPRING_LOADED, true /* animated */,
                null /* onCompleteRunnable */);
        setState(State.WORKSPACE_SPRING_LOADED);
    }

    public void exitSpringLoadedDragMode(int delay) {
@@ -2593,7 +2555,7 @@ public class Launcher extends BaseActivity
    }

    public void exitSpringLoadedDragMode(int delay, final Runnable onCompleteRunnable) {
        if (!isStateSpringLoaded()) return;
        if (!isInState(LauncherState.SPRING_LOADED)) return;

        // Unlock rotation lock
        unlockScreenOrientation(false);
@@ -2615,17 +2577,13 @@ public class Launcher extends BaseActivity
        mHandler.postDelayed(mExitSpringLoadedModeRunnable, delay);
    }

    boolean isStateSpringLoaded() {
        return mState == State.WORKSPACE_SPRING_LOADED;
    }

    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        final boolean result = super.dispatchPopulateAccessibilityEvent(event);
        final List<CharSequence> text = event.getText();
        text.clear();
        // Populate event with a fake title based on the current state.
        if (mState == State.APPS) {
        if (isInState(LauncherState.ALL_APPS)) {
            text.add(getString(R.string.all_apps_button_label));
        } else if (mWorkspace != null) {
            text.add(mWorkspace.getCurrentPageDescription());
@@ -3182,7 +3140,7 @@ public class Launcher extends BaseActivity

        if (mAppsView != null) {
            Executor pendingExecutor = getPendingExecutor();
            if (pendingExecutor != null && mState != State.APPS) {
            if (pendingExecutor != null && !isInState(LauncherState.ALL_APPS)) {
                // Wait until the fade in animation has finished before setting all apps list.
                pendingExecutor.execute(r);
                return;
@@ -3389,8 +3347,8 @@ public class Launcher extends BaseActivity
    }

    private boolean shouldShowDiscoveryBounce() {
        UserManagerCompat um = UserManagerCompat.getInstance(this);
        return mState == State.WORKSPACE && !mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false) && !um.isDemoUser();
        return isInState(LauncherState.NORMAL) && !mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false)
                && !UserManagerCompat.getInstance(this).isDemoUser();
    }

    /**
@@ -3448,7 +3406,7 @@ public class Launcher extends BaseActivity
            List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {

        ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
        if (mState == State.WORKSPACE) {
        if (isInState(LauncherState.NORMAL)) {
            shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
                    KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
        }
@@ -3474,7 +3432,7 @@ public class Launcher extends BaseActivity
        if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_A:
                    if (mState == State.WORKSPACE) {
                    if (isInState(LauncherState.NORMAL)) {
                        showAppsView(true);
                        return true;
                    }
+22 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ 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_DO_NOT_RESTORE;
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;
@@ -33,6 +34,7 @@ interface StateFlags {
    int FLAG_MULTI_PAGE = 1 << 1;
    int FLAG_HIDE_HOTSEAT = 1 << 2;
    int FLAG_DISABLE_ACCESSIBILITY = 1 << 3;
    int FLAG_DO_NOT_RESTORE = 1 << 4;
}

/**
@@ -40,16 +42,32 @@ interface StateFlags {
 */
public enum LauncherState {

    NORMAL          (ContainerType.WORKSPACE, 0, 0),
    NORMAL          (ContainerType.WORKSPACE, 0, FLAG_DO_NOT_RESTORE),
    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),
            FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_DISABLE_ACCESSIBILITY | FLAG_DO_NOT_RESTORE),
    OVERVIEW        (ContainerType.OVERVIEW, OVERVIEW_TRANSITION_MS,
            FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT);
            FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT | FLAG_DO_NOT_RESTORE);

    /**
     * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
     */
    public final int containerType;

    /**
     * True if the state can be persisted across activity restarts.
     */
    public final boolean doNotRestore;

    /**
     * True if workspace has multiple pages visible.
     */
    public final boolean hasMultipleVisiblePages;

    /**
     * Accessibility flag for workspace and its pages.
     * @see android.view.View#setImportantForAccessibility(int)
     */
    public final int workspaceAccessibilityFlag;

    // Properties related to state transition animation.
@@ -67,5 +85,6 @@ public enum LauncherState {
        this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
                ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
        this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0;
    }
}
+6 −8
Original line number Diff line number Diff line
@@ -145,8 +145,7 @@ public class LauncherStateTransitionAnimation {
    /**
     * Starts an animation to the workspace from the current overlay view.
     */
    public void startAnimationToWorkspace(final Launcher.State fromState,
            final LauncherState fromWorkspaceState, final LauncherState toWorkspaceState,
    public void startAnimationToWorkspace(final LauncherState toWorkspaceState,
            final boolean animated, final Runnable onCompleteRunnable) {
        if (toWorkspaceState != LauncherState.NORMAL &&
                toWorkspaceState != LauncherState.SPRING_LOADED &&
@@ -154,12 +153,11 @@ public class LauncherStateTransitionAnimation {
            Log.e(TAG, "Unexpected call to startAnimationToWorkspace");
        }

        if (fromState == Launcher.State.APPS || mAllAppsController.isTransitioning()) {
            startAnimationToWorkspaceFromAllApps(fromWorkspaceState, toWorkspaceState,
                    animated, onCompleteRunnable);
        if (mLauncher.isInState(LauncherState.ALL_APPS) || mAllAppsController.isTransitioning()) {
            startAnimationToWorkspaceFromAllApps(mLauncher.getWorkspace().getState(),
                    toWorkspaceState, animated, onCompleteRunnable);
        } else {
            startAnimationToNewWorkspaceState(fromWorkspaceState, toWorkspaceState,
                    animated, onCompleteRunnable);
            startAnimationToNewWorkspaceState(toWorkspaceState, animated, onCompleteRunnable);
        }
    }

@@ -233,7 +231,7 @@ public class LauncherStateTransitionAnimation {
    /**
     * Starts an animation to the workspace from another workspace state, e.g. normal to overview.
     */
    private void startAnimationToNewWorkspaceState(final LauncherState fromWorkspaceState,
    private void startAnimationToNewWorkspaceState(
            final LauncherState toWorkspaceState, final boolean animated,
            final Runnable onCompleteRunnable) {
        final View fromWorkspace = mLauncher.getWorkspace();
+7 −6
Original line number Diff line number Diff line
@@ -29,12 +29,14 @@ public class PinchThresholdManager {
    public static final float THRESHOLD_TWO = 0.70f;
    public static final float THRESHOLD_THREE = 0.95f;

    private Workspace mWorkspace;
    private final Workspace mWorkspace;
    private final Launcher mLauncher;

    private float mPassedThreshold = THRESHOLD_ZERO;

    public PinchThresholdManager(Workspace workspace) {
        mWorkspace = workspace;
        mLauncher = mWorkspace.mLauncher;
    }

    /**
@@ -50,7 +52,7 @@ public class PinchThresholdManager {
     */
    public float updateAndAnimatePassedThreshold(float progress,
            PinchAnimationManager animationManager) {
        if (!mWorkspace.isInOverviewMode()) {
        if (!mLauncher.isInState(LauncherState.OVERVIEW)) {
            // Invert the progress, because going from workspace to overview is 1 to 0.
            progress = 1f - progress;
        }
@@ -68,10 +70,9 @@ public class PinchThresholdManager {
        }

        if (mPassedThreshold != previousPassedThreshold) {
            LauncherState fromState = mWorkspace.isInOverviewMode() ? LauncherState.OVERVIEW
                    : LauncherState.NORMAL;
            LauncherState toState = mWorkspace.isInOverviewMode() ? LauncherState.NORMAL
                    : LauncherState.OVERVIEW;
            LauncherState fromState = mLauncher.getWorkspace().getState();
            LauncherState toState = mLauncher.isInState(LauncherState.OVERVIEW)
                    ? LauncherState.NORMAL : LauncherState.OVERVIEW;
            float thresholdToAnimate = mPassedThreshold;
            if (mPassedThreshold < previousPassedThreshold) {
                // User reversed pinch, so heading back to the state that they started from.
Loading