Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 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; |
Winson Chung | c620baf | 2014-03-19 17:15:29 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 21 | import android.graphics.Rect; |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 22 | import com.android.systemui.R; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 23 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 24 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Application resources that can be retrieved from the application context and are not specifically |
| 27 | * tied to the current activity. |
| 28 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 29 | public class RecentsConfiguration { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 30 | |
| 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 Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 40 | |
Winson Chung | 96d7041 | 2014-11-12 14:17:17 -0800 | [diff] [blame] | 41 | /** 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 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 53 | // Launch states |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 54 | public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState(); |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 55 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 56 | // 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 Chung | 27acf76 | 2014-09-05 17:24:20 +0200 | [diff] [blame] | 59 | boolean hasTransposedSearchBar; |
| 60 | boolean hasTransposedNavBar; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 61 | public float taskStackWidthPaddingPct; |
| 62 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 63 | // 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 Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 69 | |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 70 | /** Misc **/ |
Selim Cinek | e8199c5 | 2014-09-17 04:03:52 +0200 | [diff] [blame] | 71 | public boolean useHardwareLayers; |
Jorim Jaggi | cb55703 | 2014-09-16 23:09:24 +0200 | [diff] [blame] | 72 | public boolean fakeShadows; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 73 | public int svelteLevel; |
| 74 | public int searchBarSpaceHeightPx; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 75 | |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 76 | public RecentsConfiguration(Context context) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 77 | // Load only resources that can not change after the first load either through developer |
| 78 | // settings or via multi window |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 79 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 80 | 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 Chung | 0679563 | 2014-06-17 15:53:44 -0700 | [diff] [blame] | 85 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 86 | 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 Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 105 | void update(Rect windowRect) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 106 | // 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(); |
Winson | 23746d5 | 2015-12-03 16:13:07 -0800 | [diff] [blame] | 109 | hasTransposedNavBar = isLandscape && !isXLargeScreen; |
| 110 | hasTransposedSearchBar = isLandscape && !isXLargeScreen; |
Winson Chung | 0679563 | 2014-06-17 15:53:44 -0700 | [diff] [blame] | 111 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 112 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Returns the activity launch state. |
| 115 | * TODO: This will be refactored out of RecentsConfiguration. |
| 116 | */ |
| 117 | public RecentsActivityLaunchState getLaunchState() { |
| 118 | return mLaunchState; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 119 | } |
| 120 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Called when the configuration has changed, and we want to reset any configuration specific |
| 123 | * members. |
| 124 | */ |
Winson Chung | b01ed68 | 2014-05-29 14:25:42 -0700 | [diff] [blame] | 125 | public void updateOnConfigurationChange() { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 126 | mLaunchState.updateOnConfigurationChange(); |
Winson Chung | 521e7dc | 2014-06-02 15:31:56 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 129 | /** |
| 130 | * Returns the task stack bounds in the current orientation. These bounds do not account for |
| 131 | * the system insets. |
| 132 | */ |
Winson | 88f00ab | 2015-10-05 17:24:00 -0700 | [diff] [blame] | 133 | public void getTaskStackBounds(Rect windowBounds, int topInset, |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 134 | int rightInset, Rect searchBarBounds, Rect taskStackBounds) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 135 | if (hasTransposedNavBar) { |
| 136 | // In landscape phones, the search bar appears on the left, but we overlay it on top |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 137 | taskStackBounds.set(windowBounds.left, windowBounds.top + topInset, |
| 138 | windowBounds.right - rightInset, windowBounds.bottom); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 139 | } else { |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 140 | // In portrait, the search bar appears on the top (which already has the inset) |
Winson | 2364f26 | 2015-10-26 10:56:59 -0700 | [diff] [blame] | 141 | int top = searchBarBounds.isEmpty() ? topInset : 0; |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 142 | taskStackBounds.set(windowBounds.left, searchBarBounds.bottom + top, |
| 143 | windowBounds.right - rightInset, windowBounds.bottom); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Returns the search bar bounds in the current orientation. These bounds do not account for |
| 149 | * the system insets. |
| 150 | */ |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 151 | public void getSearchBarBounds(Rect windowBounds, int topInset, Rect searchBarSpaceBounds) { |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 152 | // Return empty rects if search is not enabled |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 153 | int searchBarSize = searchBarSpaceHeightPx; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 154 | if (hasTransposedSearchBar) { |
| 155 | // In landscape phones, the search bar appears on the left |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 156 | searchBarSpaceBounds.set(windowBounds.left, windowBounds.top + topInset, |
| 157 | windowBounds.left + searchBarSize, windowBounds.bottom); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 158 | } else { |
| 159 | // In portrait, the search bar appears on the top |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 160 | searchBarSpaceBounds.set(windowBounds.left, windowBounds.top + topInset, |
| 161 | windowBounds.right, windowBounds.top + topInset + searchBarSize); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 162 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 163 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 164 | } |