blob: d6cd8a35c935bca513e899b7463911904fa86a61 [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;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070020import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070021
Sunny Goyalbe93f262017-10-20 17:05:27 -070022import android.view.View;
23
24import com.android.launcher3.states.AllAppsState;
Sunny Goyalc99cb172017-10-19 16:15:09 -070025import com.android.launcher3.states.SpringLoadedState;
Sunny Goyal85525172017-11-06 13:00:42 -080026import com.android.launcher3.uioverrides.OverviewState;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070027import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
28
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070029import java.util.Arrays;
30
Sunny Goyal4c7f2152017-10-17 17:17:16 -070031
32/**
Sunny Goyalbe93f262017-10-20 17:05:27 -070033 * Base state for various states used for the Launcher
Sunny Goyal4c7f2152017-10-17 17:17:16 -070034 */
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070035public class LauncherState {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070036
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070037 protected static final int FLAG_SHOW_SCRIM = 1 << 0;
38 protected static final int FLAG_MULTI_PAGE = 1 << 1;
Sunny Goyalc4fa8c32017-11-07 12:23:58 -080039 protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2;
40 protected static final int FLAG_DO_NOT_RESTORE = 1 << 3;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070041
42 private static final LauncherState[] sAllStates = new LauncherState[4];
43
Sunny Goyalc99cb172017-10-19 16:15:09 -070044 public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE,
Sunny Goyalbe93f262017-10-20 17:05:27 -070045 0, 1f, FLAG_DO_NOT_RESTORE);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070046
Sunny Goyalbe93f262017-10-20 17:05:27 -070047 public static final LauncherState ALL_APPS = new AllAppsState(1);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070048
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 Goyal85525172017-11-06 13:00:42 -080051 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
Sunny Goyalbe93f262017-10-20 17:05:27 -070076 /**
77 * Properties related to state transition animation
78 *
79 * @see WorkspaceStateTransitionAnimation
80 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070081 public final boolean hasScrim;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070082 public final int transitionDuration;
83
Sunny Goyalbe93f262017-10-20 17:05:27 -070084 /**
85 * Fraction shift in the vertical translation UI and related properties
86 *
87 * @see com.android.launcher3.allapps.AllAppsTransitionController
88 */
89 public final float verticalProgress;
Sunny Goyalbe93f262017-10-20 17:05:27 -070090
91 public LauncherState(int id, int containerType, int transitionDuration, float verticalProgress,
92 int flags) {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070093 this.containerType = containerType;
94 this.transitionDuration = transitionDuration;
95
96 this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
97 this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070098 this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
99 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
100 : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700101 this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700102
Sunny Goyalbe93f262017-10-20 17:05:27 -0700103 this.verticalProgress = verticalProgress;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700104
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700105 this.ordinal = id;
106 sAllStates[id] = this;
107 }
108
109 public static LauncherState[] values() {
110 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700111 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700112
113 public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
114 return new float[] {1, 0};
115 }
116
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700117 public void onStateEnabled(Launcher launcher) {
118 dispatchWindowStateChanged(launcher);
119 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700120
121 public void onStateDisabled(Launcher launcher) { }
Sunny Goyalbe93f262017-10-20 17:05:27 -0700122
123 public View getFinalFocus(Launcher launcher) {
124 return launcher.getWorkspace();
125 }
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700126
127 public String getDescription(Launcher launcher) {
128 return launcher.getWorkspace().getCurrentPageDescription();
129 }
130
131 protected static void dispatchWindowStateChanged(Launcher launcher) {
132 launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
133 }
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700134}