diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index 4cfdc3d1f4177..6bdcf7035bc6e 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -50,6 +50,7 @@ import com.android.systemui.recents.events.activity.DockedTopTaskEvent; import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; import com.android.systemui.recents.events.activity.HideRecentsEvent; import com.android.systemui.recents.events.activity.IterateRecentsEvent; +import com.android.systemui.recents.events.activity.LaunchMostRecentTaskRequestEvent; import com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; import com.android.systemui.recents.events.activity.ToggleRecentsEvent; @@ -303,15 +304,23 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener RecentsConfiguration config = Recents.getConfiguration(); RecentsActivityLaunchState launchState = config.getLaunchState(); if (!launchState.launchedWithAltTab) { - // If the user taps quickly - if (!debugFlags.isPagingEnabled() || - (ViewConfiguration.getDoubleTapMinTime() < elapsedTime && - elapsedTime < ViewConfiguration.getDoubleTapTimeout())) { - // Launch the next focused task - EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); + // Has the user tapped quickly? + boolean isQuickTap = ViewConfiguration.getDoubleTapMinTime() < elapsedTime && + elapsedTime < ViewConfiguration.getDoubleTapTimeout(); + if (Recents.getConfiguration().isGridEnabled) { + if (isQuickTap) { + EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); + } else { + EventBus.getDefault().post(new LaunchMostRecentTaskRequestEvent()); + } } else { - // Notify recents to move onto the next task - EventBus.getDefault().post(new IterateRecentsEvent()); + if (!debugFlags.isPagingEnabled() || isQuickTap) { + // Launch the next focused task + EventBus.getDefault().post(new LaunchNextTaskRequestEvent()); + } else { + // Notify recents to move onto the next task + EventBus.getDefault().post(new IterateRecentsEvent()); + } } } else { // If the user has toggled it too quickly, then just eat up the event here (it's diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchMostRecentTaskRequestEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchMostRecentTaskRequestEvent.java new file mode 100644 index 0000000000000..24913a4c2ca63 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchMostRecentTaskRequestEvent.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.recents.events.activity; + +import com.android.systemui.recents.events.EventBus; + +/** + * This event is sent to request that the most recent task is launched. + */ +public class LaunchMostRecentTaskRequestEvent extends EventBus.Event { + // Simple event +} diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index c621918929bc5..39c913f322b6a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -64,6 +64,7 @@ import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationC import com.android.systemui.recents.events.activity.HideRecentsEvent; import com.android.systemui.recents.events.activity.HideStackActionButtonEvent; import com.android.systemui.recents.events.activity.IterateRecentsEvent; +import com.android.systemui.recents.events.activity.LaunchMostRecentTaskRequestEvent; import com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; import com.android.systemui.recents.events.activity.LaunchTaskEvent; import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent; @@ -1733,6 +1734,13 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal mUIDozeTrigger.stopDozing(); } + public final void onBusEvent(LaunchMostRecentTaskRequestEvent event) { + if (mStack.getTaskCount() > 0) { + Task mostRecentTask = mStack.getStackFrontMostTask(true /* includeFreefromTasks */); + launchTask(mostRecentTask); + } + } + public final void onBusEvent(LaunchNextTaskRequestEvent event) { if (mAwaitingFirstLayout) { mLaunchNextAfterFirstMeasure = true; @@ -1741,29 +1749,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal final Task launchTask = mStack.getNextLaunchTarget(); if (launchTask != null) { - // Stop all animations - cancelAllTaskViewAnimations(); - - float curScroll = mStackScroller.getStackScroll(); - float targetScroll = mLayoutAlgorithm.getStackScrollForTaskAtInitialOffset(launchTask); - float absScrollDiff = Math.abs(targetScroll - curScroll); - if (getChildViewForTask(launchTask) == null || absScrollDiff > 0.35f) { - int duration = (int) (LAUNCH_NEXT_SCROLL_BASE_DURATION + - absScrollDiff * LAUNCH_NEXT_SCROLL_INCR_DURATION); - mStackScroller.animateScroll(targetScroll, - duration, new Runnable() { - @Override - public void run() { - EventBus.getDefault().send(new LaunchTaskEvent( - getChildViewForTask(launchTask), launchTask, null, - INVALID_STACK_ID, false /* screenPinningRequested */)); - } - }); - } else { - EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(launchTask), - launchTask, null, INVALID_STACK_ID, false /* screenPinningRequested */)); - } - + launchTask(launchTask); MetricsLogger.action(getContext(), MetricsEvent.OVERVIEW_LAUNCH_PREVIOUS_TASK, launchTask.key.getComponent().toString()); } else if (mStack.getTaskCount() == 0) { @@ -2215,6 +2201,31 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal return -1; } + private void launchTask(Task task) { + // Stop all animations + cancelAllTaskViewAnimations(); + + float curScroll = mStackScroller.getStackScroll(); + float targetScroll = mLayoutAlgorithm.getStackScrollForTaskAtInitialOffset(task); + float absScrollDiff = Math.abs(targetScroll - curScroll); + if (getChildViewForTask(task) == null || absScrollDiff > 0.35f) { + int duration = (int) (LAUNCH_NEXT_SCROLL_BASE_DURATION + + absScrollDiff * LAUNCH_NEXT_SCROLL_INCR_DURATION); + mStackScroller.animateScroll(targetScroll, + duration, new Runnable() { + @Override + public void run() { + EventBus.getDefault().send(new LaunchTaskEvent( + getChildViewForTask(task), task, null, + INVALID_STACK_ID, false /* screenPinningRequested */)); + } + }); + } else { + EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(task), + task, null, INVALID_STACK_ID, false /* screenPinningRequested */)); + } + } + /** * Check whether we should use the grid layout. */