blob: 77f77393d7abcaab8865346026d49326cb3ec797 [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;
Winsone693aaf2016-03-01 12:05:59 -080031 public boolean launchedFromApp;
32 public boolean launchedFromAppDocked;
Winson35f30502015-09-28 11:24:36 -070033 public boolean launchedFromHome;
Winsonb1e71d02015-11-23 12:40:23 -080034 public boolean launchedViaDragGesture;
Jorim Jaggie161f082016-02-05 14:26:16 -080035 public boolean launchedWhileDocking;
Winson35f30502015-09-28 11:24:36 -070036 public int launchedToTaskId;
37 public int launchedNumVisibleTasks;
38 public int launchedNumVisibleThumbnails;
39
Jorim Jaggie161f082016-02-05 14:26:16 -080040 public void reset() {
41 launchedFromHome = false;
Winsone693aaf2016-03-01 12:05:59 -080042 launchedFromApp = false;
43 launchedFromAppDocked = false;
Jorim Jaggie161f082016-02-05 14:26:16 -080044 launchedToTaskId = -1;
45 launchedWithAltTab = false;
Jorim Jaggie161f082016-02-05 14:26:16 -080046 launchedViaDragGesture = false;
47 launchedWhileDocking = false;
48 }
49
Winson35f30502015-09-28 11:24:36 -070050 /** Called when the configuration has changed, and we want to reset any configuration specific
51 * members. */
52 public void updateOnConfigurationChange() {
Jorim Jaggi435b2e42015-11-24 15:09:30 -080053 launchedViaDragGesture = false;
Jorim Jaggie161f082016-02-05 14:26:16 -080054 launchedWhileDocking = false;
Winson35f30502015-09-28 11:24:36 -070055 }
56
Winson5da43472015-11-04 17:39:55 -080057 /**
58 * Returns the task to focus given the current launch state.
59 */
60 public int getInitialFocusTaskIndex(int numTasks) {
Winsonb61e6542016-02-04 14:37:18 -080061 RecentsDebugFlags debugFlags = Recents.getDebugFlags();
Winson05e46ca2016-02-05 15:40:29 -080062 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
Winsone693aaf2016-03-01 12:05:59 -080063 if (launchedFromApp) {
Winson05e46ca2016-02-05 15:40:29 -080064 if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
Winsonb61e6542016-02-04 14:37:18 -080065 // 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
Winson4b9cded2016-01-26 16:26:47 -080070 // If coming from another app, focus the next task
Winson23b0d3f2016-02-15 17:43:01 -080071 return Math.max(0, numTasks - 2);
Winson Chungead5c0f2015-12-14 11:18:57 -050072 } else {
Winson05e46ca2016-02-05 15:40:29 -080073 if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
Winsonb61e6542016-02-04 14:37:18 -080074 // If fast toggling, defer focusing until the next tap (which will automatically
75 // focus the front most task)
76 return -1;
77 }
78
Winson4b9cded2016-01-26 16:26:47 -080079 // If coming from home, focus the first task
80 return numTasks - 1;
Winson5da43472015-11-04 17:39:55 -080081 }
Winson5da43472015-11-04 17:39:55 -080082 }
Winson35f30502015-09-28 11:24:36 -070083}