blob: aa1437b28ee8bd2430995b41a26d99f741721312 [file] [log] [blame]
Winson35f30502015-09-28 11:24:36 -07001/*
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
19/**
20 * The launch state of the RecentsActivity.
21 *
Winson35f30502015-09-28 11:24:36 -070022 * 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 */
28public class RecentsActivityLaunchState {
29
Winson35f30502015-09-28 11:24:36 -070030 public boolean launchedWithAltTab;
Winson35f30502015-09-28 11:24:36 -070031 public boolean launchedFromAppWithThumbnail;
32 public boolean launchedFromHome;
33 public boolean launchedFromSearchHome;
34 public boolean launchedReuseTaskStackViews;
35 public boolean launchedHasConfigurationChanged;
Winsonb1e71d02015-11-23 12:40:23 -080036 public boolean launchedViaDragGesture;
Jorim Jaggie161f082016-02-05 14:26:16 -080037 public boolean launchedWhileDocking;
Winson35f30502015-09-28 11:24:36 -070038 public int launchedToTaskId;
39 public int launchedNumVisibleTasks;
40 public int launchedNumVisibleThumbnails;
41
Jorim Jaggie161f082016-02-05 14:26:16 -080042 public void reset() {
43 launchedFromHome = false;
44 launchedFromSearchHome = false;
45 launchedFromAppWithThumbnail = false;
46 launchedToTaskId = -1;
47 launchedWithAltTab = false;
48 launchedHasConfigurationChanged = false;
49 launchedViaDragGesture = false;
50 launchedWhileDocking = false;
51 }
52
Winson35f30502015-09-28 11:24:36 -070053 /** Called when the configuration has changed, and we want to reset any configuration specific
54 * members. */
55 public void updateOnConfigurationChange() {
56 // Reset this flag on configuration change to ensure that we recreate new task views
57 launchedReuseTaskStackViews = false;
58 // Set this flag to indicate that the configuration has changed since Recents last launched
59 launchedHasConfigurationChanged = true;
Jorim Jaggi435b2e42015-11-24 15:09:30 -080060 launchedViaDragGesture = false;
Jorim Jaggie161f082016-02-05 14:26:16 -080061 launchedWhileDocking = false;
Winson35f30502015-09-28 11:24:36 -070062 }
63
Winson5da43472015-11-04 17:39:55 -080064 /**
65 * Returns the task to focus given the current launch state.
66 */
67 public int getInitialFocusTaskIndex(int numTasks) {
Winsonb61e6542016-02-04 14:37:18 -080068 RecentsDebugFlags debugFlags = Recents.getDebugFlags();
Winson05e46ca2016-02-05 15:40:29 -080069 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
Winson4b9cded2016-01-26 16:26:47 -080070 if (launchedFromAppWithThumbnail) {
Winson05e46ca2016-02-05 15:40:29 -080071 if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
Winsonb61e6542016-02-04 14:37:18 -080072 // If fast toggling, focus the front most task so that the next tap will focus the
73 // N-1 task
74 return numTasks - 1;
75 }
76
Winson4b9cded2016-01-26 16:26:47 -080077 // If coming from another app, focus the next task
Winson23b0d3f2016-02-15 17:43:01 -080078 return Math.max(0, numTasks - 2);
Winson Chungead5c0f2015-12-14 11:18:57 -050079 } else {
Winson05e46ca2016-02-05 15:40:29 -080080 if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
Winsonb61e6542016-02-04 14:37:18 -080081 // If fast toggling, defer focusing until the next tap (which will automatically
82 // focus the front most task)
83 return -1;
84 }
85
Winson4b9cded2016-01-26 16:26:47 -080086 // If coming from home, focus the first task
87 return numTasks - 1;
Winson5da43472015-11-04 17:39:55 -080088 }
Winson5da43472015-11-04 17:39:55 -080089 }
Winson35f30502015-09-28 11:24:36 -070090}