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