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.launcher3.uioverrides.states; 17 18 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW; 19 20 import android.content.Context; 21 import android.graphics.Rect; 22 23 import com.android.launcher3.Flags; 24 import com.android.launcher3.Launcher; 25 import com.android.launcher3.LauncherState; 26 import com.android.quickstep.views.RecentsView; 27 28 /** 29 * An Overview state that shows the current task in a modal fashion. Modal state is where the 30 * current task is shown on its own without other tasks visible. 31 */ 32 public class OverviewModalTaskState extends OverviewState { 33 34 private static final int STATE_FLAGS = 35 FLAG_DISABLE_RESTORE | FLAG_RECENTS_VIEW_VISIBLE | FLAG_WORKSPACE_INACCESSIBLE; 36 OverviewModalTaskState(int id)37 public OverviewModalTaskState(int id) { 38 super(id, LAUNCHER_STATE_OVERVIEW, STATE_FLAGS); 39 } 40 41 @Override getTransitionDuration(Context launcher, boolean isToState)42 public int getTransitionDuration(Context launcher, boolean isToState) { 43 return 300; 44 } 45 46 @Override getVisibleElements(Launcher launcher)47 public int getVisibleElements(Launcher launcher) { 48 return OVERVIEW_ACTIONS | CLEAR_ALL_BUTTON; 49 } 50 51 @Override getOverviewScaleAndOffset(Launcher launcher)52 public float[] getOverviewScaleAndOffset(Launcher launcher) { 53 return getOverviewScaleAndOffsetForModalState(launcher.getOverviewPanel()); 54 } 55 56 @Override getOverviewModalness()57 public float getOverviewModalness() { 58 return 1.0f; 59 } 60 61 @Override onBackInvoked(Launcher launcher)62 public void onBackInvoked(Launcher launcher) { 63 launcher.getStateManager().goToState(LauncherState.OVERVIEW); 64 } 65 66 @Override isTaskbarStashed(Launcher launcher)67 public boolean isTaskbarStashed(Launcher launcher) { 68 if (Flags.enableGridOnlyOverview()) { 69 return true; 70 } 71 return super.isTaskbarStashed(launcher); 72 } 73 getOverviewScaleAndOffsetForModalState(RecentsView recentsView)74 public static float[] getOverviewScaleAndOffsetForModalState(RecentsView recentsView) { 75 Rect taskSize = recentsView.getSelectedTaskBounds(); 76 Rect modalTaskSize = new Rect(); 77 recentsView.getModalTaskSize(modalTaskSize); 78 79 float scale = Math.min((float) modalTaskSize.height() / taskSize.height(), 80 (float) modalTaskSize.width() / taskSize.width()); 81 82 return new float[] {scale, NO_OFFSET}; 83 } 84 } 85