1 /* 2 * Copyright (C) 2018 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.Flags.enableDesktopWindowingCarouselDetach; 19 import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; 20 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND; 21 22 import android.content.Context; 23 import android.graphics.Color; 24 25 import com.android.launcher3.DeviceProfile; 26 import com.android.launcher3.Launcher; 27 import com.android.launcher3.allapps.AllAppsTransitionController; 28 import com.android.quickstep.util.BaseDepthController; 29 import com.android.quickstep.util.LayoutUtils; 30 import com.android.quickstep.views.RecentsView; 31 32 /** 33 * State indicating that the Launcher is behind an app 34 */ 35 public class BackgroundAppState extends OverviewState { 36 37 private static final int STATE_FLAGS = FLAG_DISABLE_RESTORE | FLAG_RECENTS_VIEW_VISIBLE 38 | FLAG_WORKSPACE_INACCESSIBLE | FLAG_NON_INTERACTIVE | FLAG_CLOSE_POPUPS; 39 BackgroundAppState(int id)40 public BackgroundAppState(int id) { 41 this(id, LAUNCHER_STATE_BACKGROUND); 42 } 43 BackgroundAppState(int id, int logContainer)44 protected BackgroundAppState(int id, int logContainer) { 45 super(id, logContainer, STATE_FLAGS); 46 } 47 48 @Override getVerticalProgress(Launcher launcher)49 public float getVerticalProgress(Launcher launcher) { 50 if (launcher.getDeviceProfile().isVerticalBarLayout()) { 51 return super.getVerticalProgress(launcher); 52 } 53 RecentsView recentsView = launcher.getOverviewPanel(); 54 int transitionLength = LayoutUtils.getShelfTrackingDistance( 55 launcher, 56 launcher.getDeviceProfile(), 57 recentsView.getPagedOrientationHandler(), 58 recentsView.getSizeStrategy()); 59 AllAppsTransitionController controller = launcher.getAllAppsController(); 60 float scrollRange = Math.max(controller.getShiftRange(), 1); 61 float progressDelta = (transitionLength / scrollRange); 62 return super.getVerticalProgress(launcher) + progressDelta; 63 } 64 65 @Override getOverviewScaleAndOffset(Launcher launcher)66 public float[] getOverviewScaleAndOffset(Launcher launcher) { 67 return getOverviewScaleAndOffsetForBackgroundState(launcher.getOverviewPanel()); 68 } 69 70 @Override getOverviewFullscreenProgress()71 public float getOverviewFullscreenProgress() { 72 return 1; 73 } 74 75 @Override getVisibleElements(Launcher launcher)76 public int getVisibleElements(Launcher launcher) { 77 return super.getVisibleElements(launcher) 78 & ~OVERVIEW_ACTIONS 79 & ~CLEAR_ALL_BUTTON 80 & ~VERTICAL_SWIPE_INDICATOR 81 & ~ADD_DESK_BUTTON; 82 } 83 84 @Override displayOverviewTasksAsGrid(DeviceProfile deviceProfile)85 public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) { 86 return false; 87 } 88 89 @Override showTaskThumbnailSplash()90 public boolean showTaskThumbnailSplash() { 91 return true; 92 } 93 94 @Override detachDesktopCarousel()95 public boolean detachDesktopCarousel() { 96 return enableDesktopWindowingCarouselDetach(); 97 } 98 99 @Override showExplodedDesktopView()100 public boolean showExplodedDesktopView() { 101 return false; 102 } 103 104 @Override getDepthUnchecked(Context context)105 protected float getDepthUnchecked(Context context) { 106 if (Launcher.getLauncher(context).areDesktopTasksVisible()) { 107 // Don't blur the background while desktop tasks are visible 108 return BaseDepthController.DEPTH_0_PERCENT; 109 } else if (enableScalingRevealHomeAnimation()) { 110 return BaseDepthController.DEPTH_70_PERCENT; 111 } else { 112 return 1f; 113 } 114 } 115 116 @Override getWorkspaceScrimColor(Launcher launcher)117 public int getWorkspaceScrimColor(Launcher launcher) { 118 return Color.TRANSPARENT; 119 } 120 121 @Override isTaskbarAlignedWithHotseat(Launcher launcher)122 public boolean isTaskbarAlignedWithHotseat(Launcher launcher) { 123 return false; 124 } 125 126 @Override disallowTaskbarGlobalDrag()127 public boolean disallowTaskbarGlobalDrag() { 128 // Enable global drag in overview 129 return false; 130 } 131 132 @Override allowTaskbarInitialSplitSelection()133 public boolean allowTaskbarInitialSplitSelection() { 134 // Disallow split select from taskbar items in overview 135 return false; 136 } 137 getOverviewScaleAndOffsetForBackgroundState( RecentsView recentsView)138 public static float[] getOverviewScaleAndOffsetForBackgroundState( 139 RecentsView recentsView) { 140 return new float[] {recentsView.getMaxScaleForFullScreen(), NO_OFFSET}; 141 } 142 } 143