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
19/**
20 * The launch state of the RecentsActivity.
21 *
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 */
28public class RecentsActivityLaunchState {
29
30    public boolean launchedWithAltTab;
31    public boolean launchedFromApp;
32    public boolean launchedFromHome;
33    public boolean launchedViaDragGesture;
34    public boolean launchedViaDockGesture;
35    public int launchedToTaskId;
36    public int launchedNumVisibleTasks;
37    public int launchedNumVisibleThumbnails;
38
39    public void reset() {
40        launchedFromHome = false;
41        launchedFromApp = false;
42        launchedToTaskId = -1;
43        launchedWithAltTab = false;
44        launchedViaDragGesture = false;
45        launchedViaDockGesture = false;
46    }
47
48    /**
49     * Returns the task to focus given the current launch state.
50     */
51    public int getInitialFocusTaskIndex(int numTasks) {
52        RecentsDebugFlags debugFlags = Recents.getDebugFlags();
53        RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
54        if (launchedFromApp) {
55            if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
56                // If fast toggling, focus the front most task so that the next tap will focus the
57                // N-1 task
58                return numTasks - 1;
59            }
60
61            // If coming from another app, focus the next task
62            return Math.max(0, numTasks - 2);
63        } else {
64            if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) {
65                // If fast toggling, defer focusing until the next tap (which will automatically
66                // focus the front most task)
67                return -1;
68            }
69
70            // If coming from home, focus the first task
71            return numTasks - 1;
72        }
73    }
74}
75