1 /*
2  * Copyright (C) 2014 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 
17 package com.android.systemui.recents;
18 
19 import android.app.ActivityManager;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.content.res.Resources;
23 
24 import android.os.SystemProperties;
25 
26 import com.android.systemui.R;
27 import com.android.systemui.recents.misc.SystemServicesProxy;
28 import com.android.systemui.recents.views.DockState;
29 
30 /**
31  * Represents the dock regions for each orientation.
32  */
33 class DockRegion {
34     public static DockState[] PHONE_LANDSCAPE = {
35             // We only allow docking to the left in landscape for now on small devices
36             DockState.LEFT
37     };
38     public static DockState[] PHONE_PORTRAIT = {
39             // We only allow docking to the top for now on small devices
40             DockState.TOP
41     };
42     public static DockState[] TABLET_LANDSCAPE = {
43             DockState.LEFT,
44             DockState.RIGHT
45     };
46     public static DockState[] TABLET_PORTRAIT = PHONE_PORTRAIT;
47 }
48 
49 /**
50  * Application resources that can be retrieved from the application context and are not specifically
51  * tied to the current activity.
52  */
53 public class RecentsConfiguration {
54 
55     private static final int LARGE_SCREEN_MIN_DP = 600;
56     private static final int XLARGE_SCREEN_MIN_DP = 720;
57 
58     // Launch states
59     public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState();
60 
61     // Since the positions in Recents has to be calculated globally (before the RecentsActivity
62     // starts), we need to calculate some resource values ourselves, instead of relying on framework
63     // resources.
64     public final boolean isLargeScreen;
65     public final boolean isXLargeScreen;
66     public final int smallestWidth;
67 
68     /** Misc **/
69     public boolean fakeShadows;
70     public int svelteLevel;
71 
72     // Whether this product supports Grid-based Recents. If this is field is set to true, then
73     // Recents will layout task views in a grid mode when there's enough space in the screen.
74     public boolean isGridEnabled;
75 
76     // Support for Android Recents for low ram devices. If this field is set to true, then Recents
77     // will use the alternative layout.
78     public boolean isLowRamDevice;
79 
80     // Enable drag and drop split from Recents. Disabled for low ram devices.
81     public boolean dragToSplitEnabled;
82 
83     private final Context mAppContext;
84 
RecentsConfiguration(Context context)85     public RecentsConfiguration(Context context) {
86         // Load only resources that can not change after the first load either through developer
87         // settings or via multi window
88         SystemServicesProxy ssp = LegacyRecentsImpl.getSystemServices();
89         mAppContext = context.getApplicationContext();
90         Resources res = mAppContext.getResources();
91         fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
92         svelteLevel = res.getInteger(R.integer.recents_svelte_level);
93         isGridEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
94         isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
95         dragToSplitEnabled = !isLowRamDevice;
96 
97         float screenDensity = context.getResources().getDisplayMetrics().density;
98         smallestWidth = ssp.getDeviceSmallestWidth();
99         isLargeScreen = smallestWidth >= (int) (screenDensity * LARGE_SCREEN_MIN_DP);
100         isXLargeScreen = smallestWidth >= (int) (screenDensity * XLARGE_SCREEN_MIN_DP);
101     }
102 
103     /**
104      * Returns the activity launch state.
105      * TODO: This will be refactored out of RecentsConfiguration.
106      */
getLaunchState()107     public RecentsActivityLaunchState getLaunchState() {
108         return mLaunchState;
109     }
110 
111     /**
112      * Returns the preferred dock states for the current orientation.
113      * @return a list of dock states for device and its orientation
114      */
getDockStatesForCurrentOrientation()115     public DockState[] getDockStatesForCurrentOrientation() {
116         boolean isLandscape = mAppContext.getResources().getConfiguration().orientation ==
117                 Configuration.ORIENTATION_LANDSCAPE;
118         RecentsConfiguration config = LegacyRecentsImpl.getConfiguration();
119         if (config.isLargeScreen) {
120             return isLandscape ? DockRegion.TABLET_LANDSCAPE : DockRegion.TABLET_PORTRAIT;
121         } else {
122             return isLandscape ? DockRegion.PHONE_LANDSCAPE : DockRegion.PHONE_PORTRAIT;
123         }
124     }
125 
126 }
127