RecentsConfiguration.java revision 19d62382d0acafa0ffe8e48ebb4c737031b3e9c6
1303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung/*
2303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Copyright (C) 2014 The Android Open Source Project
3303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung *
4303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Licensed under the Apache License, Version 2.0 (the "License");
5303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * you may not use this file except in compliance with the License.
6303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * You may obtain a copy of the License at
7303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung *
8303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung *      http://www.apache.org/licenses/LICENSE-2.0
9303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung *
10303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * Unless required by applicable law or agreed to in writing, software
11303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * distributed under the License is distributed on an "AS IS" BASIS,
12303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * See the License for the specific language governing permissions and
14303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * limitations under the License.
15303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung */
16303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
17303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungpackage com.android.systemui.recents;
18303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
19852975d5377bfe5f4abc9d2a28e301aa2fa99994Dianne Hackbornimport android.app.ActivityManager;
20303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.content.Context;
21f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chungimport android.content.SharedPreferences;
226736905dc0e10689f7c63f6da43b31325caf966aWinson Chungimport android.content.res.Configuration;
23c620bafde865f7599401f5adf0521820ee9d4a9cWinson Chungimport android.content.res.Resources;
24303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.graphics.Rect;
2547a3e65acc35cd3061bf3867e8b20753870fd892Winson Chungimport android.provider.Settings;
26303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.util.DisplayMetrics;
27303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungimport android.util.TypedValue;
28918c0723a169cef46b8bf59c06fd3bb8021d0defWinson Chungimport android.view.animation.AnimationUtils;
29918c0723a169cef46b8bf59c06fd3bb8021d0defWinson Chungimport android.view.animation.Interpolator;
302f2ca08baa072376b3dfd60506625496aa05903fWinson Chungimport com.android.systemui.R;
31ffa2ec664479bff6b4b61d4c349d9db2cb37ca16Winson Chungimport com.android.systemui.recents.misc.Console;
3256e09b42a0f1670970872bef611a8036904ad6bfJason Monkimport com.android.systemui.recents.misc.SystemServicesProxy;
33303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
34303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
35303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung/** A static Recents configuration for the current context
36303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung * NOTE: We should not hold any references to a Context from a static instance */
37303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chungpublic class RecentsConfiguration {
38303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    static RecentsConfiguration sInstance;
3985cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung    static int sPrevConfigurationHashCode;
40303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
41d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Animations */
4200350bb3a03e15cbde74db9a07ab98eb08b4e4dfWinson Chung    public float animationPxMovementPerSecond;
432f2ca08baa072376b3dfd60506625496aa05903fWinson Chung
44d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Interpolators */
45b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    public Interpolator fastOutSlowInInterpolator;
46b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    public Interpolator fastOutLinearInInterpolator;
47b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    public Interpolator linearOutSlowInInterpolator;
48d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public Interpolator quintOutInterpolator;
49918c0723a169cef46b8bf59c06fd3bb8021d0defWinson Chung
50d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Filtering */
51e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung    public int filteringCurrentViewsAnimDuration;
52e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung    public int filteringNewViewsAnimDuration;
53cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
54d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Insets */
55d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public Rect systemInsets = new Rect();
56d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public Rect displayRect = new Rect();
57d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung
58d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Layout */
59d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    boolean isLandscape;
60d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    boolean transposeRecentsLayoutWithOrientation;
61d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung
62b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung    /** Loading */
63b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung    public int maxNumTasksToLoad;
64b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung
65d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Search bar */
66d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    int searchBarAppWidgetId = -1;
67d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public int searchBarSpaceHeightPx;
68d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung
69d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Task stack */
70ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung    public int taskStackScrollDuration;
711492646b792360945fba6bdcacc6aa7c19c6618eWinson Chung    public int taskStackMaxDim;
72cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung    public int taskStackTopPaddingPx;
73d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public float taskStackWidthPaddingPct;
74ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung    public float taskStackOverscrollPct;
75cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
76d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Task view animation and styles */
77d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public int taskViewEnterFromHomeDelay;
7819d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung    public int taskViewEnterFromHomeDuration;
7919d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung    public int taskViewEnterFromHomeStaggerDelay;
80ad6f276670443ac8f9b73497dae185bb005c3a76Winson Chung    public int taskViewExitToHomeDuration;
819f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung    public int taskViewRemoveAnimDuration;
829f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung    public int taskViewRemoveAnimTranslationXPx;
8396e3bc1f8d7c199df6fca603d0c5e59d9b70ca1bWinson Chung    public int taskViewTranslationZMinPx;
84012ef36a6c5e9745d112c734aed916cab052558cWinson Chung    public int taskViewTranslationZMaxPx;
851492646b792360945fba6bdcacc6aa7c19c6618eWinson Chung    public int taskViewRoundedCornerRadiusPx;
86cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung    public int taskViewHighlightPx;
871907cd478209f01a4215d9a3a76294c2c77c9a63Winson Chung    public int taskViewAffiliateGroupEnterOffsetPx;
8860a729c8e93461c9446d0c8cd519b40dec01e8d8Winson Chung    public float taskViewThumbnailAlpha;
89cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
90d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Task bar colors */
91f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung    public int taskBarViewDefaultBackgroundColor;
92f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung    public int taskBarViewLightTextColor;
93f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung    public int taskBarViewDarkTextColor;
94cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung    public int taskBarViewHighlightColor;
95ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung    public float taskBarViewAffiliationColorMinAlpha;
96cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
97a433fa9c17772f563163ff7db177d091d6aebd5bWinson Chung    /** Task bar size & animations */
98a433fa9c17772f563163ff7db177d091d6aebd5bWinson Chung    public int taskBarHeight;
99cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung    public int taskBarEnterAnimDuration;
100521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    public int taskBarEnterAnimDelay;
101cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung    public int taskBarExitAnimDuration;
102a26fb7822ddf3511796279b847cc216bee9e7f70Winson Chung    public int taskBarDismissDozeDelaySeconds;
103f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung
1041f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung    /** Lock to app */
1051f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung    public int taskViewLockToAppButtonHeight;
1061f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung    public int taskViewLockToAppShortAnimDuration;
1071f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung    public int taskViewLockToAppLongAnimDuration;
1081f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung
109d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Nav bar scrim */
110521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    public int navBarScrimEnterDuration;
111521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung
112d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    /** Launch states */
113d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public boolean launchedWithAltTab;
114969f586533096999f10f5587f901949791154fa2Winson Chung    public boolean launchedWithNoRecentTasks;
115d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public boolean launchedFromAppWithThumbnail;
116d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public boolean launchedFromAppWithScreenshot;
117d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung    public boolean launchedFromHome;
1186057c91563402f900dfc7714a46e952d86172e2fWinson Chung    public int launchedToTaskId;
119b44c24fb50845dfbc1f49e78085cf5e01a32067fWinson Chung
120a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung    /** Misc **/
121a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung    public int altTabKeyDelay;
122a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung
12356e09b42a0f1670970872bef611a8036904ad6bfJason Monk    /** Dev options and global settings */
12456e09b42a0f1670970872bef611a8036904ad6bfJason Monk    public boolean lockToAppEnabled;
12547a3e65acc35cd3061bf3867e8b20753870fd892Winson Chung    public boolean developerOptionsEnabled;
1268eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung    public boolean debugModeEnabled;
12747a3e65acc35cd3061bf3867e8b20753870fd892Winson Chung
128303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    /** Private constructor */
12906795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    private RecentsConfiguration(Context context) {
13006795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        // Properties that don't have to be reloaded with each configuration change can be loaded
13106795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        // here.
13206795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung
13306795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        // Interpolators
13406795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
13506795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung                com.android.internal.R.interpolator.fast_out_slow_in);
13606795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        fastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
13706795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung                com.android.internal.R.interpolator.fast_out_linear_in);
13806795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        linearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
13906795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung                com.android.internal.R.interpolator.linear_out_slow_in);
14006795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        quintOutInterpolator = AnimationUtils.loadInterpolator(context,
14106795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung                com.android.internal.R.interpolator.decelerate_quint);
14206795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    }
143303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
144303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    /** Updates the configuration to the current context */
14556e09b42a0f1670970872bef611a8036904ad6bfJason Monk    public static RecentsConfiguration reinitialize(Context context, SystemServicesProxy ssp) {
146303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        if (sInstance == null) {
14706795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung            sInstance = new RecentsConfiguration(context);
148303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        }
14985cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung        int configHashCode = context.getResources().getConfiguration().hashCode();
15085cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung        if (sPrevConfigurationHashCode != configHashCode) {
15185cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung            sInstance.update(context);
15285cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung            sPrevConfigurationHashCode = configHashCode;
15385cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung        }
15456e09b42a0f1670970872bef611a8036904ad6bfJason Monk        sInstance.updateOnReinitialize(context, ssp);
155303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        return sInstance;
156303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
157303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
158303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    /** Returns the current recents configuration */
159303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    public static RecentsConfiguration getInstance() {
160303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        return sInstance;
161303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
162303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
163303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    /** Updates the state, given the specified context */
164303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    void update(Context context) {
1658eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung        SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0);
166c620bafde865f7599401f5adf0521820ee9d4a9cWinson Chung        Resources res = context.getResources();
167c620bafde865f7599401f5adf0521820ee9d4a9cWinson Chung        DisplayMetrics dm = res.getDisplayMetrics();
168303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
1698eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung        // Debug mode
1708eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung        debugModeEnabled = settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false);
1717aceb9a07fd3883c8f301ba93726d55494b0446eWinson Chung        if (debugModeEnabled) {
1727aceb9a07fd3883c8f301ba93726d55494b0446eWinson Chung            Console.Enabled = true;
1737aceb9a07fd3883c8f301ba93726d55494b0446eWinson Chung        }
1748eaeb7dc93ed71b768a2ea8d45021cca010e8263Winson Chung
175242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung        // Layout
176b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung        isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
177242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung        transposeRecentsLayoutWithOrientation =
178242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung                res.getBoolean(R.bool.recents_transpose_layout_with_orientation);
179242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung
180242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung        // Insets
181242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung        displayRect.set(0, 0, dm.widthPixels, dm.heightPixels);
182242bbb86e8811ad8759790c1b499d0918baece8bWinson Chung
183d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Animations
18400350bb3a03e15cbde74db9a07ab98eb08b4e4dfWinson Chung        animationPxMovementPerSecond =
1852f2ca08baa072376b3dfd60506625496aa05903fWinson Chung                res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);
186d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung
187d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Filtering
188e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung        filteringCurrentViewsAnimDuration =
189e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung                res.getInteger(R.integer.recents_filter_animate_current_views_duration);
190e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung        filteringNewViewsAnimDuration =
191e0e45bc26d02e2c6ec505ea006e7487f3a5bddc5Winson Chung                res.getInteger(R.integer.recents_filter_animate_new_views_duration);
192cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
193b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung        // Loading
194852975d5377bfe5f4abc9d2a28e301aa2fa99994Dianne Hackborn        maxNumTasksToLoad = ActivityManager.getMaxRecentTasksStatic();
195b1f749906f5c27114d02ea0c3f8ce0dcea08fd3fWinson Chung
19685cfec811e35025dbde54f4dc09fe0e1337c36b8Winson Chung        // Search Bar
197d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
198d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1);
199d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung
200d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Task stack
201ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung        taskStackScrollDuration =
202ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung                res.getInteger(R.integer.recents_animate_task_stack_scroll_duration);
203cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        TypedValue widthPaddingPctValue = new TypedValue();
204cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        res.getValue(R.dimen.recents_stack_width_padding_percentage, widthPaddingPctValue, true);
205cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskStackWidthPaddingPct = widthPaddingPctValue.getFloat();
206ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung        TypedValue stackOverscrollPctValue = new TypedValue();
207ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung        res.getValue(R.dimen.recents_stack_overscroll_percentage, stackOverscrollPctValue, true);
208ebfc6981828b0699eef85c58b23a61f2cac41af3Winson Chung        taskStackOverscrollPct = stackOverscrollPctValue.getFloat();
209d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim);
210cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.recents_stack_top_padding);
211cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
212d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Task view animation and styles
213d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        taskViewEnterFromHomeDelay =
214d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung                res.getInteger(R.integer.recents_animate_task_enter_from_home_delay);
21519d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung        taskViewEnterFromHomeDuration =
21619d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung                res.getInteger(R.integer.recents_animate_task_enter_from_home_duration);
21719d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung        taskViewEnterFromHomeStaggerDelay =
21819d62382d0acafa0ffe8e48ebb4c737031b3e9c6Winson Chung                res.getInteger(R.integer.recents_animate_task_enter_from_home_stagger_delay);
219ad6f276670443ac8f9b73497dae185bb005c3a76Winson Chung        taskViewExitToHomeDuration =
220ad6f276670443ac8f9b73497dae185bb005c3a76Winson Chung                res.getInteger(R.integer.recents_animate_task_exit_to_home_duration);
2219f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung        taskViewRemoveAnimDuration =
2229f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung                res.getInteger(R.integer.recents_animate_task_view_remove_duration);
2239f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung        taskViewRemoveAnimTranslationXPx =
2249f49df933f01a32d04bdf92d53c943065aa8ddf7Winson Chung                res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x);
2251492646b792360945fba6bdcacc6aa7c19c6618eWinson Chung        taskViewRoundedCornerRadiusPx =
2261492646b792360945fba6bdcacc6aa7c19c6618eWinson Chung                res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius);
227cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight);
22896e3bc1f8d7c199df6fca603d0c5e59d9b70ca1bWinson Chung        taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min);
229012ef36a6c5e9745d112c734aed916cab052558cWinson Chung        taskViewTranslationZMaxPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_max);
2301907cd478209f01a4215d9a3a76294c2c77c9a63Winson Chung        taskViewAffiliateGroupEnterOffsetPx =
2311907cd478209f01a4215d9a3a76294c2c77c9a63Winson Chung                res.getDimensionPixelSize(R.dimen.recents_task_view_affiliate_group_enter_offset);
23260a729c8e93461c9446d0c8cd519b40dec01e8d8Winson Chung        TypedValue thumbnailAlphaValue = new TypedValue();
23360a729c8e93461c9446d0c8cd519b40dec01e8d8Winson Chung        res.getValue(R.dimen.recents_task_view_thumbnail_alpha, thumbnailAlphaValue, true);
23460a729c8e93461c9446d0c8cd519b40dec01e8d8Winson Chung        taskViewThumbnailAlpha = thumbnailAlphaValue.getFloat();
235cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
236d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Task bar colors
237f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung        taskBarViewDefaultBackgroundColor =
238f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung                res.getColor(R.color.recents_task_bar_default_background_color);
239f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung        taskBarViewLightTextColor =
240f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung                res.getColor(R.color.recents_task_bar_light_text_color);
241f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung        taskBarViewDarkTextColor =
242f5e22e71cb5f8699a4312c797af068f655cbe629Winson Chung                res.getColor(R.color.recents_task_bar_dark_text_color);
243cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskBarViewHighlightColor =
244cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung                res.getColor(R.color.recents_task_bar_highlight_color);
245ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung        TypedValue affMinAlphaPctValue = new TypedValue();
246ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung        res.getValue(R.dimen.recents_task_affiliation_color_min_alpha_percentage, affMinAlphaPctValue, true);
247ec396d6399c5c31d697d81e94aff459e9771b0c6Winson Chung        taskBarViewAffiliationColorMinAlpha = affMinAlphaPctValue.getFloat();
248cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung
249a433fa9c17772f563163ff7db177d091d6aebd5bWinson Chung        // Task bar size & animations
250a433fa9c17772f563163ff7db177d091d6aebd5bWinson Chung        taskBarHeight = res.getDimensionPixelSize(R.dimen.recents_task_bar_height);
251cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskBarEnterAnimDuration =
252cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung                res.getInteger(R.integer.recents_animate_task_bar_enter_duration);
253521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung        taskBarEnterAnimDelay =
254521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung                res.getInteger(R.integer.recents_animate_task_bar_enter_delay);
255cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung        taskBarExitAnimDuration =
256cd23c849afefe58b213d5abb1c581f15d3ad543aWinson Chung                res.getInteger(R.integer.recents_animate_task_bar_exit_duration);
257a26fb7822ddf3511796279b847cc216bee9e7f70Winson Chung        taskBarDismissDozeDelaySeconds =
258a26fb7822ddf3511796279b847cc216bee9e7f70Winson Chung                res.getInteger(R.integer.recents_task_bar_dismiss_delay_seconds);
259f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung
2601f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung        // Lock to app
2611f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung        taskViewLockToAppButtonHeight =
2621f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung                res.getDimensionPixelSize(R.dimen.recents_task_view_lock_to_app_button_height);
2631f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung        taskViewLockToAppShortAnimDuration =
2641f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung                res.getInteger(R.integer.recents_animate_lock_to_app_button_short_duration);
2651f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung        taskViewLockToAppLongAnimDuration =
2661f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung                res.getInteger(R.integer.recents_animate_lock_to_app_button_long_duration);
2671f24c7e37bc794057a156a730c7e4b53b01212edWinson Chung
268d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        // Nav bar scrim
269521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung        navBarScrimEnterDuration =
270521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung                res.getInteger(R.integer.recents_nav_bar_scrim_enter_duration);
271a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung
272a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung        // Misc
273a0e88b5013d708ac6ed6518817d83c64c87ae4b1Winson Chung        altTabKeyDelay = res.getInteger(R.integer.recents_alt_tab_key_delay);
274303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
275303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
27611ca76a53c60a1898956614315ae929668c523d6Winson Chung    /** Updates the system insets */
277303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    public void updateSystemInsets(Rect insets) {
278303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung        systemInsets.set(insets);
279303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung    }
280303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung
281f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    /** Updates the search bar app widget */
282f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    public void updateSearchBarAppWidgetId(Context context, int appWidgetId) {
283f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        searchBarAppWidgetId = appWidgetId;
284f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0);
285f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        settings.edit().putInt(Constants.Values.App.Key_SearchAppWidgetId,
286f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung                appWidgetId).apply();
287f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    }
288f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung
28956e09b42a0f1670970872bef611a8036904ad6bfJason Monk    /** Updates the states that need to be re-read whenever we re-initialize. */
29056e09b42a0f1670970872bef611a8036904ad6bfJason Monk    void updateOnReinitialize(Context context, SystemServicesProxy ssp) {
29156e09b42a0f1670970872bef611a8036904ad6bfJason Monk        // Check if the developer options are enabled
29256e09b42a0f1670970872bef611a8036904ad6bfJason Monk        developerOptionsEnabled = ssp.getGlobalSetting(context,
29356e09b42a0f1670970872bef611a8036904ad6bfJason Monk                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED) != 0;
29456e09b42a0f1670970872bef611a8036904ad6bfJason Monk        lockToAppEnabled = ssp.getSystemSetting(context,
29556e09b42a0f1670970872bef611a8036904ad6bfJason Monk                Settings.System.LOCK_TO_APP_ENABLED) != 0;
29656e09b42a0f1670970872bef611a8036904ad6bfJason Monk    }
29756e09b42a0f1670970872bef611a8036904ad6bfJason Monk
298b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    /** Called when the configuration has changed, and we want to reset any configuration specific
299b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung     * members. */
300b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    public void updateOnConfigurationChange() {
301d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        launchedWithAltTab = false;
302969f586533096999f10f5587f901949791154fa2Winson Chung        launchedWithNoRecentTasks = false;
303d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        launchedFromAppWithThumbnail = false;
304d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        launchedFromAppWithScreenshot = false;
305d42a6cfe2bf632222617450a1ed340268e82f06cWinson Chung        launchedFromHome = false;
3066057c91563402f900dfc7714a46e952d86172e2fWinson Chung        launchedToTaskId = -1;
307b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung    }
308b01ed681fe97ff5e98471c120ff9581a78db13c5Winson Chung
309521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    /** Returns whether the search bar app widget exists. */
310f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    public boolean hasSearchBarAppWidget() {
311f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        return searchBarAppWidgetId >= 0;
312f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    }
313f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung
31406795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    /** Returns whether the status bar scrim should be animated when shown for the first time. */
31506795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    public boolean shouldAnimateStatusBarScrim() {
31606795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        return launchedFromHome;
31706795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    }
31806795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung
31906795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    /** Returns whether the status bar scrim should be visible. */
32006795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    public boolean hasStatusBarScrim() {
32106795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung        return !launchedWithNoRecentTasks;
32206795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung    }
32306795630f62e1e7ad89825db23d7656f8dcd6c5aWinson Chung
324743d5c95f3a107639c0ff22f099cab2624da3e27Winson Chung    /** Returns whether the nav bar scrim should be animated when shown for the first time. */
325743d5c95f3a107639c0ff22f099cab2624da3e27Winson Chung    public boolean shouldAnimateNavBarScrim() {
326969f586533096999f10f5587f901949791154fa2Winson Chung        return true;
327743d5c95f3a107639c0ff22f099cab2624da3e27Winson Chung    }
328743d5c95f3a107639c0ff22f099cab2624da3e27Winson Chung
329521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    /** Returns whether the nav bar scrim should be visible. */
330521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    public boolean hasNavBarScrim() {
331969f586533096999f10f5587f901949791154fa2Winson Chung        // Only show the scrim if we have recent tasks, and if the nav bar is not transposed
332969f586533096999f10f5587f901949791154fa2Winson Chung        return !launchedWithNoRecentTasks &&
333969f586533096999f10f5587f901949791154fa2Winson Chung                (!transposeRecentsLayoutWithOrientation || !isLandscape);
334521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung    }
335521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung
336480dd72daf927283997bdb4060091299add66832Winson Chung    /** Returns whether the current layout is horizontal. */
337480dd72daf927283997bdb4060091299add66832Winson Chung    public boolean hasHorizontalLayout() {
338480dd72daf927283997bdb4060091299add66832Winson Chung        return isLandscape && transposeRecentsLayoutWithOrientation;
339480dd72daf927283997bdb4060091299add66832Winson Chung    }
340480dd72daf927283997bdb4060091299add66832Winson Chung
341f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    /**
342f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     * Returns the task stack bounds in the current orientation. These bounds do not account for
343f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     * the system insets.
344f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     */
345dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung    public void getTaskStackBounds(int windowWidth, int windowHeight, int topInset, int rightInset,
346dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung                                   Rect taskStackBounds) {
347dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung        Rect searchBarBounds = new Rect();
348dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung        getSearchBarBounds(windowWidth, windowHeight, topInset, searchBarBounds);
349dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung        if (isLandscape && transposeRecentsLayoutWithOrientation) {
350dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            // In landscape, the search bar appears on the left
351dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            taskStackBounds.set(searchBarBounds.right, topInset, windowWidth - rightInset, windowHeight);
352f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        } else {
353dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            // In portrait, the search bar appears on the top (which already has the inset)
354dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            taskStackBounds.set(0, searchBarBounds.bottom, windowWidth, windowHeight);
355f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        }
356f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    }
357f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung
358f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung    /**
359f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     * Returns the search bar bounds in the current orientation.  These bounds do not account for
360f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     * the system insets.
361f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung     */
362dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung    public void getSearchBarBounds(int windowWidth, int windowHeight, int topInset,
363dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung                                   Rect searchBarSpaceBounds) {
364ecd9b3031c9a322bd69380eae2810d53839e8f64Winson Chung        // Return empty rects if search is not enabled
365dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung        int searchBarSize = searchBarSpaceHeightPx;
366dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung        if (!Constants.DebugFlags.App.EnableSearchLayout || !hasSearchBarAppWidget()) {
367dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            searchBarSize = 0;
368ecd9b3031c9a322bd69380eae2810d53839e8f64Winson Chung        }
369ecd9b3031c9a322bd69380eae2810d53839e8f64Winson Chung
370521e7dc0a6782371a710ee81bf804f7e97aaa292Winson Chung        if (isLandscape && transposeRecentsLayoutWithOrientation) {
371f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung            // In landscape, the search bar appears on the left
372dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            searchBarSpaceBounds.set(0, topInset, searchBarSize, windowHeight);
373f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        } else {
374f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung            // In portrait, the search bar appears on the top
375dcfa7976fa836ae90bb4a579892a18a0abf35b3cWinson Chung            searchBarSpaceBounds.set(0, topInset, windowWidth, topInset + searchBarSize);
376f7bca430d9356c26d6df222d2c90bc7668262f6bWinson Chung        }
377ecd9b3031c9a322bd69380eae2810d53839e8f64Winson Chung    }
378303e1ff1fec8b240b587bb18b981247a99833aa8Winson Chung}
379