RecentsConfiguration.java revision f5e22e71cb5f8699a4312c797af068f655cbe629
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.res.Configuration; 21import android.content.res.Resources; 22import android.graphics.Rect; 23import android.util.DisplayMetrics; 24import android.util.TypedValue; 25import com.android.systemui.R; 26 27 28/** A static Recents configuration for the current context 29 * NOTE: We should not hold any references to a Context from a static instance */ 30public class RecentsConfiguration { 31 static RecentsConfiguration sInstance; 32 33 DisplayMetrics mDisplayMetrics; 34 35 public Rect systemInsets = new Rect(); 36 public Rect displayRect = new Rect(); 37 38 public float animationPxMovementPerSecond; 39 40 public int filteringCurrentViewsMinAnimDuration; 41 public int filteringNewViewsMinAnimDuration; 42 public int taskBarEnterAnimDuration; 43 public int taskBarExitAnimDuration; 44 public int taskStackScrollDismissInfoPaneDistance; 45 public int taskStackMaxDim; 46 public int taskViewInfoPaneAnimDuration; 47 public int taskViewRoundedCornerRadiusPx; 48 public int searchBarSpaceHeightPx; 49 public int searchBarSpaceEdgeMarginsPx; 50 51 public int taskBarViewDefaultBackgroundColor; 52 public int taskBarViewDefaultTextColor; 53 public int taskBarViewLightTextColor; 54 public int taskBarViewDarkTextColor; 55 56 public boolean launchedWithThumbnailAnimation; 57 58 /** Private constructor */ 59 private RecentsConfiguration() {} 60 61 /** Updates the configuration to the current context */ 62 public static RecentsConfiguration reinitialize(Context context) { 63 if (sInstance == null) { 64 sInstance = new RecentsConfiguration(); 65 } 66 sInstance.update(context); 67 return sInstance; 68 } 69 70 /** Returns the current recents configuration */ 71 public static RecentsConfiguration getInstance() { 72 return sInstance; 73 } 74 75 /** Updates the state, given the specified context */ 76 void update(Context context) { 77 Resources res = context.getResources(); 78 DisplayMetrics dm = res.getDisplayMetrics(); 79 mDisplayMetrics = dm; 80 81 boolean isLandscape = res.getConfiguration().orientation == 82 Configuration.ORIENTATION_LANDSCAPE; 83 Console.log(Constants.DebugFlags.UI.MeasureAndLayout, 84 "[RecentsConfiguration|orientation]", isLandscape ? "Landscape" : "Portrait", 85 Console.AnsiGreen); 86 87 displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); 88 animationPxMovementPerSecond = 89 res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second); 90 filteringCurrentViewsMinAnimDuration = 91 res.getInteger(R.integer.recents_filter_animate_current_views_min_duration); 92 filteringNewViewsMinAnimDuration = 93 res.getInteger(R.integer.recents_filter_animate_new_views_min_duration); 94 taskBarEnterAnimDuration = 95 res.getInteger(R.integer.recents_animate_task_bar_enter_duration); 96 taskBarExitAnimDuration = 97 res.getInteger(R.integer.recents_animate_task_bar_exit_duration); 98 taskStackScrollDismissInfoPaneDistance = res.getDimensionPixelSize( 99 R.dimen.recents_task_stack_scroll_dismiss_info_pane_distance); 100 taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim); 101 taskViewInfoPaneAnimDuration = 102 res.getInteger(R.integer.recents_animate_task_view_info_pane_duration); 103 taskViewRoundedCornerRadiusPx = 104 res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); 105 searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height); 106 searchBarSpaceEdgeMarginsPx = 107 res.getDimensionPixelSize(R.dimen.recents_search_bar_space_edge_margins); 108 109 taskBarViewDefaultBackgroundColor = 110 res.getColor(R.color.recents_task_bar_default_background_color); 111 taskBarViewDefaultTextColor = 112 res.getColor(R.color.recents_task_bar_default_text_color); 113 taskBarViewLightTextColor = 114 res.getColor(R.color.recents_task_bar_light_text_color); 115 taskBarViewDarkTextColor = 116 res.getColor(R.color.recents_task_bar_dark_text_color); 117 } 118 119 /** Updates the system insets */ 120 public void updateSystemInsets(Rect insets) { 121 systemInsets.set(insets); 122 } 123 124 /** Returns the search bar bounds in the specified orientation */ 125 public void getSearchBarBounds(int width, int height, 126 Rect searchBarSpaceBounds, Rect searchBarBounds) { 127 // Return empty rects if search is not enabled 128 if (!Constants.DebugFlags.App.EnableSearchButton) { 129 searchBarSpaceBounds.set(0, 0, 0, 0); 130 searchBarBounds.set(0, 0, 0, 0); 131 return; 132 } 133 134 // Calculate the search bar bounds, and account for the system insets 135 int edgeMarginPx = searchBarSpaceEdgeMarginsPx; 136 int availableWidth = width - systemInsets.left - systemInsets.right; 137 searchBarSpaceBounds.set(0, 0, availableWidth, 2 * edgeMarginPx + searchBarSpaceHeightPx); 138 139 // Inset from the search bar space to get the search bar bounds 140 searchBarBounds.set(searchBarSpaceBounds); 141 searchBarBounds.inset(edgeMarginPx, edgeMarginPx); 142 } 143 144 /** Converts from DPs to PXs */ 145 public int pxFromDp(float size) { 146 return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 147 size, mDisplayMetrics)); 148 } 149 /** Converts from SPs to PXs */ 150 public int pxFromSp(float size) { 151 return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 152 size, mDisplayMetrics)); 153 } 154} 155