From a96a617a4e722b3e3cacfae9f1ecf7b552f011b0 Mon Sep 17 00:00:00 2001 From: Manu Cornet Date: Thu, 19 Jan 2017 12:40:44 -0800 Subject: [PATCH] 2D Recents: fix toggling behavior This changes the toggling behavior so that a quick double tap on the Recents button still does the same thing as Alt-Tab, but if the second tap is slow, we go back to the most recent task. Bug: 34636734 Test: Checked toggle and alt-tab behavior on local sw600dp device. Change-Id: Idb6f30a370192be2490c74c04d9ea81f223ecfb1 --- .../android/systemui/recents/RecentsImpl.java | 25 +++++--- .../LaunchMostRecentTaskRequestEvent.java | 26 +++++++++ .../systemui/recents/views/TaskStackView.java | 57 +++++++++++-------- 3 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchMostRecentTaskRequestEvent.java diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index 0e42a54c98da1..c05f71ac2d729 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 bc2c4249dd84a..c52d758b4aa4e 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; @@ -1731,6 +1732,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; @@ -1739,29 +1747,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) { @@ -2193,6 +2179,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. */