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