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