blob: 035b9c8d333cb39f50805b979dc31db93396ecc5 [file] [log] [blame]
Sunny Goyal4c7f2152017-10-17 17:17:16 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.launcher3;
17
Kateryna Ivanova71203732023-05-24 15:09:00 +000018import static com.android.app.animation.Interpolators.ACCELERATE_2;
19import static com.android.app.animation.Interpolators.DECELERATE_2;
Winson Chungf9935182020-10-23 09:26:44 -070020import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
Tony Wickhamc5d168d2021-03-25 09:28:19 -070021import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
vadimtf6ef8792022-07-26 13:54:31 -070022import static com.android.launcher3.testing.shared.TestProtocol.ALL_APPS_STATE_ORDINAL;
23import static com.android.launcher3.testing.shared.TestProtocol.BACKGROUND_APP_STATE_ORDINAL;
Charlie Anderson438d4052023-04-25 14:38:57 -040024import static com.android.launcher3.testing.shared.TestProtocol.EDIT_MODE_STATE_ORDINAL;
vadimtf6ef8792022-07-26 13:54:31 -070025import static com.android.launcher3.testing.shared.TestProtocol.HINT_STATE_ORDINAL;
26import static com.android.launcher3.testing.shared.TestProtocol.HINT_STATE_TWO_BUTTON_ORDINAL;
27import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL;
28import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_MODAL_TASK_STATE_ORDINAL;
29import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_SPLIT_SELECT_ORDINAL;
30import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_STATE_ORDINAL;
31import static com.android.launcher3.testing.shared.TestProtocol.QUICK_SWITCH_STATE_ORDINAL;
32import static com.android.launcher3.testing.shared.TestProtocol.SPRING_LOADED_STATE_ORDINAL;
Sunny Goyal0c723352017-12-12 12:02:29 -080033
Winson Chung8687bc22020-02-27 23:34:24 -080034import android.content.Context;
Zak Cohen4d35ac32021-04-23 16:28:12 -070035import android.graphics.Color;
Sunny Goyal0c723352017-12-12 12:02:29 -080036import android.view.animation.Interpolator;
Sunny Goyalbe93f262017-10-20 17:05:27 -070037
Fengjiang Lie884c2c2022-12-19 14:42:14 -080038import androidx.annotation.FloatRange;
39
Sunny Goyal35e7d382020-05-08 13:37:58 -070040import com.android.launcher3.statemanager.BaseState;
41import com.android.launcher3.statemanager.StateManager;
Charlie Anderson438d4052023-04-25 14:38:57 -040042import com.android.launcher3.states.EditModeState;
Tony Wickham4fdba142019-11-04 16:23:51 -080043import com.android.launcher3.states.HintState;
Sunny Goyalc99cb172017-10-19 16:15:09 -070044import com.android.launcher3.states.SpringLoadedState;
vadimtf6ef8792022-07-26 13:54:31 -070045import com.android.launcher3.testing.shared.TestProtocol;
Tonye06fef42019-03-22 15:44:28 -050046import com.android.launcher3.uioverrides.states.AllAppsState;
47import com.android.launcher3.uioverrides.states.OverviewState;
Sunny Goyal54fa1102022-12-07 22:48:37 -080048import com.android.launcher3.views.ActivityContext;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070049
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070050import java.util.Arrays;
51
Sunny Goyal4c7f2152017-10-17 17:17:16 -070052/**
Sunny Goyalbe93f262017-10-20 17:05:27 -070053 * Base state for various states used for the Launcher
Sunny Goyal4c7f2152017-10-17 17:17:16 -070054 */
Sunny Goyal35e7d382020-05-08 13:37:58 -070055public abstract class LauncherState implements BaseState<LauncherState> {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070056
Sunny Goyal7185dd62018-03-14 17:51:49 -070057 /**
58 * Set of elements indicating various workspace elements which change visibility across states
59 * Note that workspace is not included here as in that case, we animate individual pages
60 */
61 public static final int NONE = 0;
Tony Wickhambd6f05e2018-03-21 08:16:33 -070062 public static final int HOTSEAT_ICONS = 1 << 0;
Sunny Goyalc373e1c2021-03-09 17:27:53 -080063 public static final int ALL_APPS_CONTENT = 1 << 1;
64 public static final int VERTICAL_SWIPE_INDICATOR = 1 << 2;
65 public static final int OVERVIEW_ACTIONS = 1 << 3;
Tony Wickham7af54402021-12-06 15:54:43 -080066 public static final int CLEAR_ALL_BUTTON = 1 << 4;
67 public static final int WORKSPACE_PAGE_INDICATOR = 1 << 5;
68 public static final int SPLIT_PLACHOLDER_VIEW = 1 << 6;
Andy Wickham64896f32023-05-30 21:46:24 -070069 public static final int FLOATING_SEARCH_BAR = 1 << 7;
Zak Cohen43a16152020-02-25 14:29:37 -080070
Sunny Goyal8f965462020-04-23 19:00:36 -070071 // Flag indicating workspace has multiple pages visible.
Sunny Goyal35e7d382020-05-08 13:37:58 -070072 public static final int FLAG_MULTI_PAGE = BaseState.getFlag(0);
Sunny Goyal8f965462020-04-23 19:00:36 -070073 // Flag indicating that workspace and its contents are not accessible
Sunny Goyal35e7d382020-05-08 13:37:58 -070074 public static final int FLAG_WORKSPACE_INACCESSIBLE = BaseState.getFlag(1);
Sunny Goyal8f965462020-04-23 19:00:36 -070075
Sunny Goyal8f965462020-04-23 19:00:36 -070076 // Flag indicating the state allows workspace icons to be dragged.
Sunny Goyal35e7d382020-05-08 13:37:58 -070077 public static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = BaseState.getFlag(2);
Sunny Goyal8f965462020-04-23 19:00:36 -070078 // Flag to indicate that workspace should draw page background
Sunny Goyal35e7d382020-05-08 13:37:58 -070079 public static final int FLAG_WORKSPACE_HAS_BACKGROUNDS = BaseState.getFlag(3);
Sunny Goyal8f965462020-04-23 19:00:36 -070080 // Flag to indicate if the state would have scrim over sysui region: statu sbar and nav bar
Sunny Goyal1eb11242022-09-09 17:14:45 -070081 public static final int FLAG_HAS_SYS_UI_SCRIM = BaseState.getFlag(4);
Sunny Goyal8f965462020-04-23 19:00:36 -070082 // Flag to inticate that all popups should be closed when this state is enabled.
Sunny Goyal1eb11242022-09-09 17:14:45 -070083 public static final int FLAG_CLOSE_POPUPS = BaseState.getFlag(5);
84 public static final int FLAG_OVERVIEW_UI = BaseState.getFlag(6);
Sunny Goyal8f965462020-04-23 19:00:36 -070085
Anushree Ganjamf6254c52022-04-29 00:46:22 +000086 // Flag indicating that hotseat and its contents are not accessible.
Sunny Goyal1eb11242022-09-09 17:14:45 -070087 public static final int FLAG_HOTSEAT_INACCESSIBLE = BaseState.getFlag(7);
Anushree Ganjamf6254c52022-04-29 00:46:22 +000088
Sunny Goyal6c6c2f42018-03-02 14:57:46 -080089
Sunny Goyalf2393f12020-04-01 20:13:12 -070090 public static final float NO_OFFSET = 0;
91 public static final float NO_SCALE = 1;
92
Sunny Goyal0c723352017-12-12 12:02:29 -080093 protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
Kateryna Ivanova71203732023-05-24 15:09:00 +000094 new PageAlphaProvider(ACCELERATE_2) {
Sunny Goyal0c723352017-12-12 12:02:29 -080095 @Override
96 public float getPageAlpha(int pageIndex) {
97 return 1;
98 }
99 };
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700100
Pat Manningb04dd602022-03-09 14:19:10 +0000101 protected static final PageTranslationProvider DEFAULT_PAGE_TRANSLATION_PROVIDER =
Kateryna Ivanova71203732023-05-24 15:09:00 +0000102 new PageTranslationProvider(DECELERATE_2) {
Pat Manningb04dd602022-03-09 14:19:10 +0000103 @Override
104 public float getPageTranslation(int pageIndex) {
105 return 0;
106 }
107 };
108
Charlie Anderson438d4052023-04-25 14:38:57 -0400109 private static final LauncherState[] sAllStates = new LauncherState[11];
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700110
Sunny Goyal75c59ac2018-01-15 14:23:11 -0800111 /**
112 * TODO: Create a separate class for NORMAL state.
113 */
vadimt6895e402019-02-15 16:42:14 -0800114 public static final LauncherState NORMAL = new LauncherState(NORMAL_STATE_ORDINAL,
Winson Chungf9935182020-10-23 09:26:44 -0700115 LAUNCHER_STATE_HOME,
Sunny Goyal1eb11242022-09-09 17:14:45 -0700116 FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HAS_SYS_UI_SCRIM) {
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800117 @Override
Alex Chauf39cc122022-04-14 17:51:59 +0100118 public int getTransitionDuration(Context context, boolean isToState) {
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800119 // Arbitrary duration, when going to NORMAL we use the state we're coming from instead.
120 return 0;
121 }
122 };
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700123
Sunny Goyal7185dd62018-03-14 17:51:49 -0700124 /**
125 * Various Launcher states arranged in the increasing order of UI layers
126 */
vadimt2a648aa2019-02-14 17:47:11 -0800127 public static final LauncherState SPRING_LOADED = new SpringLoadedState(
128 SPRING_LOADED_STATE_ORDINAL);
Charlie Anderson438d4052023-04-25 14:38:57 -0400129 public static final LauncherState EDIT_MODE = new EditModeState(EDIT_MODE_STATE_ORDINAL);
vadimt2a648aa2019-02-14 17:47:11 -0800130 public static final LauncherState ALL_APPS = new AllAppsState(ALL_APPS_STATE_ORDINAL);
Tony Wickham4fdba142019-11-04 16:23:51 -0800131 public static final LauncherState HINT_STATE = new HintState(HINT_STATE_ORDINAL);
Tony Wickhamc5d168d2021-03-25 09:28:19 -0700132 public static final LauncherState HINT_STATE_TWO_BUTTON = new HintState(
133 HINT_STATE_TWO_BUTTON_ORDINAL, LAUNCHER_STATE_OVERVIEW);
Tony1787ee92019-03-20 12:38:35 -0500134
135 public static final LauncherState OVERVIEW = new OverviewState(OVERVIEW_STATE_ORDINAL);
Zak Cohena39544d2020-04-27 16:26:55 -0700136 public static final LauncherState OVERVIEW_MODAL_TASK = OverviewState.newModalTaskState(
137 OVERVIEW_MODAL_TASK_STATE_ORDINAL);
Vinit Nayak82b8aa52023-02-03 10:15:50 -0800138 /**
139 * State when user performs a quickswitch gesture from home/workspace to the most recent
140 * app
141 */
142 public static final LauncherState QUICK_SWITCH_FROM_HOME =
Tonye4c2e2b2019-03-25 10:23:39 -0500143 OverviewState.newSwitchState(QUICK_SWITCH_STATE_ORDINAL);
Tony1787ee92019-03-20 12:38:35 -0500144 public static final LauncherState BACKGROUND_APP =
145 OverviewState.newBackgroundState(BACKGROUND_APP_STATE_ORDINAL);
Vinit Nayakd987a822021-02-22 14:49:27 -0800146 public static final LauncherState OVERVIEW_SPLIT_SELECT =
147 OverviewState.newSplitSelectState(OVERVIEW_SPLIT_SELECT_ORDINAL);
Tony Wickham6becf7c2018-04-19 11:39:34 -0700148
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700149 public final int ordinal;
150
Sunny Goyalf9403d92017-10-18 10:55:56 -0700151 /**
Winson Chungf9935182020-10-23 09:26:44 -0700152 * Used for {@link com.android.launcher3.logging.StatsLogManager}
Sunny Goyalf9403d92017-10-18 10:55:56 -0700153 */
Winson Chungf9935182020-10-23 09:26:44 -0700154 public final int statsLogOrdinal;
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700155
Sunny Goyalf9403d92017-10-18 10:55:56 -0700156 /**
Sunny Goyal6c6c2f42018-03-02 14:57:46 -0800157 * True if the state has overview panel visible.
158 */
159 public final boolean overviewUi;
160
Sunny Goyal8f965462020-04-23 19:00:36 -0700161 private final int mFlags;
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700162
Winson Chungf9935182020-10-23 09:26:44 -0700163 public LauncherState(int id, int statsLogOrdinal, int flags) {
164 this.statsLogOrdinal = statsLogOrdinal;
Sunny Goyal8f965462020-04-23 19:00:36 -0700165 this.mFlags = flags;
Sunny Goyal6c6c2f42018-03-02 14:57:46 -0800166 this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700167 this.ordinal = id;
168 sAllStates[id] = this;
169 }
170
Sunny Goyal8f965462020-04-23 19:00:36 -0700171 /**
172 * Returns if the state has the provided flag
173 */
Sunny Goyal35e7d382020-05-08 13:37:58 -0700174 @Override
Sunny Goyal8f965462020-04-23 19:00:36 -0700175 public final boolean hasFlag(int mask) {
176 return (mFlags & mask) != 0;
177 }
178
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700179 public static LauncherState[] values() {
180 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700181 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700182
Tonybc234402019-03-19 13:30:25 -0500183 public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
Sunny Goyalf2393f12020-04-01 20:13:12 -0700184 return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET);
Sunny Goyalc99cb172017-10-19 16:15:09 -0700185 }
186
Tonybc234402019-03-19 13:30:25 -0500187 public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) {
Tony Wickham57e489c2019-03-04 14:57:07 -0800188 // For most states, treat the hotseat as if it were part of the workspace.
189 return getWorkspaceScaleAndTranslation(launcher);
Tony4bb4b892019-03-03 15:32:12 -0800190 }
191
Sunny Goyalf2393f12020-04-01 20:13:12 -0700192 /**
Tony Wickham82d5a062021-05-14 14:37:12 -0700193 * Returns an array of two elements.
Samuel Fufa2ea01e42020-12-02 13:48:18 -0600194 * The first specifies the scale for the overview
195 * The second is the factor ([0, 1], 0 => center-screen; 1 => offscreen) by which overview
196 * should be shifted horizontally.
Sunny Goyalf2393f12020-04-01 20:13:12 -0700197 */
198 public float[] getOverviewScaleAndOffset(Launcher launcher) {
199 return launcher.getNormalOverviewScaleAndOffset();
Tony3bb5e8e2018-03-14 12:05:00 +0000200 }
201
Tony54068172019-05-12 13:24:51 -0500202 public float getOverviewFullscreenProgress() {
203 return 0;
204 }
205
Andy Wickham64896f32023-05-30 21:46:24 -0700206 /**
207 * How far from the bottom of the screen the <em>floating</em> search bar should rest in this
208 * state when the IME is not present.
209 * <p>
210 * To hide offscreen, use a negative value.
211 * <p>
212 * Note: if the provided value is non-negative but less than the current bottom insets, the
213 * insets will be applied. As such, you can use 0 to default to this.
214 */
215 public int getFloatingSearchBarRestingMarginBottom(Launcher launcher) {
216 DeviceProfile dp = launcher.getDeviceProfile();
217 return areElementsVisible(launcher, FLOATING_SEARCH_BAR) ? dp.getQsbOffsetY()
218 : -dp.hotseatQsbHeight;
219 }
220
221 /** Whether the <em>floating</em> search bar should use the pill UI when not focused. */
222 public boolean shouldFloatingSearchBarUsePillWhenUnfocused(Launcher launcher) {
223 return false;
224 }
225
Sunny Goyal7185dd62018-03-14 17:51:49 -0700226 public int getVisibleElements(Launcher launcher) {
Andy Wickham64896f32023-05-30 21:46:24 -0700227 int elements = HOTSEAT_ICONS | WORKSPACE_PAGE_INDICATOR | VERTICAL_SWIPE_INDICATOR;
228 // Floating search bar is visible in normal state except in landscape on phones.
229 if (!(launcher.getDeviceProfile().isPhone && launcher.getDeviceProfile().isLandscape)) {
230 elements |= FLOATING_SEARCH_BAR;
231 }
232 return elements;
Sunny Goyal7185dd62018-03-14 17:51:49 -0700233 }
234
Sunny Goyal228153d2018-01-04 15:35:22 -0800235 /**
Tony Wickhama29a0462021-03-02 12:28:25 -0800236 * A shorthand for checking getVisibleElements() & elements == elements.
237 * @return Whether all of the given elements are visible.
238 */
239 public boolean areElementsVisible(Launcher launcher, int elements) {
240 return (getVisibleElements(launcher) & elements) == elements;
241 }
242
Schneider Victor-tulias3f6c4732022-06-23 11:25:10 -0700243 /**
244 * Returns whether taskbar is stashed and thus should either:
245 * 1) replace hotseat or taskbar icons with a handle in gesture navigation mode or
246 * 2) fade out the hotseat or taskbar icons in 3-button navigation mode.
247 */
Tony Wickham24675d32021-11-24 15:43:52 -0800248 public boolean isTaskbarStashed(Launcher launcher) {
Tracy Zhou308851d2021-09-09 21:18:25 -0700249 return false;
250 }
251
Tony Wickham24675d32021-11-24 15:43:52 -0800252 /** Returns whether taskbar is aligned with the hotseat vs position inside apps */
253 public boolean isTaskbarAlignedWithHotseat(Launcher launcher) {
Schneider Victor-tulias3f6c4732022-06-23 11:25:10 -0700254 return true;
Tony Wickham24675d32021-11-24 15:43:52 -0800255 }
256
Tony Wickhama29a0462021-03-02 12:28:25 -0800257 /**
Winson Chung3bce15d2023-02-18 06:34:08 +0000258 * Returns whether taskbar global drag is disallowed in this state.
259 */
260 public boolean disallowTaskbarGlobalDrag() {
261 return false;
262 }
263
264 /**
265 * Returns whether the taskbar shortcut should trigger split selection mode.
266 */
267 public boolean allowTaskbarInitialSplitSelection() {
268 return false;
269 }
270
271 /**
Sunny Goyal228153d2018-01-04 15:35:22 -0800272 * Fraction shift in the vertical translation UI and related properties
273 *
274 * @see com.android.launcher3.allapps.AllAppsTransitionController
275 */
276 public float getVerticalProgress(Launcher launcher) {
277 return 1f;
278 }
279
Sunny Goyalc82916f2021-04-06 13:03:54 -0700280 public float getWorkspaceBackgroundAlpha(Launcher launcher) {
Sunny Goyal927447e2018-05-04 13:19:29 -0700281 return 0;
282 }
283
Zak Cohen4d35ac32021-04-23 16:28:12 -0700284 /**
285 * What color should the workspace scrim be in when at rest in this state.
286 * Return {@link Color#TRANSPARENT} for no scrim.
287 */
288 public int getWorkspaceScrimColor(Launcher launcher) {
289 return Color.TRANSPARENT;
Tony Wickhamc0880512019-07-24 17:32:08 -0700290 }
291
Winson Chung8687bc22020-02-27 23:34:24 -0800292 /**
Zak Cohena39544d2020-04-27 16:26:55 -0700293 * For this state, how modal should over view been shown. 0 modalness means all tasks drawn,
294 * 1 modalness means the current task is show on its own.
295 */
296 public float getOverviewModalness() {
297 return 0;
298 }
299
300 /**
Vinit Nayakf4f0c4d2021-05-05 10:28:05 -0700301 * For this state, how much additional translation there should be for each of the
302 * child TaskViews. Note that the translation can be its primary or secondary dimension.
Vinit Nayakd987a822021-02-22 14:49:27 -0800303 */
Vinit Nayakf4f0c4d2021-05-05 10:28:05 -0700304 public float getSplitSelectTranslation(Launcher launcher) {
Vinit Nayakd987a822021-02-22 14:49:27 -0800305 return 0;
306 }
307
308 /**
Lucas Dupin4918ed32020-03-17 17:11:32 -0700309 * The amount of blur and wallpaper zoom to apply to the background of either the app
310 * or Launcher surface in this state. Should be a number between 0 and 1, inclusive.
311 *
312 * 0 means completely zoomed in, without blurs. 1 is zoomed out, with blurs.
Winson Chung8687bc22020-02-27 23:34:24 -0800313 */
Sunny Goyal54fa1102022-12-07 22:48:37 -0800314 public final <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext>
Alex Chau31935222022-09-01 21:24:52 +0100315 float getDepth(DEVICE_PROFILE_CONTEXT context) {
Jon Miranda36d10152020-06-19 16:35:08 -0700316 return getDepth(context,
317 BaseDraggingActivity.fromContext(context).getDeviceProfile().isMultiWindowMode);
318 }
319
320 /**
321 * Returns the amount of blur and wallpaper zoom for this state with {@param isMultiWindowMode}.
Samuel Fufa2ea01e42020-12-02 13:48:18 -0600322 *
Jon Miranda36d10152020-06-19 16:35:08 -0700323 * @see #getDepth(Context).
324 */
Sunny Goyal54fa1102022-12-07 22:48:37 -0800325 public final <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext>
Alex Chau31935222022-09-01 21:24:52 +0100326 float getDepth(DEVICE_PROFILE_CONTEXT context, boolean isMultiWindowMode) {
Jon Miranda36d10152020-06-19 16:35:08 -0700327 if (isMultiWindowMode) {
Winson Chungb330d6e2020-04-20 11:57:11 -0700328 return 0;
329 }
330 return getDepthUnchecked(context);
331 }
332
Sunny Goyal54fa1102022-12-07 22:48:37 -0800333 protected <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext>
Alex Chau31935222022-09-01 21:24:52 +0100334 float getDepthUnchecked(DEVICE_PROFILE_CONTEXT context) {
Lucas Dupin4918ed32020-03-17 17:11:32 -0700335 return 0f;
Winson Chung8687bc22020-02-27 23:34:24 -0800336 }
337
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700338 public String getDescription(Launcher launcher) {
339 return launcher.getWorkspace().getCurrentPageDescription();
340 }
341
Sunny Goyalbc683e92017-12-06 10:25:07 -0800342 public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
Jon Mirandae3832222020-07-06 15:38:38 -0700343 if ((this != NORMAL && this != HINT_STATE)
344 || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
Sunny Goyalbc683e92017-12-06 10:25:07 -0800345 return DEFAULT_ALPHA_PROVIDER;
346 }
Sunny Goyal228153d2018-01-04 15:35:22 -0800347 final int centerPage = launcher.getWorkspace().getNextPage();
Kateryna Ivanova71203732023-05-24 15:09:00 +0000348 return new PageAlphaProvider(ACCELERATE_2) {
Sunny Goyal0c723352017-12-12 12:02:29 -0800349 @Override
350 public float getPageAlpha(int pageIndex) {
Samuel Fufa2ea01e42020-12-02 13:48:18 -0600351 return pageIndex != centerPage ? 0 : 1f;
Sunny Goyal0c723352017-12-12 12:02:29 -0800352 }
353 };
Sunny Goyalbc683e92017-12-06 10:25:07 -0800354 }
355
Pat Manningb04dd602022-03-09 14:19:10 +0000356 /**
357 * Gets the translation provider for workspace pages.
358 */
359 public PageTranslationProvider getWorkspacePageTranslationProvider(Launcher launcher) {
Charlie Anderson438d4052023-04-25 14:38:57 -0400360 if (this != SPRING_LOADED
361 || this != EDIT_MODE
362 || !launcher.getDeviceProfile().isTwoPanels) {
Pat Manningb04dd602022-03-09 14:19:10 +0000363 return DEFAULT_PAGE_TRANSLATION_PROVIDER;
364 }
365 final float quarterPageSpacing = launcher.getWorkspace().getPageSpacing() / 4f;
Kateryna Ivanova71203732023-05-24 15:09:00 +0000366 return new PageTranslationProvider(DECELERATE_2) {
Pat Manningb04dd602022-03-09 14:19:10 +0000367 @Override
368 public float getPageTranslation(int pageIndex) {
369 boolean isRtl = launcher.getWorkspace().mIsRtl;
370 boolean isFirstPage = pageIndex % 2 == 0;
371 return ((isFirstPage && !isRtl) || (!isFirstPage && isRtl)) ? -quarterPageSpacing
372 : quarterPageSpacing;
373 }
374 };
375 }
376
Charlie Anderson438d4052023-04-25 14:38:57 -0400377 /**
378 * Called when leaving this LauncherState
379 * @param launcher - Launcher instance
380 * @param toState - New LauncherState that is being entered
381 */
382 public void onLeavingState(Launcher launcher, LauncherState toState) {
383 // no-op
384 // override to handle when leaving current LauncherState
385 }
386
Sunny Goyal35e7d382020-05-08 13:37:58 -0700387 @Override
Sunny Goyal49bcf342018-01-11 13:59:53 -0800388 public LauncherState getHistoryForState(LauncherState previousState) {
389 // No history is supported
390 return NORMAL;
391 }
392
Sunny Goyal35e7d382020-05-08 13:37:58 -0700393 @Override
394 public String toString() {
Tony Wickhamf844ee92020-05-27 15:41:32 -0500395 return TestProtocol.stateOrdinalToString(ordinal);
Sunny Goyal35e7d382020-05-08 13:37:58 -0700396 }
397
Sunny Goyale39690b2018-08-02 13:35:07 -0700398 public void onBackPressed(Launcher launcher) {
399 if (this != NORMAL) {
Sunny Goyal35e7d382020-05-08 13:37:58 -0700400 StateManager<LauncherState> lsm = launcher.getStateManager();
Sunny Goyale39690b2018-08-02 13:35:07 -0700401 LauncherState lastState = lsm.getLastState();
Sunny Goyale39690b2018-08-02 13:35:07 -0700402 lsm.goToState(lastState);
403 }
404 }
405
Fengjiang Lie884c2c2022-12-19 14:42:14 -0800406 /**
407 * Find {@link StateManager} and target {@link LauncherState} to handle back progress in
408 * predictive back gesture.
409 */
410 public void onBackProgressed(
411 Launcher launcher, @FloatRange(from = 0.0, to = 1.0) float backProgress) {
412 StateManager<LauncherState> lsm = launcher.getStateManager();
413 LauncherState toState = lsm.getLastState();
414 lsm.onBackProgressed(toState, backProgress);
415 }
416
417 /**
418 * Find {@link StateManager} and target {@link LauncherState} to handle backProgress in
419 * predictive back gesture.
420 */
421 public void onBackCancelled(Launcher launcher) {
422 StateManager<LauncherState> lsm = launcher.getStateManager();
423 LauncherState toState = lsm.getLastState();
424 lsm.onBackCancelled(toState);
425 }
426
Sunny Goyal0c723352017-12-12 12:02:29 -0800427 public static abstract class PageAlphaProvider {
Sunny Goyalbc683e92017-12-06 10:25:07 -0800428
Sunny Goyal0c723352017-12-12 12:02:29 -0800429 public final Interpolator interpolator;
430
431 public PageAlphaProvider(Interpolator interpolator) {
432 this.interpolator = interpolator;
433 }
434
435 public abstract float getPageAlpha(int pageIndex);
Sunny Goyalbc683e92017-12-06 10:25:07 -0800436 }
Tonybc234402019-03-19 13:30:25 -0500437
Pat Manningb04dd602022-03-09 14:19:10 +0000438 /**
439 * Provider for the translation and animation interpolation of workspace pages.
440 */
441 public abstract static class PageTranslationProvider {
442
443 public final Interpolator interpolator;
444
445 public PageTranslationProvider(Interpolator interpolator) {
446 this.interpolator = interpolator;
447 }
448
449 /**
450 * Gets the translation of the workspace page at the provided page index.
451 */
452 public abstract float getPageTranslation(int pageIndex);
453 }
454
Tonybc234402019-03-19 13:30:25 -0500455 public static class ScaleAndTranslation {
456 public float scale;
457 public float translationX;
458 public float translationY;
459
460 public ScaleAndTranslation(float scale, float translationX, float translationY) {
461 this.scale = scale;
462 this.translationX = translationX;
463 this.translationY = translationY;
464 }
465 }
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700466}