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

Commit 8f96546e authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Generalizing LauncherState definition so that it can be used in RecentsActivity

> Removing 'Launcher' as parameter from state methods called by StateManager
> Converting state properties to methods for easier abstraction
> Moving state handling drom state definition to activity class

Change-Id: I997627df606a7e0bb3bf32688d045a942a47fc94
parent d75c1da9
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -15,9 +15,16 @@
 */
package com.android.launcher3.uioverrides;

import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;

import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherState.OVERVIEW_MODAL_TASK;
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
import static com.android.launcher3.testing.TestProtocol.HINT_STATE_ORDINAL;
import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL;
import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;

import android.content.Intent;
@@ -31,6 +38,8 @@ import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.Folder;
@@ -56,6 +65,7 @@ import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -175,6 +185,49 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
        }
    }

    @Override
    public void onStateSetEnd(LauncherState state) {
        super.onStateSetEnd(state);

        switch (state.ordinal) {
            case HINT_STATE_ORDINAL: {
                Workspace workspace = getWorkspace();
                boolean willMoveScreens = workspace.getNextPage() != Workspace.DEFAULT_PAGE;
                getStateManager().goToState(NORMAL, true,
                        willMoveScreens ? null : getScrimView()::startDragHandleEducationAnim);
                if (willMoveScreens) {
                    workspace.post(workspace::moveToDefaultScreen);
                }
                break;
            }
            case OVERVIEW_STATE_ORDINAL: {
                DiscoveryBounce.showForOverviewIfNeeded(this);
                RecentsView rv = getOverviewPanel();
                sendCustomAccessibilityEvent(
                        rv.getPageAt(rv.getCurrentPage()), TYPE_VIEW_FOCUSED, null);
                break;
            }
            case QUICK_SWITCH_STATE_ORDINAL: {
                RecentsView rv = getOverviewPanel();
                TaskView tasktolaunch = rv.getTaskViewAt(0);
                if (tasktolaunch != null) {
                    tasktolaunch.launchTask(false, success -> {
                        if (!success) {
                            getStateManager().goToState(OVERVIEW);
                            tasktolaunch.notifyTaskLaunchFailed(TAG);
                        } else {
                            getStateManager().moveToRestState();
                        }
                    }, MAIN_EXECUTOR.getHandler());
                } else {
                    getStateManager().goToState(NORMAL);
                }
                break;
            }

        }
    }

    @Override
    public TouchController[] createTouchControllers() {
        Mode mode = SysUINavigationMode.getMode(this);
+2 −9
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package com.android.launcher3.uioverrides.states;

import android.content.Context;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -29,9 +28,8 @@ import com.android.quickstep.views.RecentsView;
 */
public class BackgroundAppState extends OverviewState {

    private static final int STATE_FLAGS =
            FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY
                    | FLAG_DISABLE_INTERACTION;
    private static final int STATE_FLAGS = FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI
            | FLAG_WORKSPACE_INACCESSIBLE | FLAG_NON_INTERACTIVE | FLAG_CLOSE_POPUPS;

    public BackgroundAppState(int id) {
        this(id, LauncherLogProto.ContainerType.TASKSWITCHER);
@@ -41,11 +39,6 @@ public class BackgroundAppState extends OverviewState {
        super(id, logContainer, STATE_FLAGS);
    }

    @Override
    public void onStateEnabled(Launcher launcher) {
        AbstractFloatingView.closeAllOpenViews(launcher, false);
    }

    @Override
    public float getVerticalProgress(Launcher launcher) {
        if (launcher.getDeviceProfile().isVerticalBarLayout()) {
+3 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.uioverrides.states;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;

@@ -30,14 +31,14 @@ import com.android.quickstep.views.RecentsView;
public class OverviewModalTaskState extends OverviewState {

    private static final int STATE_FLAGS =
            FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY;
            FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_WORKSPACE_INACCESSIBLE;

    public OverviewModalTaskState(int id) {
        super(id, ContainerType.OVERVIEW, STATE_FLAGS);
    }

    @Override
    public int getTransitionDuration(Launcher launcher) {
    public int getTransitionDuration(Context launcher) {
        return 300;
    }

+4 −21
Original line number Diff line number Diff line
@@ -37,17 +37,13 @@ import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Interpolator;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -67,7 +63,8 @@ public class OverviewState extends LauncherState {
    protected static final Rect sTempRect = new Rect();

    private static final int STATE_FLAGS = FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED
            | FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_DISABLE_ACCESSIBILITY;
            | FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_WORKSPACE_INACCESSIBLE
            | FLAG_CLOSE_POPUPS;

    public OverviewState(int id) {
        this(id, STATE_FLAGS);
@@ -82,9 +79,9 @@ public class OverviewState extends LauncherState {
    }

    @Override
    public int getTransitionDuration(Launcher launcher) {
    public int getTransitionDuration(Context context) {
        // In no-button mode, overview comes in all the way from the left, so give it more time.
        boolean isNoButtonMode = SysUINavigationMode.INSTANCE.get(launcher).getMode() == NO_BUTTON;
        boolean isNoButtonMode = SysUINavigationMode.INSTANCE.get(context).getMode() == NO_BUTTON;
        return isNoButtonMode && ENABLE_OVERVIEW_ACTIONS.get() ? 380 : 250;
    }

@@ -136,20 +133,6 @@ public class OverviewState extends LauncherState {
        return super.getQsbScaleAndTranslation(launcher);
    }

    @Override
    public void onStateEnabled(Launcher launcher) {
        AbstractFloatingView.closeAllOpenViews(launcher);
    }

    @Override
    public void onStateTransitionEnd(Launcher launcher) {
        DiscoveryBounce.showForOverviewIfNeeded(launcher);
        RecentsView recentsView = launcher.getOverviewPanel();
        AccessibilityManagerCompat.sendCustomAccessibilityEvent(
                recentsView.getPageAt(recentsView.getCurrentPage()),
                AccessibilityEvent.TYPE_VIEW_FOCUSED, null);
    }

    @Override
    public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
        return new PageAlphaProvider(DEACCEL_2) {
+1 −26
Original line number Diff line number Diff line
@@ -15,24 +15,16 @@
 */
package com.android.launcher3.uioverrides.states;

import android.os.Handler;
import android.os.Looper;

import com.android.launcher3.Launcher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.GestureState;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;

/**
 * State to indicate we are about to launch a recent task. Note that this state is only used when
 * quick switching from launcher; quick switching from an app uses LauncherSwipeHandler.
 * @see GestureState.GestureEndTarget#NEW_TASK
 * @see com.android.quickstep.GestureState.GestureEndTarget#NEW_TASK
 */
public class QuickSwitchState extends BackgroundAppState {

    private static final String TAG = "QuickSwitchState";

    public QuickSwitchState(int id) {
        super(id, LauncherLogProto.ContainerType.APP);
    }
@@ -49,21 +41,4 @@ public class QuickSwitchState extends BackgroundAppState {
    public int getVisibleElements(Launcher launcher) {
        return NONE;
    }

    @Override
    public void onStateTransitionEnd(Launcher launcher) {
        TaskView tasktolaunch = launcher.<RecentsView>getOverviewPanel().getTaskViewAt(0);
        if (tasktolaunch != null) {
            tasktolaunch.launchTask(false, success -> {
                if (!success) {
                    launcher.getStateManager().goToState(OVERVIEW);
                    tasktolaunch.notifyTaskLaunchFailed(TAG);
                } else {
                    launcher.getStateManager().moveToRestState();
                }
            }, new Handler(Looper.getMainLooper()));
        } else {
            launcher.getStateManager().goToState(NORMAL);
        }
    }
}
Loading