blob: 0ac27e5385c8f05592ef7971fd18f62caa0916e8 [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;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070022
Sunny Goyalc99cb172017-10-19 16:15:09 -070023import com.android.launcher3.states.OverviewState;
24import com.android.launcher3.states.SpringLoadedState;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070025import 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
Sunny Goyalc99cb172017-10-19 16:15:09 -070043 public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE,
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070044 0, FLAG_DO_NOT_RESTORE);
45
Sunny Goyalc99cb172017-10-19 16:15:09 -070046 public static final LauncherState ALL_APPS = new LauncherState(1, ContainerType.ALLAPPS,
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070047 ALL_APPS_TRANSITION_MS, FLAG_DISABLE_ACCESSIBILITY);
48
Sunny Goyalc99cb172017-10-19 16:15:09 -070049 public static final LauncherState SPRING_LOADED = new SpringLoadedState(2);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070050
Sunny Goyalc99cb172017-10-19 16:15:09 -070051 public static final LauncherState OVERVIEW = new OverviewState(3);
Sunny Goyal4c7f2152017-10-17 17:17:16 -070052
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070053 public final int ordinal;
54
Sunny Goyalf9403d92017-10-18 10:55:56 -070055 /**
56 * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
57 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070058 public final int containerType;
59
Sunny Goyalf9403d92017-10-18 10:55:56 -070060 /**
61 * True if the state can be persisted across activity restarts.
62 */
63 public final boolean doNotRestore;
64
65 /**
66 * True if workspace has multiple pages visible.
67 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070068 public final boolean hasMultipleVisiblePages;
Sunny Goyalf9403d92017-10-18 10:55:56 -070069
70 /**
71 * Accessibility flag for workspace and its pages.
72 * @see android.view.View#setImportantForAccessibility(int)
73 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070074 public final int workspaceAccessibilityFlag;
75
76 // Properties related to state transition animation.
77 public final boolean hasScrim;
78 public final boolean hideHotseat;
79 public final int transitionDuration;
80
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070081 public LauncherState(int id, int containerType, int transitionDuration, int flags) {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070082 this.containerType = containerType;
83 this.transitionDuration = transitionDuration;
84
85 this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
86 this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
87 this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0;
88 this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
89 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
90 : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Sunny Goyalf9403d92017-10-18 10:55:56 -070091 this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070092
93 this.ordinal = id;
94 sAllStates[id] = this;
95 }
96
97 public static LauncherState[] values() {
98 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -070099 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700100
101 public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
102 return new float[] {1, 0};
103 }
104
105 public void onStateEnabled(Launcher launcher) { }
106
107 public void onStateDisabled(Launcher launcher) { }
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700108}