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