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 | |
| 24 | import com.android.launcher3.states.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; |
| 40 | protected static final int FLAG_DO_NOT_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 | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 42 | |
| 43 | private static final LauncherState[] sAllStates = new LauncherState[4]; |
| 44 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 45 | public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame^] | 46 | 0, 1f, FLAG_DO_NOT_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 47 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 48 | public static final LauncherState ALL_APPS = new AllAppsState(1); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 49 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 50 | public static final LauncherState SPRING_LOADED = new SpringLoadedState(2); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 51 | |
Sunny Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 52 | public static final LauncherState OVERVIEW = new OverviewState(3); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 53 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 54 | public final int ordinal; |
| 55 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} |
| 58 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 59 | public final int containerType; |
| 60 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 61 | /** |
| 62 | * True if the state can be persisted across activity restarts. |
| 63 | */ |
| 64 | public final boolean doNotRestore; |
| 65 | |
| 66 | /** |
| 67 | * True if workspace has multiple pages visible. |
| 68 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 69 | public final boolean hasMultipleVisiblePages; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Accessibility flag for workspace and its pages. |
| 73 | * @see android.view.View#setImportantForAccessibility(int) |
| 74 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 75 | public final int workspaceAccessibilityFlag; |
| 76 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Properties related to state transition animation |
| 79 | * |
| 80 | * @see WorkspaceStateTransitionAnimation |
| 81 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 82 | public final boolean hasScrim; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 83 | public final int transitionDuration; |
| 84 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Fraction shift in the vertical translation UI and related properties |
| 87 | * |
| 88 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 89 | */ |
| 90 | public final float verticalProgress; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 91 | |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame^] | 92 | /** |
| 93 | * True if the state allows workspace icons to be dragged. |
| 94 | */ |
| 95 | public final boolean workspaceIconsCanBeDragged; |
| 96 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 97 | public LauncherState(int id, int containerType, int transitionDuration, float verticalProgress, |
| 98 | int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 99 | this.containerType = containerType; |
| 100 | this.transitionDuration = transitionDuration; |
| 101 | |
| 102 | this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0; |
| 103 | this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 104 | this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0 |
| 105 | ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 106 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 107 | this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0; |
Tony Wickham | 5337067 | 2017-12-05 10:10:55 -0800 | [diff] [blame^] | 108 | this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 109 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 110 | this.verticalProgress = verticalProgress; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 111 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 112 | this.ordinal = id; |
| 113 | sAllStates[id] = this; |
| 114 | } |
| 115 | |
| 116 | public static LauncherState[] values() { |
| 117 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 118 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 119 | |
| 120 | public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { |
| 121 | return new float[] {1, 0}; |
| 122 | } |
| 123 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 124 | public void onStateEnabled(Launcher launcher) { |
| 125 | dispatchWindowStateChanged(launcher); |
| 126 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 127 | |
| 128 | public void onStateDisabled(Launcher launcher) { } |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 129 | |
| 130 | public View getFinalFocus(Launcher launcher) { |
| 131 | return launcher.getWorkspace(); |
| 132 | } |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 133 | |
| 134 | public String getDescription(Launcher launcher) { |
| 135 | return launcher.getWorkspace().getCurrentPageDescription(); |
| 136 | } |
| 137 | |
| 138 | protected static void dispatchWindowStateChanged(Launcher launcher) { |
| 139 | launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED); |
| 140 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 141 | } |