RecentsConfiguration.java revision e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5
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.ContentResolver; 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; 31 32 33/** A static Recents configuration for the current context 34 * NOTE: We should not hold any references to a Context from a static instance */ 35public class RecentsConfiguration { 36 static RecentsConfiguration sInstance; 37 38 DisplayMetrics mDisplayMetrics; 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 /** Search bar */ 62 int searchBarAppWidgetId = -1; 63 public int searchBarSpaceHeightPx; 64 65 /** Task stack */ 66 public int taskStackMaxDim; 67 public int taskStackTopPaddingPx; 68 public float taskStackWidthPaddingPct; 69 70 /** Task view animation and styles */ 71 public int taskViewEnterFromHomeDuration; 72 public int taskViewEnterFromHomeDelay; 73 public int taskViewExitToHomeDuration; 74 public int taskViewRemoveAnimDuration; 75 public int taskViewRemoveAnimTranslationXPx; 76 public int taskViewTranslationZMinPx; 77 public int taskViewTranslationZIncrementPx; 78 public int taskViewShadowOutlineBottomInsetPx; 79 public int taskViewRoundedCornerRadiusPx; 80 public int taskViewHighlightPx; 81 82 /** Task bar colors */ 83 public int taskBarViewDefaultBackgroundColor; 84 public int taskBarViewDefaultTextColor; 85 public int taskBarViewLightTextColor; 86 public int taskBarViewDarkTextColor; 87 public int taskBarViewHighlightColor; 88 89 /** Task bar animations */ 90 public int taskBarEnterAnimDuration; 91 public int taskBarEnterAnimDelay; 92 public int taskBarExitAnimDuration; 93 public int taskBarDismissDozeDelaySeconds; 94 95 /** Nav bar scrim */ 96 public int navBarScrimEnterDuration; 97 98 /** Launch states */ 99 public boolean launchedWithAltTab; 100 public boolean launchedWithNoRecentTasks; 101 public boolean launchedFromAppWithThumbnail; 102 public boolean launchedFromAppWithScreenshot; 103 public boolean launchedFromHome; 104 105 /** Dev options */ 106 public boolean developerOptionsEnabled; 107 108 /** Private constructor */ 109 private RecentsConfiguration(Context context) { 110 // Properties that don't have to be reloaded with each configuration change can be loaded 111 // here. 112 113 // Interpolators 114 fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 115 com.android.internal.R.interpolator.fast_out_slow_in); 116 fastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context, 117 com.android.internal.R.interpolator.fast_out_linear_in); 118 linearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 119 com.android.internal.R.interpolator.linear_out_slow_in); 120 quintOutInterpolator = AnimationUtils.loadInterpolator(context, 121 com.android.internal.R.interpolator.decelerate_quint); 122 123 // Check if the developer options are enabled 124 ContentResolver cr = context.getContentResolver(); 125 developerOptionsEnabled = Settings.Global.getInt(cr, 126 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; 127 } 128 129 /** Updates the configuration to the current context */ 130 public static RecentsConfiguration reinitialize(Context context) { 131 if (sInstance == null) { 132 sInstance = new RecentsConfiguration(context); 133 } 134 sInstance.update(context); 135 return sInstance; 136 } 137 138 /** Returns the current recents configuration */ 139 public static RecentsConfiguration getInstance() { 140 return sInstance; 141 } 142 143 /** Updates the state, given the specified context */ 144 void update(Context context) { 145 Resources res = context.getResources(); 146 DisplayMetrics dm = res.getDisplayMetrics(); 147 mDisplayMetrics = dm; 148 149 // Animations 150 animationPxMovementPerSecond = 151 res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second); 152 153 // Filtering 154 filteringCurrentViewsAnimDuration = 155 res.getInteger(R.integer.recents_filter_animate_current_views_duration); 156 filteringNewViewsAnimDuration = 157 res.getInteger(R.integer.recents_filter_animate_new_views_duration); 158 159 // Insets 160 displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); 161 162 // Layout 163 isLandscape = res.getConfiguration().orientation == 164 Configuration.ORIENTATION_LANDSCAPE; 165 transposeRecentsLayoutWithOrientation = 166 res.getBoolean(R.bool.recents_transpose_layout_with_orientation); 167 168 // Search bar 169 searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); 170 171 // Update the search widget id 172 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 173 searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1); 174 175 // Task stack 176 TypedValue widthPaddingPctValue = new TypedValue(); 177 res.getValue(R.dimen.recents_stack_width_padding_percentage, widthPaddingPctValue, true); 178 taskStackWidthPaddingPct = widthPaddingPctValue.getFloat(); 179 taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim); 180 taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.recents_stack_top_padding); 181 182 // Task view animation and styles 183 taskViewEnterFromHomeDuration = 184 res.getInteger(R.integer.recents_animate_task_enter_from_home_duration); 185 taskViewEnterFromHomeDelay = 186 res.getInteger(R.integer.recents_animate_task_enter_from_home_delay); 187 taskViewExitToHomeDuration = 188 res.getInteger(R.integer.recents_animate_task_exit_to_home_duration); 189 taskViewRemoveAnimDuration = 190 res.getInteger(R.integer.recents_animate_task_view_remove_duration); 191 taskViewRemoveAnimTranslationXPx = 192 res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x); 193 taskViewRoundedCornerRadiusPx = 194 res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); 195 taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight); 196 taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min); 197 taskViewTranslationZIncrementPx = 198 res.getDimensionPixelSize(R.dimen.recents_task_view_z_increment); 199 taskViewShadowOutlineBottomInsetPx = 200 res.getDimensionPixelSize(R.dimen.recents_task_view_shadow_outline_bottom_inset); 201 202 // Task bar colors 203 taskBarViewDefaultBackgroundColor = 204 res.getColor(R.color.recents_task_bar_default_background_color); 205 taskBarViewDefaultTextColor = 206 res.getColor(R.color.recents_task_bar_default_text_color); 207 taskBarViewLightTextColor = 208 res.getColor(R.color.recents_task_bar_light_text_color); 209 taskBarViewDarkTextColor = 210 res.getColor(R.color.recents_task_bar_dark_text_color); 211 taskBarViewHighlightColor = 212 res.getColor(R.color.recents_task_bar_highlight_color); 213 214 // Task bar animations 215 taskBarEnterAnimDuration = 216 res.getInteger(R.integer.recents_animate_task_bar_enter_duration); 217 taskBarEnterAnimDelay = 218 res.getInteger(R.integer.recents_animate_task_bar_enter_delay); 219 taskBarExitAnimDuration = 220 res.getInteger(R.integer.recents_animate_task_bar_exit_duration); 221 taskBarDismissDozeDelaySeconds = 222 res.getInteger(R.integer.recents_task_bar_dismiss_delay_seconds); 223 224 // Nav bar scrim 225 navBarScrimEnterDuration = 226 res.getInteger(R.integer.recents_nav_bar_scrim_enter_duration); 227 228 if (Console.Enabled) { 229 Console.log(Constants.Log.UI.MeasureAndLayout, 230 "[RecentsConfiguration|orientation]", isLandscape ? "Landscape" : "Portrait", 231 Console.AnsiGreen); 232 } 233 } 234 235 /** Updates the system insets */ 236 public void updateSystemInsets(Rect insets) { 237 systemInsets.set(insets); 238 } 239 240 /** Updates the search bar app widget */ 241 public void updateSearchBarAppWidgetId(Context context, int appWidgetId) { 242 searchBarAppWidgetId = appWidgetId; 243 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 244 settings.edit().putInt(Constants.Values.App.Key_SearchAppWidgetId, 245 appWidgetId).apply(); 246 } 247 248 /** Called when the configuration has changed, and we want to reset any configuration specific 249 * members. */ 250 public void updateOnConfigurationChange() { 251 launchedWithAltTab = false; 252 launchedWithNoRecentTasks = false; 253 launchedFromAppWithThumbnail = false; 254 launchedFromAppWithScreenshot = false; 255 launchedFromHome = false; 256 } 257 258 /** Returns whether the search bar app widget exists. */ 259 public boolean hasSearchBarAppWidget() { 260 return searchBarAppWidgetId >= 0; 261 } 262 263 /** Returns whether the status bar scrim should be animated when shown for the first time. */ 264 public boolean shouldAnimateStatusBarScrim() { 265 return launchedFromHome; 266 } 267 268 /** Returns whether the status bar scrim should be visible. */ 269 public boolean hasStatusBarScrim() { 270 return !launchedWithNoRecentTasks; 271 } 272 273 /** Returns whether the nav bar scrim should be animated when shown for the first time. */ 274 public boolean shouldAnimateNavBarScrim() { 275 return true; 276 } 277 278 /** Returns whether the nav bar scrim should be visible. */ 279 public boolean hasNavBarScrim() { 280 // Only show the scrim if we have recent tasks, and if the nav bar is not transposed 281 return !launchedWithNoRecentTasks && 282 (!transposeRecentsLayoutWithOrientation || !isLandscape); 283 } 284 285 /** 286 * Returns the task stack bounds in the current orientation. These bounds do not account for 287 * the system insets. 288 */ 289 public void getTaskStackBounds(int width, int height, Rect taskStackBounds) { 290 if (hasSearchBarAppWidget()) { 291 Rect searchBarBounds = new Rect(); 292 getSearchBarBounds(width, height, searchBarBounds); 293 if (isLandscape && transposeRecentsLayoutWithOrientation) { 294 // In landscape, the search bar appears on the left, so shift the task rect right 295 taskStackBounds.set(searchBarBounds.width(), 0, width, height); 296 } else { 297 // In portrait, the search bar appears on the top, so shift the task rect below 298 taskStackBounds.set(0, searchBarBounds.height(), width, height); 299 } 300 } else { 301 taskStackBounds.set(0, 0, width, height); 302 } 303 } 304 305 /** 306 * Returns the search bar bounds in the current orientation. These bounds do not account for 307 * the system insets. 308 */ 309 public void getSearchBarBounds(int width, int height, Rect searchBarSpaceBounds) { 310 // Return empty rects if search is not enabled 311 if (!Constants.DebugFlags.App.EnableSearchLayout) { 312 searchBarSpaceBounds.set(0, 0, 0, 0); 313 return; 314 } 315 316 if (isLandscape && transposeRecentsLayoutWithOrientation) { 317 // In landscape, the search bar appears on the left 318 searchBarSpaceBounds.set(0, 0, searchBarSpaceHeightPx, height); 319 } else { 320 // In portrait, the search bar appears on the top 321 searchBarSpaceBounds.set(0, 0, width, searchBarSpaceHeightPx); 322 } 323 } 324} 325