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