blob: e2b867e138f95f1af499db53c258e57d3da6f724 [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
18import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
19import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
Tony Wickham59c69012019-06-18 16:34:37 -070020import static android.view.View.VISIBLE;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070021import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
Tony Wickham59c69012019-06-18 16:34:37 -070022
Tony Wickham59c69012019-06-18 16:34:37 -070023import static com.android.launcher3.anim.Interpolators.ACCEL;
Sunny Goyal210e1742019-10-17 12:05:38 -070024import static com.android.launcher3.anim.Interpolators.ACCEL_2;
Tony Wickham59c69012019-06-18 16:34:37 -070025import static com.android.launcher3.anim.Interpolators.DEACCEL;
26import static com.android.launcher3.anim.Interpolators.DEACCEL_1_7;
27import static com.android.launcher3.anim.Interpolators.clampToProgress;
Tony Wickham4fdba142019-11-04 16:23:51 -080028import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS;
Sunny Goyal210e1742019-10-17 12:05:38 -070029import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070030import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE;
31import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE;
32import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X;
33import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE;
34import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE;
Sunny Goyalab3963d2019-05-23 00:50:08 -070035import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL;
36import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL;
Tony Wickham4fdba142019-11-04 16:23:51 -080037import static com.android.launcher3.testing.TestProtocol.HINT_STATE_ORDINAL;
Sunny Goyalab3963d2019-05-23 00:50:08 -070038import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL;
Zak Cohena39544d2020-04-27 16:26:55 -070039import static com.android.launcher3.testing.TestProtocol.OVERVIEW_MODAL_TASK_STATE_ORDINAL;
Sunny Goyalab3963d2019-05-23 00:50:08 -070040import static com.android.launcher3.testing.TestProtocol.OVERVIEW_PEEK_STATE_ORDINAL;
41import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL;
42import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL;
43import static com.android.launcher3.testing.TestProtocol.SPRING_LOADED_STATE_ORDINAL;
Sunny Goyal0c723352017-12-12 12:02:29 -080044
Winson Chung8687bc22020-02-27 23:34:24 -080045import android.content.Context;
Tony Wickham04fca162020-02-05 15:06:52 -080046import android.view.View;
Sunny Goyal0c723352017-12-12 12:02:29 -080047import android.view.animation.Interpolator;
Sunny Goyalbe93f262017-10-20 17:05:27 -070048
Tony Wickham04fca162020-02-05 15:06:52 -080049import com.android.launcher3.allapps.AllAppsContainerView;
Tony Wickham4fdba142019-11-04 16:23:51 -080050import com.android.launcher3.states.HintState;
Sunny Goyalc99cb172017-10-19 16:15:09 -070051import com.android.launcher3.states.SpringLoadedState;
Sunny Goyalf3ac7032020-03-13 13:01:33 -070052import com.android.launcher3.states.StateAnimationConfig;
Tonye06fef42019-03-22 15:44:28 -050053import com.android.launcher3.uioverrides.states.AllAppsState;
54import com.android.launcher3.uioverrides.states.OverviewState;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070055import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
56
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070057import java.util.Arrays;
58
Sunny Goyal4c7f2152017-10-17 17:17:16 -070059
60/**
Sunny Goyalbe93f262017-10-20 17:05:27 -070061 * Base state for various states used for the Launcher
Sunny Goyal4c7f2152017-10-17 17:17:16 -070062 */
Tony Wickhamc7203ad2020-02-03 18:36:06 -080063public abstract class LauncherState {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070064
Sunny Goyal7185dd62018-03-14 17:51:49 -070065
66 /**
67 * Set of elements indicating various workspace elements which change visibility across states
68 * Note that workspace is not included here as in that case, we animate individual pages
69 */
70 public static final int NONE = 0;
Tony Wickhambd6f05e2018-03-21 08:16:33 -070071 public static final int HOTSEAT_ICONS = 1 << 0;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -070072 public static final int HOTSEAT_SEARCH_BOX = 1 << 1;
Tony Wickhambd6f05e2018-03-21 08:16:33 -070073 public static final int ALL_APPS_HEADER = 1 << 2;
74 public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions
75 public static final int ALL_APPS_CONTENT = 1 << 4;
Sunny Goyal56e10192018-05-22 13:22:25 -070076 public static final int VERTICAL_SWIPE_INDICATOR = 1 << 5;
Sunny Goyal514dfa22020-03-26 15:28:36 -070077 public static final int OVERVIEW_BUTTONS = 1 << 6;
Sunny Goyal7185dd62018-03-14 17:51:49 -070078
Zak Cohen43a16152020-02-25 14:29:37 -080079 /** Mask of all the items that are contained in the apps view. */
80 public static final int APPS_VIEW_ITEM_MASK =
81 HOTSEAT_SEARCH_BOX | ALL_APPS_HEADER | ALL_APPS_HEADER_EXTRA | ALL_APPS_CONTENT;
82
Sunny Goyal927447e2018-05-04 13:19:29 -070083 protected static final int FLAG_MULTI_PAGE = 1 << 0;
84 protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 1;
85 protected static final int FLAG_DISABLE_RESTORE = 1 << 2;
86 protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 3;
87 protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 4;
88 protected static final int FLAG_PAGE_BACKGROUNDS = 1 << 5;
89 protected static final int FLAG_DISABLE_INTERACTION = 1 << 6;
90 protected static final int FLAG_OVERVIEW_UI = 1 << 7;
91 protected static final int FLAG_HIDE_BACK_BUTTON = 1 << 8;
Sunny Goyal5d1873a2018-05-08 11:10:44 -070092 protected static final int FLAG_HAS_SYS_UI_SCRIM = 1 << 9;
Sunny Goyal6c6c2f42018-03-02 14:57:46 -080093
Sunny Goyalf2393f12020-04-01 20:13:12 -070094 public static final float NO_OFFSET = 0;
95 public static final float NO_SCALE = 1;
96
Sunny Goyal0c723352017-12-12 12:02:29 -080097 protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
98 new PageAlphaProvider(ACCEL_2) {
99 @Override
100 public float getPageAlpha(int pageIndex) {
101 return 1;
102 }
103 };
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700104
Zak Cohena39544d2020-04-27 16:26:55 -0700105 private static final LauncherState[] sAllStates = new LauncherState[9];
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700106
Sunny Goyal75c59ac2018-01-15 14:23:11 -0800107 /**
108 * TODO: Create a separate class for NORMAL state.
109 */
vadimt6895e402019-02-15 16:42:14 -0800110 public static final LauncherState NORMAL = new LauncherState(NORMAL_STATE_ORDINAL,
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800111 ContainerType.WORKSPACE,
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700112 FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HIDE_BACK_BUTTON |
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800113 FLAG_HAS_SYS_UI_SCRIM) {
114 @Override
115 public int getTransitionDuration(Launcher launcher) {
116 // Arbitrary duration, when going to NORMAL we use the state we're coming from instead.
117 return 0;
118 }
119 };
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700120
Sunny Goyal7185dd62018-03-14 17:51:49 -0700121 /**
122 * Various Launcher states arranged in the increasing order of UI layers
123 */
vadimt2a648aa2019-02-14 17:47:11 -0800124 public static final LauncherState SPRING_LOADED = new SpringLoadedState(
125 SPRING_LOADED_STATE_ORDINAL);
vadimt2a648aa2019-02-14 17:47:11 -0800126 public static final LauncherState ALL_APPS = new AllAppsState(ALL_APPS_STATE_ORDINAL);
Tony Wickham4fdba142019-11-04 16:23:51 -0800127 public static final LauncherState HINT_STATE = new HintState(HINT_STATE_ORDINAL);
Tony1787ee92019-03-20 12:38:35 -0500128
129 public static final LauncherState OVERVIEW = new OverviewState(OVERVIEW_STATE_ORDINAL);
130 public static final LauncherState OVERVIEW_PEEK =
131 OverviewState.newPeekState(OVERVIEW_PEEK_STATE_ORDINAL);
Zak Cohena39544d2020-04-27 16:26:55 -0700132 public static final LauncherState OVERVIEW_MODAL_TASK = OverviewState.newModalTaskState(
133 OVERVIEW_MODAL_TASK_STATE_ORDINAL);
Tonye4c2e2b2019-03-25 10:23:39 -0500134 public static final LauncherState QUICK_SWITCH =
135 OverviewState.newSwitchState(QUICK_SWITCH_STATE_ORDINAL);
Tony1787ee92019-03-20 12:38:35 -0500136 public static final LauncherState BACKGROUND_APP =
137 OverviewState.newBackgroundState(BACKGROUND_APP_STATE_ORDINAL);
Tony Wickham6becf7c2018-04-19 11:39:34 -0700138
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700139 public final int ordinal;
140
Sunny Goyalf9403d92017-10-18 10:55:56 -0700141 /**
142 * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
143 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700144 public final int containerType;
145
Sunny Goyalf9403d92017-10-18 10:55:56 -0700146 /**
147 * True if the state can be persisted across activity restarts.
148 */
Sunny Goyalbc683e92017-12-06 10:25:07 -0800149 public final boolean disableRestore;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700150
151 /**
152 * True if workspace has multiple pages visible.
153 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700154 public final boolean hasMultipleVisiblePages;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700155
156 /**
157 * Accessibility flag for workspace and its pages.
158 * @see android.view.View#setImportantForAccessibility(int)
159 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700160 public final int workspaceAccessibilityFlag;
161
Sunny Goyalbe93f262017-10-20 17:05:27 -0700162 /**
163 * Properties related to state transition animation
164 *
165 * @see WorkspaceStateTransitionAnimation
166 */
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800167 public final boolean hasWorkspacePageBackground;
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800168
Sunny Goyalbe93f262017-10-20 17:05:27 -0700169 /**
Tony Wickham53370672017-12-05 10:10:55 -0800170 * True if the state allows workspace icons to be dragged.
171 */
172 public final boolean workspaceIconsCanBeDragged;
173
Sunny Goyalbc683e92017-12-06 10:25:07 -0800174 /**
175 * True if the workspace pages should not be clipped relative to the workspace bounds
176 * for this state.
177 */
178 public final boolean disablePageClipping;
179
Sunny Goyal6c6c2f42018-03-02 14:57:46 -0800180 /**
181 * True if launcher can not be directly interacted in this state;
182 */
183 public final boolean disableInteraction;
184
185 /**
186 * True if the state has overview panel visible.
187 */
188 public final boolean overviewUi;
189
Tony Wickham76cf2362018-03-20 14:13:16 -0700190 /**
191 * True if the back button should be hidden when in this state (assuming no floating views are
192 * open, launcher has window focus, etc).
193 */
194 public final boolean hideBackButton;
195
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700196 public final boolean hasSysUiScrim;
197
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800198 public LauncherState(int id, int containerType, int flags) {
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700199 this.containerType = containerType;
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700200
Sunny Goyal6639a5d2018-02-28 15:09:36 -0800201 this.hasWorkspacePageBackground = (flags & FLAG_PAGE_BACKGROUNDS) != 0;
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700202 this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700203 this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
204 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
205 : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Sunny Goyalbc683e92017-12-06 10:25:07 -0800206 this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0;
Tony Wickham53370672017-12-05 10:10:55 -0800207 this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
Sunny Goyalbc683e92017-12-06 10:25:07 -0800208 this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0;
Sunny Goyal6c6c2f42018-03-02 14:57:46 -0800209 this.disableInteraction = (flags & FLAG_DISABLE_INTERACTION) != 0;
210 this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0;
Tony Wickham76cf2362018-03-20 14:13:16 -0700211 this.hideBackButton = (flags & FLAG_HIDE_BACK_BUTTON) != 0;
Sunny Goyal5d1873a2018-05-08 11:10:44 -0700212 this.hasSysUiScrim = (flags & FLAG_HAS_SYS_UI_SCRIM) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700213
214 this.ordinal = id;
215 sAllStates[id] = this;
216 }
217
218 public static LauncherState[] values() {
219 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700220 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700221
Tony Wickhamc7203ad2020-02-03 18:36:06 -0800222 /**
223 * @return How long the animation to this state should take (or from this state to NORMAL).
224 * @param launcher
225 */
226 public abstract int getTransitionDuration(Launcher launcher);
227
Tonybc234402019-03-19 13:30:25 -0500228 public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
Sunny Goyalf2393f12020-04-01 20:13:12 -0700229 return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET);
Sunny Goyalc99cb172017-10-19 16:15:09 -0700230 }
231
Tonybc234402019-03-19 13:30:25 -0500232 public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) {
Tony Wickham57e489c2019-03-04 14:57:07 -0800233 // For most states, treat the hotseat as if it were part of the workspace.
234 return getWorkspaceScaleAndTranslation(launcher);
Tony4bb4b892019-03-03 15:32:12 -0800235 }
236
Sunny Goyalf2393f12020-04-01 20:13:12 -0700237 /**
238 * Returns an array of two elements.
239 * The first specifies the scale for the overview
240 * The second is the factor ([0, 1], 0 => center-screen; 1 => offscreen) by which overview
241 * should be shifted horizontally.
242 */
243 public float[] getOverviewScaleAndOffset(Launcher launcher) {
244 return launcher.getNormalOverviewScaleAndOffset();
Tony3bb5e8e2018-03-14 12:05:00 +0000245 }
246
Tony Wickham4fdba142019-11-04 16:23:51 -0800247 public ScaleAndTranslation getQsbScaleAndTranslation(Launcher launcher) {
Sunny Goyalf2393f12020-04-01 20:13:12 -0700248 return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET);
Tony Wickham4fdba142019-11-04 16:23:51 -0800249 }
250
Tony54068172019-05-12 13:24:51 -0500251 public float getOverviewFullscreenProgress() {
252 return 0;
253 }
254
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700255 public void onStateEnabled(Launcher launcher) {
256 dispatchWindowStateChanged(launcher);
257 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700258
259 public void onStateDisabled(Launcher launcher) { }
Sunny Goyalbe93f262017-10-20 17:05:27 -0700260
Sunny Goyal7185dd62018-03-14 17:51:49 -0700261 public int getVisibleElements(Launcher launcher) {
Tony Wickhambd6f05e2018-03-21 08:16:33 -0700262 if (launcher.getDeviceProfile().isVerticalBarLayout()) {
Sunny Goyal56e10192018-05-22 13:22:25 -0700263 return HOTSEAT_ICONS | VERTICAL_SWIPE_INDICATOR;
Tony Wickhambd6f05e2018-03-21 08:16:33 -0700264 }
Sunny Goyal56e10192018-05-22 13:22:25 -0700265 return HOTSEAT_ICONS | HOTSEAT_SEARCH_BOX | VERTICAL_SWIPE_INDICATOR;
Sunny Goyal7185dd62018-03-14 17:51:49 -0700266 }
267
Sunny Goyal228153d2018-01-04 15:35:22 -0800268 /**
269 * Fraction shift in the vertical translation UI and related properties
270 *
271 * @see com.android.launcher3.allapps.AllAppsTransitionController
272 */
273 public float getVerticalProgress(Launcher launcher) {
274 return 1f;
275 }
276
Sunny Goyal927447e2018-05-04 13:19:29 -0700277 public float getWorkspaceScrimAlpha(Launcher launcher) {
278 return 0;
279 }
280
Tony Wickhamc0880512019-07-24 17:32:08 -0700281 public float getOverviewScrimAlpha(Launcher launcher) {
282 return 0;
283 }
284
Winson Chung8687bc22020-02-27 23:34:24 -0800285 /**
Zak Cohena39544d2020-04-27 16:26:55 -0700286 * For this state, how modal should over view been shown. 0 modalness means all tasks drawn,
287 * 1 modalness means the current task is show on its own.
288 */
289 public float getOverviewModalness() {
290 return 0;
291 }
292
293 /**
Lucas Dupin4918ed32020-03-17 17:11:32 -0700294 * The amount of blur and wallpaper zoom to apply to the background of either the app
295 * or Launcher surface in this state. Should be a number between 0 and 1, inclusive.
296 *
297 * 0 means completely zoomed in, without blurs. 1 is zoomed out, with blurs.
Winson Chung8687bc22020-02-27 23:34:24 -0800298 */
Winson Chungb330d6e2020-04-20 11:57:11 -0700299 public final float getDepth(Context context) {
300 if (BaseDraggingActivity.fromContext(context).getDeviceProfile().isMultiWindowMode) {
301 return 0;
302 }
303 return getDepthUnchecked(context);
304 }
305
306 protected float getDepthUnchecked(Context context) {
Lucas Dupin4918ed32020-03-17 17:11:32 -0700307 return 0f;
Winson Chung8687bc22020-02-27 23:34:24 -0800308 }
309
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700310 public String getDescription(Launcher launcher) {
311 return launcher.getWorkspace().getCurrentPageDescription();
312 }
313
Sunny Goyalbc683e92017-12-06 10:25:07 -0800314 public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
315 if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
316 return DEFAULT_ALPHA_PROVIDER;
317 }
Sunny Goyal228153d2018-01-04 15:35:22 -0800318 final int centerPage = launcher.getWorkspace().getNextPage();
Sunny Goyal0c723352017-12-12 12:02:29 -0800319 return new PageAlphaProvider(ACCEL_2) {
320 @Override
321 public float getPageAlpha(int pageIndex) {
322 return pageIndex != centerPage ? 0 : 1f;
323 }
324 };
Sunny Goyalbc683e92017-12-06 10:25:07 -0800325 }
326
Sunny Goyal49bcf342018-01-11 13:59:53 -0800327 public LauncherState getHistoryForState(LauncherState previousState) {
328 // No history is supported
329 return NORMAL;
330 }
331
Sunny Goyal75c59ac2018-01-15 14:23:11 -0800332 /**
333 * Called when the start transition ends and the user settles on this particular state.
334 */
335 public void onStateTransitionEnd(Launcher launcher) {
Hyunyoung Song4bd47252018-06-05 16:26:32 -0700336 if (this == NORMAL) {
Sunny Goyal623eddd2018-03-02 12:24:41 -0800337 // Clear any rotation locks when going to normal state
338 launcher.getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
Sunny Goyal75c59ac2018-01-15 14:23:11 -0800339 }
340 }
341
Sunny Goyale39690b2018-08-02 13:35:07 -0700342 public void onBackPressed(Launcher launcher) {
343 if (this != NORMAL) {
344 LauncherStateManager lsm = launcher.getStateManager();
345 LauncherState lastState = lsm.getLastState();
Sunny Goyale39690b2018-08-02 13:35:07 -0700346 lsm.goToState(lastState);
347 }
348 }
349
Tony Wickham59c69012019-06-18 16:34:37 -0700350 /**
351 * Prepares for a non-user controlled animation from fromState to this state. Preparations
352 * include:
353 * - Setting interpolators for various animations included in the state transition.
354 * - Setting some start values (e.g. scale) for views that are hidden but about to be shown.
355 */
356 public void prepareForAtomicAnimation(Launcher launcher, LauncherState fromState,
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700357 StateAnimationConfig config) {
Tony Wickham59c69012019-06-18 16:34:37 -0700358 if (this == NORMAL && fromState == OVERVIEW) {
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700359 config.setInterpolator(ANIM_WORKSPACE_SCALE, DEACCEL);
360 config.setInterpolator(ANIM_WORKSPACE_FADE, ACCEL);
361 config.setInterpolator(ANIM_OVERVIEW_SCALE, clampToProgress(ACCEL, 0, 0.9f));
362 config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, ACCEL);
363 config.setInterpolator(ANIM_OVERVIEW_FADE, DEACCEL_1_7);
Tony Wickham59c69012019-06-18 16:34:37 -0700364 Workspace workspace = launcher.getWorkspace();
365
366 // Start from a higher workspace scale, but only if we're invisible so we don't jump.
367 boolean isWorkspaceVisible = workspace.getVisibility() == VISIBLE;
368 if (isWorkspaceVisible) {
369 CellLayout currentChild = (CellLayout) workspace.getChildAt(
370 workspace.getCurrentPage());
371 isWorkspaceVisible = currentChild.getVisibility() == VISIBLE
372 && currentChild.getShortcutsAndWidgets().getAlpha() > 0;
373 }
374 if (!isWorkspaceVisible) {
375 workspace.setScaleX(0.92f);
376 workspace.setScaleY(0.92f);
377 }
378 Hotseat hotseat = launcher.getHotseat();
379 boolean isHotseatVisible = hotseat.getVisibility() == VISIBLE && hotseat.getAlpha() > 0;
380 if (!isHotseatVisible) {
381 hotseat.setScaleX(0.92f);
382 hotseat.setScaleY(0.92f);
Tony Wickham4fdba142019-11-04 16:23:51 -0800383 if (ENABLE_OVERVIEW_ACTIONS.get()) {
Tony Wickham04fca162020-02-05 15:06:52 -0800384 AllAppsContainerView qsbContainer = launcher.getAppsView();
385 View qsb = qsbContainer.getSearchView();
386 boolean qsbVisible = qsb.getVisibility() == VISIBLE && qsb.getAlpha() > 0;
387 if (!qsbVisible) {
388 qsbContainer.setScaleX(0.92f);
389 qsbContainer.setScaleY(0.92f);
390 }
Tony Wickham4fdba142019-11-04 16:23:51 -0800391 }
Tony Wickham59c69012019-06-18 16:34:37 -0700392 }
393 } else if (this == NORMAL && fromState == OVERVIEW_PEEK) {
394 // Keep fully visible until the very end (when overview is offscreen) to make invisible.
Sunny Goyalf3ac7032020-03-13 13:01:33 -0700395 config.setInterpolator(ANIM_OVERVIEW_FADE, t -> t < 1 ? 0 : 1);
Tony Wickham59c69012019-06-18 16:34:37 -0700396 }
397 }
398
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700399 protected static void dispatchWindowStateChanged(Launcher launcher) {
400 launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
401 }
Sunny Goyalbc683e92017-12-06 10:25:07 -0800402
Sunny Goyal0c723352017-12-12 12:02:29 -0800403 public static abstract class PageAlphaProvider {
Sunny Goyalbc683e92017-12-06 10:25:07 -0800404
Sunny Goyal0c723352017-12-12 12:02:29 -0800405 public final Interpolator interpolator;
406
407 public PageAlphaProvider(Interpolator interpolator) {
408 this.interpolator = interpolator;
409 }
410
411 public abstract float getPageAlpha(int pageIndex);
Sunny Goyalbc683e92017-12-06 10:25:07 -0800412 }
Tonybc234402019-03-19 13:30:25 -0500413
414 public static class ScaleAndTranslation {
415 public float scale;
416 public float translationX;
417 public float translationY;
418
419 public ScaleAndTranslation(float scale, float translationX, float translationY) {
420 this.scale = scale;
421 this.translationX = translationX;
422 this.translationY = translationY;
423 }
424 }
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700425}