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 | |
| 18 | import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 19 | import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 20 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 21 | import static com.android.launcher3.anim.Interpolators.ACCEL_2; |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 22 | import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 23 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 24 | import android.view.View; |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 25 | import android.view.animation.Interpolator; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 26 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 27 | import com.android.launcher3.states.SpringLoadedState; |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 28 | import com.android.launcher3.uioverrides.AllAppsState; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 29 | import com.android.launcher3.uioverrides.FastOverviewState; |
Sunny Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 30 | import com.android.launcher3.uioverrides.OverviewState; |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 31 | import com.android.launcher3.uioverrides.UiFactory; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 32 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 33 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 34 | import java.util.Arrays; |
| 35 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 38 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 39 | */ |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 40 | public class LauncherState { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 41 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Set of elements indicating various workspace elements which change visibility across states |
| 45 | * Note that workspace is not included here as in that case, we animate individual pages |
| 46 | */ |
| 47 | public static final int NONE = 0; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 48 | public static final int HOTSEAT_ICONS = 1 << 0; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 49 | public static final int HOTSEAT_SEARCH_BOX = 1 << 1; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 50 | public static final int ALL_APPS_HEADER = 1 << 2; |
| 51 | public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions |
| 52 | public static final int ALL_APPS_CONTENT = 1 << 4; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 53 | public static final int DRAG_HANDLE_INDICATOR = 1 << 5; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 54 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 55 | protected static final int FLAG_SHOW_SCRIM = 1 << 0; |
| 56 | protected static final int FLAG_MULTI_PAGE = 1 << 1; |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 57 | protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 58 | protected static final int FLAG_DISABLE_RESTORE = 1 << 3; |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 59 | protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 60 | protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5; |
Sunny Goyal | 6639a5d | 2018-02-28 15:09:36 -0800 | [diff] [blame] | 61 | protected static final int FLAG_PAGE_BACKGROUNDS = 1 << 6; |
| 62 | protected static final int FLAG_ALL_APPS_SCRIM = 1 << 7; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 63 | protected static final int FLAG_DISABLE_INTERACTION = 1 << 8; |
| 64 | protected static final int FLAG_OVERVIEW_UI = 1 << 9; |
Tony Wickham | 76cf236 | 2018-03-20 14:13:16 -0700 | [diff] [blame] | 65 | protected static final int FLAG_HIDE_BACK_BUTTON = 1 << 10; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 66 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 67 | protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = |
| 68 | new PageAlphaProvider(ACCEL_2) { |
| 69 | @Override |
| 70 | public float getPageAlpha(int pageIndex) { |
| 71 | return 1; |
| 72 | } |
| 73 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 74 | |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 75 | private static final LauncherState[] sAllStates = new LauncherState[5]; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 76 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 77 | /** |
| 78 | * TODO: Create a separate class for NORMAL state. |
| 79 | */ |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 80 | public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, |
Tony Wickham | 76cf236 | 2018-03-20 14:13:16 -0700 | [diff] [blame] | 81 | 0, FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HIDE_BACK_BUTTON); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 82 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Various Launcher states arranged in the increasing order of UI layers |
| 85 | */ |
| 86 | public static final LauncherState SPRING_LOADED = new SpringLoadedState(1); |
| 87 | public static final LauncherState OVERVIEW = new OverviewState(2); |
| 88 | public static final LauncherState FAST_OVERVIEW = new FastOverviewState(3); |
| 89 | public static final LauncherState ALL_APPS = new AllAppsState(4); |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 90 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 91 | public final int ordinal; |
| 92 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 93 | /** |
| 94 | * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} |
| 95 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 96 | public final int containerType; |
| 97 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 98 | /** |
| 99 | * True if the state can be persisted across activity restarts. |
| 100 | */ |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 101 | public final boolean disableRestore; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * True if workspace has multiple pages visible. |
| 105 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 106 | public final boolean hasMultipleVisiblePages; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Accessibility flag for workspace and its pages. |
| 110 | * @see android.view.View#setImportantForAccessibility(int) |
| 111 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 112 | public final int workspaceAccessibilityFlag; |
| 113 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 114 | /** |
| 115 | * Properties related to state transition animation |
| 116 | * |
| 117 | * @see WorkspaceStateTransitionAnimation |
| 118 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 119 | public final boolean hasScrim; |
Sunny Goyal | 6639a5d | 2018-02-28 15:09:36 -0800 | [diff] [blame] | 120 | public final boolean hasWorkspacePageBackground; |
| 121 | public final boolean hasAllAppsScrim; |
| 122 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 123 | public final int transitionDuration; |
| 124 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 125 | /** |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 126 | * True if the state allows workspace icons to be dragged. |
| 127 | */ |
| 128 | public final boolean workspaceIconsCanBeDragged; |
| 129 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 130 | /** |
| 131 | * True if the workspace pages should not be clipped relative to the workspace bounds |
| 132 | * for this state. |
| 133 | */ |
| 134 | public final boolean disablePageClipping; |
| 135 | |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 136 | /** |
| 137 | * True if launcher can not be directly interacted in this state; |
| 138 | */ |
| 139 | public final boolean disableInteraction; |
| 140 | |
| 141 | /** |
| 142 | * True if the state has overview panel visible. |
| 143 | */ |
| 144 | public final boolean overviewUi; |
| 145 | |
Tony Wickham | 76cf236 | 2018-03-20 14:13:16 -0700 | [diff] [blame] | 146 | /** |
| 147 | * True if the back button should be hidden when in this state (assuming no floating views are |
| 148 | * open, launcher has window focus, etc). |
| 149 | */ |
| 150 | public final boolean hideBackButton; |
| 151 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 152 | public LauncherState(int id, int containerType, int transitionDuration, int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 153 | this.containerType = containerType; |
| 154 | this.transitionDuration = transitionDuration; |
| 155 | |
| 156 | this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0; |
Sunny Goyal | 6639a5d | 2018-02-28 15:09:36 -0800 | [diff] [blame] | 157 | this.hasWorkspacePageBackground = (flags & FLAG_PAGE_BACKGROUNDS) != 0; |
| 158 | this.hasAllAppsScrim = (flags & FLAG_ALL_APPS_SCRIM) != 0; |
| 159 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 160 | this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 161 | this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0 |
| 162 | ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 163 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 164 | this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0; |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 165 | this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 166 | this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0; |
Sunny Goyal | 6c6c2f4 | 2018-03-02 14:57:46 -0800 | [diff] [blame] | 167 | this.disableInteraction = (flags & FLAG_DISABLE_INTERACTION) != 0; |
| 168 | this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0; |
Tony Wickham | 76cf236 | 2018-03-20 14:13:16 -0700 | [diff] [blame] | 169 | this.hideBackButton = (flags & FLAG_HIDE_BACK_BUTTON) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 170 | |
| 171 | this.ordinal = id; |
| 172 | sAllStates[id] = this; |
| 173 | } |
| 174 | |
| 175 | public static LauncherState[] values() { |
| 176 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 177 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 178 | |
| 179 | public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | 9328a51 | 2017-12-21 12:40:38 -0800 | [diff] [blame] | 180 | return new float[] {1, 0, 0}; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Tony | e9054e3 | 2018-03-15 12:48:51 +0000 | [diff] [blame] | 183 | /** |
| 184 | * Returns 2 floats designating how much to translate overview: |
| 185 | * X factor is based on width, e.g. 0 is fully onscreen and 1 is fully offscreen |
| 186 | * Y factor is based on padding, e.g. 0 is top aligned and 0.5 is centered vertically |
| 187 | */ |
| 188 | public float[] getOverviewTranslationFactor(Launcher launcher) { |
| 189 | return new float[] {1f, 0f}; |
Tony | 3bb5e8e | 2018-03-14 12:05:00 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 192 | public void onStateEnabled(Launcher launcher) { |
| 193 | dispatchWindowStateChanged(launcher); |
| 194 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 195 | |
| 196 | public void onStateDisabled(Launcher launcher) { } |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 197 | |
| 198 | public View getFinalFocus(Launcher launcher) { |
| 199 | return launcher.getWorkspace(); |
| 200 | } |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 201 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 202 | public int getVisibleElements(Launcher launcher) { |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 203 | if (launcher.getDeviceProfile().isVerticalBarLayout()) { |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 204 | return HOTSEAT_ICONS | DRAG_HANDLE_INDICATOR; |
Tony Wickham | bd6f05e | 2018-03-21 08:16:33 -0700 | [diff] [blame] | 205 | } |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 206 | return HOTSEAT_ICONS | DRAG_HANDLE_INDICATOR | HOTSEAT_SEARCH_BOX; |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Fraction shift in the vertical translation UI and related properties |
| 211 | * |
| 212 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 213 | */ |
| 214 | public float getVerticalProgress(Launcher launcher) { |
| 215 | return 1f; |
| 216 | } |
| 217 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 218 | public String getDescription(Launcher launcher) { |
| 219 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 220 | } |
| 221 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 222 | public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) { |
| 223 | if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) { |
| 224 | return DEFAULT_ALPHA_PROVIDER; |
| 225 | } |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 226 | final int centerPage = launcher.getWorkspace().getNextPage(); |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 227 | return new PageAlphaProvider(ACCEL_2) { |
| 228 | @Override |
| 229 | public float getPageAlpha(int pageIndex) { |
| 230 | return pageIndex != centerPage ? 0 : 1f; |
| 231 | } |
| 232 | }; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Sunny Goyal | 49bcf34 | 2018-01-11 13:59:53 -0800 | [diff] [blame] | 235 | public LauncherState getHistoryForState(LauncherState previousState) { |
| 236 | // No history is supported |
| 237 | return NORMAL; |
| 238 | } |
| 239 | |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 240 | /** |
| 241 | * Called when the start transition ends and the user settles on this particular state. |
| 242 | */ |
| 243 | public void onStateTransitionEnd(Launcher launcher) { |
| 244 | if (this == NORMAL) { |
| 245 | UiFactory.resetOverview(launcher); |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 246 | // Clear any rotation locks when going to normal state |
| 247 | launcher.getRotationHelper().setCurrentStateRequest(REQUEST_NONE); |
Sunny Goyal | 75c59ac | 2018-01-15 14:23:11 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 251 | protected static void dispatchWindowStateChanged(Launcher launcher) { |
| 252 | launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED); |
| 253 | } |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 254 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 255 | public static abstract class PageAlphaProvider { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 256 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 257 | public final Interpolator interpolator; |
| 258 | |
| 259 | public PageAlphaProvider(Interpolator interpolator) { |
| 260 | this.interpolator = interpolator; |
| 261 | } |
| 262 | |
| 263 | public abstract float getPageAlpha(int pageIndex); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 264 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 265 | } |