blob: 4619f4e58e9777fa3724a58d4dc9d47ae5e71980 [file] [log] [blame]
Sunny Goyal4c7f2152017-10-17 17:17:16 -07001/*
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 */
16package com.android.launcher3;
17
18import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
19import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
20
21import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS;
22import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
23import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070024
25import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
26
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070027import java.util.Arrays;
28
Sunny Goyal4c7f2152017-10-17 17:17:16 -070029
30/**
31 * Various states for launcher
32 */
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070033public class LauncherState {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070034
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070035 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 Goyalf9403d92017-10-18 10:55:56 -070055 FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT | FLAG_DO_NOT_RESTORE);
Sunny Goyal4c7f2152017-10-17 17:17:16 -070056
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070057 public final int ordinal;
58
Sunny Goyalf9403d92017-10-18 10:55:56 -070059 /**
60 * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
61 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070062 public final int containerType;
63
Sunny Goyalf9403d92017-10-18 10:55:56 -070064 /**
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 Goyal4c7f2152017-10-17 17:17:16 -070072 public final boolean hasMultipleVisiblePages;
Sunny Goyalf9403d92017-10-18 10:55:56 -070073
74 /**
75 * Accessibility flag for workspace and its pages.
76 * @see android.view.View#setImportantForAccessibility(int)
77 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070078 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 Goyalcd7c0aa2017-10-19 12:36:27 -070085 public LauncherState(int id, int containerType, int transitionDuration, int flags) {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070086 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 Goyalf9403d92017-10-18 10:55:56 -070095 this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070096
97 this.ordinal = id;
98 sAllStates[id] = this;
99 }
100
101 public static LauncherState[] values() {
102 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700103 }
104}