1 /* 2 * Copyright (C) 2020 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.quickstep.fallback; 17 18 import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS; 19 import static com.android.launcher3.uioverrides.states.BackgroundAppState.getOverviewScaleAndOffsetForBackgroundState; 20 import static com.android.launcher3.uioverrides.states.OverviewModalTaskState.getOverviewScaleAndOffsetForModalState; 21 22 import android.content.Context; 23 import android.graphics.Color; 24 25 import com.android.launcher3.DeviceProfile; 26 import com.android.launcher3.R; 27 import com.android.launcher3.statemanager.BaseState; 28 import com.android.launcher3.util.Themes; 29 import com.android.quickstep.views.RecentsViewContainer; 30 31 /** 32 * State definition for Fallback recents 33 */ 34 public class RecentsState implements BaseState<RecentsState> { 35 36 private static final int FLAG_MODAL = BaseState.getFlag(0); 37 private static final int FLAG_CLEAR_ALL_BUTTON = BaseState.getFlag(1); 38 private static final int FLAG_FULL_SCREEN = BaseState.getFlag(2); 39 private static final int FLAG_OVERVIEW_ACTIONS = BaseState.getFlag(3); 40 private static final int FLAG_SHOW_AS_GRID = BaseState.getFlag(4); 41 private static final int FLAG_SCRIM = BaseState.getFlag(5); 42 private static final int FLAG_LIVE_TILE = BaseState.getFlag(6); 43 private static final int FLAG_RECENTS_VIEW_VISIBLE = BaseState.getFlag(7); 44 private static final int FLAG_TASK_THUMBNAIL_SPLASH = BaseState.getFlag(8); 45 46 public static final RecentsState DEFAULT = new RecentsState(0, 47 FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_SHOW_AS_GRID 48 | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_RECENTS_VIEW_VISIBLE); 49 public static final RecentsState MODAL_TASK = new ModalState(1, 50 FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_MODAL 51 | FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_RECENTS_VIEW_VISIBLE); 52 public static final RecentsState BACKGROUND_APP = new BackgroundAppState(2, 53 FLAG_DISABLE_RESTORE | FLAG_NON_INTERACTIVE | FLAG_FULL_SCREEN 54 | FLAG_RECENTS_VIEW_VISIBLE 55 | FLAG_TASK_THUMBNAIL_SPLASH); 56 public static final RecentsState HOME = new RecentsState(3, 0); 57 public static final RecentsState BG_LAUNCHER = new LauncherState(4, 0); 58 public static final RecentsState OVERVIEW_SPLIT_SELECT = new RecentsState(5, 59 FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_RECENTS_VIEW_VISIBLE | FLAG_CLOSE_POPUPS 60 | FLAG_DISABLE_RESTORE); 61 62 public final int ordinal; 63 private final int mFlags; 64 65 private static final float NO_OFFSET = 0; 66 private static final float NO_SCALE = 1; 67 RecentsState(int id, int flags)68 public RecentsState(int id, int flags) { 69 this.ordinal = id; 70 this.mFlags = flags; 71 } 72 73 74 @Override toString()75 public String toString() { 76 return "Ordinal-" + ordinal; 77 } 78 79 @Override hasFlag(int mask)80 public final boolean hasFlag(int mask) { 81 return (mFlags & mask) != 0; 82 } 83 84 @Override getTransitionDuration(Context context, boolean isToState)85 public int getTransitionDuration(Context context, boolean isToState) { 86 return 250; 87 } 88 89 @Override getHistoryForState(RecentsState previousState)90 public RecentsState getHistoryForState(RecentsState previousState) { 91 return DEFAULT; 92 } 93 94 /** 95 * For this state, how modal should over view been shown. 0 modalness means all tasks drawn, 96 * 1 modalness means the current task is show on its own. 97 */ getOverviewModalness()98 public float getOverviewModalness() { 99 return hasFlag(FLAG_MODAL) ? 1 : 0; 100 } 101 isFullScreen()102 public boolean isFullScreen() { 103 return hasFlag(FLAG_FULL_SCREEN); 104 } 105 106 /** 107 * For this state, whether clear all button should be shown. 108 */ hasClearAllButton()109 public boolean hasClearAllButton() { 110 return hasFlag(FLAG_CLEAR_ALL_BUTTON); 111 } 112 113 /** 114 * For this state, whether overview actions should be shown. 115 */ hasOverviewActions()116 public boolean hasOverviewActions() { 117 return hasFlag(FLAG_OVERVIEW_ACTIONS); 118 } 119 120 /** 121 * For this state, whether live tile should be shown. 122 */ hasLiveTile()123 public boolean hasLiveTile() { 124 return hasFlag(FLAG_LIVE_TILE); 125 } 126 127 /** 128 * For this state, what color scrim should be drawn behind overview. 129 */ getScrimColor(Context context)130 public int getScrimColor(Context context) { 131 return hasFlag(FLAG_SCRIM) 132 ? Themes.getAttrColor(context, R.attr.overviewScrimColor) 133 : Color.TRANSPARENT; 134 } 135 getOverviewScaleAndOffset(RecentsViewContainer container)136 public float[] getOverviewScaleAndOffset(RecentsViewContainer container) { 137 return new float[] { NO_SCALE, NO_OFFSET }; 138 } 139 140 /** 141 * For this state, whether tasks should layout as a grid rather than a list. 142 */ displayOverviewTasksAsGrid(DeviceProfile deviceProfile)143 public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) { 144 return hasFlag(FLAG_SHOW_AS_GRID) && deviceProfile.isTablet; 145 } 146 147 @Override showTaskThumbnailSplash()148 public boolean showTaskThumbnailSplash() { 149 return hasFlag(FLAG_TASK_THUMBNAIL_SPLASH); 150 } 151 152 /** 153 * True if the state has overview panel visible. 154 */ isRecentsViewVisible()155 public boolean isRecentsViewVisible() { 156 return hasFlag(FLAG_RECENTS_VIEW_VISIBLE); 157 } 158 159 private static class ModalState extends RecentsState { 160 ModalState(int id, int flags)161 public ModalState(int id, int flags) { 162 super(id, flags); 163 } 164 165 @Override getOverviewScaleAndOffset(RecentsViewContainer container)166 public float[] getOverviewScaleAndOffset(RecentsViewContainer container) { 167 return getOverviewScaleAndOffsetForModalState(container.getOverviewPanel()); 168 } 169 } 170 171 private static class BackgroundAppState extends RecentsState { BackgroundAppState(int id, int flags)172 public BackgroundAppState(int id, int flags) { 173 super(id, flags); 174 } 175 176 @Override getOverviewScaleAndOffset(RecentsViewContainer container)177 public float[] getOverviewScaleAndOffset(RecentsViewContainer container) { 178 return getOverviewScaleAndOffsetForBackgroundState(container.getOverviewPanel()); 179 } 180 } 181 182 private static class LauncherState extends RecentsState { LauncherState(int id, int flags)183 LauncherState(int id, int flags) { 184 super(id, flags); 185 } 186 187 @Override getOverviewScaleAndOffset(RecentsViewContainer container)188 public float[] getOverviewScaleAndOffset(RecentsViewContainer container) { 189 return new float[] { NO_SCALE, 1 }; 190 } 191 } 192 } 193