Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.recents; |
| 18 | |
| 19 | /** |
| 20 | * The launch state of the RecentsActivity. |
| 21 | * |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 22 | * Current Constraints: |
| 23 | * - needed in onStart() before onNewIntent() |
| 24 | * - needs to be reset when Recents is hidden |
| 25 | * - needs to be computed in Recents component |
| 26 | * - needs to be accessible by views |
| 27 | */ |
| 28 | public class RecentsActivityLaunchState { |
| 29 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 30 | public boolean launchedWithAltTab; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 31 | public boolean launchedFromApp; |
| 32 | public boolean launchedFromAppDocked; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 33 | public boolean launchedFromHome; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 34 | public boolean launchedViaDragGesture; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 35 | public boolean launchedWhileDocking; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 36 | public int launchedToTaskId; |
| 37 | public int launchedNumVisibleTasks; |
| 38 | public int launchedNumVisibleThumbnails; |
| 39 | |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 40 | public void reset() { |
| 41 | launchedFromHome = false; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 42 | launchedFromApp = false; |
| 43 | launchedFromAppDocked = false; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 44 | launchedToTaskId = -1; |
| 45 | launchedWithAltTab = false; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 46 | launchedViaDragGesture = false; |
| 47 | launchedWhileDocking = false; |
| 48 | } |
| 49 | |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 50 | /** Called when the configuration has changed, and we want to reset any configuration specific |
| 51 | * members. */ |
| 52 | public void updateOnConfigurationChange() { |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 53 | launchedViaDragGesture = false; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 54 | launchedWhileDocking = false; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Winson | 5da4347 | 2015-11-04 17:39:55 -0800 | [diff] [blame] | 57 | /** |
| 58 | * Returns the task to focus given the current launch state. |
| 59 | */ |
| 60 | public int getInitialFocusTaskIndex(int numTasks) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 61 | RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 62 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 63 | if (launchedFromApp) { |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 64 | if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 65 | // If fast toggling, focus the front most task so that the next tap will focus the |
| 66 | // N-1 task |
| 67 | return numTasks - 1; |
| 68 | } |
| 69 | |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 70 | // If coming from another app, focus the next task |
Winson | 23b0d3f | 2016-02-15 17:43:01 -0800 | [diff] [blame] | 71 | return Math.max(0, numTasks - 2); |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 72 | } else { |
Winson | 05e46ca | 2016-02-05 15:40:29 -0800 | [diff] [blame] | 73 | if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 74 | // If fast toggling, defer focusing until the next tap (which will automatically |
| 75 | // focus the front most task) |
| 76 | return -1; |
| 77 | } |
| 78 | |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 79 | // If coming from home, focus the first task |
| 80 | return numTasks - 1; |
Winson | 5da4347 | 2015-11-04 17:39:55 -0800 | [diff] [blame] | 81 | } |
Winson | 5da4347 | 2015-11-04 17:39:55 -0800 | [diff] [blame] | 82 | } |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 83 | } |