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