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.enableScalingRevealHomeAnimation;
19 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;
20 import static com.android.quickstep.TaskAnimationManager.ENABLE_SHELL_TRANSITIONS;
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(launcher,
55                 launcher.getDeviceProfile(),
56                 recentsView.getPagedOrientationHandler());
57         AllAppsTransitionController controller = launcher.getAllAppsController();
58         float scrollRange = Math.max(controller.getShiftRange(), 1);
59         float progressDelta = (transitionLength / scrollRange);
60         return super.getVerticalProgress(launcher) + progressDelta;
61     }
62 
63     @Override
getOverviewScaleAndOffset(Launcher launcher)64     public float[] getOverviewScaleAndOffset(Launcher launcher) {
65         return getOverviewScaleAndOffsetForBackgroundState(launcher.getOverviewPanel());
66     }
67 
68     @Override
getOverviewFullscreenProgress()69     public float getOverviewFullscreenProgress() {
70         return 1;
71     }
72 
73     @Override
getVisibleElements(Launcher launcher)74     public int getVisibleElements(Launcher launcher) {
75         return super.getVisibleElements(launcher)
76                 & ~OVERVIEW_ACTIONS
77                 & ~CLEAR_ALL_BUTTON
78                 & ~VERTICAL_SWIPE_INDICATOR;
79     }
80 
81     @Override
displayOverviewTasksAsGrid(DeviceProfile deviceProfile)82     public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
83         return false;
84     }
85 
86     @Override
showTaskThumbnailSplash()87     public boolean showTaskThumbnailSplash() {
88         return true;
89     }
90 
91     @Override
getDepthUnchecked(Context context)92     protected float getDepthUnchecked(Context context) {
93         if (Launcher.getLauncher(context).areDesktopTasksVisible()) {
94             // Don't blur the background while desktop tasks are visible
95             return BaseDepthController.DEPTH_0_PERCENT;
96         } else if (enableScalingRevealHomeAnimation()) {
97             return BaseDepthController.DEPTH_70_PERCENT;
98         } else {
99             return 1f;
100         }
101     }
102 
103     @Override
getWorkspaceScrimColor(Launcher launcher)104     public int getWorkspaceScrimColor(Launcher launcher) {
105         return Color.TRANSPARENT;
106     }
107 
108     @Override
isTaskbarAlignedWithHotseat(Launcher launcher)109     public boolean isTaskbarAlignedWithHotseat(Launcher launcher) {
110         if (ENABLE_SHELL_TRANSITIONS) return false;
111         return super.isTaskbarAlignedWithHotseat(launcher);
112     }
113 
114     @Override
disallowTaskbarGlobalDrag()115     public boolean disallowTaskbarGlobalDrag() {
116         // Enable global drag in overview
117         return false;
118     }
119 
120     @Override
allowTaskbarInitialSplitSelection()121     public boolean allowTaskbarInitialSplitSelection() {
122         // Disallow split select from taskbar items in overview
123         return false;
124     }
125 
getOverviewScaleAndOffsetForBackgroundState( RecentsView recentsView)126     public static float[] getOverviewScaleAndOffsetForBackgroundState(
127             RecentsView recentsView) {
128         return new float[] {recentsView.getMaxScaleForFullScreen(), NO_OFFSET};
129     }
130 }
131