RecentsConfiguration.java revision e8199c582d826a39e6e47b0d8418834c15242fec
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.app.ActivityManager; 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; 32import com.android.systemui.recents.misc.SystemServicesProxy; 33 34 35/** A static Recents configuration for the current context 36 * NOTE: We should not hold any references to a Context from a static instance */ 37public class RecentsConfiguration { 38 static RecentsConfiguration sInstance; 39 static int sPrevConfigurationHashCode; 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 hasTransposedSearchBar; 61 boolean hasTransposedNavBar; 62 63 /** Loading */ 64 public int maxNumTasksToLoad; 65 66 /** Search bar */ 67 int searchBarAppWidgetId = -1; 68 public int searchBarSpaceHeightPx; 69 70 /** Task stack */ 71 public int taskStackScrollDuration; 72 public int taskStackMaxDim; 73 public int taskStackTopPaddingPx; 74 public float taskStackWidthPaddingPct; 75 public float taskStackOverscrollPct; 76 77 /** Task view animation and styles */ 78 public int taskViewEnterFromHomeDelay; 79 public int taskViewEnterFromHomeDuration; 80 public int taskViewEnterFromHomeStaggerDelay; 81 public int taskViewExitToHomeDuration; 82 public int taskViewRemoveAnimDuration; 83 public int taskViewRemoveAnimTranslationXPx; 84 public int taskViewTranslationZMinPx; 85 public int taskViewTranslationZMaxPx; 86 public int taskViewRoundedCornerRadiusPx; 87 public int taskViewHighlightPx; 88 public int taskViewAffiliateGroupEnterOffsetPx; 89 public float taskViewThumbnailAlpha; 90 91 /** Task bar colors */ 92 public int taskBarViewDefaultBackgroundColor; 93 public int taskBarViewLightTextColor; 94 public int taskBarViewDarkTextColor; 95 public int taskBarViewHighlightColor; 96 public float taskBarViewAffiliationColorMinAlpha; 97 98 /** Task bar size & animations */ 99 public int taskBarHeight; 100 public int taskBarEnterAnimDuration; 101 public int taskBarEnterAnimDelay; 102 public int taskBarExitAnimDuration; 103 public int taskBarDismissDozeDelaySeconds; 104 105 /** Lock to app */ 106 public int taskViewLockToAppButtonHeight; 107 public int taskViewLockToAppShortAnimDuration; 108 public int taskViewLockToAppLongAnimDuration; 109 110 /** Nav bar scrim */ 111 public int navBarScrimEnterDuration; 112 113 /** Launch states */ 114 public boolean launchedWithAltTab; 115 public boolean launchedWithNoRecentTasks; 116 public boolean launchedFromAppWithThumbnail; 117 public boolean launchedFromAppWithScreenshot; 118 public boolean launchedFromHome; 119 public int launchedToTaskId; 120 121 /** Misc **/ 122 public boolean useHardwareLayers; 123 public int altTabKeyDelay; 124 125 /** Dev options and global settings */ 126 public boolean lockToAppEnabled; 127 public boolean developerOptionsEnabled; 128 public boolean debugModeEnabled; 129 130 /** Private constructor */ 131 private RecentsConfiguration(Context context) { 132 // Properties that don't have to be reloaded with each configuration change can be loaded 133 // here. 134 135 // Interpolators 136 fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 137 com.android.internal.R.interpolator.fast_out_slow_in); 138 fastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context, 139 com.android.internal.R.interpolator.fast_out_linear_in); 140 linearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 141 com.android.internal.R.interpolator.linear_out_slow_in); 142 quintOutInterpolator = AnimationUtils.loadInterpolator(context, 143 com.android.internal.R.interpolator.decelerate_quint); 144 } 145 146 /** Updates the configuration to the current context */ 147 public static RecentsConfiguration reinitialize(Context context, SystemServicesProxy ssp) { 148 if (sInstance == null) { 149 sInstance = new RecentsConfiguration(context); 150 } 151 int configHashCode = context.getResources().getConfiguration().hashCode(); 152 if (sPrevConfigurationHashCode != configHashCode) { 153 sInstance.update(context); 154 sPrevConfigurationHashCode = configHashCode; 155 } 156 sInstance.updateOnReinitialize(context, ssp); 157 return sInstance; 158 } 159 160 /** Returns the current recents configuration */ 161 public static RecentsConfiguration getInstance() { 162 return sInstance; 163 } 164 165 /** Updates the state, given the specified context */ 166 void update(Context context) { 167 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 168 Resources res = context.getResources(); 169 DisplayMetrics dm = res.getDisplayMetrics(); 170 171 // Debug mode 172 debugModeEnabled = settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false); 173 if (debugModeEnabled) { 174 Console.Enabled = true; 175 } 176 177 // Layout 178 isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; 179 hasTransposedSearchBar = res.getBoolean(R.bool.recents_has_transposed_search_bar); 180 hasTransposedNavBar = res.getBoolean(R.bool.recents_has_transposed_nav_bar); 181 182 // Insets 183 displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); 184 185 // Animations 186 animationPxMovementPerSecond = 187 res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second); 188 189 // Filtering 190 filteringCurrentViewsAnimDuration = 191 res.getInteger(R.integer.recents_filter_animate_current_views_duration); 192 filteringNewViewsAnimDuration = 193 res.getInteger(R.integer.recents_filter_animate_new_views_duration); 194 195 // Loading 196 maxNumTasksToLoad = ActivityManager.getMaxRecentTasksStatic(); 197 198 // Search Bar 199 searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); 200 searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1); 201 202 // Task stack 203 taskStackScrollDuration = 204 res.getInteger(R.integer.recents_animate_task_stack_scroll_duration); 205 TypedValue widthPaddingPctValue = new TypedValue(); 206 res.getValue(R.dimen.recents_stack_width_padding_percentage, widthPaddingPctValue, true); 207 taskStackWidthPaddingPct = widthPaddingPctValue.getFloat(); 208 TypedValue stackOverscrollPctValue = new TypedValue(); 209 res.getValue(R.dimen.recents_stack_overscroll_percentage, stackOverscrollPctValue, true); 210 taskStackOverscrollPct = stackOverscrollPctValue.getFloat(); 211 taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim); 212 taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.recents_stack_top_padding); 213 214 // Task view animation and styles 215 taskViewEnterFromHomeDelay = 216 res.getInteger(R.integer.recents_animate_task_enter_from_home_delay); 217 taskViewEnterFromHomeDuration = 218 res.getInteger(R.integer.recents_animate_task_enter_from_home_duration); 219 taskViewEnterFromHomeStaggerDelay = 220 res.getInteger(R.integer.recents_animate_task_enter_from_home_stagger_delay); 221 taskViewExitToHomeDuration = 222 res.getInteger(R.integer.recents_animate_task_exit_to_home_duration); 223 taskViewRemoveAnimDuration = 224 res.getInteger(R.integer.recents_animate_task_view_remove_duration); 225 taskViewRemoveAnimTranslationXPx = 226 res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x); 227 taskViewRoundedCornerRadiusPx = 228 res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); 229 taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight); 230 taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min); 231 taskViewTranslationZMaxPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_max); 232 taskViewAffiliateGroupEnterOffsetPx = 233 res.getDimensionPixelSize(R.dimen.recents_task_view_affiliate_group_enter_offset); 234 TypedValue thumbnailAlphaValue = new TypedValue(); 235 res.getValue(R.dimen.recents_task_view_thumbnail_alpha, thumbnailAlphaValue, true); 236 taskViewThumbnailAlpha = thumbnailAlphaValue.getFloat(); 237 238 // Task bar colors 239 taskBarViewDefaultBackgroundColor = 240 res.getColor(R.color.recents_task_bar_default_background_color); 241 taskBarViewLightTextColor = 242 res.getColor(R.color.recents_task_bar_light_text_color); 243 taskBarViewDarkTextColor = 244 res.getColor(R.color.recents_task_bar_dark_text_color); 245 taskBarViewHighlightColor = 246 res.getColor(R.color.recents_task_bar_highlight_color); 247 TypedValue affMinAlphaPctValue = new TypedValue(); 248 res.getValue(R.dimen.recents_task_affiliation_color_min_alpha_percentage, affMinAlphaPctValue, true); 249 taskBarViewAffiliationColorMinAlpha = affMinAlphaPctValue.getFloat(); 250 251 // Task bar size & animations 252 taskBarHeight = res.getDimensionPixelSize(R.dimen.recents_task_bar_height); 253 taskBarEnterAnimDuration = 254 res.getInteger(R.integer.recents_animate_task_bar_enter_duration); 255 taskBarEnterAnimDelay = 256 res.getInteger(R.integer.recents_animate_task_bar_enter_delay); 257 taskBarExitAnimDuration = 258 res.getInteger(R.integer.recents_animate_task_bar_exit_duration); 259 taskBarDismissDozeDelaySeconds = 260 res.getInteger(R.integer.recents_task_bar_dismiss_delay_seconds); 261 262 // Lock to app 263 taskViewLockToAppButtonHeight = 264 res.getDimensionPixelSize(R.dimen.recents_task_view_lock_to_app_button_height); 265 taskViewLockToAppShortAnimDuration = 266 res.getInteger(R.integer.recents_animate_lock_to_app_button_short_duration); 267 taskViewLockToAppLongAnimDuration = 268 res.getInteger(R.integer.recents_animate_lock_to_app_button_long_duration); 269 270 // Nav bar scrim 271 navBarScrimEnterDuration = 272 res.getInteger(R.integer.recents_nav_bar_scrim_enter_duration); 273 274 // Misc 275 useHardwareLayers = res.getBoolean(R.bool.config_recents_use_hardware_layers); 276 altTabKeyDelay = res.getInteger(R.integer.recents_alt_tab_key_delay); 277 } 278 279 /** Updates the system insets */ 280 public void updateSystemInsets(Rect insets) { 281 systemInsets.set(insets); 282 } 283 284 /** Updates the search bar app widget */ 285 public void updateSearchBarAppWidgetId(Context context, int appWidgetId) { 286 searchBarAppWidgetId = appWidgetId; 287 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 288 settings.edit().putInt(Constants.Values.App.Key_SearchAppWidgetId, 289 appWidgetId).apply(); 290 } 291 292 /** Updates the states that need to be re-read whenever we re-initialize. */ 293 void updateOnReinitialize(Context context, SystemServicesProxy ssp) { 294 // Check if the developer options are enabled 295 developerOptionsEnabled = ssp.getGlobalSetting(context, 296 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED) != 0; 297 lockToAppEnabled = ssp.getSystemSetting(context, 298 Settings.System.LOCK_TO_APP_ENABLED) != 0; 299 } 300 301 /** Called when the configuration has changed, and we want to reset any configuration specific 302 * members. */ 303 public void updateOnConfigurationChange() { 304 launchedWithAltTab = false; 305 launchedWithNoRecentTasks = false; 306 launchedFromAppWithThumbnail = false; 307 launchedFromAppWithScreenshot = false; 308 launchedFromHome = false; 309 launchedToTaskId = -1; 310 } 311 312 /** Returns whether the search bar app widget exists. */ 313 public boolean hasSearchBarAppWidget() { 314 return searchBarAppWidgetId >= 0; 315 } 316 317 /** Returns whether the status bar scrim should be animated when shown for the first time. */ 318 public boolean shouldAnimateStatusBarScrim() { 319 return launchedFromHome; 320 } 321 322 /** Returns whether the status bar scrim should be visible. */ 323 public boolean hasStatusBarScrim() { 324 return !launchedWithNoRecentTasks; 325 } 326 327 /** Returns whether the nav bar scrim should be animated when shown for the first time. */ 328 public boolean shouldAnimateNavBarScrim() { 329 return true; 330 } 331 332 /** Returns whether the nav bar scrim should be visible. */ 333 public boolean hasNavBarScrim() { 334 // Only show the scrim if we have recent tasks, and if the nav bar is not transposed 335 return !launchedWithNoRecentTasks && (!hasTransposedNavBar || !isLandscape); 336 } 337 338 /** Returns whether the current layout is horizontal. */ 339 public boolean hasHorizontalLayout() { 340 return isLandscape && hasTransposedSearchBar; 341 } 342 343 /** 344 * Returns the task stack bounds in the current orientation. These bounds do not account for 345 * the system insets. 346 */ 347 public void getTaskStackBounds(int windowWidth, int windowHeight, int topInset, int rightInset, 348 Rect taskStackBounds) { 349 Rect searchBarBounds = new Rect(); 350 getSearchBarBounds(windowWidth, windowHeight, topInset, searchBarBounds); 351 if (isLandscape && hasTransposedSearchBar) { 352 // In landscape, the search bar appears on the left, but we overlay it on top 353 taskStackBounds.set(0, topInset, windowWidth - rightInset, windowHeight); 354 } else { 355 // In portrait, the search bar appears on the top (which already has the inset) 356 taskStackBounds.set(0, searchBarBounds.bottom, windowWidth, windowHeight); 357 } 358 } 359 360 /** 361 * Returns the search bar bounds in the current orientation. These bounds do not account for 362 * the system insets. 363 */ 364 public void getSearchBarBounds(int windowWidth, int windowHeight, int topInset, 365 Rect searchBarSpaceBounds) { 366 // Return empty rects if search is not enabled 367 int searchBarSize = searchBarSpaceHeightPx; 368 if (!Constants.DebugFlags.App.EnableSearchLayout || !hasSearchBarAppWidget()) { 369 searchBarSize = 0; 370 } 371 372 if (isLandscape && hasTransposedSearchBar) { 373 // In landscape, the search bar appears on the left 374 searchBarSpaceBounds.set(0, topInset, searchBarSize, windowHeight); 375 } else { 376 // In portrait, the search bar appears on the top 377 searchBarSpaceBounds.set(0, topInset, windowWidth, topInset + searchBarSize); 378 } 379 } 380} 381