RecentsConfiguration.java revision 1492646b792360945fba6bdcacc6aa7c19c6618e
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 taskStackScrollDismissInfoPaneDistance;
44    public int taskStackMaxDim;
45    public int taskViewInfoPaneAnimDuration;
46    public int taskViewRoundedCornerRadiusPx;
47
48    public boolean launchedWithThumbnailAnimation;
49
50    /** Private constructor */
51    private RecentsConfiguration() {}
52
53    /** Updates the configuration to the current context */
54    public static RecentsConfiguration reinitialize(Context context) {
55        if (sInstance == null) {
56            sInstance = new RecentsConfiguration();
57        }
58        sInstance.update(context);
59        return sInstance;
60    }
61
62    /** Returns the current recents configuration */
63    public static RecentsConfiguration getInstance() {
64        return sInstance;
65    }
66
67    /** Updates the state, given the specified context */
68    void update(Context context) {
69        Resources res = context.getResources();
70        DisplayMetrics dm = res.getDisplayMetrics();
71        mDisplayMetrics = dm;
72
73        boolean isLandscape = res.getConfiguration().orientation ==
74                Configuration.ORIENTATION_LANDSCAPE;
75        Console.log(Constants.DebugFlags.UI.MeasureAndLayout,
76                "[RecentsConfiguration|orientation]", isLandscape ? "Landscape" : "Portrait",
77                Console.AnsiGreen);
78
79        displayRect.set(0, 0, dm.widthPixels, dm.heightPixels);
80        animationPxMovementPerSecond =
81                res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);
82        filteringCurrentViewsMinAnimDuration =
83                res.getInteger(R.integer.recents_filter_animate_current_views_min_duration);
84        filteringNewViewsMinAnimDuration =
85                res.getInteger(R.integer.recents_filter_animate_new_views_min_duration);
86        taskBarEnterAnimDuration =
87                res.getInteger(R.integer.recents_animate_task_bar_enter_duration);
88        taskStackScrollDismissInfoPaneDistance = res.getDimensionPixelSize(
89                R.dimen.recents_task_stack_scroll_dismiss_info_pane_distance);
90        taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim);
91        taskViewInfoPaneAnimDuration =
92                res.getInteger(R.integer.recents_animate_task_view_info_pane_duration);
93        taskViewRoundedCornerRadiusPx =
94                res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius);
95    }
96
97    /** Updates the system insets */
98    public void updateSystemInsets(Rect insets) {
99        systemInsets.set(insets);
100    }
101
102    /** Converts from DPs to PXs */
103    public int pxFromDp(float size) {
104        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
105                size, mDisplayMetrics));
106    }
107    /** Converts from SPs to PXs */
108    public int pxFromSp(float size) {
109        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
110                size, mDisplayMetrics));
111    }
112}
113