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