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