RecentsConfiguration.java revision ffa2ec664479bff6b4b61d4c349d9db2cb37ca16
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 17package com.android.systemui.recents; 18 19import android.content.ContentResolver; 20import android.content.Context; 21import android.content.SharedPreferences; 22import android.content.res.Configuration; 23import android.content.res.Resources; 24import android.graphics.Rect; 25import android.provider.Settings; 26import android.util.DisplayMetrics; 27import android.util.TypedValue; 28import android.view.animation.AnimationUtils; 29import android.view.animation.Interpolator; 30import com.android.systemui.R; 31import com.android.systemui.recents.misc.Console; 32 33 34/** A static Recents configuration for the current context 35 * NOTE: We should not hold any references to a Context from a static instance */ 36public class RecentsConfiguration { 37 static RecentsConfiguration sInstance; 38 39 DisplayMetrics mDisplayMetrics; 40 41 /** Animations */ 42 public float animationPxMovementPerSecond; 43 44 /** Interpolators */ 45 public Interpolator fastOutSlowInInterpolator; 46 public Interpolator fastOutLinearInInterpolator; 47 public Interpolator linearOutSlowInInterpolator; 48 public Interpolator quintOutInterpolator; 49 50 /** Filtering */ 51 public int filteringCurrentViewsAnimDuration; 52 public int filteringNewViewsAnimDuration; 53 54 /** Insets */ 55 public Rect systemInsets = new Rect(); 56 public Rect displayRect = new Rect(); 57 58 /** Layout */ 59 boolean isLandscape; 60 boolean transposeRecentsLayoutWithOrientation; 61 62 /** Search bar */ 63 int searchBarAppWidgetId = -1; 64 public int searchBarSpaceHeightPx; 65 66 /** Task stack */ 67 public int taskStackMaxDim; 68 public int taskStackTopPaddingPx; 69 public float taskStackWidthPaddingPct; 70 71 /** Task view animation and styles */ 72 public int taskViewEnterFromHomeDuration; 73 public int taskViewEnterFromHomeDelay; 74 public int taskViewExitToHomeDuration; 75 public int taskViewRemoveAnimDuration; 76 public int taskViewRemoveAnimTranslationXPx; 77 public int taskViewTranslationZMinPx; 78 public int taskViewTranslationZIncrementPx; 79 public int taskViewRoundedCornerRadiusPx; 80 public int taskViewHighlightPx; 81 82 /** Task bar colors */ 83 public int taskBarViewDefaultBackgroundColor; 84 public int taskBarViewLightTextColor; 85 public int taskBarViewDarkTextColor; 86 public int taskBarViewHighlightColor; 87 88 /** Task bar animations */ 89 public int taskBarEnterAnimDuration; 90 public int taskBarEnterAnimDelay; 91 public int taskBarExitAnimDuration; 92 public int taskBarDismissDozeDelaySeconds; 93 94 /** Nav bar scrim */ 95 public int navBarScrimEnterDuration; 96 97 /** Launch states */ 98 public boolean launchedWithAltTab; 99 public boolean launchedWithNoRecentTasks; 100 public boolean launchedFromAppWithThumbnail; 101 public boolean launchedFromAppWithScreenshot; 102 public boolean launchedFromHome; 103 104 /** Dev options */ 105 public boolean developerOptionsEnabled; 106 public boolean debugModeEnabled; 107 108 /** Private constructor */ 109 private RecentsConfiguration(Context context) { 110 // Properties that don't have to be reloaded with each configuration change can be loaded 111 // here. 112 113 // Interpolators 114 fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 115 com.android.internal.R.interpolator.fast_out_slow_in); 116 fastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context, 117 com.android.internal.R.interpolator.fast_out_linear_in); 118 linearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 119 com.android.internal.R.interpolator.linear_out_slow_in); 120 quintOutInterpolator = AnimationUtils.loadInterpolator(context, 121 com.android.internal.R.interpolator.decelerate_quint); 122 123 // Check if the developer options are enabled 124 ContentResolver cr = context.getContentResolver(); 125 developerOptionsEnabled = Settings.Global.getInt(cr, 126 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; 127 } 128 129 /** Updates the configuration to the current context */ 130 public static RecentsConfiguration reinitialize(Context context) { 131 if (sInstance == null) { 132 sInstance = new RecentsConfiguration(context); 133 } 134 sInstance.update(context); 135 return sInstance; 136 } 137 138 /** Returns the current recents configuration */ 139 public static RecentsConfiguration getInstance() { 140 return sInstance; 141 } 142 143 /** Updates the state, given the specified context */ 144 void update(Context context) { 145 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 146 Resources res = context.getResources(); 147 DisplayMetrics dm = res.getDisplayMetrics(); 148 mDisplayMetrics = dm; 149 150 // Debug mode 151 debugModeEnabled = settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false); 152 if (debugModeEnabled) { 153 Console.Enabled = true; 154 } 155 156 // Animations 157 animationPxMovementPerSecond = 158 res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second); 159 160 // Filtering 161 filteringCurrentViewsAnimDuration = 162 res.getInteger(R.integer.recents_filter_animate_current_views_duration); 163 filteringNewViewsAnimDuration = 164 res.getInteger(R.integer.recents_filter_animate_new_views_duration); 165 166 // Insets 167 displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); 168 169 // Layout 170 isLandscape = res.getConfiguration().orientation == 171 Configuration.ORIENTATION_LANDSCAPE; 172 transposeRecentsLayoutWithOrientation = 173 res.getBoolean(R.bool.recents_transpose_layout_with_orientation); 174 175 // Search bar 176 searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); 177 178 // Update the search widget id 179 searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1); 180 181 // Task stack 182 TypedValue widthPaddingPctValue = new TypedValue(); 183 res.getValue(R.dimen.recents_stack_width_padding_percentage, widthPaddingPctValue, true); 184 taskStackWidthPaddingPct = widthPaddingPctValue.getFloat(); 185 taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim); 186 taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.recents_stack_top_padding); 187 188 // Task view animation and styles 189 taskViewEnterFromHomeDuration = 190 res.getInteger(R.integer.recents_animate_task_enter_from_home_duration); 191 taskViewEnterFromHomeDelay = 192 res.getInteger(R.integer.recents_animate_task_enter_from_home_delay); 193 taskViewExitToHomeDuration = 194 res.getInteger(R.integer.recents_animate_task_exit_to_home_duration); 195 taskViewRemoveAnimDuration = 196 res.getInteger(R.integer.recents_animate_task_view_remove_duration); 197 taskViewRemoveAnimTranslationXPx = 198 res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x); 199 taskViewRoundedCornerRadiusPx = 200 res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); 201 taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight); 202 taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min); 203 taskViewTranslationZIncrementPx = 204 res.getDimensionPixelSize(R.dimen.recents_task_view_z_increment); 205 206 // Task bar colors 207 taskBarViewDefaultBackgroundColor = 208 res.getColor(R.color.recents_task_bar_default_background_color); 209 taskBarViewLightTextColor = 210 res.getColor(R.color.recents_task_bar_light_text_color); 211 taskBarViewDarkTextColor = 212 res.getColor(R.color.recents_task_bar_dark_text_color); 213 taskBarViewHighlightColor = 214 res.getColor(R.color.recents_task_bar_highlight_color); 215 216 // Task bar animations 217 taskBarEnterAnimDuration = 218 res.getInteger(R.integer.recents_animate_task_bar_enter_duration); 219 taskBarEnterAnimDelay = 220 res.getInteger(R.integer.recents_animate_task_bar_enter_delay); 221 taskBarExitAnimDuration = 222 res.getInteger(R.integer.recents_animate_task_bar_exit_duration); 223 taskBarDismissDozeDelaySeconds = 224 res.getInteger(R.integer.recents_task_bar_dismiss_delay_seconds); 225 226 // Nav bar scrim 227 navBarScrimEnterDuration = 228 res.getInteger(R.integer.recents_nav_bar_scrim_enter_duration); 229 230 if (Console.Enabled) { 231 Console.log(Constants.Log.UI.MeasureAndLayout, 232 "[RecentsConfiguration|orientation]", isLandscape ? "Landscape" : "Portrait", 233 Console.AnsiGreen); 234 } 235 } 236 237 /** Updates the system insets */ 238 public void updateSystemInsets(Rect insets) { 239 systemInsets.set(insets); 240 } 241 242 /** Updates the search bar app widget */ 243 public void updateSearchBarAppWidgetId(Context context, int appWidgetId) { 244 searchBarAppWidgetId = appWidgetId; 245 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 246 settings.edit().putInt(Constants.Values.App.Key_SearchAppWidgetId, 247 appWidgetId).apply(); 248 } 249 250 /** Called when the configuration has changed, and we want to reset any configuration specific 251 * members. */ 252 public void updateOnConfigurationChange() { 253 launchedWithAltTab = false; 254 launchedWithNoRecentTasks = false; 255 launchedFromAppWithThumbnail = false; 256 launchedFromAppWithScreenshot = false; 257 launchedFromHome = false; 258 } 259 260 /** Returns whether the search bar app widget exists. */ 261 public boolean hasSearchBarAppWidget() { 262 return searchBarAppWidgetId >= 0; 263 } 264 265 /** Returns whether the status bar scrim should be animated when shown for the first time. */ 266 public boolean shouldAnimateStatusBarScrim() { 267 return launchedFromHome; 268 } 269 270 /** Returns whether the status bar scrim should be visible. */ 271 public boolean hasStatusBarScrim() { 272 return !launchedWithNoRecentTasks; 273 } 274 275 /** Returns whether the nav bar scrim should be animated when shown for the first time. */ 276 public boolean shouldAnimateNavBarScrim() { 277 return true; 278 } 279 280 /** Returns whether the nav bar scrim should be visible. */ 281 public boolean hasNavBarScrim() { 282 // Only show the scrim if we have recent tasks, and if the nav bar is not transposed 283 return !launchedWithNoRecentTasks && 284 (!transposeRecentsLayoutWithOrientation || !isLandscape); 285 } 286 287 /** 288 * Returns the task stack bounds in the current orientation. These bounds do not account for 289 * the system insets. 290 */ 291 public void getTaskStackBounds(int width, int height, Rect taskStackBounds) { 292 if (hasSearchBarAppWidget()) { 293 Rect searchBarBounds = new Rect(); 294 getSearchBarBounds(width, height, searchBarBounds); 295 if (isLandscape && transposeRecentsLayoutWithOrientation) { 296 // In landscape, the search bar appears on the left, so shift the task rect right 297 taskStackBounds.set(searchBarBounds.width(), 0, width, height); 298 } else { 299 // In portrait, the search bar appears on the top, so shift the task rect below 300 taskStackBounds.set(0, searchBarBounds.height(), width, height); 301 } 302 } else { 303 taskStackBounds.set(0, 0, width, height); 304 } 305 } 306 307 /** 308 * Returns the search bar bounds in the current orientation. These bounds do not account for 309 * the system insets. 310 */ 311 public void getSearchBarBounds(int width, int height, Rect searchBarSpaceBounds) { 312 // Return empty rects if search is not enabled 313 if (!Constants.DebugFlags.App.EnableSearchLayout) { 314 searchBarSpaceBounds.set(0, 0, 0, 0); 315 return; 316 } 317 318 if (isLandscape && transposeRecentsLayoutWithOrientation) { 319 // In landscape, the search bar appears on the left 320 searchBarSpaceBounds.set(0, 0, searchBarSpaceHeightPx, height); 321 } else { 322 // In portrait, the search bar appears on the top 323 searchBarSpaceBounds.set(0, 0, width, searchBarSpaceHeightPx); 324 } 325 } 326} 327