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; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 22 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 23 | import android.view.View; |
| 24 | |
| 25 | import com.android.launcher3.states.AllAppsState; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 26 | import com.android.launcher3.states.OverviewState; |
| 27 | import com.android.launcher3.states.SpringLoadedState; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 28 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 29 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 30 | import java.util.Arrays; |
| 31 | |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 34 | * Base state for various states used for the Launcher |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 35 | */ |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 36 | public class LauncherState { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 37 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 38 | protected static final int FLAG_SHOW_SCRIM = 1 << 0; |
| 39 | protected static final int FLAG_MULTI_PAGE = 1 << 1; |
| 40 | protected static final int FLAG_HIDE_HOTSEAT = 1 << 2; |
| 41 | protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 3; |
| 42 | protected static final int FLAG_DO_NOT_RESTORE = 1 << 4; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 43 | protected static final int FLAG_HAS_SPRING = 1 << 5; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 44 | |
| 45 | private static final LauncherState[] sAllStates = new LauncherState[4]; |
| 46 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 47 | public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 48 | 0, 1f, FLAG_DO_NOT_RESTORE); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 49 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 50 | public static final LauncherState ALL_APPS = new AllAppsState(1); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 51 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 52 | public static final LauncherState SPRING_LOADED = new SpringLoadedState(2); |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 53 | |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 54 | public static final LauncherState OVERVIEW = new OverviewState(3); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 55 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 56 | public final int ordinal; |
| 57 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher} |
| 60 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 61 | public final int containerType; |
| 62 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 63 | /** |
| 64 | * True if the state can be persisted across activity restarts. |
| 65 | */ |
| 66 | public final boolean doNotRestore; |
| 67 | |
| 68 | /** |
| 69 | * True if workspace has multiple pages visible. |
| 70 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 71 | public final boolean hasMultipleVisiblePages; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Accessibility flag for workspace and its pages. |
| 75 | * @see android.view.View#setImportantForAccessibility(int) |
| 76 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 77 | public final int workspaceAccessibilityFlag; |
| 78 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 79 | /** |
| 80 | * Properties related to state transition animation |
| 81 | * |
| 82 | * @see WorkspaceStateTransitionAnimation |
| 83 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 84 | public final boolean hasScrim; |
| 85 | public final boolean hideHotseat; |
| 86 | public final int transitionDuration; |
| 87 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 88 | /** |
| 89 | * Fraction shift in the vertical translation UI and related properties |
| 90 | * |
| 91 | * @see com.android.launcher3.allapps.AllAppsTransitionController |
| 92 | */ |
| 93 | public final float verticalProgress; |
| 94 | public final boolean hasVerticalSpring; |
| 95 | |
| 96 | public LauncherState(int id, int containerType, int transitionDuration, float verticalProgress, |
| 97 | int flags) { |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 98 | this.containerType = containerType; |
| 99 | this.transitionDuration = transitionDuration; |
| 100 | |
| 101 | this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0; |
| 102 | this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0; |
| 103 | this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0; |
| 104 | this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0 |
| 105 | ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 106 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 107 | this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0; |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 108 | |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 109 | this.verticalProgress = verticalProgress; |
| 110 | this.hasVerticalSpring = (flags & FLAG_HAS_SPRING) != 0; |
| 111 | |
Sunny Goyal | cd7c0aa | 2017-10-19 12:36:27 -0700 | [diff] [blame] | 112 | this.ordinal = id; |
| 113 | sAllStates[id] = this; |
| 114 | } |
| 115 | |
| 116 | public static LauncherState[] values() { |
| 117 | return Arrays.copyOf(sAllStates, sAllStates.length); |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 118 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 119 | |
| 120 | public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { |
| 121 | return new float[] {1, 0}; |
| 122 | } |
| 123 | |
| 124 | public void onStateEnabled(Launcher launcher) { } |
| 125 | |
| 126 | public void onStateDisabled(Launcher launcher) { } |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame^] | 127 | |
| 128 | public View getFinalFocus(Launcher launcher) { |
| 129 | return launcher.getWorkspace(); |
| 130 | } |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 131 | } |