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