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 | |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 18 | import static com.android.app.animation.Interpolators.ACCELERATE_2; |
| 19 | import static com.android.app.animation.Interpolators.DECELERATE_2; |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; |
Tony Wickham | c5d168d | 2021-03-25 09:28:19 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW; |
vadimt | f6ef879 | 2022-07-26 13:54:31 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.testing.shared.TestProtocol.ALL_APPS_STATE_ORDINAL; |
| 23 | import static com.android.launcher3.testing.shared.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 24 | import static com.android.launcher3.testing.shared.TestProtocol.EDIT_MODE_STATE_ORDINAL; |
vadimt | f6ef879 | 2022-07-26 13:54:31 -0700 | [diff] [blame] | 25 | import static com.android.launcher3.testing.shared.TestProtocol.HINT_STATE_ORDINAL; |
| 26 | import static com.android.launcher3.testing.shared.TestProtocol.HINT_STATE_TWO_BUTTON_ORDINAL; |
| 27 | import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL; |
| 28 | import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_MODAL_TASK_STATE_ORDINAL; |
| 29 | import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_SPLIT_SELECT_ORDINAL; |
| 30 | import static com.android.launcher3.testing.shared.TestProtocol.OVERVIEW_STATE_ORDINAL; |
| 31 | import static com.android.launcher3.testing.shared.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; |
| 32 | import static com.android.launcher3.testing.shared.TestProtocol.SPRING_LOADED_STATE_ORDINAL; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 33 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 34 | import android.content.Context; |
Zak Cohen | 4d35ac3 | 2021-04-23 16:28:12 -0700 | [diff] [blame] | 35 | import android.graphics.Color; |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame^] | 36 | import android.view.View; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 37 | import android.view.animation.Interpolator; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 38 | |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 39 | import androidx.annotation.FloatRange; |
| 40 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 41 | import com.android.launcher3.statemanager.BaseState; |
| 42 | import com.android.launcher3.statemanager.StateManager; |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 43 | import com.android.launcher3.states.EditModeState; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 44 | import com.android.launcher3.states.HintState; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 45 | import com.android.launcher3.states.SpringLoadedState; |
vadimt | f6ef879 | 2022-07-26 13:54:31 -0700 | [diff] [blame] | 46 | import com.android.launcher3.testing.shared.TestProtocol; |
Tony | e06fef4 | 2019-03-22 15:44:28 -0500 | [diff] [blame] | 47 | import com.android.launcher3.uioverrides.states.AllAppsState; |
| 48 | import com.android.launcher3.uioverrides.states.OverviewState; |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 49 | import com.android.launcher3.views.ActivityContext; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 50 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 51 | import java.util.Arrays; |
| 52 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 53 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 54 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 55 | */ |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 56 | public abstract class LauncherState implements BaseState<LauncherState> { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 57 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Set of elements indicating various workspace elements which change visibility across states |
| 60 | * Note that workspace is not included here as in that case, we animate individual pages |
| 61 | */ |
| 62 | public static final int NONE = 0; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 63 | public static final int HOTSEAT_ICONS = 1 << 0; |
Sunny Goyal | c373e1c | 2021-03-09 17:27:53 -0800 | [diff] [blame] | 64 | public static final int ALL_APPS_CONTENT = 1 << 1; |
| 65 | public static final int VERTICAL_SWIPE_INDICATOR = 1 << 2; |
| 66 | public static final int OVERVIEW_ACTIONS = 1 << 3; |
Tony Wickham | 7af5440 | 2021-12-06 15:54:43 -0800 | [diff] [blame] | 67 | public static final int CLEAR_ALL_BUTTON = 1 << 4; |
| 68 | public static final int WORKSPACE_PAGE_INDICATOR = 1 << 5; |
| 69 | public static final int SPLIT_PLACHOLDER_VIEW = 1 << 6; |
Andy Wickham | 64896f3 | 2023-05-30 21:46:24 -0700 | [diff] [blame] | 70 | public static final int FLOATING_SEARCH_BAR = 1 << 7; |
Zak Cohen | 43a1615 | 2020-02-25 14:29:37 -0800 | [diff] [blame] | 71 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 72 | // Flag indicating workspace has multiple pages visible. |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 73 | public static final int FLAG_MULTI_PAGE = BaseState.getFlag(0); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 74 | // Flag indicating that workspace and its contents are not accessible |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 75 | public static final int FLAG_WORKSPACE_INACCESSIBLE = BaseState.getFlag(1); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 76 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 77 | // Flag indicating the state allows workspace icons to be dragged. |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 78 | 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] | 79 | // Flag to indicate that workspace should draw page background |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 80 | public static final int FLAG_WORKSPACE_HAS_BACKGROUNDS = BaseState.getFlag(3); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 81 | // Flag to indicate if the state would have scrim over sysui region: statu sbar and nav bar |
Sunny Goyal | 1eb1124 | 2022-09-09 17:14:45 -0700 | [diff] [blame] | 82 | public static final int FLAG_HAS_SYS_UI_SCRIM = BaseState.getFlag(4); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 83 | // Flag to inticate that all popups should be closed when this state is enabled. |
Sunny Goyal | 1eb1124 | 2022-09-09 17:14:45 -0700 | [diff] [blame] | 84 | public static final int FLAG_CLOSE_POPUPS = BaseState.getFlag(5); |
| 85 | public static final int FLAG_OVERVIEW_UI = BaseState.getFlag(6); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 86 | |
Anushree Ganjam | f6254c5 | 2022-04-29 00:46:22 +0000 | [diff] [blame] | 87 | // Flag indicating that hotseat and its contents are not accessible. |
Sunny Goyal | 1eb1124 | 2022-09-09 17:14:45 -0700 | [diff] [blame] | 88 | public static final int FLAG_HOTSEAT_INACCESSIBLE = BaseState.getFlag(7); |
Anushree Ganjam | f6254c5 | 2022-04-29 00:46:22 +0000 | [diff] [blame] | 89 | |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 90 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 91 | public static final float NO_OFFSET = 0; |
| 92 | public static final float NO_SCALE = 1; |
| 93 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 94 | protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 95 | new PageAlphaProvider(ACCELERATE_2) { |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 96 | @Override |
| 97 | public float getPageAlpha(int pageIndex) { |
| 98 | return 1; |
| 99 | } |
| 100 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 101 | |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 102 | protected static final PageTranslationProvider DEFAULT_PAGE_TRANSLATION_PROVIDER = |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 103 | new PageTranslationProvider(DECELERATE_2) { |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 104 | @Override |
| 105 | public float getPageTranslation(int pageIndex) { |
| 106 | return 0; |
| 107 | } |
| 108 | }; |
| 109 | |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 110 | private static final LauncherState[] sAllStates = new LauncherState[11]; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 111 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 112 | /** |
| 113 | * TODO: Create a separate class for NORMAL state. |
| 114 | */ |
vadimt | 6895e40 | 2019-02-15 16:42:14 -0800 | [diff] [blame] | 115 | public static final LauncherState NORMAL = new LauncherState(NORMAL_STATE_ORDINAL, |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 116 | LAUNCHER_STATE_HOME, |
Sunny Goyal | 1eb1124 | 2022-09-09 17:14:45 -0700 | [diff] [blame] | 117 | FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HAS_SYS_UI_SCRIM) { |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 118 | @Override |
Alex Chau | f39cc12 | 2022-04-14 17:51:59 +0100 | [diff] [blame] | 119 | public int getTransitionDuration(Context context, boolean isToState) { |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 120 | // Arbitrary duration, when going to NORMAL we use the state we're coming from instead. |
| 121 | return 0; |
| 122 | } |
| 123 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 124 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Various Launcher states arranged in the increasing order of UI layers |
| 127 | */ |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 128 | public static final LauncherState SPRING_LOADED = new SpringLoadedState( |
| 129 | SPRING_LOADED_STATE_ORDINAL); |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 130 | public static final LauncherState EDIT_MODE = new EditModeState(EDIT_MODE_STATE_ORDINAL); |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 131 | public static final LauncherState ALL_APPS = new AllAppsState(ALL_APPS_STATE_ORDINAL); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 132 | public static final LauncherState HINT_STATE = new HintState(HINT_STATE_ORDINAL); |
Tony Wickham | c5d168d | 2021-03-25 09:28:19 -0700 | [diff] [blame] | 133 | public static final LauncherState HINT_STATE_TWO_BUTTON = new HintState( |
| 134 | HINT_STATE_TWO_BUTTON_ORDINAL, LAUNCHER_STATE_OVERVIEW); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 135 | |
| 136 | public static final LauncherState OVERVIEW = new OverviewState(OVERVIEW_STATE_ORDINAL); |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 137 | public static final LauncherState OVERVIEW_MODAL_TASK = OverviewState.newModalTaskState( |
| 138 | OVERVIEW_MODAL_TASK_STATE_ORDINAL); |
Vinit Nayak | 82b8aa5 | 2023-02-03 10:15:50 -0800 | [diff] [blame] | 139 | /** |
| 140 | * State when user performs a quickswitch gesture from home/workspace to the most recent |
| 141 | * app |
| 142 | */ |
| 143 | public static final LauncherState QUICK_SWITCH_FROM_HOME = |
Tony | e4c2e2b | 2019-03-25 10:23:39 -0500 | [diff] [blame] | 144 | OverviewState.newSwitchState(QUICK_SWITCH_STATE_ORDINAL); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 145 | public static final LauncherState BACKGROUND_APP = |
| 146 | OverviewState.newBackgroundState(BACKGROUND_APP_STATE_ORDINAL); |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 147 | public static final LauncherState OVERVIEW_SPLIT_SELECT = |
| 148 | OverviewState.newSplitSelectState(OVERVIEW_SPLIT_SELECT_ORDINAL); |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 149 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 150 | public final int ordinal; |
| 151 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 152 | /** |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 153 | * Used for {@link com.android.launcher3.logging.StatsLogManager} |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 154 | */ |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 155 | public final int statsLogOrdinal; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 156 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 157 | /** |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 158 | * True if the state has overview panel visible. |
| 159 | */ |
| 160 | public final boolean overviewUi; |
| 161 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 162 | private final int mFlags; |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 163 | |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 164 | public LauncherState(int id, int statsLogOrdinal, int flags) { |
| 165 | this.statsLogOrdinal = statsLogOrdinal; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 166 | this.mFlags = flags; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 167 | this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 168 | this.ordinal = id; |
| 169 | sAllStates[id] = this; |
| 170 | } |
| 171 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 172 | /** |
| 173 | * Returns if the state has the provided flag |
| 174 | */ |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 175 | @Override |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 176 | public final boolean hasFlag(int mask) { |
| 177 | return (mFlags & mask) != 0; |
| 178 | } |
| 179 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 180 | public static LauncherState[] values() { |
| 181 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 182 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 183 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 184 | public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 185 | return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET); |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 188 | public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) { |
Tony Wickham | 57e489c | 2019-03-04 14:57:07 -0800 | [diff] [blame] | 189 | // For most states, treat the hotseat as if it were part of the workspace. |
| 190 | return getWorkspaceScaleAndTranslation(launcher); |
Tony | 4bb4b89 | 2019-03-03 15:32:12 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 193 | /** |
Tony Wickham | 82d5a06 | 2021-05-14 14:37:12 -0700 | [diff] [blame] | 194 | * Returns an array of two elements. |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 195 | * The first specifies the scale for the overview |
| 196 | * The second is the factor ([0, 1], 0 => center-screen; 1 => offscreen) by which overview |
| 197 | * should be shifted horizontally. |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 198 | */ |
| 199 | public float[] getOverviewScaleAndOffset(Launcher launcher) { |
| 200 | return launcher.getNormalOverviewScaleAndOffset(); |
Tony | 3bb5e8e | 2018-03-14 12:05:00 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Tony | 5406817 | 2019-05-12 13:24:51 -0500 | [diff] [blame] | 203 | public float getOverviewFullscreenProgress() { |
| 204 | return 0; |
| 205 | } |
| 206 | |
Andy Wickham | 64896f3 | 2023-05-30 21:46:24 -0700 | [diff] [blame] | 207 | /** |
| 208 | * How far from the bottom of the screen the <em>floating</em> search bar should rest in this |
| 209 | * state when the IME is not present. |
| 210 | * <p> |
| 211 | * To hide offscreen, use a negative value. |
| 212 | * <p> |
| 213 | * Note: if the provided value is non-negative but less than the current bottom insets, the |
| 214 | * insets will be applied. As such, you can use 0 to default to this. |
| 215 | */ |
| 216 | public int getFloatingSearchBarRestingMarginBottom(Launcher launcher) { |
| 217 | DeviceProfile dp = launcher.getDeviceProfile(); |
| 218 | return areElementsVisible(launcher, FLOATING_SEARCH_BAR) ? dp.getQsbOffsetY() |
| 219 | : -dp.hotseatQsbHeight; |
| 220 | } |
| 221 | |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame^] | 222 | /** |
| 223 | * How far from the start of the screen the <em>floating</em> search bar should rest. |
| 224 | * <p> |
| 225 | * To use original margin, return a negative value. |
| 226 | */ |
| 227 | public int getFloatingSearchBarRestingMarginStart(Launcher launcher) { |
| 228 | boolean isRtl = Utilities.isRtl(launcher.getResources()); |
| 229 | View qsb = launcher.getHotseat().getQsb(); |
| 230 | return isRtl ? launcher.getHotseat().getRight() - qsb.getRight() : qsb.getLeft(); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * How far from the end of the screen the <em>floating</em> search bar should rest. |
| 235 | * <p> |
| 236 | * To use original margin, return a negative value. |
| 237 | */ |
| 238 | public int getFloatingSearchBarRestingMarginEnd(Launcher launcher) { |
| 239 | DeviceProfile dp = launcher.getDeviceProfile(); |
| 240 | if (dp.isQsbInline) { |
| 241 | int marginStart = getFloatingSearchBarRestingMarginStart(launcher); |
| 242 | return dp.widthPx - marginStart - dp.hotseatQsbWidth; |
| 243 | } |
| 244 | |
| 245 | boolean isRtl = Utilities.isRtl(launcher.getResources()); |
| 246 | View qsb = launcher.getHotseat().getQsb(); |
| 247 | return isRtl ? qsb.getLeft() : launcher.getHotseat().getRight() - qsb.getRight(); |
| 248 | } |
| 249 | |
Andy Wickham | 64896f3 | 2023-05-30 21:46:24 -0700 | [diff] [blame] | 250 | /** Whether the <em>floating</em> search bar should use the pill UI when not focused. */ |
| 251 | public boolean shouldFloatingSearchBarUsePillWhenUnfocused(Launcher launcher) { |
| 252 | return false; |
| 253 | } |
| 254 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 255 | public int getVisibleElements(Launcher launcher) { |
Andy Wickham | 64896f3 | 2023-05-30 21:46:24 -0700 | [diff] [blame] | 256 | int elements = HOTSEAT_ICONS | WORKSPACE_PAGE_INDICATOR | VERTICAL_SWIPE_INDICATOR; |
| 257 | // Floating search bar is visible in normal state except in landscape on phones. |
| 258 | if (!(launcher.getDeviceProfile().isPhone && launcher.getDeviceProfile().isLandscape)) { |
| 259 | elements |= FLOATING_SEARCH_BAR; |
| 260 | } |
| 261 | return elements; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 264 | /** |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 265 | * A shorthand for checking getVisibleElements() & elements == elements. |
| 266 | * @return Whether all of the given elements are visible. |
| 267 | */ |
| 268 | public boolean areElementsVisible(Launcher launcher, int elements) { |
| 269 | return (getVisibleElements(launcher) & elements) == elements; |
| 270 | } |
| 271 | |
Schneider Victor-tulias | 3f6c473 | 2022-06-23 11:25:10 -0700 | [diff] [blame] | 272 | /** |
| 273 | * Returns whether taskbar is stashed and thus should either: |
| 274 | * 1) replace hotseat or taskbar icons with a handle in gesture navigation mode or |
| 275 | * 2) fade out the hotseat or taskbar icons in 3-button navigation mode. |
| 276 | */ |
Tony Wickham | 24675d3 | 2021-11-24 15:43:52 -0800 | [diff] [blame] | 277 | public boolean isTaskbarStashed(Launcher launcher) { |
Tracy Zhou | 308851d | 2021-09-09 21:18:25 -0700 | [diff] [blame] | 278 | return false; |
| 279 | } |
| 280 | |
Tony Wickham | 24675d3 | 2021-11-24 15:43:52 -0800 | [diff] [blame] | 281 | /** Returns whether taskbar is aligned with the hotseat vs position inside apps */ |
| 282 | public boolean isTaskbarAlignedWithHotseat(Launcher launcher) { |
Schneider Victor-tulias | 3f6c473 | 2022-06-23 11:25:10 -0700 | [diff] [blame] | 283 | return true; |
Tony Wickham | 24675d3 | 2021-11-24 15:43:52 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 286 | /** |
Winson Chung | 3bce15d | 2023-02-18 06:34:08 +0000 | [diff] [blame] | 287 | * Returns whether taskbar global drag is disallowed in this state. |
| 288 | */ |
| 289 | public boolean disallowTaskbarGlobalDrag() { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Returns whether the taskbar shortcut should trigger split selection mode. |
| 295 | */ |
| 296 | public boolean allowTaskbarInitialSplitSelection() { |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | /** |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 301 | * Fraction shift in the vertical translation UI and related properties |
| 302 | * |
| 303 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 304 | */ |
| 305 | public float getVerticalProgress(Launcher launcher) { |
| 306 | return 1f; |
| 307 | } |
| 308 | |
Sunny Goyal | c82916f | 2021-04-06 13:03:54 -0700 | [diff] [blame] | 309 | public float getWorkspaceBackgroundAlpha(Launcher launcher) { |
Sunny Goyal | 927447e | 2018-05-04 13:19:29 -0700 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
Zak Cohen | 4d35ac3 | 2021-04-23 16:28:12 -0700 | [diff] [blame] | 313 | /** |
| 314 | * What color should the workspace scrim be in when at rest in this state. |
| 315 | * Return {@link Color#TRANSPARENT} for no scrim. |
| 316 | */ |
| 317 | public int getWorkspaceScrimColor(Launcher launcher) { |
| 318 | return Color.TRANSPARENT; |
Tony Wickham | c088051 | 2019-07-24 17:32:08 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 321 | /** |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 322 | * For this state, how modal should over view been shown. 0 modalness means all tasks drawn, |
| 323 | * 1 modalness means the current task is show on its own. |
| 324 | */ |
| 325 | public float getOverviewModalness() { |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | /** |
Vinit Nayak | f4f0c4d | 2021-05-05 10:28:05 -0700 | [diff] [blame] | 330 | * For this state, how much additional translation there should be for each of the |
| 331 | * child TaskViews. Note that the translation can be its primary or secondary dimension. |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 332 | */ |
Vinit Nayak | f4f0c4d | 2021-05-05 10:28:05 -0700 | [diff] [blame] | 333 | public float getSplitSelectTranslation(Launcher launcher) { |
Vinit Nayak | d987a82 | 2021-02-22 14:49:27 -0800 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /** |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 338 | * The amount of blur and wallpaper zoom to apply to the background of either the app |
| 339 | * or Launcher surface in this state. Should be a number between 0 and 1, inclusive. |
| 340 | * |
| 341 | * 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] | 342 | */ |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 343 | public final <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext> |
Alex Chau | 3193522 | 2022-09-01 21:24:52 +0100 | [diff] [blame] | 344 | float getDepth(DEVICE_PROFILE_CONTEXT context) { |
Jon Miranda | 36d1015 | 2020-06-19 16:35:08 -0700 | [diff] [blame] | 345 | return getDepth(context, |
| 346 | BaseDraggingActivity.fromContext(context).getDeviceProfile().isMultiWindowMode); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * 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] | 351 | * |
Jon Miranda | 36d1015 | 2020-06-19 16:35:08 -0700 | [diff] [blame] | 352 | * @see #getDepth(Context). |
| 353 | */ |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 354 | public final <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext> |
Alex Chau | 3193522 | 2022-09-01 21:24:52 +0100 | [diff] [blame] | 355 | float getDepth(DEVICE_PROFILE_CONTEXT context, boolean isMultiWindowMode) { |
Jon Miranda | 36d1015 | 2020-06-19 16:35:08 -0700 | [diff] [blame] | 356 | if (isMultiWindowMode) { |
Winson Chung | b330d6e | 2020-04-20 11:57:11 -0700 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | return getDepthUnchecked(context); |
| 360 | } |
| 361 | |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 362 | protected <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext> |
Alex Chau | 3193522 | 2022-09-01 21:24:52 +0100 | [diff] [blame] | 363 | float getDepthUnchecked(DEVICE_PROFILE_CONTEXT context) { |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 364 | return 0f; |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 367 | public String getDescription(Launcher launcher) { |
| 368 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 369 | } |
| 370 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 371 | public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) { |
Jon Miranda | e383222 | 2020-07-06 15:38:38 -0700 | [diff] [blame] | 372 | if ((this != NORMAL && this != HINT_STATE) |
| 373 | || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 374 | return DEFAULT_ALPHA_PROVIDER; |
| 375 | } |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 376 | final int centerPage = launcher.getWorkspace().getNextPage(); |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 377 | return new PageAlphaProvider(ACCELERATE_2) { |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 378 | @Override |
| 379 | public float getPageAlpha(int pageIndex) { |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame] | 380 | return pageIndex != centerPage ? 0 : 1f; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 381 | } |
| 382 | }; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 385 | /** |
| 386 | * Gets the translation provider for workspace pages. |
| 387 | */ |
| 388 | public PageTranslationProvider getWorkspacePageTranslationProvider(Launcher launcher) { |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 389 | if (this != SPRING_LOADED |
| 390 | || this != EDIT_MODE |
| 391 | || !launcher.getDeviceProfile().isTwoPanels) { |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 392 | return DEFAULT_PAGE_TRANSLATION_PROVIDER; |
| 393 | } |
| 394 | final float quarterPageSpacing = launcher.getWorkspace().getPageSpacing() / 4f; |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 395 | return new PageTranslationProvider(DECELERATE_2) { |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 396 | @Override |
| 397 | public float getPageTranslation(int pageIndex) { |
| 398 | boolean isRtl = launcher.getWorkspace().mIsRtl; |
| 399 | boolean isFirstPage = pageIndex % 2 == 0; |
| 400 | return ((isFirstPage && !isRtl) || (!isFirstPage && isRtl)) ? -quarterPageSpacing |
| 401 | : quarterPageSpacing; |
| 402 | } |
| 403 | }; |
| 404 | } |
| 405 | |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 406 | /** |
| 407 | * Called when leaving this LauncherState |
| 408 | * @param launcher - Launcher instance |
| 409 | * @param toState - New LauncherState that is being entered |
| 410 | */ |
| 411 | public void onLeavingState(Launcher launcher, LauncherState toState) { |
| 412 | // no-op |
| 413 | // override to handle when leaving current LauncherState |
| 414 | } |
| 415 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 416 | @Override |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 417 | public LauncherState getHistoryForState(LauncherState previousState) { |
| 418 | // No history is supported |
| 419 | return NORMAL; |
| 420 | } |
| 421 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 422 | @Override |
| 423 | public String toString() { |
Tony Wickham | f844ee9 | 2020-05-27 15:41:32 -0500 | [diff] [blame] | 424 | return TestProtocol.stateOrdinalToString(ordinal); |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 427 | public void onBackPressed(Launcher launcher) { |
| 428 | if (this != NORMAL) { |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 429 | StateManager<LauncherState> lsm = launcher.getStateManager(); |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 430 | LauncherState lastState = lsm.getLastState(); |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 431 | lsm.goToState(lastState); |
| 432 | } |
| 433 | } |
| 434 | |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 435 | /** |
| 436 | * Find {@link StateManager} and target {@link LauncherState} to handle back progress in |
| 437 | * predictive back gesture. |
| 438 | */ |
| 439 | public void onBackProgressed( |
| 440 | Launcher launcher, @FloatRange(from = 0.0, to = 1.0) float backProgress) { |
| 441 | StateManager<LauncherState> lsm = launcher.getStateManager(); |
| 442 | LauncherState toState = lsm.getLastState(); |
| 443 | lsm.onBackProgressed(toState, backProgress); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Find {@link StateManager} and target {@link LauncherState} to handle backProgress in |
| 448 | * predictive back gesture. |
| 449 | */ |
| 450 | public void onBackCancelled(Launcher launcher) { |
| 451 | StateManager<LauncherState> lsm = launcher.getStateManager(); |
| 452 | LauncherState toState = lsm.getLastState(); |
| 453 | lsm.onBackCancelled(toState); |
| 454 | } |
| 455 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 456 | public static abstract class PageAlphaProvider { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 457 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 458 | public final Interpolator interpolator; |
| 459 | |
| 460 | public PageAlphaProvider(Interpolator interpolator) { |
| 461 | this.interpolator = interpolator; |
| 462 | } |
| 463 | |
| 464 | public abstract float getPageAlpha(int pageIndex); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 465 | } |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 466 | |
Pat Manning | b04dd60 | 2022-03-09 14:19:10 +0000 | [diff] [blame] | 467 | /** |
| 468 | * Provider for the translation and animation interpolation of workspace pages. |
| 469 | */ |
| 470 | public abstract static class PageTranslationProvider { |
| 471 | |
| 472 | public final Interpolator interpolator; |
| 473 | |
| 474 | public PageTranslationProvider(Interpolator interpolator) { |
| 475 | this.interpolator = interpolator; |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Gets the translation of the workspace page at the provided page index. |
| 480 | */ |
| 481 | public abstract float getPageTranslation(int pageIndex); |
| 482 | } |
| 483 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 484 | public static class ScaleAndTranslation { |
| 485 | public float scale; |
| 486 | public float translationX; |
| 487 | public float translationY; |
| 488 | |
| 489 | public ScaleAndTranslation(float scale, float translationX, float translationY) { |
| 490 | this.scale = scale; |
| 491 | this.translationX = translationX; |
| 492 | this.translationY = translationY; |
| 493 | } |
| 494 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 495 | } |