Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.launcher3; |
| 17 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 18 | import static com.android.launcher3.anim.Interpolators.ACCEL_2; |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; |
| 21 | import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 22 | import static com.android.launcher3.testing.TestProtocol.HINT_STATE_ORDINAL; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 23 | import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL; |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 24 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_MODAL_TASK_STATE_ORDINAL; |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 25 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_SPLIT_SELECT_ORDINAL; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; |
| 27 | import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; |
| 28 | import static com.android.launcher3.testing.TestProtocol.SPRING_LOADED_STATE_ORDINAL; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 29 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 30 | import android.content.Context; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 31 | import android.view.animation.Interpolator; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 32 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 33 | import com.android.launcher3.statemanager.BaseState; |
| 34 | import com.android.launcher3.statemanager.StateManager; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 35 | import com.android.launcher3.states.HintState; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 36 | import com.android.launcher3.states.SpringLoadedState; |
Tony Wickham | f844ee9 | 2020-05-27 15:41:32 -0500 | [diff] [blame] | 37 | import com.android.launcher3.testing.TestProtocol; |
Tony | e06fef4 | 2019-03-22 15:44:28 -0500 | [diff] [blame] | 38 | import com.android.launcher3.uioverrides.states.AllAppsState; |
| 39 | import com.android.launcher3.uioverrides.states.OverviewState; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 40 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 41 | import java.util.Arrays; |
| 42 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 43 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 44 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 45 | */ |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 46 | public abstract class LauncherState implements BaseState<LauncherState> { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 47 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Set of elements indicating various workspace elements which change visibility across states |
| 50 | * Note that workspace is not included here as in that case, we animate individual pages |
| 51 | */ |
| 52 | public static final int NONE = 0; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 53 | public static final int HOTSEAT_ICONS = 1 << 0; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame^] | 54 | public static final int ALL_APPS_CONTENT = 1 << 1; |
| 55 | public static final int VERTICAL_SWIPE_INDICATOR = 1 << 2; |
| 56 | public static final int OVERVIEW_ACTIONS = 1 << 3; |
| 57 | public static final int TASKBAR = 1 << 4; |
| 58 | public static final int CLEAR_ALL_BUTTON = 1 << 5; |
| 59 | public static final int WORKSPACE_PAGE_INDICATOR = 1 << 6; |
| 60 | public static final int SPLIT_PLACHOLDER_VIEW = 1 << 7; |
Zak Cohen | 43a1615 | 2020-02-25 14:29:37 -0800 | [diff] [blame] | 61 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 62 | // Flag indicating workspace has multiple pages visible. |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 63 | public static final int FLAG_MULTI_PAGE = BaseState.getFlag(0); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 64 | // Flag indicating that workspace and its contents are not accessible |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 65 | public static final int FLAG_WORKSPACE_INACCESSIBLE = BaseState.getFlag(1); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 66 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 67 | // Flag indicating the state allows workspace icons to be dragged. |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 68 | public static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = BaseState.getFlag(2); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 69 | // Flag to indicate that workspace should draw page background |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 70 | public static final int FLAG_WORKSPACE_HAS_BACKGROUNDS = BaseState.getFlag(3); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 71 | // True if the back button should be hidden when in this state (assuming no floating views are |
| 72 | // open, launcher has window focus, etc). |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 73 | public static final int FLAG_HIDE_BACK_BUTTON = BaseState.getFlag(4); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 74 | // Flag to indicate if the state would have scrim over sysui region: statu sbar and nav bar |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 75 | public static final int FLAG_HAS_SYS_UI_SCRIM = BaseState.getFlag(5); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 76 | // Flag to inticate that all popups should be closed when this state is enabled. |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 77 | public static final int FLAG_CLOSE_POPUPS = BaseState.getFlag(6); |
| 78 | public static final int FLAG_OVERVIEW_UI = BaseState.getFlag(7); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 79 | |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 80 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 81 | public static final float NO_OFFSET = 0; |
| 82 | public static final float NO_SCALE = 1; |
| 83 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 84 | protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = |
| 85 | new PageAlphaProvider(ACCEL_2) { |
| 86 | @Override |
| 87 | public float getPageAlpha(int pageIndex) { |
| 88 | return 1; |
| 89 | } |
| 90 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 91 | |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 92 | private static final LauncherState[] sAllStates = new LauncherState[9]; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 93 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 94 | /** |
| 95 | * TODO: Create a separate class for NORMAL state. |
| 96 | */ |
vadimt | 6895e40 | 2019-02-15 16:42:14 -0800 | [diff] [blame] | 97 | public static final LauncherState NORMAL = new LauncherState(NORMAL_STATE_ORDINAL, |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 98 | LAUNCHER_STATE_HOME, |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 99 | FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HIDE_BACK_BUTTON | |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 100 | FLAG_HAS_SYS_UI_SCRIM) { |
| 101 | @Override |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 102 | public int getTransitionDuration(Context context) { |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 103 | // Arbitrary duration, when going to NORMAL we use the state we're coming from instead. |
| 104 | return 0; |
| 105 | } |
| 106 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 107 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Various Launcher states arranged in the increasing order of UI layers |
| 110 | */ |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 111 | public static final LauncherState SPRING_LOADED = new SpringLoadedState( |
| 112 | SPRING_LOADED_STATE_ORDINAL); |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 113 | public static final LauncherState ALL_APPS = new AllAppsState(ALL_APPS_STATE_ORDINAL); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 114 | public static final LauncherState HINT_STATE = new HintState(HINT_STATE_ORDINAL); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 115 | |
| 116 | public static final LauncherState OVERVIEW = new OverviewState(OVERVIEW_STATE_ORDINAL); |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 117 | public static final LauncherState OVERVIEW_MODAL_TASK = OverviewState.newModalTaskState( |
| 118 | OVERVIEW_MODAL_TASK_STATE_ORDINAL); |
Tony | e4c2e2b | 2019-03-25 10:23:39 -0500 | [diff] [blame] | 119 | public static final LauncherState QUICK_SWITCH = |
| 120 | OverviewState.newSwitchState(QUICK_SWITCH_STATE_ORDINAL); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 121 | public static final LauncherState BACKGROUND_APP = |
| 122 | OverviewState.newBackgroundState(BACKGROUND_APP_STATE_ORDINAL); |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 123 | public static final LauncherState OVERVIEW_SPLIT_SELECT = |
| 124 | OverviewState.newSplitSelectState(OVERVIEW_SPLIT_SELECT_ORDINAL); |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 125 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 126 | public final int ordinal; |
| 127 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 128 | /** |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 129 | * Used for {@link com.android.launcher3.logging.StatsLogManager} |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 130 | */ |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 131 | public final int statsLogOrdinal; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 132 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 133 | /** |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 134 | * True if the state has overview panel visible. |
| 135 | */ |
| 136 | public final boolean overviewUi; |
| 137 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 138 | private final int mFlags; |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 139 | |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 140 | public LauncherState(int id, int statsLogOrdinal, int flags) { |
| 141 | this.statsLogOrdinal = statsLogOrdinal; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 142 | this.mFlags = flags; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 143 | this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 144 | this.ordinal = id; |
| 145 | sAllStates[id] = this; |
| 146 | } |
| 147 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Returns if the state has the provided flag |
| 150 | */ |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 151 | @Override |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 152 | public final boolean hasFlag(int mask) { |
| 153 | return (mFlags & mask) != 0; |
| 154 | } |
| 155 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 156 | public static LauncherState[] values() { |
| 157 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 158 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 159 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 160 | public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 161 | return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET); |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 164 | public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) { |
Tony Wickham | 57e489c | 2019-03-04 14:57:07 -0800 | [diff] [blame] | 165 | // For most states, treat the hotseat as if it were part of the workspace. |
| 166 | return getWorkspaceScaleAndTranslation(launcher); |
Tony | 4bb4b89 | 2019-03-03 15:32:12 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 169 | /** |
| 170 | * Returns an array of two elements. |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 171 | * The first specifies the scale for the overview |
| 172 | * The second is the factor ([0, 1], 0 => center-screen; 1 => offscreen) by which overview |
| 173 | * should be shifted horizontally. |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 174 | */ |
| 175 | public float[] getOverviewScaleAndOffset(Launcher launcher) { |
| 176 | return launcher.getNormalOverviewScaleAndOffset(); |
Tony | 3bb5e8e | 2018-03-14 12:05:00 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 179 | public ScaleAndTranslation getQsbScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 180 | return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Tony | 5406817 | 2019-05-12 13:24:51 -0500 | [diff] [blame] | 183 | public float getOverviewFullscreenProgress() { |
| 184 | return 0; |
| 185 | } |
| 186 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 187 | public int getVisibleElements(Launcher launcher) { |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 188 | DeviceProfile deviceProfile = launcher.getDeviceProfile(); |
| 189 | int flags = WORKSPACE_PAGE_INDICATOR | VERTICAL_SWIPE_INDICATOR | TASKBAR; |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 190 | if (!deviceProfile.isTaskbarPresent) { |
| 191 | flags |= HOTSEAT_ICONS; |
| 192 | } |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 193 | return flags; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 196 | /** |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 197 | * A shorthand for checking getVisibleElements() & elements == elements. |
| 198 | * @return Whether all of the given elements are visible. |
| 199 | */ |
| 200 | public boolean areElementsVisible(Launcher launcher, int elements) { |
| 201 | return (getVisibleElements(launcher) & elements) == elements; |
| 202 | } |
| 203 | |
| 204 | /** |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 205 | * Fraction shift in the vertical translation UI and related properties |
| 206 | * |
| 207 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 208 | */ |
| 209 | public float getVerticalProgress(Launcher launcher) { |
| 210 | return 1f; |
| 211 | } |
| 212 | |
Sunny Goyal | 927447e | 2018-05-04 13:19:29 -0700 | [diff] [blame] | 213 | public float getWorkspaceScrimAlpha(Launcher launcher) { |
| 214 | return 0; |
| 215 | } |
| 216 | |
Tony Wickham | c088051 | 2019-07-24 17:32:08 -0700 | [diff] [blame] | 217 | public float getOverviewScrimAlpha(Launcher launcher) { |
| 218 | return 0; |
| 219 | } |
| 220 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 221 | /** |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 222 | * For this state, how modal should over view been shown. 0 modalness means all tasks drawn, |
| 223 | * 1 modalness means the current task is show on its own. |
| 224 | */ |
| 225 | public float getOverviewModalness() { |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /** |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 230 | * For this state, how much additional vertical translation there should be for each of the |
| 231 | * child TaskViews. |
| 232 | */ |
| 233 | public float getOverviewSecondaryTranslation(Launcher launcher) { |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /** |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 238 | * The amount of blur and wallpaper zoom to apply to the background of either the app |
| 239 | * or Launcher surface in this state. Should be a number between 0 and 1, inclusive. |
| 240 | * |
| 241 | * 0 means completely zoomed in, without blurs. 1 is zoomed out, with blurs. |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 242 | */ |
Winson Chung | b330d6e | 2020-04-20 11:57:11 -0700 | [diff] [blame] | 243 | public final float getDepth(Context context) { |
Jon Miranda | 36d1015 | 2020-06-19 16:35:08 -0700 | [diff] [blame] | 244 | return getDepth(context, |
| 245 | BaseDraggingActivity.fromContext(context).getDeviceProfile().isMultiWindowMode); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Returns the amount of blur and wallpaper zoom for this state with {@param isMultiWindowMode}. |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 250 | * |
Jon Miranda | 36d1015 | 2020-06-19 16:35:08 -0700 | [diff] [blame] | 251 | * @see #getDepth(Context). |
| 252 | */ |
| 253 | public final float getDepth(Context context, boolean isMultiWindowMode) { |
| 254 | if (isMultiWindowMode) { |
Winson Chung | b330d6e | 2020-04-20 11:57:11 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | return getDepthUnchecked(context); |
| 258 | } |
| 259 | |
| 260 | protected float getDepthUnchecked(Context context) { |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 261 | return 0f; |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 264 | public String getDescription(Launcher launcher) { |
| 265 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 266 | } |
| 267 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 268 | public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) { |
Jon Miranda | e383222 | 2020-07-06 15:38:38 -0700 | [diff] [blame] | 269 | if ((this != NORMAL && this != HINT_STATE) |
| 270 | || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 271 | return DEFAULT_ALPHA_PROVIDER; |
| 272 | } |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 273 | final int centerPage = launcher.getWorkspace().getNextPage(); |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 274 | return new PageAlphaProvider(ACCEL_2) { |
| 275 | @Override |
| 276 | public float getPageAlpha(int pageIndex) { |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 277 | return pageIndex != centerPage ? 0 : 1f; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 278 | } |
| 279 | }; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 282 | @Override |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 283 | public LauncherState getHistoryForState(LauncherState previousState) { |
| 284 | // No history is supported |
| 285 | return NORMAL; |
| 286 | } |
| 287 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 288 | @Override |
| 289 | public String toString() { |
Tony Wickham | f844ee9 | 2020-05-27 15:41:32 -0500 | [diff] [blame] | 290 | return TestProtocol.stateOrdinalToString(ordinal); |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 293 | public void onBackPressed(Launcher launcher) { |
| 294 | if (this != NORMAL) { |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 295 | StateManager<LauncherState> lsm = launcher.getStateManager(); |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 296 | LauncherState lastState = lsm.getLastState(); |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 297 | lsm.goToState(lastState); |
| 298 | } |
| 299 | } |
| 300 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 301 | public static abstract class PageAlphaProvider { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 302 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 303 | public final Interpolator interpolator; |
| 304 | |
| 305 | public PageAlphaProvider(Interpolator interpolator) { |
| 306 | this.interpolator = interpolator; |
| 307 | } |
| 308 | |
| 309 | public abstract float getPageAlpha(int pageIndex); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 310 | } |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 311 | |
| 312 | public static class ScaleAndTranslation { |
| 313 | public float scale; |
| 314 | public float translationX; |
| 315 | public float translationY; |
| 316 | |
| 317 | public ScaleAndTranslation(float scale, float translationX, float translationY) { |
| 318 | this.scale = scale; |
| 319 | this.translationX = translationX; |
| 320 | this.translationY = translationY; |
| 321 | } |
| 322 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 323 | } |