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; |
| 20 | |
| 21 | import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS; |
| 22 | import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; |
| 23 | import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 24 | |
| 25 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 26 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame^] | 27 | import java.util.Arrays; |
| 28 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Various states for launcher |
| 32 | */ |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame^] | 33 | public class LauncherState { |
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 | protected static final int FLAG_SHOW_SCRIM = 1 << 0; |
| 36 | protected static final int FLAG_MULTI_PAGE = 1 << 1; |
| 37 | protected static final int FLAG_HIDE_HOTSEAT = 1 << 2; |
| 38 | protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 3; |
| 39 | protected static final int FLAG_DO_NOT_RESTORE = 1 << 4; |
| 40 | |
| 41 | private static final LauncherState[] sAllStates = new LauncherState[4]; |
| 42 | |
| 43 | public static LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, |
| 44 | 0, FLAG_DO_NOT_RESTORE); |
| 45 | |
| 46 | public static LauncherState ALL_APPS = new LauncherState(1, ContainerType.ALLAPPS, |
| 47 | ALL_APPS_TRANSITION_MS, FLAG_DISABLE_ACCESSIBILITY); |
| 48 | |
| 49 | public static LauncherState SPRING_LOADED = new LauncherState(2, ContainerType.WORKSPACE, |
| 50 | SPRING_LOADED_TRANSITION_MS, |
| 51 | FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_DISABLE_ACCESSIBILITY | FLAG_DO_NOT_RESTORE); |
| 52 | |
| 53 | public static LauncherState OVERVIEW = new LauncherState(3, ContainerType.OVERVIEW, |
| 54 | OVERVIEW_TRANSITION_MS, |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 55 | FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT | FLAG_DO_NOT_RESTORE); |
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 | */ |
| 67 | public final boolean doNotRestore; |
| 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 | |
| 80 | // Properties related to state transition animation. |
| 81 | public final boolean hasScrim; |
| 82 | public final boolean hideHotseat; |
| 83 | public final int transitionDuration; |
| 84 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame^] | 85 | public LauncherState(int id, int containerType, int transitionDuration, int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 86 | this.containerType = containerType; |
| 87 | this.transitionDuration = transitionDuration; |
| 88 | |
| 89 | this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0; |
| 90 | this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0; |
| 91 | this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0; |
| 92 | this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0 |
| 93 | ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 94 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 95 | this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame^] | 96 | |
| 97 | this.ordinal = id; |
| 98 | sAllStates[id] = this; |
| 99 | } |
| 100 | |
| 101 | public static LauncherState[] values() { |
| 102 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 103 | } |
| 104 | } |