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
This commit is contained in:
Sunny Goyal
2020-04-23 19:00:36 -07:00
parent d75c1da9c7
commit 8f96546e79
19 changed files with 198 additions and 258 deletions
@@ -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);
@@ -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()) {
@@ -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;
}
@@ -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) {
@@ -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);
}
}
}
@@ -212,7 +212,7 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
final LauncherState startState = launcher.getStateManager().getState();
LauncherState resetState = startState;
if (startState.disableRestore) {
if (startState.shouldDisableRestore()) {
resetState = launcher.getStateManager().getRestState();
}
launcher.getStateManager().setRestState(resetState);
@@ -17,6 +17,7 @@ package com.android.launcher3;
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.FLAG_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY;
@@ -257,7 +258,7 @@ public abstract class BaseQuickstepLauncher extends Launcher
private void onLauncherStateOrFocusChanged() {
Mode mode = SysUINavigationMode.getMode(this);
boolean shouldBackButtonBeHidden = mode.hasGestures
&& getStateManager().getState().hideBackButton
&& getStateManager().getState().hasFlag(FLAG_HIDE_BACK_BUTTON)
&& hasWindowFocus()
&& (getActivityFlags() & ACTIVITY_STATE_TRANSITION_ACTIVE) == 0;
if (shouldBackButtonBeHidden) {
@@ -16,6 +16,7 @@
package com.android.launcher3.statehandlers;
import static com.android.launcher3.LauncherState.FLAG_HIDE_BACK_BUTTON;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.quickstep.AnimatedFloat.VALUE;
@@ -59,7 +60,8 @@ public class BackButtonAlphaHandler implements LauncherStateManager.StateHandler
}
mBackAlpha.value = SystemUiProxy.INSTANCE.get(mLauncher).getLastBackButtonAlpha();
animation.setFloat(mBackAlpha, VALUE, toState.hideBackButton ? 0 : 1, LINEAR);
animation.setFloat(mBackAlpha, VALUE,
toState.hasFlag(FLAG_HIDE_BACK_BUTTON) ? 0 : 1, LINEAR);
}
private void updateBackAlpha() {
@@ -21,7 +21,6 @@ import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import android.content.Context;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.allapps.AllAppsContainerView;
@@ -33,7 +32,7 @@ import com.android.quickstep.SysUINavigationMode;
*/
public class AllAppsState extends LauncherState {
private static final int STATE_FLAGS = FLAG_DISABLE_ACCESSIBILITY;
private static final int STATE_FLAGS = FLAG_WORKSPACE_INACCESSIBLE | FLAG_CLOSE_POPUPS;
private static final PageAlphaProvider PAGE_ALPHA_PROVIDER = new PageAlphaProvider(DEACCEL_2) {
@Override
@@ -47,22 +46,10 @@ public class AllAppsState extends LauncherState {
}
@Override
public int getTransitionDuration(Launcher launcher) {
public int getTransitionDuration(Context context) {
return 320;
}
@Override
public void onStateEnabled(Launcher launcher) {
AbstractFloatingView.closeAllOpenViews(launcher);
dispatchWindowStateChanged(launcher);
}
@Override
public void onStateDisabled(Launcher launcher) {
super.onStateDisabled(launcher);
AbstractFloatingView.closeAllOpenViews(launcher);
}
@Override
public String getDescription(Launcher launcher) {
AllAppsContainerView appsView = launcher.getAppsView();
+42 -4
View File
@@ -18,23 +18,30 @@ package com.android.launcher3;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR;
import static com.android.launcher3.InstallShortcutReceiver.FLAG_DRAG_AND_DROP;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS;
import static com.android.launcher3.LauncherState.FLAG_MULTI_PAGE;
import static com.android.launcher3.LauncherState.FLAG_NON_INTERACTIVE;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.NO_OFFSET;
import static com.android.launcher3.LauncherState.NO_SCALE;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherState.OVERVIEW_PEEK;
import static com.android.launcher3.LauncherState.SPRING_LOADED;
import static com.android.launcher3.Utilities.postAsyncCallback;
import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import static com.android.launcher3.popup.SystemShortcut.APP_INFO;
import static com.android.launcher3.popup.SystemShortcut.INSTALL;
import static com.android.launcher3.popup.SystemShortcut.WIDGETS;
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
import android.animation.Animator;
@@ -92,6 +99,7 @@ import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dot.DotInfo;
import com.android.launcher3.dragndrop.DragController;
@@ -934,7 +942,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
private void handleDeferredResume() {
if (hasBeenResumed() && !mStateManager.getState().disableInteraction) {
if (hasBeenResumed() && !mStateManager.getState().hasFlag(FLAG_NON_INTERACTIVE)) {
logStopAndResume(Action.Command.RESUME);
getUserEventDispatcher().startSession();
@@ -982,7 +990,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
if (!mDeferOverlayCallbacks) {
return;
}
if (isStarted() && (!hasBeenResumed() || mStateManager.getState().disableInteraction)) {
if (isStarted() && (!hasBeenResumed()
|| mStateManager.getState().hasFlag(FLAG_NON_INTERACTIVE))) {
return;
}
mDeferOverlayCallbacks = false;
@@ -1017,13 +1026,42 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
scheduleDeferredCheck();
}
addActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
if (state.hasFlag(FLAG_CLOSE_POPUPS)) {
AbstractFloatingView.closeAllOpenViews(this, !state.hasFlag(FLAG_NON_INTERACTIVE));
}
if (state == SPRING_LOADED) {
// Prevent any Un/InstallShortcutReceivers from updating the db while we are
// not on homescreen
InstallShortcutReceiver.enableInstallQueue(FLAG_DRAG_AND_DROP);
getRotationHelper().setCurrentStateRequest(REQUEST_LOCK);
mWorkspace.showPageIndicatorAtCurrentScroll();
mWorkspace.setClipChildren(false);
}
// When multiple pages are visible, show persistent page indicator
mWorkspace.getPageIndicator().setShouldAutoHide(!state.hasFlag(FLAG_MULTI_PAGE));
}
public void onStateSetEnd(LauncherState state) {
getAppWidgetHost().setResumed(state == LauncherState.NORMAL);
getWorkspace().setClipChildren(!state.disablePageClipping);
getWorkspace().setClipChildren(!state.hasFlag(FLAG_MULTI_PAGE));
finishAutoCancelActionMode();
removeActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE);
// dispatch window state changed
getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
AccessibilityManagerCompat.sendStateEventToTest(this, state.ordinal);
if (state == NORMAL) {
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
InstallShortcutReceiver.disableAndFlushInstallQueue(FLAG_DRAG_AND_DROP, this);
// Clear any rotation locks when going to normal state
getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
}
}
@Override
@@ -1094,7 +1132,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
LauncherState[] stateValues = LauncherState.values();
LauncherState state = stateValues[stateOrdinal];
if (!state.disableRestore) {
if (!state.shouldDisableRestore()) {
mStateManager.goToState(state, false /* animated */);
}
+39 -97
View File
@@ -15,10 +15,7 @@
*/
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 android.view.View.VISIBLE;
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
import static com.android.launcher3.anim.Interpolators.ACCEL;
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
@@ -26,7 +23,6 @@ import static com.android.launcher3.anim.Interpolators.DEACCEL;
import static com.android.launcher3.anim.Interpolators.DEACCEL_1_7;
import static com.android.launcher3.anim.Interpolators.clampToProgress;
import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS;
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X;
@@ -62,7 +58,6 @@ import java.util.Arrays;
*/
public abstract class LauncherState {
/**
* Set of elements indicating various workspace elements which change visibility across states
* Note that workspace is not included here as in that case, we animate individual pages
@@ -80,16 +75,27 @@ public abstract class LauncherState {
public static final int APPS_VIEW_ITEM_MASK =
HOTSEAT_SEARCH_BOX | ALL_APPS_HEADER | ALL_APPS_HEADER_EXTRA | ALL_APPS_CONTENT;
protected static final int FLAG_MULTI_PAGE = 1 << 0;
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 1;
protected static final int FLAG_DISABLE_RESTORE = 1 << 2;
protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 3;
protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 4;
protected static final int FLAG_PAGE_BACKGROUNDS = 1 << 5;
protected static final int FLAG_DISABLE_INTERACTION = 1 << 6;
protected static final int FLAG_OVERVIEW_UI = 1 << 7;
protected static final int FLAG_HIDE_BACK_BUTTON = 1 << 8;
protected static final int FLAG_HAS_SYS_UI_SCRIM = 1 << 9;
// Flag indicating workspace has multiple pages visible.
public static final int FLAG_MULTI_PAGE = 1 << 0;
// Flag indicating that workspace and its contents are not accessible
public static final int FLAG_WORKSPACE_INACCESSIBLE = 1 << 1;
public static final int FLAG_DISABLE_RESTORE = 1 << 2;
// Flag indicating the state allows workspace icons to be dragged.
public static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 3;
// Flag to indicate that workspace should draw page background
public static final int FLAG_WORKSPACE_HAS_BACKGROUNDS = 1 << 4;
// Flag to indicate that Launcher is non-interactive in this state
public static final int FLAG_NON_INTERACTIVE = 1 << 5;
// True if the back button should be hidden when in this state (assuming no floating views are
// open, launcher has window focus, etc).
public static final int FLAG_HIDE_BACK_BUTTON = 1 << 6;
// Flag to indicate if the state would have scrim over sysui region: statu sbar and nav bar
public static final int FLAG_HAS_SYS_UI_SCRIM = 1 << 7;
// Flag to inticate that all popups should be closed when this state is enabled.
public static final int FLAG_CLOSE_POPUPS = 1 << 8;
public static final int FLAG_OVERVIEW_UI = 1 << 9;
public static final float NO_OFFSET = 0;
public static final float NO_SCALE = 1;
@@ -112,7 +118,7 @@ public abstract class LauncherState {
FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HIDE_BACK_BUTTON |
FLAG_HAS_SYS_UI_SCRIM) {
@Override
public int getTransitionDuration(Launcher launcher) {
public int getTransitionDuration(Context context) {
// Arbitrary duration, when going to NORMAL we use the state we're coming from instead.
return 0;
}
@@ -143,87 +149,43 @@ public abstract class LauncherState {
*/
public final int containerType;
/**
* True if the state can be persisted across activity restarts.
*/
public final boolean disableRestore;
/**
* 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
*
* @see WorkspaceStateTransitionAnimation
*/
public final boolean hasWorkspacePageBackground;
/**
* True if the state allows workspace icons to be dragged.
*/
public final boolean workspaceIconsCanBeDragged;
/**
* True if the workspace pages should not be clipped relative to the workspace bounds
* for this state.
*/
public final boolean disablePageClipping;
/**
* True if launcher can not be directly interacted in this state;
*/
public final boolean disableInteraction;
/**
* True if the state has overview panel visible.
*/
public final boolean overviewUi;
/**
* True if the back button should be hidden when in this state (assuming no floating views are
* open, launcher has window focus, etc).
*/
public final boolean hideBackButton;
public final boolean hasSysUiScrim;
private final int mFlags;
public LauncherState(int id, int containerType, int flags) {
this.containerType = containerType;
this.hasWorkspacePageBackground = (flags & FLAG_PAGE_BACKGROUNDS) != 0;
this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
: IMPORTANT_FOR_ACCESSIBILITY_AUTO;
this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0;
this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0;
this.disableInteraction = (flags & FLAG_DISABLE_INTERACTION) != 0;
this.mFlags = flags;
this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0;
this.hideBackButton = (flags & FLAG_HIDE_BACK_BUTTON) != 0;
this.hasSysUiScrim = (flags & FLAG_HAS_SYS_UI_SCRIM) != 0;
this.ordinal = id;
sAllStates[id] = this;
}
/**
* Returns if the state has the provided flag
*/
public final boolean hasFlag(int mask) {
return (mFlags & mask) != 0;
}
/**
* @return true if the state can be persisted across activity restarts.
*/
public final boolean shouldDisableRestore() {
return hasFlag(FLAG_DISABLE_RESTORE);
}
public static LauncherState[] values() {
return Arrays.copyOf(sAllStates, sAllStates.length);
}
/**
* @return How long the animation to this state should take (or from this state to NORMAL).
* @param launcher
*/
public abstract int getTransitionDuration(Launcher launcher);
public abstract int getTransitionDuration(Context context);
public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET);
@@ -252,12 +214,6 @@ public abstract class LauncherState {
return 0;
}
public void onStateEnabled(Launcher launcher) {
dispatchWindowStateChanged(launcher);
}
public void onStateDisabled(Launcher launcher) { }
public int getVisibleElements(Launcher launcher) {
if (launcher.getDeviceProfile().isVerticalBarLayout()) {
return HOTSEAT_ICONS | VERTICAL_SWIPE_INDICATOR;
@@ -329,16 +285,6 @@ public abstract class LauncherState {
return NORMAL;
}
/**
* Called when the start transition ends and the user settles on this particular state.
*/
public void onStateTransitionEnd(Launcher launcher) {
if (this == NORMAL) {
// Clear any rotation locks when going to normal state
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
}
}
public void onBackPressed(Launcher launcher) {
if (this != NORMAL) {
LauncherStateManager lsm = launcher.getStateManager();
@@ -396,10 +342,6 @@ public abstract class LauncherState {
}
}
protected static void dispatchWindowStateChanged(Launcher launcher) {
launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
}
public static abstract class PageAlphaProvider {
public final Interpolator interpolator;
@@ -29,7 +29,6 @@ import android.os.Looper;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.states.StateAnimationConfig.AnimationFlags;
@@ -355,18 +354,9 @@ public class LauncherStateManager {
}
private void onStateTransitionStart(LauncherState state) {
if (mState != state) {
mState.onStateDisabled(mLauncher);
}
mState = state;
mState.onStateEnabled(mLauncher);
mLauncher.onStateSetStart(mState);
if (state.disablePageClipping) {
// Only disable clipping if needed, otherwise leave it as previous value.
mLauncher.getWorkspace().setClipChildren(false);
}
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onStateTransitionStart(state);
}
@@ -379,9 +369,7 @@ public class LauncherStateManager {
mCurrentStableState = state;
}
state.onStateTransitionEnd(mLauncher);
mLauncher.onStateSetEnd(state);
if (state == NORMAL) {
setRestState(null);
}
@@ -389,8 +377,6 @@ public class LauncherStateManager {
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onStateTransitionComplete(state);
}
AccessibilityManagerCompat.sendStateEventToTest(mLauncher, state.ordinal);
}
public LauncherState getLastState() {
@@ -402,7 +388,7 @@ public class LauncherStateManager {
// The user is doing something. Lets not mess it up
return;
}
if (mState.disableRestore) {
if (mState.shouldDisableRestore()) {
goToState(getRestState());
// Reset history
mLastStableState = NORMAL;
+9 -3
View File
@@ -19,6 +19,9 @@ package com.android.launcher3;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.FLAG_MULTI_PAGE;
import static com.android.launcher3.LauncherState.FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED;
import static com.android.launcher3.LauncherState.FLAG_WORKSPACE_INACCESSIBLE;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherState.SPRING_LOADED;
@@ -1208,7 +1211,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
/** Returns whether a drag should be allowed to be started from the current workspace state. */
public boolean workspaceIconsCanBeDragged() {
return mLauncher.getStateManager().getState().workspaceIconsCanBeDragged;
return mLauncher.getStateManager().getState().hasFlag(FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED);
}
private void updateChildrenLayersEnabled() {
@@ -1318,7 +1321,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// Invalidate the pages now, so that we have the visible pages before the
// animation is started
if (toState.hasMultipleVisiblePages) {
if (toState.hasFlag(FLAG_MULTI_PAGE)) {
mForceDrawAdjacentPages = true;
}
invalidate(); // This will call dispatchDraw(), which calls getVisiblePages().
@@ -1336,7 +1339,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
public void updateAccessibilityFlags() {
// TODO: Update the accessibility flags appropriately when dragging.
int accessibilityFlag = mLauncher.getStateManager().getState().workspaceAccessibilityFlag;
int accessibilityFlag =
mLauncher.getStateManager().getState().hasFlag(FLAG_WORKSPACE_INACCESSIBLE)
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
: IMPORTANT_FOR_ACCESSIBILITY_AUTO;
if (!mLauncher.getAccessibilityDelegate().isInAccessibleDrag()) {
int total = getPageCount();
for (int i = 0; i < total; i++) {
@@ -21,6 +21,8 @@ import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.LauncherState.FLAG_HAS_SYS_UI_SCRIM;
import static com.android.launcher3.LauncherState.FLAG_WORKSPACE_HAS_BACKGROUNDS;
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.ZOOM_OUT;
@@ -161,7 +163,8 @@ public class WorkspaceStateTransitionAnimation {
WorkspaceAndHotseatScrim scrim = mLauncher.getDragLayer().getScrim();
propertySetter.setFloat(scrim, SCRIM_PROGRESS, state.getWorkspaceScrimAlpha(mLauncher),
LINEAR);
propertySetter.setFloat(scrim, SYSUI_PROGRESS, state.hasSysUiScrim ? 1 : 0, LINEAR);
propertySetter.setFloat(scrim, SYSUI_PROGRESS,
state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR);
}
public void applyChildState(LauncherState state, CellLayout cl, int childIndex) {
@@ -173,7 +176,8 @@ public class WorkspaceStateTransitionAnimation {
PageAlphaProvider pageAlphaProvider, PropertySetter propertySetter,
StateAnimationConfig config) {
float pageAlpha = pageAlphaProvider.getPageAlpha(childIndex);
int drawableAlpha = Math.round(pageAlpha * (state.hasWorkspacePageBackground ? 255 : 0));
int drawableAlpha = state.hasFlag(FLAG_WORKSPACE_HAS_BACKGROUNDS)
? Math.round(pageAlpha * 255) : 0;
if (!config.onlyPlayAtomicComponent()) {
// Don't update the scrim during the atomic animation.
@@ -15,10 +15,10 @@
*/
package com.android.launcher3.states;
import android.content.Context;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
/**
@@ -26,7 +26,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
*/
public class HintState extends LauncherState {
private static final int STATE_FLAGS = FLAG_DISABLE_ACCESSIBILITY | FLAG_DISABLE_RESTORE
private static final int STATE_FLAGS = FLAG_WORKSPACE_INACCESSIBLE | FLAG_DISABLE_RESTORE
| FLAG_HAS_SYS_UI_SCRIM;
public HintState(int id) {
@@ -34,7 +34,7 @@ public class HintState extends LauncherState {
}
@Override
public int getTransitionDuration(Launcher launcher) {
public int getTransitionDuration(Context context) {
return 80;
}
@@ -48,16 +48,4 @@ public class HintState extends LauncherState {
// Treat the QSB as part of the hotseat so they move together.
return getHotseatScaleAndTranslation(launcher);
}
@Override
public void onStateTransitionEnd(Launcher launcher) {
LauncherStateManager stateManager = launcher.getStateManager();
Workspace workspace = launcher.getWorkspace();
boolean willMoveScreens = workspace.getNextPage() != Workspace.DEFAULT_PAGE;
stateManager.goToState(NORMAL, true, willMoveScreens ? null
: launcher.getScrimView()::startDragHandleEducationAnim);
if (willMoveScreens) {
workspace.post(workspace::moveToDefaultScreen);
}
}
}
@@ -15,13 +15,10 @@
*/
package com.android.launcher3.states;
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
import android.content.Context;
import android.graphics.Rect;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
@@ -32,16 +29,17 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
*/
public class SpringLoadedState extends LauncherState {
private static final int STATE_FLAGS = FLAG_MULTI_PAGE |
FLAG_DISABLE_ACCESSIBILITY | FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED |
FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS | FLAG_HIDE_BACK_BUTTON;
private static final int STATE_FLAGS = FLAG_MULTI_PAGE
| FLAG_WORKSPACE_INACCESSIBLE | FLAG_DISABLE_RESTORE
| FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_WORKSPACE_HAS_BACKGROUNDS
| FLAG_HIDE_BACK_BUTTON;
public SpringLoadedState(int id) {
super(id, ContainerType.OVERVIEW, STATE_FLAGS);
}
@Override
public int getTransitionDuration(Launcher launcher) {
public int getTransitionDuration(Context context) {
return 150;
}
@@ -87,29 +85,8 @@ public class SpringLoadedState extends LauncherState {
return new ScaleAndTranslation(1, 0, 0);
}
@Override
public void onStateEnabled(Launcher launcher) {
Workspace ws = launcher.getWorkspace();
ws.showPageIndicatorAtCurrentScroll();
ws.getPageIndicator().setShouldAutoHide(false);
// Prevent any Un/InstallShortcutReceivers from updating the db while we are
// in spring loaded mode
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_LOCK);
}
@Override
public float getWorkspaceScrimAlpha(Launcher launcher) {
return 0.3f;
}
@Override
public void onStateDisabled(final Launcher launcher) {
launcher.getWorkspace().getPageIndicator().setShouldAutoHide(true);
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
InstallShortcutReceiver.disableAndFlushInstallQueue(
InstallShortcutReceiver.FLAG_DRAG_AND_DROP, launcher);
}
}
@@ -33,6 +33,7 @@ import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.LauncherStateManager.StateListener;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsPagedView;
@@ -43,7 +44,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto;
/**
* On boarding flow for users right after setting up work profile
*/
public class WorkEduView extends AbstractSlideInView implements Insettable {
public class WorkEduView extends AbstractSlideInView implements Insettable, StateListener {
private static final int DEFAULT_CLOSE_DURATION = 200;
public static final String KEY_WORK_EDU_STEP = "showed_work_profile_edu";
@@ -81,6 +82,12 @@ public class WorkEduView extends AbstractSlideInView implements Insettable {
handleClose(true, DEFAULT_CLOSE_DURATION);
}
@Override
protected void onCloseComplete() {
super.onCloseComplete();
mLauncher.getStateManager().removeStateListener(this);
}
@Override
public void logActionCommand(int command) {
// Since this is on-boarding popup, it is not a user controlled action.
@@ -150,6 +157,7 @@ public class WorkEduView extends AbstractSlideInView implements Insettable {
private void show() {
attachToContainer();
animateOpen();
mLauncher.getStateManager().addStateListener(this);
}
@Override
@@ -222,4 +230,9 @@ public class WorkEduView extends AbstractSlideInView implements Insettable {
private static boolean hasSeenLegacyEdu(Launcher launcher) {
return launcher.getSharedPrefs().getBoolean(KEY_LEGACY_WORK_EDU_SEEN, false);
}
@Override
public void onStateTransitionComplete(LauncherState finalState) {
close(false);
}
}
@@ -16,9 +16,9 @@
package com.android.launcher3.uioverrides.states;
import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
import static com.android.launcher3.util.OnboardingPrefs.HOME_BOUNCE_SEEN;
import com.android.launcher3.AbstractFloatingView;
import android.content.Context;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
@@ -31,7 +31,7 @@ public class AllAppsState extends LauncherState {
private static final float PARALLAX_COEFFICIENT = .125f;
private static final int STATE_FLAGS = FLAG_DISABLE_ACCESSIBILITY;
private static final int STATE_FLAGS = FLAG_WORKSPACE_INACCESSIBLE;
private static final PageAlphaProvider PAGE_ALPHA_PROVIDER = new PageAlphaProvider(DEACCEL_2) {
@Override
@@ -45,20 +45,10 @@ public class AllAppsState extends LauncherState {
}
@Override
public int getTransitionDuration(Launcher context) {
public int getTransitionDuration(Context context) {
return 320;
}
@Override
public void onStateEnabled(Launcher launcher) {
if (!launcher.getSharedPrefs().getBoolean(HOME_BOUNCE_SEEN, false)) {
launcher.getSharedPrefs().edit().putBoolean(HOME_BOUNCE_SEEN, true).apply();
}
AbstractFloatingView.closeAllOpenViews(launcher);
dispatchWindowStateChanged(launcher);
}
@Override
public String getDescription(Launcher launcher) {
return launcher.getString(R.string.all_apps_button_label);
@@ -15,7 +15,8 @@
*/
package com.android.launcher3.uioverrides.states;
import com.android.launcher3.Launcher;
import android.content.Context;
import com.android.launcher3.LauncherState;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -29,7 +30,7 @@ public class OverviewState extends LauncherState {
}
@Override
public int getTransitionDuration(Launcher context) {
public int getTransitionDuration(Context context) {
return 250;
}