RecentsConfiguration.java revision 918c0723a169cef46b8bf59c06fd3bb8021d0def
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.util.DisplayMetrics; 25import android.util.TypedValue; 26import android.view.animation.AnimationUtils; 27import android.view.animation.Interpolator; 28import com.android.systemui.R; 29 30 31/** A static Recents configuration for the current context 32 * NOTE: We should not hold any references to a Context from a static instance */ 33public class RecentsConfiguration { 34 static RecentsConfiguration sInstance; 35 36 DisplayMetrics mDisplayMetrics; 37 38 public Rect systemInsets = new Rect(); 39 public Rect displayRect = new Rect(); 40 41 boolean isLandscape; 42 boolean transposeSearchLayoutWithOrientation; 43 int searchBarAppWidgetId = -1; 44 45 public float animationPxMovementPerSecond; 46 47 public Interpolator defaultBezierInterpolator; 48 49 public int filteringCurrentViewsMinAnimDuration; 50 public int filteringNewViewsMinAnimDuration; 51 public int taskBarEnterAnimDuration; 52 public int taskBarExitAnimDuration; 53 public int taskStackScrollDismissInfoPaneDistance; 54 public int taskStackMaxDim; 55 public int taskViewInfoPaneAnimDuration; 56 public int taskViewRemoveAnimDuration; 57 public int taskViewRemoveAnimTranslationXPx; 58 public int taskViewTranslationZMinPx; 59 public int taskViewTranslationZIncrementPx; 60 public int taskViewRoundedCornerRadiusPx; 61 public int searchBarSpaceHeightPx; 62 63 public int taskBarViewDefaultBackgroundColor; 64 public int taskBarViewDefaultTextColor; 65 public int taskBarViewLightTextColor; 66 public int taskBarViewDarkTextColor; 67 68 public boolean launchedWithThumbnailAnimation; 69 70 /** Private constructor */ 71 private RecentsConfiguration() {} 72 73 /** Updates the configuration to the current context */ 74 public static RecentsConfiguration reinitialize(Context context) { 75 if (sInstance == null) { 76 sInstance = new RecentsConfiguration(); 77 } 78 sInstance.update(context); 79 return sInstance; 80 } 81 82 /** Returns the current recents configuration */ 83 public static RecentsConfiguration getInstance() { 84 return sInstance; 85 } 86 87 /** Updates the state, given the specified context */ 88 void update(Context context) { 89 Resources res = context.getResources(); 90 DisplayMetrics dm = res.getDisplayMetrics(); 91 mDisplayMetrics = dm; 92 93 isLandscape = res.getConfiguration().orientation == 94 Configuration.ORIENTATION_LANDSCAPE; 95 transposeSearchLayoutWithOrientation = 96 res.getBoolean(R.bool.recents_transpose_search_layout_with_orientation); 97 Console.log(Constants.Log.UI.MeasureAndLayout, 98 "[RecentsConfiguration|orientation]", isLandscape ? "Landscape" : "Portrait", 99 Console.AnsiGreen); 100 101 displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); 102 animationPxMovementPerSecond = 103 res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second); 104 filteringCurrentViewsMinAnimDuration = 105 res.getInteger(R.integer.recents_filter_animate_current_views_min_duration); 106 filteringNewViewsMinAnimDuration = 107 res.getInteger(R.integer.recents_filter_animate_new_views_min_duration); 108 taskBarEnterAnimDuration = 109 res.getInteger(R.integer.recents_animate_task_bar_enter_duration); 110 taskBarExitAnimDuration = 111 res.getInteger(R.integer.recents_animate_task_bar_exit_duration); 112 taskStackScrollDismissInfoPaneDistance = res.getDimensionPixelSize( 113 R.dimen.recents_task_stack_scroll_dismiss_info_pane_distance); 114 taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim); 115 taskViewInfoPaneAnimDuration = 116 res.getInteger(R.integer.recents_animate_task_view_info_pane_duration); 117 taskViewRemoveAnimDuration = 118 res.getInteger(R.integer.recents_animate_task_view_remove_duration); 119 taskViewRemoveAnimTranslationXPx = 120 res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x); 121 taskViewRoundedCornerRadiusPx = 122 res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); 123 taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min); 124 taskViewTranslationZIncrementPx = 125 res.getDimensionPixelSize(R.dimen.recents_task_view_z_increment); 126 searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); 127 128 taskBarViewDefaultBackgroundColor = 129 res.getColor(R.color.recents_task_bar_default_background_color); 130 taskBarViewDefaultTextColor = 131 res.getColor(R.color.recents_task_bar_default_text_color); 132 taskBarViewLightTextColor = 133 res.getColor(R.color.recents_task_bar_light_text_color); 134 taskBarViewDarkTextColor = 135 res.getColor(R.color.recents_task_bar_dark_text_color); 136 137 defaultBezierInterpolator = AnimationUtils.loadInterpolator(context, 138 com.android.internal.R.interpolator.fast_out_slow_in); 139 140 // Update the search widget id 141 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 142 searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1); 143 } 144 145 /** Updates the system insets */ 146 public void updateSystemInsets(Rect insets) { 147 systemInsets.set(insets); 148 } 149 150 /** Updates the search bar app widget */ 151 public void updateSearchBarAppWidgetId(Context context, int appWidgetId) { 152 searchBarAppWidgetId = appWidgetId; 153 SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0); 154 settings.edit().putInt(Constants.Values.App.Key_SearchAppWidgetId, 155 appWidgetId).apply(); 156 } 157 158 /** Returns whether the search bar app widget exists */ 159 public boolean hasSearchBarAppWidget() { 160 return searchBarAppWidgetId >= 0; 161 } 162 163 /** 164 * Returns the task stack bounds in the current orientation. These bounds do not account for 165 * the system insets. 166 */ 167 public void getTaskStackBounds(int width, int height, Rect taskStackBounds) { 168 if (hasSearchBarAppWidget()) { 169 Rect searchBarBounds = new Rect(); 170 getSearchBarBounds(width, height, searchBarBounds); 171 if (isLandscape && transposeSearchLayoutWithOrientation) { 172 // In landscape, the search bar appears on the left, so shift the task rect right 173 taskStackBounds.set(searchBarBounds.width(), 0, width, height); 174 } else { 175 // In portrait, the search bar appears on the top, so shift the task rect below 176 taskStackBounds.set(0, searchBarBounds.height(), width, height); 177 } 178 } else { 179 taskStackBounds.set(0, 0, width, height); 180 } 181 } 182 183 /** 184 * Returns the search bar bounds in the current orientation. These bounds do not account for 185 * the system insets. 186 */ 187 public void getSearchBarBounds(int width, int height, Rect searchBarSpaceBounds) { 188 // Return empty rects if search is not enabled 189 if (!Constants.DebugFlags.App.EnableSearchLayout) { 190 searchBarSpaceBounds.set(0, 0, 0, 0); 191 return; 192 } 193 194 if (isLandscape && transposeSearchLayoutWithOrientation) { 195 // In landscape, the search bar appears on the left 196 searchBarSpaceBounds.set(0, 0, searchBarSpaceHeightPx, height); 197 } else { 198 // In portrait, the search bar appears on the top 199 searchBarSpaceBounds.set(0, 0, width, searchBarSpaceHeightPx); 200 } 201 } 202 203 /** Converts from DPs to PXs */ 204 public int pxFromDp(float size) { 205 return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 206 size, mDisplayMetrics)); 207 } 208 /** Converts from SPs to PXs */ 209 public int pxFromSp(float size) { 210 return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 211 size, mDisplayMetrics)); 212 } 213} 214