1 /*
2  * Copyright (C) 2017 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.anim.Interpolators.DEACCEL_2;
19 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW;
20 
21 import android.content.Context;
22 import android.graphics.Rect;
23 import android.os.SystemProperties;
24 
25 import com.android.launcher3.DeviceProfile;
26 import com.android.launcher3.Launcher;
27 import com.android.launcher3.LauncherState;
28 import com.android.launcher3.R;
29 import com.android.launcher3.util.Themes;
30 import com.android.quickstep.SysUINavigationMode;
31 import com.android.quickstep.util.LayoutUtils;
32 import com.android.quickstep.views.RecentsView;
33 import com.android.quickstep.views.TaskView;
34 
35 /**
36  * Definition for overview state
37  */
38 public class OverviewState extends LauncherState {
39 
40     protected static final Rect sTempRect = new Rect();
41 
42     private static final int STATE_FLAGS = FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED
43             | FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI | FLAG_WORKSPACE_INACCESSIBLE
44             | FLAG_CLOSE_POPUPS;
45 
OverviewState(int id)46     public OverviewState(int id) {
47         this(id, STATE_FLAGS);
48     }
49 
OverviewState(int id, int stateFlags)50     protected OverviewState(int id, int stateFlags) {
51         this(id, LAUNCHER_STATE_OVERVIEW, stateFlags);
52     }
53 
OverviewState(int id, int logContainer, int stateFlags)54     protected OverviewState(int id, int logContainer, int stateFlags) {
55         super(id, logContainer, stateFlags);
56     }
57 
58     @Override
getTransitionDuration(Context context)59     public int getTransitionDuration(Context context) {
60         // In gesture modes, overview comes in all the way from the side, so give it more time.
61         return SysUINavigationMode.INSTANCE.get(context).getMode().hasGestures ? 380 : 250;
62     }
63 
64     @Override
getWorkspaceScaleAndTranslation(Launcher launcher)65     public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
66         RecentsView recentsView = launcher.getOverviewPanel();
67         float workspacePageWidth = launcher.getDeviceProfile().getWorkspaceWidth();
68         recentsView.getTaskSize(sTempRect);
69         float scale = (float) sTempRect.width() / workspacePageWidth;
70         float parallaxFactor = 0.5f;
71         return new ScaleAndTranslation(scale, 0, -getDefaultSwipeHeight(launcher) * parallaxFactor);
72     }
73 
74     @Override
getOverviewScaleAndOffset(Launcher launcher)75     public float[] getOverviewScaleAndOffset(Launcher launcher) {
76         return new float[] {NO_SCALE, NO_OFFSET};
77     }
78 
79     @Override
getWorkspacePageAlphaProvider(Launcher launcher)80     public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
81         return new PageAlphaProvider(DEACCEL_2) {
82             @Override
83             public float getPageAlpha(int pageIndex) {
84                 return 0;
85             }
86         };
87     }
88 
89     @Override
90     public int getVisibleElements(Launcher launcher) {
91         return CLEAR_ALL_BUTTON | OVERVIEW_ACTIONS;
92     }
93 
94     @Override
95     public boolean isTaskbarStashed(Launcher launcher) {
96         return true;
97     }
98 
99     @Override
100     public int getWorkspaceScrimColor(Launcher launcher) {
101         return Themes.getAttrColor(launcher, R.attr.overviewScrimColor);
102     }
103 
104     @Override
105     public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
106         return deviceProfile.overviewShowAsGrid;
107     }
108 
109     @Override
110     public String getDescription(Launcher launcher) {
111         return launcher.getString(R.string.accessibility_recent_apps);
112     }
113 
114     public static float getDefaultSwipeHeight(Launcher launcher) {
115         return LayoutUtils.getDefaultSwipeHeight(launcher, launcher.getDeviceProfile());
116     }
117 
118     @Override
119     protected float getDepthUnchecked(Context context) {
120         //TODO revert when b/178661709 is fixed
121         return SystemProperties.getBoolean("ro.launcher.depth.overview", true) ? 1 : 0;
122     }
123 
124     @Override
125     public void onBackPressed(Launcher launcher) {
126         TaskView taskView = launcher.<RecentsView>getOverviewPanel().getRunningTaskView();
127         if (taskView != null) {
128             taskView.launchTaskAnimated();
129         } else {
130             super.onBackPressed(launcher);
131         }
132     }
133 
134     public static OverviewState newBackgroundState(int id) {
135         return new BackgroundAppState(id);
136     }
137 
138     public static OverviewState newSwitchState(int id) {
139         return new QuickSwitchState(id);
140     }
141 
142     /**
143      *  New Overview substate that represents the overview in modal mode (one task shown on its own)
144      */
145     public static OverviewState newModalTaskState(int id) {
146         return new OverviewModalTaskState(id);
147     }
148 
149     /**
150      * New Overview substate representing state where 1 app for split screen has been selected and
151      * pinned and user is selecting the second one
152      */
153     public static OverviewState newSplitSelectState(int id) {
154         return new SplitScreenSelectState(id);
155     }
156 }
157