blob: 670f57997a0c0f17d4102b6b6c395e9d5fbb1e36 [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 Goyal0c723352017-12-12 12:02:29 -080022import static com.android.launcher3.anim.Interpolators.ACCEL_2;
23
Sunny Goyalbe93f262017-10-20 17:05:27 -070024import android.view.View;
Sunny Goyal0c723352017-12-12 12:02:29 -080025import android.view.animation.Interpolator;
Sunny Goyalbe93f262017-10-20 17:05:27 -070026
Sunny Goyalbc683e92017-12-06 10:25:07 -080027import com.android.launcher3.uioverrides.AllAppsState;
Sunny Goyalc99cb172017-10-19 16:15:09 -070028import com.android.launcher3.states.SpringLoadedState;
Sunny Goyal85525172017-11-06 13:00:42 -080029import com.android.launcher3.uioverrides.OverviewState;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070030import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
31
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070032import java.util.Arrays;
33
Sunny Goyal4c7f2152017-10-17 17:17:16 -070034
35/**
Sunny Goyalbe93f262017-10-20 17:05:27 -070036 * Base state for various states used for the Launcher
Sunny Goyal4c7f2152017-10-17 17:17:16 -070037 */
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070038public class LauncherState {
Sunny Goyal4c7f2152017-10-17 17:17:16 -070039
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070040 protected static final int FLAG_SHOW_SCRIM = 1 << 0;
41 protected static final int FLAG_MULTI_PAGE = 1 << 1;
Sunny Goyalc4fa8c32017-11-07 12:23:58 -080042 protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2;
Sunny Goyalbc683e92017-12-06 10:25:07 -080043 protected static final int FLAG_DISABLE_RESTORE = 1 << 3;
Tony Wickham53370672017-12-05 10:10:55 -080044 protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4;
Sunny Goyalbc683e92017-12-06 10:25:07 -080045 protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5;
46
Sunny Goyal0c723352017-12-12 12:02:29 -080047 protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
48 new PageAlphaProvider(ACCEL_2) {
49 @Override
50 public float getPageAlpha(int pageIndex) {
51 return 1;
52 }
53 };
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070054
55 private static final LauncherState[] sAllStates = new LauncherState[4];
56
Sunny Goyalc99cb172017-10-19 16:15:09 -070057 public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE,
Sunny Goyal228153d2018-01-04 15:35:22 -080058 0, FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070059
Sunny Goyalbe93f262017-10-20 17:05:27 -070060 public static final LauncherState ALL_APPS = new AllAppsState(1);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070061
Sunny Goyalc99cb172017-10-19 16:15:09 -070062 public static final LauncherState SPRING_LOADED = new SpringLoadedState(2);
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070063
Sunny Goyal85525172017-11-06 13:00:42 -080064 public static final LauncherState OVERVIEW = new OverviewState(3);
Sunny Goyal4c7f2152017-10-17 17:17:16 -070065
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -070066 public final int ordinal;
67
Sunny Goyalf9403d92017-10-18 10:55:56 -070068 /**
69 * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
70 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070071 public final int containerType;
72
Sunny Goyalf9403d92017-10-18 10:55:56 -070073 /**
74 * True if the state can be persisted across activity restarts.
75 */
Sunny Goyalbc683e92017-12-06 10:25:07 -080076 public final boolean disableRestore;
Sunny Goyalf9403d92017-10-18 10:55:56 -070077
78 /**
79 * True if workspace has multiple pages visible.
80 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070081 public final boolean hasMultipleVisiblePages;
Sunny Goyalf9403d92017-10-18 10:55:56 -070082
83 /**
84 * Accessibility flag for workspace and its pages.
85 * @see android.view.View#setImportantForAccessibility(int)
86 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070087 public final int workspaceAccessibilityFlag;
88
Sunny Goyalbe93f262017-10-20 17:05:27 -070089 /**
90 * Properties related to state transition animation
91 *
92 * @see WorkspaceStateTransitionAnimation
93 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070094 public final boolean hasScrim;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070095 public final int transitionDuration;
96
Sunny Goyalbe93f262017-10-20 17:05:27 -070097 /**
Tony Wickham53370672017-12-05 10:10:55 -080098 * True if the state allows workspace icons to be dragged.
99 */
100 public final boolean workspaceIconsCanBeDragged;
101
Sunny Goyalbc683e92017-12-06 10:25:07 -0800102 /**
103 * True if the workspace pages should not be clipped relative to the workspace bounds
104 * for this state.
105 */
106 public final boolean disablePageClipping;
107
Sunny Goyal228153d2018-01-04 15:35:22 -0800108 public LauncherState(int id, int containerType, int transitionDuration, int flags) {
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700109 this.containerType = containerType;
110 this.transitionDuration = transitionDuration;
111
112 this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
113 this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700114 this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
115 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
116 : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Sunny Goyalbc683e92017-12-06 10:25:07 -0800117 this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0;
Tony Wickham53370672017-12-05 10:10:55 -0800118 this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
Sunny Goyalbc683e92017-12-06 10:25:07 -0800119 this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0;
Sunny Goyalcd7c0aa2017-10-19 12:36:27 -0700120
121 this.ordinal = id;
122 sAllStates[id] = this;
123 }
124
125 public static LauncherState[] values() {
126 return Arrays.copyOf(sAllStates, sAllStates.length);
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700127 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700128
129 public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
Sunny Goyal9328a512017-12-21 12:40:38 -0800130 return new float[] {1, 0, 0};
Sunny Goyalc99cb172017-10-19 16:15:09 -0700131 }
132
Tony Wickhama447bd82017-12-05 14:24:37 -0800133 public float getHoseatAlpha(Launcher launcher) {
134 return 1f;
135 }
136
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700137 public void onStateEnabled(Launcher launcher) {
138 dispatchWindowStateChanged(launcher);
139 }
Sunny Goyalc99cb172017-10-19 16:15:09 -0700140
141 public void onStateDisabled(Launcher launcher) { }
Sunny Goyalbe93f262017-10-20 17:05:27 -0700142
143 public View getFinalFocus(Launcher launcher) {
144 return launcher.getWorkspace();
145 }
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700146
Sunny Goyal228153d2018-01-04 15:35:22 -0800147 /**
148 * Fraction shift in the vertical translation UI and related properties
149 *
150 * @see com.android.launcher3.allapps.AllAppsTransitionController
151 */
152 public float getVerticalProgress(Launcher launcher) {
153 return 1f;
154 }
155
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700156 public String getDescription(Launcher launcher) {
157 return launcher.getWorkspace().getCurrentPageDescription();
158 }
159
Sunny Goyalbc683e92017-12-06 10:25:07 -0800160 public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
161 if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
162 return DEFAULT_ALPHA_PROVIDER;
163 }
Sunny Goyal228153d2018-01-04 15:35:22 -0800164 final int centerPage = launcher.getWorkspace().getNextPage();
Sunny Goyal0c723352017-12-12 12:02:29 -0800165 return new PageAlphaProvider(ACCEL_2) {
166 @Override
167 public float getPageAlpha(int pageIndex) {
168 return pageIndex != centerPage ? 0 : 1f;
169 }
170 };
Sunny Goyalbc683e92017-12-06 10:25:07 -0800171 }
172
Sunny Goyal49bcf342018-01-11 13:59:53 -0800173 public LauncherState getHistoryForState(LauncherState previousState) {
174 // No history is supported
175 return NORMAL;
176 }
177
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700178 protected static void dispatchWindowStateChanged(Launcher launcher) {
179 launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
180 }
Sunny Goyalbc683e92017-12-06 10:25:07 -0800181
Sunny Goyal0c723352017-12-12 12:02:29 -0800182 public static abstract class PageAlphaProvider {
Sunny Goyalbc683e92017-12-06 10:25:07 -0800183
Sunny Goyal0c723352017-12-12 12:02:29 -0800184 public final Interpolator interpolator;
185
186 public PageAlphaProvider(Interpolator interpolator) {
187 this.interpolator = interpolator;
188 }
189
190 public abstract float getPageAlpha(int pageIndex);
Sunny Goyalbc683e92017-12-06 10:25:07 -0800191 }
Sunny Goyal4c7f2152017-10-17 17:17:16 -0700192}