RecentsConfiguration.java revision 00350bb3a03e15cbde74db9a07ab98eb08b4e4df
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.Resources;
21import android.graphics.Rect;
22import android.util.DisplayMetrics;
23import android.util.TypedValue;
24import com.android.systemui.R;
25
26
27/** A static Recents configuration for the current context
28 * NOTE: We should not hold any references to a Context from a static instance */
29public class RecentsConfiguration {
30    static RecentsConfiguration sInstance;
31
32    DisplayMetrics mDisplayMetrics;
33
34    public Rect systemInsets = new Rect();
35    public Rect displayRect = new Rect();
36
37    public float animationPxMovementPerSecond;
38
39    public int filteringCurrentViewsMinAnimDuration;
40    public int filteringNewViewsMinAnimDuration;
41
42    /** Private constructor */
43    private RecentsConfiguration() {}
44
45    /** Updates the configuration to the current context */
46    public static RecentsConfiguration reinitialize(Context context) {
47        if (sInstance == null) {
48            sInstance = new RecentsConfiguration();
49        }
50        sInstance.update(context);
51        return sInstance;
52    }
53
54    /** Returns the current recents configuration */
55    public static RecentsConfiguration getInstance() {
56        return sInstance;
57    }
58
59    /** Updates the state, given the specified context */
60    void update(Context context) {
61        Resources res = context.getResources();
62        DisplayMetrics dm = res.getDisplayMetrics();
63        mDisplayMetrics = dm;
64
65        displayRect.set(0, 0, dm.widthPixels, dm.heightPixels);
66        animationPxMovementPerSecond =
67                res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);
68        filteringCurrentViewsMinAnimDuration =
69                res.getInteger(R.integer.recents_filter_animate_current_views_min_duration);
70        filteringNewViewsMinAnimDuration =
71                res.getInteger(R.integer.recents_filter_animate_new_views_min_duration);
72    }
73
74    public void updateSystemInsets(Rect insets) {
75        systemInsets.set(insets);
76    }
77
78    /** Converts from DPs to PXs */
79    public int pxFromDp(float size) {
80        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
81                size, mDisplayMetrics));
82    }
83    /** Converts from SPs to PXs */
84    public int pxFromSp(float size) {
85        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
86                size, mDisplayMetrics));
87    }
88}
89