blob: 67135d5621b45baabc7b6c8cc95b702011fc22b2 [file] [log] [blame]
Winson Chung303e1ff2014-03-07 15:06:19 -08001/*
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
17package com.android.systemui.recents;
18
19import android.content.Context;
Winson Chungc620baf2014-03-19 17:15:29 -070020import android.content.res.Resources;
Winson Chung303e1ff2014-03-07 15:06:19 -080021import android.graphics.Rect;
Winson Chung2f2ca082014-04-03 18:05:29 -070022import com.android.systemui.R;
Jason Monk56e09b42014-07-18 10:29:14 -040023import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chung303e1ff2014-03-07 15:06:19 -080024
Winson35f30502015-09-28 11:24:36 -070025/**
26 * Application resources that can be retrieved from the application context and are not specifically
27 * tied to the current activity.
28 */
Winson Chung303e1ff2014-03-07 15:06:19 -080029public class RecentsConfiguration {
Winson35f30502015-09-28 11:24:36 -070030
31 private static final int LARGE_SCREEN_MIN_DP = 600;
32 private static final int XLARGE_SCREEN_MIN_DP = 720;
33
34 // Variables that are used for global calculations
35 private static final float STACK_SIDE_PADDING_PHONES_PCT = 0.03333f;
36 private static final float STACK_SIZE_PADDING_TABLETS_PCT = 0.075f;
37 private static final float STACK_SIZE_PADDING_LARGE_TABLETS_PCT = 0.15f;
38 private static final int SEARCH_BAR_SPACE_HEIGHT_PHONES_DPS = 64;
39 private static final int SEARCH_BAR_SPACE_HEIGHT_TABLETS_DPS = 72;
Winson Chung303e1ff2014-03-07 15:06:19 -080040
Winson Chung96d70412014-11-12 14:17:17 -080041 /** Levels of svelte in increasing severity/austerity. */
42 // No svelting.
43 public static final int SVELTE_NONE = 0;
44 // Limit thumbnail cache to number of visible thumbnails when Recents was loaded, disable
45 // caching thumbnails as you scroll.
46 public static final int SVELTE_LIMIT_CACHE = 1;
47 // Disable the thumbnail cache, load thumbnails asynchronously when the activity loads and
48 // evict all thumbnails when hidden.
49 public static final int SVELTE_DISABLE_CACHE = 2;
50 // Disable all thumbnail loading.
51 public static final int SVELTE_DISABLE_LOADING = 3;
52
Winson35f30502015-09-28 11:24:36 -070053 // Launch states
Winson53ec42c2015-10-28 15:55:35 -070054 public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState();
Winson Chung918c0722014-05-08 15:04:23 -070055
Winson35f30502015-09-28 11:24:36 -070056 // TODO: Values determined by the current context, needs to be refactored into something that is
57 // agnostic of the activity context, but still calculable from the Recents component for
58 // the transition into recents
Winson Chung27acf762014-09-05 17:24:20 +020059 boolean hasTransposedSearchBar;
60 boolean hasTransposedNavBar;
Winson Chungd42a6cf2014-06-03 16:24:04 -070061 public float taskStackWidthPaddingPct;
62
Winson35f30502015-09-28 11:24:36 -070063 // Since the positions in Recents has to be calculated globally (before the RecentsActivity
64 // starts), we need to calculate some resource values ourselves, instead of relying on framework
65 // resources.
66 public final boolean isLargeScreen;
67 public final boolean isXLargeScreen;
68 public final int smallestWidth;
Winson Chungb44c24f2014-04-09 15:17:43 -070069
Winson Chunga0e88b52014-08-11 19:25:42 -070070 /** Misc **/
Selim Cineke8199c52014-09-17 04:03:52 +020071 public boolean useHardwareLayers;
Jorim Jaggicb557032014-09-16 23:09:24 +020072 public boolean fakeShadows;
Winson35f30502015-09-28 11:24:36 -070073 public int svelteLevel;
74 public int searchBarSpaceHeightPx;
Winson Chunga0e88b52014-08-11 19:25:42 -070075
Winson53ec42c2015-10-28 15:55:35 -070076 public RecentsConfiguration(Context context) {
Winson35f30502015-09-28 11:24:36 -070077 // Load only resources that can not change after the first load either through developer
78 // settings or via multi window
Winson53ec42c2015-10-28 15:55:35 -070079 SystemServicesProxy ssp = Recents.getSystemServices();
Winson35f30502015-09-28 11:24:36 -070080 Context appContext = context.getApplicationContext();
81 Resources res = appContext.getResources();
82 useHardwareLayers = res.getBoolean(R.bool.config_recents_use_hardware_layers);
83 fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
84 svelteLevel = res.getInteger(R.integer.recents_svelte_level);
Winson Chung06795632014-06-17 15:53:44 -070085
Winson35f30502015-09-28 11:24:36 -070086 float density = context.getResources().getDisplayMetrics().density;
87 smallestWidth = ssp.getDeviceSmallestWidth();
88 isLargeScreen = smallestWidth >= (int) (density * LARGE_SCREEN_MIN_DP);
89 isXLargeScreen = smallestWidth >= (int) (density * XLARGE_SCREEN_MIN_DP);
90 searchBarSpaceHeightPx = isLargeScreen ?
91 (int) (density * SEARCH_BAR_SPACE_HEIGHT_TABLETS_DPS) :
92 (int) (density * SEARCH_BAR_SPACE_HEIGHT_PHONES_DPS);
93 if (isLargeScreen) {
94 taskStackWidthPaddingPct = STACK_SIZE_PADDING_TABLETS_PCT;
95 } else if (isXLargeScreen) {
96 taskStackWidthPaddingPct = STACK_SIZE_PADDING_LARGE_TABLETS_PCT;
97 } else {
98 taskStackWidthPaddingPct = STACK_SIDE_PADDING_PHONES_PCT;
99 }
100 }
101
102 /**
103 * Updates the configuration based on the current state of the system
104 */
Winson Chung931c51f2015-12-17 17:08:55 -0500105 void update(Rect windowRect) {
Winson35f30502015-09-28 11:24:36 -0700106 // Recompute some values based on the given state, since we can not rely on the resource
107 // system to get certain values.
108 boolean isLandscape = windowRect.width() > windowRect.height();
Winson23746d52015-12-03 16:13:07 -0800109 hasTransposedNavBar = isLandscape && !isXLargeScreen;
110 hasTransposedSearchBar = isLandscape && !isXLargeScreen;
Winson Chung06795632014-06-17 15:53:44 -0700111 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800112
Winson35f30502015-09-28 11:24:36 -0700113 /**
114 * Returns the activity launch state.
115 * TODO: This will be refactored out of RecentsConfiguration.
116 */
117 public RecentsActivityLaunchState getLaunchState() {
118 return mLaunchState;
Jason Monk56e09b42014-07-18 10:29:14 -0400119 }
120
Winsone7f138c2015-10-22 16:15:21 -0700121 /**
122 * Called when the configuration has changed, and we want to reset any configuration specific
123 * members.
124 */
Winson Chungb01ed682014-05-29 14:25:42 -0700125 public void updateOnConfigurationChange() {
Winson35f30502015-09-28 11:24:36 -0700126 mLaunchState.updateOnConfigurationChange();
Winson Chung521e7dc2014-06-02 15:31:56 -0700127 }
128
Winson Chungf7bca432014-04-30 17:11:13 -0700129 /**
130 * Returns the task stack bounds in the current orientation. These bounds do not account for
131 * the system insets.
132 */
Winson88f00ab2015-10-05 17:24:00 -0700133 public void getTaskStackBounds(Rect windowBounds, int topInset,
Winson Chungaf3bb692015-06-03 17:31:39 -0700134 int rightInset, Rect searchBarBounds, Rect taskStackBounds) {
Winson35f30502015-09-28 11:24:36 -0700135 if (hasTransposedNavBar) {
136 // In landscape phones, the search bar appears on the left, but we overlay it on top
Winson Chungead5c0f2015-12-14 11:18:57 -0500137 taskStackBounds.set(windowBounds.left, windowBounds.top + topInset,
138 windowBounds.right - rightInset, windowBounds.bottom);
Winson Chungf7bca432014-04-30 17:11:13 -0700139 } else {
Winson Chungdcfa7972014-07-22 12:27:13 -0700140 // In portrait, the search bar appears on the top (which already has the inset)
Winson2364f262015-10-26 10:56:59 -0700141 int top = searchBarBounds.isEmpty() ? topInset : 0;
Winson Chungead5c0f2015-12-14 11:18:57 -0500142 taskStackBounds.set(windowBounds.left, searchBarBounds.bottom + top,
143 windowBounds.right - rightInset, windowBounds.bottom);
Winson Chungf7bca432014-04-30 17:11:13 -0700144 }
145 }
146
147 /**
148 * Returns the search bar bounds in the current orientation. These bounds do not account for
149 * the system insets.
150 */
Winson147ecaf2015-09-16 16:49:55 -0700151 public void getSearchBarBounds(Rect windowBounds, int topInset, Rect searchBarSpaceBounds) {
Winson Chungecd9b302014-04-16 17:07:18 -0700152 // Return empty rects if search is not enabled
Winson Chungdcfa7972014-07-22 12:27:13 -0700153 int searchBarSize = searchBarSpaceHeightPx;
Winson35f30502015-09-28 11:24:36 -0700154 if (hasTransposedSearchBar) {
155 // In landscape phones, the search bar appears on the left
Winson147ecaf2015-09-16 16:49:55 -0700156 searchBarSpaceBounds.set(windowBounds.left, windowBounds.top + topInset,
157 windowBounds.left + searchBarSize, windowBounds.bottom);
Winson Chungf7bca432014-04-30 17:11:13 -0700158 } else {
159 // In portrait, the search bar appears on the top
Winson147ecaf2015-09-16 16:49:55 -0700160 searchBarSpaceBounds.set(windowBounds.left, windowBounds.top + topInset,
161 windowBounds.right, windowBounds.top + topInset + searchBarSize);
Winson Chungf7bca432014-04-30 17:11:13 -0700162 }
Winson Chungecd9b302014-04-16 17:07:18 -0700163 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800164}