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 | |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 18 | import static android.view.View.VISIBLE; |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 19 | |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.anim.Interpolators.ACCEL; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.anim.Interpolators.ACCEL_2; |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.anim.Interpolators.DEACCEL; |
| 23 | import static com.android.launcher3.anim.Interpolators.DEACCEL_1_7; |
| 24 | import static com.android.launcher3.anim.Interpolators.clampToProgress; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 25 | import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE; |
| 27 | import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE; |
| 28 | import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X; |
| 29 | import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE; |
| 30 | import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 31 | import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; |
| 32 | import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 33 | import static com.android.launcher3.testing.TestProtocol.HINT_STATE_ORDINAL; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 34 | import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL; |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 35 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_MODAL_TASK_STATE_ORDINAL; |
Sunny Goyal | ab3963d | 2019-05-23 00:50:08 -0700 | [diff] [blame] | 36 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_PEEK_STATE_ORDINAL; |
| 37 | import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; |
| 38 | import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; |
| 39 | import static com.android.launcher3.testing.TestProtocol.SPRING_LOADED_STATE_ORDINAL; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 40 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 41 | import android.content.Context; |
Tony Wickham | 04fca16 | 2020-02-05 15:06:52 -0800 | [diff] [blame] | 42 | import android.view.View; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 43 | import android.view.animation.Interpolator; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 44 | |
Tony Wickham | 04fca16 | 2020-02-05 15:06:52 -0800 | [diff] [blame] | 45 | import com.android.launcher3.allapps.AllAppsContainerView; |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 46 | import com.android.launcher3.states.HintState; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 47 | import com.android.launcher3.states.SpringLoadedState; |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 48 | import com.android.launcher3.states.StateAnimationConfig; |
Tony | e06fef4 | 2019-03-22 15:44:28 -0500 | [diff] [blame] | 49 | import com.android.launcher3.uioverrides.states.AllAppsState; |
| 50 | import com.android.launcher3.uioverrides.states.OverviewState; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 51 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 52 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 53 | import java.util.Arrays; |
| 54 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 57 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 58 | */ |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 59 | public abstract class LauncherState { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 60 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Set of elements indicating various workspace elements which change visibility across states |
| 63 | * Note that workspace is not included here as in that case, we animate individual pages |
| 64 | */ |
| 65 | public static final int NONE = 0; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 66 | public static final int HOTSEAT_ICONS = 1 << 0; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 67 | public static final int HOTSEAT_SEARCH_BOX = 1 << 1; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 68 | public static final int ALL_APPS_HEADER = 1 << 2; |
| 69 | public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions |
| 70 | public static final int ALL_APPS_CONTENT = 1 << 4; |
Sunny Goyal | 56e1019 | 2018-05-22 13:22:25 -0700 | [diff] [blame] | 71 | public static final int VERTICAL_SWIPE_INDICATOR = 1 << 5; |
Sunny Goyal | 514dfa2 | 2020-03-26 15:28:36 -0700 | [diff] [blame] | 72 | public static final int OVERVIEW_BUTTONS = 1 << 6; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 73 | |
Zak Cohen | 43a1615 | 2020-02-25 14:29:37 -0800 | [diff] [blame] | 74 | /** Mask of all the items that are contained in the apps view. */ |
| 75 | public static final int APPS_VIEW_ITEM_MASK = |
| 76 | HOTSEAT_SEARCH_BOX | ALL_APPS_HEADER | ALL_APPS_HEADER_EXTRA | ALL_APPS_CONTENT; |
| 77 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 78 | // Flag indicating workspace has multiple pages visible. |
| 79 | public static final int FLAG_MULTI_PAGE = 1 << 0; |
| 80 | // Flag indicating that workspace and its contents are not accessible |
| 81 | public static final int FLAG_WORKSPACE_INACCESSIBLE = 1 << 1; |
| 82 | |
| 83 | public static final int FLAG_DISABLE_RESTORE = 1 << 2; |
| 84 | // Flag indicating the state allows workspace icons to be dragged. |
| 85 | public static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 3; |
| 86 | // Flag to indicate that workspace should draw page background |
| 87 | public static final int FLAG_WORKSPACE_HAS_BACKGROUNDS = 1 << 4; |
| 88 | // Flag to indicate that Launcher is non-interactive in this state |
| 89 | public static final int FLAG_NON_INTERACTIVE = 1 << 5; |
| 90 | // True if the back button should be hidden when in this state (assuming no floating views are |
| 91 | // open, launcher has window focus, etc). |
| 92 | public static final int FLAG_HIDE_BACK_BUTTON = 1 << 6; |
| 93 | // Flag to indicate if the state would have scrim over sysui region: statu sbar and nav bar |
| 94 | public static final int FLAG_HAS_SYS_UI_SCRIM = 1 << 7; |
| 95 | // Flag to inticate that all popups should be closed when this state is enabled. |
| 96 | public static final int FLAG_CLOSE_POPUPS = 1 << 8; |
| 97 | public static final int FLAG_OVERVIEW_UI = 1 << 9; |
| 98 | |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 99 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 100 | public static final float NO_OFFSET = 0; |
| 101 | public static final float NO_SCALE = 1; |
| 102 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 103 | protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = |
| 104 | new PageAlphaProvider(ACCEL_2) { |
| 105 | @Override |
| 106 | public float getPageAlpha(int pageIndex) { |
| 107 | return 1; |
| 108 | } |
| 109 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 110 | |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 111 | private static final LauncherState[] sAllStates = new LauncherState[9]; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 112 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 113 | /** |
| 114 | * TODO: Create a separate class for NORMAL state. |
| 115 | */ |
vadimt | 6895e40 | 2019-02-15 16:42:14 -0800 | [diff] [blame] | 116 | public static final LauncherState NORMAL = new LauncherState(NORMAL_STATE_ORDINAL, |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 117 | ContainerType.WORKSPACE, |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 118 | 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] | 119 | FLAG_HAS_SYS_UI_SCRIM) { |
| 120 | @Override |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 121 | public int getTransitionDuration(Context context) { |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 122 | // Arbitrary duration, when going to NORMAL we use the state we're coming from instead. |
| 123 | return 0; |
| 124 | } |
| 125 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 126 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Various Launcher states arranged in the increasing order of UI layers |
| 129 | */ |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 130 | public static final LauncherState SPRING_LOADED = new SpringLoadedState( |
| 131 | SPRING_LOADED_STATE_ORDINAL); |
vadimt | 2a648aa | 2019-02-14 17:47:11 -0800 | [diff] [blame] | 132 | public static final LauncherState ALL_APPS = new AllAppsState(ALL_APPS_STATE_ORDINAL); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 133 | public static final LauncherState HINT_STATE = new HintState(HINT_STATE_ORDINAL); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 134 | |
| 135 | public static final LauncherState OVERVIEW = new OverviewState(OVERVIEW_STATE_ORDINAL); |
| 136 | public static final LauncherState OVERVIEW_PEEK = |
| 137 | OverviewState.newPeekState(OVERVIEW_PEEK_STATE_ORDINAL); |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 138 | public static final LauncherState OVERVIEW_MODAL_TASK = OverviewState.newModalTaskState( |
| 139 | OVERVIEW_MODAL_TASK_STATE_ORDINAL); |
Tony | e4c2e2b | 2019-03-25 10:23:39 -0500 | [diff] [blame] | 140 | public static final LauncherState QUICK_SWITCH = |
| 141 | OverviewState.newSwitchState(QUICK_SWITCH_STATE_ORDINAL); |
Tony | 1787ee9 | 2019-03-20 12:38:35 -0500 | [diff] [blame] | 142 | public static final LauncherState BACKGROUND_APP = |
| 143 | OverviewState.newBackgroundState(BACKGROUND_APP_STATE_ORDINAL); |
Tony Wickham | 6becf7c | 2018-04-19 11:39:34 -0700 | [diff] [blame] | 144 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 145 | public final int ordinal; |
| 146 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 147 | /** |
| 148 | * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} |
| 149 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 150 | public final int containerType; |
| 151 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 152 | /** |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 153 | * True if the state has overview panel visible. |
| 154 | */ |
| 155 | public final boolean overviewUi; |
| 156 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 157 | private final int mFlags; |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 158 | |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 159 | public LauncherState(int id, int containerType, int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 160 | this.containerType = containerType; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 161 | this.mFlags = flags; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 162 | this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 163 | this.ordinal = id; |
| 164 | sAllStates[id] = this; |
| 165 | } |
| 166 | |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 167 | /** |
| 168 | * Returns if the state has the provided flag |
| 169 | */ |
| 170 | public final boolean hasFlag(int mask) { |
| 171 | return (mFlags & mask) != 0; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return true if the state can be persisted across activity restarts. |
| 176 | */ |
| 177 | public final boolean shouldDisableRestore() { |
| 178 | return hasFlag(FLAG_DISABLE_RESTORE); |
| 179 | } |
| 180 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 181 | public static LauncherState[] values() { |
| 182 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 183 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 184 | |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 185 | /** |
| 186 | * @return How long the animation to this state should take (or from this state to NORMAL). |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 187 | */ |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame^] | 188 | public abstract int getTransitionDuration(Context context); |
Tony Wickham | c7203ad | 2020-02-03 18:36:06 -0800 | [diff] [blame] | 189 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 190 | public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 191 | return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET); |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 194 | public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) { |
Tony Wickham | 57e489c | 2019-03-04 14:57:07 -0800 | [diff] [blame] | 195 | // For most states, treat the hotseat as if it were part of the workspace. |
| 196 | return getWorkspaceScaleAndTranslation(launcher); |
Tony | 4bb4b89 | 2019-03-03 15:32:12 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Returns an array of two elements. |
| 201 | * The first specifies the scale for the overview |
| 202 | * The second is the factor ([0, 1], 0 => center-screen; 1 => offscreen) by which overview |
| 203 | * should be shifted horizontally. |
| 204 | */ |
| 205 | public float[] getOverviewScaleAndOffset(Launcher launcher) { |
| 206 | return launcher.getNormalOverviewScaleAndOffset(); |
Tony | 3bb5e8e | 2018-03-14 12:05:00 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 209 | public ScaleAndTranslation getQsbScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 210 | return new ScaleAndTranslation(NO_SCALE, NO_OFFSET, NO_OFFSET); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Tony | 5406817 | 2019-05-12 13:24:51 -0500 | [diff] [blame] | 213 | public float getOverviewFullscreenProgress() { |
| 214 | return 0; |
| 215 | } |
| 216 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 217 | public int getVisibleElements(Launcher launcher) { |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 218 | if (launcher.getDeviceProfile().isVerticalBarLayout()) { |
Sunny Goyal | 56e1019 | 2018-05-22 13:22:25 -0700 | [diff] [blame] | 219 | return HOTSEAT_ICONS | VERTICAL_SWIPE_INDICATOR; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 220 | } |
Sunny Goyal | 56e1019 | 2018-05-22 13:22:25 -0700 | [diff] [blame] | 221 | return HOTSEAT_ICONS | HOTSEAT_SEARCH_BOX | VERTICAL_SWIPE_INDICATOR; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Fraction shift in the vertical translation UI and related properties |
| 226 | * |
| 227 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 228 | */ |
| 229 | public float getVerticalProgress(Launcher launcher) { |
| 230 | return 1f; |
| 231 | } |
| 232 | |
Sunny Goyal | 927447e | 2018-05-04 13:19:29 -0700 | [diff] [blame] | 233 | public float getWorkspaceScrimAlpha(Launcher launcher) { |
| 234 | return 0; |
| 235 | } |
| 236 | |
Tony Wickham | c088051 | 2019-07-24 17:32:08 -0700 | [diff] [blame] | 237 | public float getOverviewScrimAlpha(Launcher launcher) { |
| 238 | return 0; |
| 239 | } |
| 240 | |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 241 | /** |
Zak Cohen | a39544d | 2020-04-27 16:26:55 -0700 | [diff] [blame] | 242 | * For this state, how modal should over view been shown. 0 modalness means all tasks drawn, |
| 243 | * 1 modalness means the current task is show on its own. |
| 244 | */ |
| 245 | public float getOverviewModalness() { |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | /** |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 250 | * The amount of blur and wallpaper zoom to apply to the background of either the app |
| 251 | * or Launcher surface in this state. Should be a number between 0 and 1, inclusive. |
| 252 | * |
| 253 | * 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] | 254 | */ |
Winson Chung | b330d6e | 2020-04-20 11:57:11 -0700 | [diff] [blame] | 255 | public final float getDepth(Context context) { |
| 256 | if (BaseDraggingActivity.fromContext(context).getDeviceProfile().isMultiWindowMode) { |
| 257 | return 0; |
| 258 | } |
| 259 | return getDepthUnchecked(context); |
| 260 | } |
| 261 | |
| 262 | protected float getDepthUnchecked(Context context) { |
Lucas Dupin | 4918ed3 | 2020-03-17 17:11:32 -0700 | [diff] [blame] | 263 | return 0f; |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 266 | public String getDescription(Launcher launcher) { |
| 267 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 268 | } |
| 269 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 270 | public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) { |
| 271 | if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) { |
| 272 | return DEFAULT_ALPHA_PROVIDER; |
| 273 | } |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 274 | final int centerPage = launcher.getWorkspace().getNextPage(); |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 275 | return new PageAlphaProvider(ACCEL_2) { |
| 276 | @Override |
| 277 | public float getPageAlpha(int pageIndex) { |
| 278 | return pageIndex != centerPage ? 0 : 1f; |
| 279 | } |
| 280 | }; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 281 | } |
| 282 | |
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 | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 288 | public void onBackPressed(Launcher launcher) { |
| 289 | if (this != NORMAL) { |
| 290 | LauncherStateManager lsm = launcher.getStateManager(); |
| 291 | LauncherState lastState = lsm.getLastState(); |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 292 | lsm.goToState(lastState); |
| 293 | } |
| 294 | } |
| 295 | |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Prepares for a non-user controlled animation from fromState to this state. Preparations |
| 298 | * include: |
| 299 | * - Setting interpolators for various animations included in the state transition. |
| 300 | * - Setting some start values (e.g. scale) for views that are hidden but about to be shown. |
| 301 | */ |
| 302 | public void prepareForAtomicAnimation(Launcher launcher, LauncherState fromState, |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 303 | StateAnimationConfig config) { |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 304 | if (this == NORMAL && fromState == OVERVIEW) { |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 305 | config.setInterpolator(ANIM_WORKSPACE_SCALE, DEACCEL); |
| 306 | config.setInterpolator(ANIM_WORKSPACE_FADE, ACCEL); |
| 307 | config.setInterpolator(ANIM_OVERVIEW_SCALE, clampToProgress(ACCEL, 0, 0.9f)); |
| 308 | config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, ACCEL); |
| 309 | config.setInterpolator(ANIM_OVERVIEW_FADE, DEACCEL_1_7); |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 310 | Workspace workspace = launcher.getWorkspace(); |
| 311 | |
| 312 | // Start from a higher workspace scale, but only if we're invisible so we don't jump. |
| 313 | boolean isWorkspaceVisible = workspace.getVisibility() == VISIBLE; |
| 314 | if (isWorkspaceVisible) { |
| 315 | CellLayout currentChild = (CellLayout) workspace.getChildAt( |
| 316 | workspace.getCurrentPage()); |
| 317 | isWorkspaceVisible = currentChild.getVisibility() == VISIBLE |
| 318 | && currentChild.getShortcutsAndWidgets().getAlpha() > 0; |
| 319 | } |
| 320 | if (!isWorkspaceVisible) { |
| 321 | workspace.setScaleX(0.92f); |
| 322 | workspace.setScaleY(0.92f); |
| 323 | } |
| 324 | Hotseat hotseat = launcher.getHotseat(); |
| 325 | boolean isHotseatVisible = hotseat.getVisibility() == VISIBLE && hotseat.getAlpha() > 0; |
| 326 | if (!isHotseatVisible) { |
| 327 | hotseat.setScaleX(0.92f); |
| 328 | hotseat.setScaleY(0.92f); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 329 | if (ENABLE_OVERVIEW_ACTIONS.get()) { |
Tony Wickham | 04fca16 | 2020-02-05 15:06:52 -0800 | [diff] [blame] | 330 | AllAppsContainerView qsbContainer = launcher.getAppsView(); |
| 331 | View qsb = qsbContainer.getSearchView(); |
| 332 | boolean qsbVisible = qsb.getVisibility() == VISIBLE && qsb.getAlpha() > 0; |
| 333 | if (!qsbVisible) { |
| 334 | qsbContainer.setScaleX(0.92f); |
| 335 | qsbContainer.setScaleY(0.92f); |
| 336 | } |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 337 | } |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 338 | } |
| 339 | } else if (this == NORMAL && fromState == OVERVIEW_PEEK) { |
| 340 | // Keep fully visible until the very end (when overview is offscreen) to make invisible. |
Sunny Goyal | f3ac703 | 2020-03-13 13:01:33 -0700 | [diff] [blame] | 341 | config.setInterpolator(ANIM_OVERVIEW_FADE, t -> t < 1 ? 0 : 1); |
Tony Wickham | 59c6901 | 2019-06-18 16:34:37 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 345 | public static abstract class PageAlphaProvider { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 346 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 347 | public final Interpolator interpolator; |
| 348 | |
| 349 | public PageAlphaProvider(Interpolator interpolator) { |
| 350 | this.interpolator = interpolator; |
| 351 | } |
| 352 | |
| 353 | public abstract float getPageAlpha(int pageIndex); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 354 | } |
Tony | bc23440 | 2019-03-19 13:30:25 -0500 | [diff] [blame] | 355 | |
| 356 | public static class ScaleAndTranslation { |
| 357 | public float scale; |
| 358 | public float translationX; |
| 359 | public float translationY; |
| 360 | |
| 361 | public ScaleAndTranslation(float scale, float translationX, float translationY) { |
| 362 | this.scale = scale; |
| 363 | this.translationX = translationX; |
| 364 | this.translationY = translationY; |
| 365 | } |
| 366 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 367 | } |