From b61e654b9a46e79827355104760a3ac5228380bc Mon Sep 17 00:00:00 2001 From: Winson Date: Thu, 4 Feb 2016 14:37:18 -0800 Subject: [PATCH] Fallback 1 for Recents timeout behaviour - Removing initial timeout - Adding double tap to switch tasks Change-Id: Ice6a508b842377809bf0dcea0997522164d0ccdf --- .../systemui/recents/RecentsActivity.java | 24 ++----------- .../recents/RecentsActivityLaunchState.java | 13 +++++++ .../systemui/recents/RecentsDebugFlags.java | 5 --- .../android/systemui/recents/RecentsImpl.java | 22 +++++++++--- .../activity/LaunchNextTaskRequestEvent.java | 27 +++++++++++++++ .../views/TaskStackLayoutAlgorithm.java | 2 +- .../systemui/recents/views/TaskStackView.java | 34 +++++++++++-------- 7 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchNextTaskRequestEvent.java diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index 5b800bf04d5b3..3f482c82011a4 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -45,7 +45,6 @@ import com.android.systemui.recents.events.activity.AppWidgetProviderChangedEven import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent; import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; -import com.android.systemui.recents.events.activity.EnterRecentsTaskStackAnimationCompletedEvent; import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; @@ -438,11 +437,8 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD protected void onPause() { super.onPause(); - RecentsDebugFlags flags = Recents.getDebugFlags(); - if (flags.isFastToggleRecentsEnabled()) { - // Stop the fast-toggle dozer - mIterateTrigger.stopDozing(); - } + // Stop the fast-toggle dozer + mIterateTrigger.stopDozing(); } @Override @@ -649,6 +645,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD } public final void onBusEvent(UserInteractionEvent event) { + // Stop the fast-toggle dozer mIterateTrigger.stopDozing(); } @@ -695,21 +692,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD } } - public final void onBusEvent(EnterRecentsTaskStackAnimationCompletedEvent event) { - RecentsDebugFlags debugFlags = Recents.getDebugFlags(); - RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); - if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled() && - RecentsDebugFlags.Static.EnableFastToggleTimeoutOnEnter) { - mIterateTrigger.setDozeDuration( - getResources().getInteger(R.integer.recents_auto_advance_duration)); - if (!mIterateTrigger.isDozing()) { - mIterateTrigger.startDozing(); - } else { - mIterateTrigger.poke(); - } - } - } - public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) { EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(true)); mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java index 0afa1f6a495f7..177e8417f3fbd 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java @@ -52,10 +52,23 @@ public class RecentsActivityLaunchState { * Returns the task to focus given the current launch state. */ public int getInitialFocusTaskIndex(int numTasks) { + RecentsDebugFlags debugFlags = Recents.getDebugFlags(); if (launchedFromAppWithThumbnail) { + if (debugFlags.isFastToggleRecentsEnabled()) { + // If fast toggling, focus the front most task so that the next tap will focus the + // N-1 task + return numTasks - 1; + } + // If coming from another app, focus the next task return numTasks - 2; } else { + if (debugFlags.isFastToggleRecentsEnabled()) { + // If fast toggling, defer focusing until the next tap (which will automatically + // focus the front most task) + return -1; + } + // If coming from home, focus the first task return numTasks - 1; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java index 6b8968f02a112..fc14758af0f41 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java @@ -39,8 +39,6 @@ public class RecentsDebugFlags implements TunerService.Tunable { public static final boolean EnableAffiliatedTaskGroups = true; // Overrides the Tuner flags and enables the fast toggle and timeout public static final boolean EnableFastToggleTimeoutOverride = true; - // Enables toggling the fast-toggle timeout immediately after entering Recents - public static final boolean EnableFastToggleTimeoutOnEnter = true; // Enables us to create mock recents tasks public static final boolean EnableMockTasks = false; @@ -90,9 +88,6 @@ public class RecentsDebugFlags implements TunerService.Tunable { * @return whether the initial stack state is paging. */ public boolean isInitialStatePaging() { - if (Static.EnableFastToggleTimeoutOnEnter) { - return true; - } return mInitialStatePaging; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index dead0dbbc6f9e..dd7b7c1b89e62 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -38,6 +38,7 @@ import android.util.MutableBoolean; import android.view.AppTransitionAnimationSpec; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewConfiguration; import com.android.internal.logging.MetricsLogger; import com.android.systemui.Prefs; @@ -48,6 +49,7 @@ import com.android.systemui.recents.events.activity.DockingTopTaskEvent; 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.LaunchNextTaskRequestEvent; import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; import com.android.systemui.recents.events.activity.ToggleRecentsEvent; import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; @@ -81,8 +83,10 @@ import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener { private final static String TAG = "RecentsImpl"; + // The minimum amount of time between each recents button press that we will handle private final static int MIN_TOGGLE_DELAY_MS = 350; + // The duration within which the user releasing the alt tab (from when they pressed alt tab) // that the fast alt-tab animation will run. If the user's alt-tab takes longer than this // duration, then we will toggle recents after this duration. @@ -337,21 +341,31 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener mTriggeredFromAltTab = false; try { + ViewConfiguration viewConfig = ViewConfiguration.get(mContext); SystemServicesProxy ssp = Recents.getSystemServices(); ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask(); MutableBoolean isTopTaskHome = new MutableBoolean(true); + long elapsedTime = SystemClock.elapsedRealtime() - mLastToggleTime; + if (topTask != null && ssp.isRecentsTopMost(topTask, isTopTaskHome)) { RecentsConfiguration config = Recents.getConfiguration(); RecentsActivityLaunchState launchState = config.getLaunchState(); if (!launchState.launchedWithAltTab) { - // Notify recents to move onto the next task - EventBus.getDefault().post(new IterateRecentsEvent()); + // If the user taps quickly + if (ViewConfiguration.getDoubleTapMinTime() < elapsedTime && + elapsedTime < ViewConfiguration.getDoubleTapTimeout()) { + // 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 // better than showing a janky screenshot). // NOTE: Ideally, the screenshot mechanism would take the window transform into // account - if ((SystemClock.elapsedRealtime() - mLastToggleTime) < MIN_TOGGLE_DELAY_MS) { + if (elapsedTime < MIN_TOGGLE_DELAY_MS) { return; } @@ -364,7 +378,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener // better than showing a janky screenshot). // NOTE: Ideally, the screenshot mechanism would take the window transform into // account - if ((SystemClock.elapsedRealtime() - mLastToggleTime) < MIN_TOGGLE_DELAY_MS) { + if (elapsedTime < MIN_TOGGLE_DELAY_MS) { return; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchNextTaskRequestEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchNextTaskRequestEvent.java new file mode 100644 index 0000000000000..11604b51b4a50 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchNextTaskRequestEvent.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2016 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 next task is launched after a double-tap on the Recents + * button. + */ +public class LaunchNextTaskRequestEvent extends EventBus.Event { + // Simple event +} diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java index bcfa93007c93d..bd37c3bfd7610 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java @@ -383,6 +383,7 @@ public class TaskStackLayoutAlgorithm { */ void update(TaskStack stack, ArraySet ignoreTasksSet) { SystemServicesProxy ssp = Recents.getSystemServices(); + RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); // Clear the progress map mTaskIndexMap.clear(); @@ -449,7 +450,6 @@ public class TaskStackLayoutAlgorithm { if (!ssp.hasFreeformWorkspaceSupport() && mNumStackTasks == 1) { mInitialScrollP = mMinScrollP; } else if (getDefaultFocusState() > 0f) { - RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); if (launchState.launchedFromHome) { mInitialScrollP = Math.max(mMinScrollP, Math.min(mMaxScrollP, launchTaskIndex)); } else { 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 829d67936838e..bb74de493f58c 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -58,6 +58,7 @@ import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationC import com.android.systemui.recents.events.activity.HideHistoryButtonEvent; import com.android.systemui.recents.events.activity.HideHistoryEvent; import com.android.systemui.recents.events.activity.IterateRecentsEvent; +import com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent; import com.android.systemui.recents.events.activity.LaunchTaskEvent; import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent; import com.android.systemui.recents.events.activity.PackagesChangedEvent; @@ -1544,6 +1545,24 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal mUIDozeTrigger.stopDozing(); } + public final void onBusEvent(LaunchNextTaskRequestEvent event) { + int launchTaskIndex = mStack.indexOfStackTask(mStack.getLaunchTarget()); + if (launchTaskIndex != -1) { + launchTaskIndex = Math.max(0, launchTaskIndex - 1); + } else { + launchTaskIndex = mStack.getTaskCount() - 1; + } + if (launchTaskIndex != -1) { + // Stop all animations + mUIDozeTrigger.stopDozing(); + cancelAllTaskViewAnimations(); + + Task launchTask = mStack.getStackTasks().get(launchTaskIndex); + EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(launchTask), + launchTask, null, INVALID_STACK_ID, false /* screenPinningRequested */)); + } + } + public final void onBusEvent(LaunchTaskStartedEvent event) { mAnimationHelper.startLaunchTaskAnimation(event.taskView, event.screenPinningRequested, event.getAnimationTrigger()); @@ -1762,21 +1781,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal } } - public final void onBusEvent(EnterRecentsTaskStackAnimationCompletedEvent event) { - RecentsDebugFlags debugFlags = Recents.getDebugFlags(); - RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); - if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled() && - RecentsDebugFlags.Static.EnableFastToggleTimeoutOnEnter) { - if (mFocusedTask != null) { - int timerIndicatorDuration = getResources().getInteger( - R.integer.recents_auto_advance_duration); - int focusedTaskIndex = mStack.indexOfStackTask(mFocusedTask); - setFocusedTask(focusedTaskIndex, false /* scrollToTask */, - false /* requestViewFocus */, timerIndicatorDuration); - } - } - } - public final void onBusEvent(UpdateFreeformTaskViewVisibilityEvent event) { List taskViews = getTaskViews(); int taskViewCount = taskViews.size();