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; |
| 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 | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 27 | import com.android.launcher3.uioverrides.AllAppsState; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 28 | import com.android.launcher3.states.SpringLoadedState; |
Sunny Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 29 | import com.android.launcher3.uioverrides.OverviewState; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 30 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 31 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 32 | import java.util.Arrays; |
| 33 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 36 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 37 | */ |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 38 | public class LauncherState { |
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 | protected static final int FLAG_SHOW_SCRIM = 1 << 0; |
| 41 | protected static final int FLAG_MULTI_PAGE = 1 << 1; |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 42 | protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 43 | protected static final int FLAG_DISABLE_RESTORE = 1 << 3; |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 44 | protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 45 | protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5; |
| 46 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 47 | protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = |
| 48 | new PageAlphaProvider(ACCEL_2) { |
| 49 | @Override |
| 50 | public float getPageAlpha(int pageIndex) { |
| 51 | return 1; |
| 52 | } |
| 53 | }; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 54 | |
| 55 | private static final LauncherState[] sAllStates = new LauncherState[4]; |
| 56 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 57 | public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame^] | 58 | 0, FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 59 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 60 | public static final LauncherState ALL_APPS = new AllAppsState(1); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 61 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 62 | public static final LauncherState SPRING_LOADED = new SpringLoadedState(2); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 63 | |
Sunny Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 64 | public static final LauncherState OVERVIEW = new OverviewState(3); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 65 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 66 | public final int ordinal; |
| 67 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} |
| 70 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 71 | public final int containerType; |
| 72 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 73 | /** |
| 74 | * True if the state can be persisted across activity restarts. |
| 75 | */ |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 76 | public final boolean disableRestore; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * True if workspace has multiple pages visible. |
| 80 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 81 | public final boolean hasMultipleVisiblePages; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Accessibility flag for workspace and its pages. |
| 85 | * @see android.view.View#setImportantForAccessibility(int) |
| 86 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 87 | public final int workspaceAccessibilityFlag; |
| 88 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Properties related to state transition animation |
| 91 | * |
| 92 | * @see WorkspaceStateTransitionAnimation |
| 93 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 94 | public final boolean hasScrim; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 95 | public final int transitionDuration; |
| 96 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 97 | /** |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 98 | * True if the state allows workspace icons to be dragged. |
| 99 | */ |
| 100 | public final boolean workspaceIconsCanBeDragged; |
| 101 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 102 | /** |
| 103 | * True if the workspace pages should not be clipped relative to the workspace bounds |
| 104 | * for this state. |
| 105 | */ |
| 106 | public final boolean disablePageClipping; |
| 107 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame^] | 108 | public LauncherState(int id, int containerType, int transitionDuration, int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 109 | this.containerType = containerType; |
| 110 | this.transitionDuration = transitionDuration; |
| 111 | |
| 112 | this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0; |
| 113 | this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 114 | this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0 |
| 115 | ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 116 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 117 | this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0; |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame] | 118 | this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 119 | this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 120 | |
| 121 | this.ordinal = id; |
| 122 | sAllStates[id] = this; |
| 123 | } |
| 124 | |
| 125 | public static LauncherState[] values() { |
| 126 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 127 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 128 | |
| 129 | public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { |
Sunny Goyal | 9328a51 | 2017-12-21 12:40:38 -0800 | [diff] [blame] | 130 | return new float[] {1, 0, 0}; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Tony Wickham | a447bd8 | 2017-12-05 14:24:37 -0800 | [diff] [blame] | 133 | public float getHoseatAlpha(Launcher launcher) { |
| 134 | return 1f; |
| 135 | } |
| 136 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 137 | public void onStateEnabled(Launcher launcher) { |
| 138 | dispatchWindowStateChanged(launcher); |
| 139 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 140 | |
| 141 | public void onStateDisabled(Launcher launcher) { } |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 142 | |
| 143 | public View getFinalFocus(Launcher launcher) { |
| 144 | return launcher.getWorkspace(); |
| 145 | } |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 146 | |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame^] | 147 | /** |
| 148 | * Fraction shift in the vertical translation UI and related properties |
| 149 | * |
| 150 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 151 | */ |
| 152 | public float getVerticalProgress(Launcher launcher) { |
| 153 | return 1f; |
| 154 | } |
| 155 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 156 | public String getDescription(Launcher launcher) { |
| 157 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 158 | } |
| 159 | |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 160 | public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) { |
| 161 | if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) { |
| 162 | return DEFAULT_ALPHA_PROVIDER; |
| 163 | } |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame^] | 164 | final int centerPage = launcher.getWorkspace().getNextPage(); |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 165 | return new PageAlphaProvider(ACCEL_2) { |
| 166 | @Override |
| 167 | public float getPageAlpha(int pageIndex) { |
| 168 | return pageIndex != centerPage ? 0 : 1f; |
| 169 | } |
| 170 | }; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 173 | protected static void dispatchWindowStateChanged(Launcher launcher) { |
| 174 | launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED); |
| 175 | } |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 176 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 177 | public static abstract class PageAlphaProvider { |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 178 | |
Sunny Goyal | 0c72335 | 2017-12-12 12:02:29 -0800 | [diff] [blame] | 179 | public final Interpolator interpolator; |
| 180 | |
| 181 | public PageAlphaProvider(Interpolator interpolator) { |
| 182 | this.interpolator = interpolator; |
| 183 | } |
| 184 | |
| 185 | public abstract float getPageAlpha(int pageIndex); |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 186 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 187 | } |