Skip to content

Commit b1f7499

Browse files
Winson Chungdsandler
authored andcommitted
Initial changes to support swiping on the nav bar to switch affiliated tasks.
- Actual sideways animations to come once they've been finalized Bug: 16846966 Change-Id: If6d40495498197a86a98f9b03f54ced3d2baf64a
1 parent 7036cb6 commit b1f7499

12 files changed

Lines changed: 299 additions & 19 deletions

packages/SystemUI/res/values/config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
<integer name="recents_animate_task_view_remove_duration">250</integer>
146146
<!-- The minimum alpha for the dim applied to cards that go deeper into the stack. -->
147147
<integer name="recents_max_task_stack_view_dim">96</integer>
148+
<!-- The number of tasks that RecentsTaskLoader should load. -->
149+
<integer name="recents_max_num_tasks_to_load">50</integer>
148150
<!-- Transposes the recents layout in landscape. -->
149151
<bool name="recents_transpose_layout_with_orientation">true</bool>
150152

packages/SystemUI/src/com/android/systemui/RecentsComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ public interface Callbacks {
2929
void toggleRecents(Display display, int layoutDirection, View statusBarView);
3030
void preloadRecents();
3131
void cancelPreloadingRecents();
32+
void showNextAffiliatedTask();
33+
void showPrevAffiliatedTask();
3234
void setCallback(Callbacks cb);
3335
}

packages/SystemUI/src/com/android/systemui/recent/Recents.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ public void cancelPreloadingRecents() {
273273
}
274274
}
275275

276+
@Override
277+
public void showNextAffiliatedTask() {
278+
if (mUseAlternateRecents) {
279+
mAlternateRecents.onShowNextAffiliatedTask();
280+
}
281+
}
282+
283+
@Override
284+
public void showPrevAffiliatedTask() {
285+
if (mUseAlternateRecents) {
286+
mAlternateRecents.onShowPrevAffiliatedTask();
287+
}
288+
}
289+
276290
@Override
277291
public void setCallback(Callbacks cb) {
278292
if (mUseAlternateRecents) {

packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import com.android.systemui.RecentsComponent;
3535
import com.android.systemui.recents.misc.Console;
3636
import com.android.systemui.recents.misc.SystemServicesProxy;
37+
import com.android.systemui.recents.misc.Utilities;
3738
import com.android.systemui.recents.model.RecentsTaskLoader;
3839
import com.android.systemui.recents.model.Task;
40+
import com.android.systemui.recents.model.TaskGrouping;
3941
import com.android.systemui.recents.model.TaskStack;
4042
import com.android.systemui.recents.views.TaskStackView;
4143
import com.android.systemui.recents.views.TaskStackViewLayoutAlgorithm;
@@ -165,6 +167,77 @@ public void onCancelPreloadingRecents() {
165167
// Do nothing
166168
}
167169

170+
void showRelativeAffiliatedTask(boolean showNextTask) {
171+
TaskStack stack = RecentsTaskLoader.getShallowTaskStack(mSystemServicesProxy,
172+
Integer.MAX_VALUE);
173+
// Return early if there are no tasks
174+
if (stack.getTaskCount() == 0) return;
175+
176+
ActivityManager.RunningTaskInfo runningTask = getTopMostTask();
177+
// Return early if the running task is in the home stack (optimization)
178+
if (mSystemServicesProxy.isInHomeStack(runningTask.id)) return;
179+
180+
// Find the task in the recents list
181+
ArrayList<Task> tasks = stack.getTasks();
182+
Task toTask = null;
183+
ActivityOptions launchOpts = null;
184+
int taskCount = tasks.size();
185+
for (int i = 0; i < taskCount; i++) {
186+
Task task = tasks.get(i);
187+
if (task.key.id == runningTask.id) {
188+
TaskGrouping group = task.group;
189+
Task.TaskKey toTaskKey;
190+
if (showNextTask) {
191+
toTaskKey = group.getNextTaskInGroup(task);
192+
// XXX: We will actually set the appropriate launch animations here
193+
} else {
194+
toTaskKey = group.getPrevTaskInGroup(task);
195+
// XXX: We will actually set the appropriate launch animations here
196+
}
197+
if (toTaskKey != null) {
198+
toTask = stack.findTaskWithId(toTaskKey.id);
199+
}
200+
break;
201+
}
202+
}
203+
204+
// Return early if there is no next task
205+
if (toTask == null) {
206+
// XXX: We will actually show a bounce animation here
207+
return;
208+
}
209+
210+
// Launch the task
211+
if (toTask.isActive) {
212+
// Bring an active task to the foreground
213+
mSystemServicesProxy.moveTaskToFront(toTask.key.id, launchOpts);
214+
} else {
215+
// Launch the activity anew with the desired animation
216+
boolean isDocument = Utilities.isDocument(toTask.key.baseIntent);
217+
Intent intent = new Intent(toTask.key.baseIntent);
218+
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
219+
| Intent.FLAG_ACTIVITY_TASK_ON_HOME);
220+
if (!isDocument) {
221+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
222+
}
223+
try {
224+
mSystemServicesProxy.startActivityFromRecents(toTask.key.id, launchOpts);
225+
} catch (ActivityNotFoundException anfe) {}
226+
227+
// Remove the old task from activity manager
228+
RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(toTask.key.id,
229+
isDocument);
230+
}
231+
}
232+
233+
public void onShowNextAffiliatedTask() {
234+
showRelativeAffiliatedTask(true);
235+
}
236+
237+
public void onShowPrevAffiliatedTask() {
238+
showRelativeAffiliatedTask(false);
239+
}
240+
168241
public void onConfigurationChanged(Configuration newConfig) {
169242
mConfig = RecentsConfiguration.reinitialize(mContext, mSystemServicesProxy);
170243
mConfig.updateOnConfigurationChange();
@@ -318,7 +391,7 @@ ActivityOptions getThumbnailTransitionActivityOptions(ActivityManager.RunningTas
318391
/** Returns the transition rect for the given task id. */
319392
Rect getThumbnailTransitionRect(int runningTaskId) {
320393
// Get the stack of tasks that we are animating into
321-
TaskStack stack = RecentsTaskLoader.getShallowTaskStack(mSystemServicesProxy);
394+
TaskStack stack = RecentsTaskLoader.getShallowTaskStack(mSystemServicesProxy, -1);
322395
if (stack.getTaskCount() == 0) {
323396
return new Rect();
324397
}

packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public class RecentsConfiguration {
5858
boolean isLandscape;
5959
boolean transposeRecentsLayoutWithOrientation;
6060

61+
/** Loading */
62+
public int maxNumTasksToLoad;
63+
6164
/** Search bar */
6265
int searchBarAppWidgetId = -1;
6366
public int searchBarSpaceHeightPx;
@@ -162,8 +165,7 @@ void update(Context context) {
162165
}
163166

164167
// Layout
165-
isLandscape = res.getConfiguration().orientation ==
166-
Configuration.ORIENTATION_LANDSCAPE;
168+
isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
167169
transposeRecentsLayoutWithOrientation =
168170
res.getBoolean(R.bool.recents_transpose_layout_with_orientation);
169171

@@ -180,6 +182,9 @@ void update(Context context) {
180182
filteringNewViewsAnimDuration =
181183
res.getInteger(R.integer.recents_filter_animate_new_views_duration);
182184

185+
// Loading
186+
maxNumTasksToLoad = res.getInteger(R.integer.recents_max_num_tasks_to_load);
187+
183188
// Search Bar
184189
searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
185190
searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1);

packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,15 @@ public SystemServicesProxy getSystemServicesProxy() {
295295
}
296296

297297
/** Gets the list of recent tasks, ordered from back to front. */
298-
private static List<ActivityManager.RecentTaskInfo> getRecentTasks(SystemServicesProxy ssp) {
298+
private static List<ActivityManager.RecentTaskInfo> getRecentTasks(SystemServicesProxy ssp,
299+
int numTasks) {
300+
// Set a default number of tasks to query if none is provided
301+
if (numTasks < 0) {
302+
RecentsConfiguration config = RecentsConfiguration.getInstance();
303+
numTasks = config.maxNumTasksToLoad;
304+
}
299305
List<ActivityManager.RecentTaskInfo> tasks =
300-
ssp.getRecentTasks(50, UserHandle.CURRENT.getIdentifier());
306+
ssp.getRecentTasks(numTasks, UserHandle.CURRENT.getIdentifier());
301307
Collections.reverse(tasks);
302308
return tasks;
303309
}
@@ -313,7 +319,7 @@ public SpaceNode reload(Context context, int preloadCount) {
313319

314320
// Get the recent tasks
315321
SystemServicesProxy ssp = mSystemServicesProxy;
316-
List<ActivityManager.RecentTaskInfo> tasks = getRecentTasks(ssp);
322+
List<ActivityManager.RecentTaskInfo> tasks = getRecentTasks(ssp, -1);
317323

318324
// From back to front, add each task to the task stack
319325
int taskCount = tasks.size();
@@ -395,9 +401,9 @@ public SpaceNode reload(Context context, int preloadCount) {
395401
}
396402

397403
/** Creates a lightweight stack of the current recent tasks, without thumbnails and icons. */
398-
public static TaskStack getShallowTaskStack(SystemServicesProxy ssp) {
404+
public static TaskStack getShallowTaskStack(SystemServicesProxy ssp, int numTasks) {
399405
RecentsConfiguration config = RecentsConfiguration.getInstance();
400-
List<ActivityManager.RecentTaskInfo> tasks = getRecentTasks(ssp);
406+
List<ActivityManager.RecentTaskInfo> tasks = getRecentTasks(ssp, numTasks);
401407
TaskStack stack = new TaskStack();
402408

403409
int taskCount = tasks.size();

packages/SystemUI/src/com/android/systemui/recents/model/TaskGrouping.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ void removeTask(Task t) {
4343
updateTaskIndices();
4444
}
4545

46+
/** Returns the key of the next task in the group. */
47+
public Task.TaskKey getNextTaskInGroup(Task t) {
48+
int i = indexOf(t);
49+
if ((i + 1) < getTaskCount()) {
50+
return mTaskKeys.get(i + 1);
51+
}
52+
return null;
53+
}
54+
55+
/** Returns the key of the previous task in the group. */
56+
public Task.TaskKey getPrevTaskInGroup(Task t) {
57+
int i = indexOf(t);
58+
if ((i - 1) >= 0) {
59+
return mTaskKeys.get(i - 1);
60+
}
61+
return null;
62+
}
63+
4664
/** Gets the front task */
4765
public boolean isFrontMostTask(Task t) {
4866
return (t.key == mFrontMostTaskKey);

packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ public int indexOfTask(Task t) {
266266
return mTaskList.indexOf(t);
267267
}
268268

269+
/** Finds the task with the specified task id. */
270+
public Task findTaskWithId(int taskId) {
271+
ArrayList<Task> tasks = mTaskList.getTasks();
272+
int taskCount = tasks.size();
273+
for (int i = 0; i < taskCount; i++) {
274+
Task task = tasks.get(i);
275+
if (task.key.id == taskId) {
276+
return task;
277+
}
278+
}
279+
return null;
280+
}
281+
269282
/******** Filtering ********/
270283

271284
/** Filters the stack into tasks similar to the one specified */

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ public abstract class BaseStatusBar extends SystemUI implements
109109
protected static final int MSG_TOGGLE_RECENTS_APPS = 1021;
110110
protected static final int MSG_PRELOAD_RECENT_APPS = 1022;
111111
protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;
112-
protected static final int MSG_OPEN_SEARCH_PANEL = 1024;
113-
protected static final int MSG_CLOSE_SEARCH_PANEL = 1025;
114-
protected static final int MSG_SHOW_HEADS_UP = 1026;
115-
protected static final int MSG_HIDE_HEADS_UP = 1027;
116-
protected static final int MSG_ESCALATE_HEADS_UP = 1028;
117-
protected static final int MSG_DECAY_HEADS_UP = 1029;
112+
protected static final int MSG_SHOW_NEXT_AFFILIATED_TASK = 1024;
113+
protected static final int MSG_SHOW_PREV_AFFILIATED_TASK = 1025;
114+
protected static final int MSG_OPEN_SEARCH_PANEL = 1026;
115+
protected static final int MSG_CLOSE_SEARCH_PANEL = 1027;
116+
protected static final int MSG_SHOW_HEADS_UP = 1028;
117+
protected static final int MSG_HIDE_HEADS_UP = 1029;
118+
protected static final int MSG_ESCALATE_HEADS_UP = 1030;
119+
protected static final int MSG_DECAY_HEADS_UP = 1031;
118120

119121
protected static final boolean ENABLE_HEADS_UP = true;
120122
// scores above this threshold should be displayed in heads up mode.
@@ -689,6 +691,20 @@ public void cancelPreloadRecentApps() {
689691
mHandler.sendEmptyMessage(msg);
690692
}
691693

694+
/** Jumps to the next affiliated task in the group. */
695+
public void showNextAffiliatedTask() {
696+
int msg = MSG_SHOW_NEXT_AFFILIATED_TASK;
697+
mHandler.removeMessages(msg);
698+
mHandler.sendEmptyMessage(msg);
699+
}
700+
701+
/** Jumps to the previous affiliated task in the group. */
702+
public void showPreviousAffiliatedTask() {
703+
int msg = MSG_SHOW_PREV_AFFILIATED_TASK;
704+
mHandler.removeMessages(msg);
705+
mHandler.sendEmptyMessage(msg);
706+
}
707+
692708
@Override
693709
public void showSearchPanel() {
694710
int msg = MSG_OPEN_SEARCH_PANEL;
@@ -800,6 +816,18 @@ protected void cancelPreloadingRecents() {
800816
}
801817
}
802818

819+
protected void showRecentsNextAffiliatedTask() {
820+
if (mRecents != null) {
821+
mRecents.showNextAffiliatedTask();
822+
}
823+
}
824+
825+
protected void showRecentsPreviousAffiliatedTask() {
826+
if (mRecents != null) {
827+
mRecents.showPrevAffiliatedTask();
828+
}
829+
}
830+
803831
@Override
804832
public void onVisibilityChanged(boolean visible) {
805833
// Do nothing
@@ -884,6 +912,12 @@ public void handleMessage(Message m) {
884912
case MSG_CANCEL_PRELOAD_RECENT_APPS:
885913
cancelPreloadingRecents();
886914
break;
915+
case MSG_SHOW_NEXT_AFFILIATED_TASK:
916+
showRecentsNextAffiliatedTask();
917+
break;
918+
case MSG_SHOW_PREV_AFFILIATED_TASK:
919+
showRecentsPreviousAffiliatedTask();
920+
break;
887921
case MSG_OPEN_SEARCH_PANEL:
888922
if (DEBUG) Log.d(TAG, "opening search panel");
889923
if (mSearchPanelView != null && mSearchPanelView.isAssistantAvailable()) {

packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@
3737
import android.view.View;
3838
import android.view.ViewGroup;
3939
import android.view.WindowManager;
40-
import android.view.accessibility.AccessibilityManager;
41-
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
4240
import android.view.inputmethod.InputMethodManager;
4341
import android.widget.ImageView;
4442
import android.widget.LinearLayout;
45-
4643
import com.android.systemui.R;
4744
import com.android.systemui.statusbar.BaseStatusBar;
4845
import com.android.systemui.statusbar.DelegateViewHelper;
@@ -77,6 +74,7 @@ public class NavigationBarView extends LinearLayout {
7774
private Drawable mRecentIcon;
7875
private Drawable mRecentLandIcon;
7976

77+
private NavigationBarViewTaskSwitchHelper mTaskSwitchHelper;
8078
private DelegateViewHelper mDelegateHelper;
8179
private DeadZone mDeadZone;
8280
private final NavigationBarTransitions mBarTransitions;
@@ -177,6 +175,7 @@ public NavigationBarView(Context context, AttributeSet attrs) {
177175
mVertical = false;
178176
mShowMenu = false;
179177
mDelegateHelper = new DelegateViewHelper(this);
178+
mTaskSwitchHelper = new NavigationBarViewTaskSwitchHelper(context);
180179

181180
getIcons(res);
182181

@@ -192,6 +191,7 @@ public void setDelegateView(View view) {
192191
}
193192

194193
public void setBar(BaseStatusBar phoneStatusBar) {
194+
mTaskSwitchHelper.setBar(phoneStatusBar);
195195
mDelegateHelper.setBar(phoneStatusBar);
196196
}
197197

@@ -201,6 +201,9 @@ public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalCha
201201

202202
@Override
203203
public boolean onTouchEvent(MotionEvent event) {
204+
if (mTaskSwitchHelper.onTouchEvent(event)) {
205+
return true;
206+
}
204207
if (mDeadZone != null && event.getAction() == MotionEvent.ACTION_OUTSIDE) {
205208
mDeadZone.poke(event);
206209
}
@@ -213,7 +216,8 @@ public boolean onTouchEvent(MotionEvent event) {
213216

214217
@Override
215218
public boolean onInterceptTouchEvent(MotionEvent event) {
216-
return mDelegateHelper.onInterceptTouchEvent(event);
219+
return mTaskSwitchHelper.onInterceptTouchEvent(event) ||
220+
mDelegateHelper.onInterceptTouchEvent(event);
217221
}
218222

219223
private H mHandler = new H();
@@ -421,6 +425,8 @@ public void reorient() {
421425
if (mDelegateHelper != null) {
422426
mDelegateHelper.setSwapXY(mVertical);
423427
}
428+
boolean isRTL = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
429+
mTaskSwitchHelper.setBarState(mVertical, isRTL);
424430

425431
setNavigationIconHints(mNavigationIconHints, true);
426432
}

0 commit comments

Comments
 (0)