RecentsActivityLaunchState.java revision 116b2c2c5430122ad7dfa14470bc640bf3c1c59f
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 launchedWithNoRecentTasks; 32 public boolean launchedFromAppWithThumbnail; 33 public boolean launchedFromHome; 34 public boolean launchedFromSearchHome; 35 public boolean launchedReuseTaskStackViews; 36 public boolean launchedHasConfigurationChanged; 37 public boolean launchedViaDragGesture; 38 public int launchedToTaskId; 39 public int launchedNumVisibleTasks; 40 public int launchedNumVisibleThumbnails; 41 42 /** Called when the configuration has changed, and we want to reset any configuration specific 43 * members. */ 44 public void updateOnConfigurationChange() { 45 // Reset this flag on configuration change to ensure that we recreate new task views 46 launchedReuseTaskStackViews = false; 47 // Set this flag to indicate that the configuration has changed since Recents last launched 48 launchedHasConfigurationChanged = true; 49 launchedViaDragGesture = false; 50 } 51 52 /** Returns whether the status bar scrim should be animated when shown for the first time. */ 53 public boolean shouldAnimateStatusBarScrim() { 54 return true; 55 } 56 57 /** Returns whether the status bar scrim should be visible. */ 58 public boolean hasStatusBarScrim() { 59 return !launchedWithNoRecentTasks; 60 } 61 62 /** Returns whether the nav bar scrim should be animated when shown for the first time. */ 63 public boolean shouldAnimateNavBarScrim() { 64 return true; 65 } 66 67 /** Returns whether the nav bar scrim should be visible. */ 68 public boolean hasNavBarScrim() { 69 // Only show the scrim if we have recent tasks, and if the nav bar is not transposed 70 RecentsConfiguration config = Recents.getConfiguration(); 71 return !launchedWithNoRecentTasks && !config.hasTransposedNavBar; 72 } 73 74 /** 75 * Returns the task to focus given the current launch state. 76 */ 77 public int getInitialFocusTaskIndex(int numTasks) { 78 RecentsDebugFlags flags = Recents.getDebugFlags(); 79 if (flags.isPageOnToggleEnabled() && !launchedWithAltTab) { 80 // If we are fast toggling, then focus the next task depending on when you are on home 81 // or coming in from another app 82 if (launchedFromHome) { 83 return numTasks - 1; 84 } else { 85 if (flags.isFastToggleRecentsEnabled() || !flags.isInitialStatePaging()) { 86 return numTasks - 1; 87 } else { 88 return numTasks - 2; 89 } 90 } 91 } 92 93 if (launchedWithAltTab && launchedFromAppWithThumbnail) { 94 // If alt-tabbing from another app, focus the next task 95 return numTasks - 2; 96 } else if ((launchedWithAltTab && launchedFromHome) || 97 (!launchedWithAltTab && launchedFromAppWithThumbnail)) { 98 // If alt-tabbing from home, or launching from an app normally, focus that task 99 return numTasks - 1; 100 } else { 101 // Otherwise, we are launching recents from home normally, focus no tasks so that we 102 // know to return home 103 return -1; 104 } 105 } 106 107 @Override 108 public String toString() { 109 return "RecentsActivityLaunchState altTab: " + launchedWithAltTab + 110 ", noTasks: " + launchedWithNoRecentTasks + 111 ", fromHome: " + launchedFromHome + 112 ", fromSearchHome: " + launchedFromSearchHome + 113 ", reuse: " + launchedReuseTaskStackViews; 114 } 115} 116