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.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;
19 
20 import android.content.Context;
21 import android.graphics.Color;
22 
23 import com.android.launcher3.BaseDraggingActivity;
24 import com.android.launcher3.DeviceProfile;
25 import com.android.launcher3.Launcher;
26 import com.android.launcher3.R;
27 import com.android.launcher3.allapps.AllAppsTransitionController;
28 import com.android.quickstep.util.LayoutUtils;
29 import com.android.quickstep.views.RecentsView;
30 
31 /**
32  * State indicating that the Launcher is behind an app
33  */
34 public class BackgroundAppState extends OverviewState {
35 
36     private static final int STATE_FLAGS = FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI
37             | FLAG_WORKSPACE_INACCESSIBLE | FLAG_NON_INTERACTIVE | FLAG_CLOSE_POPUPS;
38 
BackgroundAppState(int id)39     public BackgroundAppState(int id) {
40         this(id, LAUNCHER_STATE_BACKGROUND);
41     }
42 
BackgroundAppState(int id, int logContainer)43     protected BackgroundAppState(int id, int logContainer) {
44         super(id, logContainer, STATE_FLAGS);
45     }
46 
47     @Override
getVerticalProgress(Launcher launcher)48     public float getVerticalProgress(Launcher launcher) {
49         if (launcher.getDeviceProfile().isVerticalBarLayout()) {
50             return super.getVerticalProgress(launcher);
51         }
52         RecentsView recentsView = launcher.getOverviewPanel();
53         int transitionLength = LayoutUtils.getShelfTrackingDistance(launcher,
54                 launcher.getDeviceProfile(),
55                 recentsView.getPagedOrientationHandler());
56         AllAppsTransitionController controller = launcher.getAllAppsController();
57         float scrollRange = Math.max(controller.getShiftRange(), 1);
58         float progressDelta = (transitionLength / scrollRange);
59         return super.getVerticalProgress(launcher) + progressDelta;
60     }
61 
62     @Override
getOverviewScaleAndOffset(Launcher launcher)63     public float[] getOverviewScaleAndOffset(Launcher launcher) {
64         return getOverviewScaleAndOffsetForBackgroundState(launcher);
65     }
66 
67     @Override
getOverviewFullscreenProgress()68     public float getOverviewFullscreenProgress() {
69         return 1;
70     }
71 
72     @Override
getVisibleElements(Launcher launcher)73     public int getVisibleElements(Launcher launcher) {
74         return super.getVisibleElements(launcher)
75                 & ~OVERVIEW_ACTIONS
76                 & ~CLEAR_ALL_BUTTON
77                 & ~VERTICAL_SWIPE_INDICATOR;
78     }
79 
80     @Override
displayOverviewTasksAsGrid(DeviceProfile deviceProfile)81     public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
82         return false;
83     }
84 
85     @Override
getDepthUnchecked(Context context)86     protected float getDepthUnchecked(Context context) {
87         return 1;
88     }
89 
90     @Override
getWorkspaceScrimColor(Launcher launcher)91     public int getWorkspaceScrimColor(Launcher launcher) {
92         DeviceProfile dp = launcher.getDeviceProfile();
93         if (dp.isTaskbarPresentInApps) {
94             return launcher.getColor(R.color.taskbar_background);
95         }
96         return Color.TRANSPARENT;
97     }
98 
getOverviewScaleAndOffsetForBackgroundState( BaseDraggingActivity activity)99     public static float[] getOverviewScaleAndOffsetForBackgroundState(
100             BaseDraggingActivity activity) {
101         return new float[] {
102                 ((RecentsView) activity.getOverviewPanel()).getMaxScaleForFullScreen(),
103                 NO_OFFSET};
104     }
105 }
106