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