From ef06413afce31800dc8dfee65e5f89bb610f192a Mon Sep 17 00:00:00 2001 From: Winson Date: Tue, 5 Jan 2016 12:11:31 -0800 Subject: [PATCH] Moving more callbacks to animated events. - In preparation for the animation refactoring, this CL just moves the enter/exit callbacks that route though RecentsView into events that the task stack can handle directly. Change-Id: I90f602c5486e1781129225a73dbf97af29477479 --- .../android/systemui/recents/RecentsActivity.java | 67 ++++++--------- .../DismissRecentsToHomeAnimationStarted.java | 10 ++- .../EnterRecentsWindowAnimationCompletedEvent.java | 2 +- .../ExitRecentsWindowFirstAnimationFrameEvent.java | 2 +- .../recents/events/activity/LaunchTaskEvent.java | 2 +- .../events/activity/LaunchTaskStartedEvent.java | 36 ++++++++ ...missTaskEvent.java => DeleteTaskDataEvent.java} | 7 +- .../recents/events/ui/DismissTaskViewEvent.java | 10 +-- .../recents/events/ui/TaskViewDismissedEvent.java | 35 ++++++++ .../ui/focus/DismissFocusedTaskViewEvent.java | 3 +- .../history/RecentsHistoryItemTouchCallbacks.java | 4 +- .../recents/misc/ReferenceCountedTrigger.java | 4 +- .../views/FreeformWorkspaceLayoutAlgorithm.java | 7 -- .../recents/views/RecentsTransitionHelper.java | 20 +++-- .../systemui/recents/views/RecentsView.java | 43 +++------- .../recents/views/TaskStackLayoutAlgorithm.java | 23 +---- .../systemui/recents/views/TaskStackView.java | 99 +++++++++++++++------- .../recents/views/TaskStackViewTouchHandler.java | 4 +- .../android/systemui/recents/views/TaskView.java | 9 +- 19 files changed, 222 insertions(+), 165 deletions(-) rename packages/SystemUI/src/com/android/systemui/recents/{ => events/activity}/ExitRecentsWindowFirstAnimationFrameEvent.java (94%) create mode 100644 packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java rename packages/SystemUI/src/com/android/systemui/recents/events/ui/{DismissTaskEvent.java => DeleteTaskDataEvent.java} (81%) create mode 100644 packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index 57074df392db..0cfe0763938a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -43,8 +43,10 @@ import com.android.systemui.recents.events.EventBus; import com.android.systemui.recents.events.activity.AppWidgetProviderChangedEvent; 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.EnterRecentsWindowAnimationCompletedEvent; import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; +import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; import com.android.systemui.recents.events.activity.HideHistoryEvent; import com.android.systemui.recents.events.activity.HideRecentsEvent; import com.android.systemui.recents.events.activity.IterateRecentsEvent; @@ -56,8 +58,7 @@ import com.android.systemui.recents.events.activity.ToggleRecentsEvent; import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; -import com.android.systemui.recents.events.ui.DismissTaskEvent; -import com.android.systemui.recents.events.ui.DismissTaskViewEvent; +import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent; import com.android.systemui.recents.events.ui.StackViewScrolledEvent; import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; @@ -76,7 +77,6 @@ import com.android.systemui.recents.model.Task; import com.android.systemui.recents.model.TaskStack; import com.android.systemui.recents.views.RecentsView; import com.android.systemui.recents.views.SystemBarScrimViews; -import com.android.systemui.recents.views.ViewAnimation; import com.android.systemui.statusbar.BaseStatusBar; import java.util.ArrayList; @@ -274,7 +274,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD // If we have a focused Task, launch that Task now if (mRecentsView.launchPreviousTask()) return true; // If none of the other cases apply, then just go Home - dismissRecentsToHome(true); + dismissRecentsToHome(true /* animateTaskViews */); } return false; } @@ -288,7 +288,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD // If we have a focused Task, launch that Task now if (mRecentsView.launchFocusedTask()) return true; // If none of the other cases apply, then just go Home - dismissRecentsToHome(true); + dismissRecentsToHome(true /* animateTaskViews */); return true; } return false; @@ -297,32 +297,18 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD /** * Dismisses Recents directly to Home without checking whether it is currently visible. */ - void dismissRecentsToHome(boolean animated) { - if (animated) { - ReferenceCountedTrigger exitTrigger = new ReferenceCountedTrigger(); - exitTrigger.increment(); - exitTrigger.addLastDecrementRunnable(mFinishLaunchHomeRunnable); - exitTrigger.addLastDecrementRunnable(new Runnable() { - @Override - public void run() { - Recents.getSystemServices().sendCloseSystemWindows( - BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); - } - }); - mRecentsView.startExitToHomeAnimation( - new ViewAnimation.TaskViewExitContext(exitTrigger)); - exitTrigger.decrement(); - } else { - mFinishLaunchHomeRunnable.run(); - Recents.getSystemServices().sendCloseSystemWindows( - BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); - } - } - - /** Dismisses Recents directly to Home without transition animation. */ - void dismissRecentsToHomeWithoutTransitionAnimation() { - finish(); - overridePendingTransition(0, 0); + void dismissRecentsToHome(boolean animateTaskViews) { + DismissRecentsToHomeAnimationStarted dismissEvent = + new DismissRecentsToHomeAnimationStarted(animateTaskViews); + dismissEvent.addPostAnimationCallback(mFinishLaunchHomeRunnable); + dismissEvent.addPostAnimationCallback(new Runnable() { + @Override + public void run() { + Recents.getSystemServices().sendCloseSystemWindows( + BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); + } + }); + EventBus.getDefault().send(dismissEvent); } /** Dismisses Recents directly to Home if we currently aren't transitioning. */ @@ -609,7 +595,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD if (!dismissHistory()) { RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); if (launchState.launchedFromHome) { - dismissRecentsToHome(true); + dismissRecentsToHome(true /* animateTaskViews */); } else { dismissRecentsToLaunchTargetTaskOrHome(); } @@ -650,13 +636,13 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD hideEvent.addPostAnimationCallback(new Runnable() { @Override public void run() { - dismissRecentsToHome(true /* animated */); + dismissRecentsToHome(true /* animateTaskViews */); } }); EventBus.getDefault().send(hideEvent); } else { - dismissRecentsToHome(true /* animated */); + dismissRecentsToHome(true /* animateTaskViews */); } } else { // Do nothing @@ -665,12 +651,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { // Try and start the enter animation (or restart it on configuration changed) - ReferenceCountedTrigger t = new ReferenceCountedTrigger(); - ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t); - ctx.postAnimationTrigger.increment(); if (RecentsDebugFlags.Static.EnableSearchBar) { if (mSearchWidgetInfo != null) { - ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() { + event.addPostAnimationCallback(new Runnable() { @Override public void run() { // Start listening for widget package changes if there is one bound @@ -681,8 +664,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD }); } } - mRecentsView.startEnterRecentsAnimation(ctx); - ctx.postAnimationTrigger.decrement(); } public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) { @@ -727,7 +708,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD MetricsLogger.count(this, "overview_app_info", 1); } - public final void onBusEvent(DismissTaskEvent event) { + public final void onBusEvent(DeleteTaskDataEvent event) { // Remove any stored data from the loader RecentsTaskLoader loader = Recents.getTaskLoader(); loader.deleteTaskData(event.task, false); @@ -743,7 +724,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD mRecentsView.showEmptyView(); } else { // Just go straight home (no animation necessary because there are no more task views) - dismissRecentsToHome(false /* animated */); + dismissRecentsToHome(false /* animateTaskViews */); } // Keep track of all-deletions @@ -756,7 +737,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD public final void onBusEvent(LaunchTaskFailedEvent event) { // Return to Home - dismissRecentsToHome(true); + dismissRecentsToHome(true /* animateTaskViews */); MetricsLogger.count(this, "overview_task_launch_failed", 1); } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java index 5f3e830197ed..992afb42a1ca 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java @@ -21,6 +21,12 @@ import com.android.systemui.recents.events.EventBus; /** * This is sent when the task animation when dismissing Recents starts. */ -public class DismissRecentsToHomeAnimationStarted extends EventBus.Event { - // Simple event +public class DismissRecentsToHomeAnimationStarted extends EventBus.AnimatedEvent { + + public final boolean animated; + + public DismissRecentsToHomeAnimationStarted(boolean animated) { + this.animated = animated; + } + } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java index b31f32090ac7..918875a2561b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java @@ -23,6 +23,6 @@ import com.android.systemui.recents.events.EventBus; * we can start in-app animations so that they don't conflict with the window transition into * Recents. */ -public class EnterRecentsWindowAnimationCompletedEvent extends EventBus.Event { +public class EnterRecentsWindowAnimationCompletedEvent extends EventBus.AnimatedEvent { // Simple event } diff --git a/packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java similarity index 94% rename from packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java rename to packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java index 8ae8c53a9197..fa806eb24ad1 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.recents; +package com.android.systemui.recents.events.activity; import com.android.systemui.recents.events.EventBus; diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java index 457d81eecd7c..21b9301755ad 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java @@ -22,7 +22,7 @@ import com.android.systemui.recents.model.Task; import com.android.systemui.recents.views.TaskView; /** - * This is sent to launch a task from Recents. + * This event is sent to request that a particular task is launched. */ public class LaunchTaskEvent extends EventBus.Event { diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java new file mode 100644 index 000000000000..3925ab1186dc --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2015 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; +import com.android.systemui.recents.views.TaskView; + +/** + * This event is sent following {@link LaunchTaskEvent} after the call to the system is made to + * start the task. + */ +public class LaunchTaskStartedEvent extends EventBus.AnimatedEvent { + + public final TaskView taskView; + public final boolean screenPinningRequested; + + public LaunchTaskStartedEvent(TaskView taskView, boolean screenPinningRequested) { + this.taskView = taskView; + this.screenPinningRequested = screenPinningRequested; + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java similarity index 81% rename from packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java rename to packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java index bcbbde84a160..bf14082e661b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java @@ -21,13 +21,14 @@ import com.android.systemui.recents.model.Task; import com.android.systemui.recents.views.TaskView; /** - * This is sent when a {@link Task} has been dismissed. + * This is sent when the data associated with a given {@link Task} should be deleted from the + * system. */ -public class DismissTaskEvent extends EventBus.Event { +public class DeleteTaskDataEvent extends EventBus.Event { public final Task task; - public DismissTaskEvent(Task task) { + public DeleteTaskDataEvent(Task task) { this.task = task; } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java index 968890aea2f1..1165f4e76861 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java @@ -21,15 +21,15 @@ import com.android.systemui.recents.model.Task; import com.android.systemui.recents.views.TaskView; /** - * This is sent when a {@link TaskView} has been dismissed. + * This event is sent to request that the given {@link TaskView} is dismissed. */ -public class DismissTaskViewEvent extends EventBus.Event { +public class DismissTaskViewEvent extends EventBus.AnimatedEvent { - public final Task task; public final TaskView taskView; + public final Task task; - public DismissTaskViewEvent(Task task, TaskView taskView) { - this.task = task; + public DismissTaskViewEvent(TaskView taskView, Task task) { this.taskView = taskView; + this.task = task; } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java new file mode 100644 index 000000000000..7bd0958ebb24 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 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.ui; + +import com.android.systemui.recents.events.EventBus; +import com.android.systemui.recents.model.Task; +import com.android.systemui.recents.views.TaskView; + +/** + * This event is sent when a {@link TaskView} has been dismissed and is no longer visible. + */ +public class TaskViewDismissedEvent extends EventBus.Event { + + public final Task task; + public final TaskView taskView; + + public TaskViewDismissedEvent(Task task, TaskView taskView) { + this.task = task; + this.taskView = taskView; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java index 9f3e9d5e3362..df740185f1e8 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java @@ -17,9 +17,10 @@ package com.android.systemui.recents.events.ui.focus; import com.android.systemui.recents.events.EventBus; +import com.android.systemui.recents.views.TaskView; /** - * Dismisses the currently focused task view. + * This event is sent to request that the currently focused {@link TaskView} is dismissed. */ public class DismissFocusedTaskViewEvent extends EventBus.Event { // Simple event diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java index e0a27308dd1a..a91ea7e94f48 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java +++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java @@ -22,7 +22,7 @@ import android.support.v7.widget.helper.ItemTouchHelper; import com.android.internal.logging.MetricsLogger; import com.android.systemui.recents.Constants; import com.android.systemui.recents.events.EventBus; -import com.android.systemui.recents.events.ui.DismissTaskEvent; +import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; /** @@ -65,7 +65,7 @@ public class RecentsHistoryItemTouchCallbacks extends ItemTouchHelper.SimpleCall RecentsHistoryAdapter.TaskRow taskRow = (RecentsHistoryAdapter.TaskRow) row; // Remove the task from the system - EventBus.getDefault().send(new DismissTaskEvent(taskRow.task)); + EventBus.getDefault().send(new DeleteTaskDataEvent(taskRow.task)); mAdapter.onTaskRemoved(taskRow.task, position); // Keep track of deletions by swiping within history diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java b/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java index 367f2e268af5..90eaca79c8a5 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java @@ -30,8 +30,8 @@ import java.util.ArrayList; public class ReferenceCountedTrigger { int mCount; - ArrayList mFirstIncRunnables = new ArrayList(); - ArrayList mLastDecRunnables = new ArrayList(); + ArrayList mFirstIncRunnables = new ArrayList<>(); + ArrayList mLastDecRunnables = new ArrayList<>(); Runnable mErrorRunnable; // Convenience runnables diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java index 7f907ef86a2a..871afd9449c1 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java @@ -33,9 +33,6 @@ import java.util.List; */ public class FreeformWorkspaceLayoutAlgorithm { - private static final String TAG = "FreeformWorkspaceLayoutAlgorithm"; - private static final boolean DEBUG = false; - // Optimization, allows for quick lookup of task -> rect private HashMap mTaskRectMap = new HashMap<>(); @@ -177,10 +174,6 @@ public class FreeformWorkspaceLayoutAlgorithm { transformOut.rect.offset(stackLayout.mFreeformRect.left, stackLayout.mFreeformRect.top); transformOut.visible = true; transformOut.p = 1f; - - if (DEBUG) { - Log.d(TAG, "getTransform: " + task.key + ", " + transformOut); - } return transformOut; } return null; diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java index 0af7c1e9379e..796556d11e49 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java @@ -32,15 +32,16 @@ import android.view.AppTransitionAnimationSpec; import android.view.IAppTransitionAnimationSpecsFuture; import android.view.WindowManagerGlobal; import com.android.internal.annotations.GuardedBy; -import com.android.systemui.recents.ExitRecentsWindowFirstAnimationFrameEvent; +import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; import com.android.systemui.recents.Recents; import com.android.systemui.recents.RecentsDebugFlags; import com.android.systemui.recents.events.EventBus; import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent; +import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent; import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent; import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; -import com.android.systemui.recents.events.ui.DismissTaskViewEvent; +import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.recents.model.Task; import com.android.systemui.recents.model.TaskStack; @@ -90,7 +91,7 @@ public class RecentsTransitionHelper { */ public void launchTaskFromRecents(final TaskStack stack, @Nullable final Task task, final TaskStackView stackView, final TaskView taskView, - final boolean lockToTask, final Rect bounds, int destinationStack) { + final boolean screenPinningRequested, final Rect bounds, int destinationStack) { final ActivityOptions opts = ActivityOptions.makeBasic(); if (bounds != null) { opts.setLaunchBounds(bounds.isEmpty() ? null : bounds); @@ -109,7 +110,7 @@ public class RecentsTransitionHelper { EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(task)); EventBus.getDefault().send(new ExitRecentsWindowFirstAnimationFrameEvent()); - if (lockToTask) { + if (screenPinningRequested) { // Request screen pinning after the animation runs mHandler.postDelayed(mStartScreenPinningRunnable, 350); } @@ -131,16 +132,19 @@ public class RecentsTransitionHelper { // task views, and we can launch immediately startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener); } else { + LaunchTaskStartedEvent launchStartedEvent = new LaunchTaskStartedEvent(taskView, + screenPinningRequested); if (task.group != null && !task.group.isFrontMostTask(task)) { - stackView.startLaunchTaskAnimation(taskView, new Runnable() { + launchStartedEvent.addPostAnimationCallback(new Runnable() { @Override public void run() { startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener); } - }, lockToTask); + }); + EventBus.getDefault().send(launchStartedEvent); } else { - stackView.startLaunchTaskAnimation(taskView, null, lockToTask); + EventBus.getDefault().send(launchStartedEvent); startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener); } @@ -167,7 +171,7 @@ public class RecentsTransitionHelper { EventBus.getDefault().send(new LaunchTaskSucceededEvent(taskIndexFromFront)); } else { // Dismiss the task if we fail to launch it - EventBus.getDefault().send(new DismissTaskViewEvent(task, taskView)); + taskView.dismissTask(); // Keep track of failed launches EventBus.getDefault().send(new LaunchTaskFailedEvent()); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java index c95c73bc4f89..9e9956e0a3b9 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -262,39 +262,6 @@ public class RecentsView extends FrameLayout { return false; } - /** Requests all task stacks to start their enter-recents animation */ - public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { - // We have to increment/decrement the post animation trigger in case there are no children - // to ensure that it runs - ctx.postAnimationTrigger.increment(); - if (mTaskStackView != null) { - mTaskStackView.startEnterRecentsAnimation(ctx); - } - ctx.postAnimationTrigger.decrement(); - } - - /** Requests all task stacks to start their exit-recents animation */ - public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { - // We have to increment/decrement the post animation trigger in case there are no children - // to ensure that it runs - ctx.postAnimationTrigger.increment(); - if (mTaskStackView != null) { - mTaskStackView.startExitToHomeAnimation(ctx); - } - ctx.postAnimationTrigger.decrement(); - - // Hide the history button - int taskViewExitToHomeDuration = getResources().getInteger( - R.integer.recents_task_exit_to_home_duration); - hideHistoryButton(taskViewExitToHomeDuration); - - // If we are going home, cancel the previous task's window transition - EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); - - // Notify sof the exit animation - EventBus.getDefault().send(new DismissRecentsToHomeAnimationStarted()); - } - /** Adds the search bar */ public void setSearchBar(RecentsAppWidgetHostView searchBar) { // Remove the previous search bar if one exists @@ -496,6 +463,16 @@ public class RecentsView extends FrameLayout { event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack); } + public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { + // Hide the history button + int taskViewExitToHomeDuration = getResources().getInteger( + R.integer.recents_task_exit_to_home_duration); + hideHistoryButton(taskViewExitToHomeDuration); + + // If we are going home, cancel the previous task's window transition + EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); + } + public final void onBusEvent(DragStartEvent event) { updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), TaskStack.DockState.NONE.viewState.dockAreaAlpha); 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 9d391b0c8c86..901799e27bf6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java @@ -103,9 +103,6 @@ class Range { */ public class TaskStackLayoutAlgorithm { - private static final String TAG = "TaskStackViewLayoutAlgorithm"; - private static final boolean DEBUG = false; - // The scale factor to apply to the user movement in the stack to unfocus it private static final float UNFOCUS_MULTIPLIER = 0.8f; @@ -130,7 +127,7 @@ public class TaskStackLayoutAlgorithm { * allocate to the freeform workspace * @param freeformBackgroundAlpha the background alpha for the freeform workspace */ - StackState(float freeformHeightPct, int freeformBackgroundAlpha) { + private StackState(float freeformHeightPct, int freeformBackgroundAlpha) { this.freeformHeightPct = freeformHeightPct; this.freeformBackgroundAlpha = freeformBackgroundAlpha; } @@ -368,14 +365,6 @@ public class TaskStackLayoutAlgorithm { mUnfocusedCurveInterpolator = new FreePathInterpolator(mUnfocusedCurve); mFocusedCurve = constructFocusedCurve(); mFocusedCurveInterpolator = new FreePathInterpolator(mFocusedCurve); - - if (DEBUG) { - Log.d(TAG, "initialize"); - Log.d(TAG, "\tmFreeformRect: " + mFreeformRect); - Log.d(TAG, "\tmStackRect: " + mStackRect); - Log.d(TAG, "\tmTaskRect: " + mTaskRect); - Log.d(TAG, "\tmSystemInsets: " + mSystemInsets); - } } /** @@ -455,13 +444,6 @@ public class TaskStackLayoutAlgorithm { mInitialScrollP = (mNumStackTasks - 1) - mUnfocusedRange.getAbsoluteX(normX); } } - - if (DEBUG) { - Log.d(TAG, "mNumStackTasks: " + mNumStackTasks); - Log.d(TAG, "mNumFreeformTasks: " + mNumFreeformTasks); - Log.d(TAG, "mMinScrollP: " + mMinScrollP); - Log.d(TAG, "mMaxScrollP: " + mMaxScrollP); - } } /** @@ -617,9 +599,6 @@ public class TaskStackLayoutAlgorithm { if (task.thumbnail != null) { transformOut.thumbnailScale = (float) mTaskRect.width() / task.thumbnail.getWidth(); } - if (DEBUG) { - Log.d(TAG, "getTransform: " + task.key + ", " + transformOut); - } return transformOut; } } 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 94fae1381d85..ba67ad8bec4f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -47,19 +47,22 @@ import com.android.systemui.recents.RecentsActivityLaunchState; import com.android.systemui.recents.RecentsConfiguration; import com.android.systemui.recents.events.EventBus; import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; +import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; 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.LaunchTaskEvent; +import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent; import com.android.systemui.recents.events.activity.PackagesChangedEvent; import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent; import com.android.systemui.recents.events.activity.ShowHistoryEvent; import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; -import com.android.systemui.recents.events.ui.DismissTaskEvent; +import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; import com.android.systemui.recents.events.ui.DismissTaskViewEvent; import com.android.systemui.recents.events.ui.StackViewScrolledEvent; +import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; import com.android.systemui.recents.events.ui.UserInteractionEvent; import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; @@ -136,8 +139,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal boolean mStackViewsClipDirty = true; boolean mAwaitingFirstLayout = true; boolean mEnterAnimationComplete = false; - boolean mStartEnterAnimationRequestedAfterLayout; - ViewAnimation.TaskViewEnterContext mStartEnterAnimationContext; Rect mTaskStackBounds = new Rect(); int[] mTmpVisibleRange = new int[2]; @@ -586,6 +587,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal // Find the next view to clip against for (int j = i + 1; j < taskViewCount; j++) { tmpTv = taskViews.get(j); + if (tmpTv.shouldClipViewInStack()) { frontTv = tmpTv; break; @@ -1031,14 +1033,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal tv.prepareEnterRecentsAnimation(hideTask, occludesLaunchTarget, offscreenY); } - // If the enter animation started already and we haven't completed a layout yet, do the - // enter animation now - if (mStartEnterAnimationRequestedAfterLayout) { - startEnterRecentsAnimation(mStartEnterAnimationContext); - mStartEnterAnimationRequestedAfterLayout = false; - mStartEnterAnimationContext = null; - } - // Animate in the freeform workspace animateFreeformWorkspaceBackgroundAlpha( mLayoutAlgorithm.getStackState().freeformBackgroundAlpha, 150, @@ -1061,20 +1055,10 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal } else { EventBus.getDefault().send(new HideHistoryButtonEvent()); } - - // Start dozing - mUIDozeTrigger.startDozing(); } /** Requests this task stacks to start it's enter-recents animation */ public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { - // If we are still waiting to layout, then just defer until then - if (mAwaitingFirstLayout) { - mStartEnterAnimationRequestedAfterLayout = true; - mStartEnterAnimationContext = ctx; - return; - } - if (mStack.getStackTaskCount() > 0) { // Find the launch target task Task launchTargetTask = mStack.getLaunchTarget(); @@ -1435,17 +1419,27 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal mUIDozeTrigger.stopDozing(); } - public final void onBusEvent(DismissTaskViewEvent event) { - removeTaskViewFromStack(event.taskView); - EventBus.getDefault().send(new DismissTaskEvent(event.task)); + public final void onBusEvent(LaunchTaskStartedEvent event) { + event.getAnimationTrigger().increment(); + startLaunchTaskAnimation(event.taskView, event.getAnimationTrigger().decrementAsRunnable(), + event.screenPinningRequested); } - public final void onBusEvent(FocusNextTaskViewEvent event) { - setRelativeFocusedTask(true, false /* stackTasksOnly */, true /* animated */); - } + public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { + // Stop any scrolling + mStackScroller.stopScroller(); + mStackScroller.stopBoundScrollAnimation(); - public final void onBusEvent(FocusPreviousTaskViewEvent event) { - setRelativeFocusedTask(false, false /* stackTasksOnly */, true /* animated */); + // Start the task animations + ViewAnimation.TaskViewExitContext context = new ViewAnimation.TaskViewExitContext( + event.getAnimationTrigger()); + startExitToHomeAnimation(context); + + // Dismiss the freeform workspace background + int taskViewExitToHomeDuration = getResources().getInteger( + R.integer.recents_task_exit_to_home_duration); + animateFreeformWorkspaceBackgroundAlpha(0, taskViewExitToHomeDuration, + mFastOutSlowInInterpolator); } public final void onBusEvent(DismissFocusedTaskViewEvent event) { @@ -1458,6 +1452,26 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal } } + public final void onBusEvent(final DismissTaskViewEvent event) { + // For visible children, defer removing the task until after the animation + event.getAnimationTrigger().increment(); + event.taskView.startDeleteTaskAnimation( + event.getAnimationTrigger().decrementAsRunnable(), 0); + } + + public final void onBusEvent(TaskViewDismissedEvent event) { + removeTaskViewFromStack(event.taskView); + EventBus.getDefault().send(new DeleteTaskDataEvent(event.task)); + } + + public final void onBusEvent(FocusNextTaskViewEvent event) { + setRelativeFocusedTask(true, false /* stackTasksOnly */, true /* animated */); + } + + public final void onBusEvent(FocusPreviousTaskViewEvent event) { + setRelativeFocusedTask(false, false /* stackTasksOnly */, true /* animated */); + } + public final void onBusEvent(UserInteractionEvent event) { // Poke the doze trigger on user interaction mUIDozeTrigger.poke(); @@ -1553,6 +1567,33 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { mEnterAnimationComplete = true; + + if (mStack.getStackTaskCount() > 0) { + // Start the task enter animations + ViewAnimation.TaskViewEnterContext context = new ViewAnimation.TaskViewEnterContext( + event.getAnimationTrigger()); + startEnterRecentsAnimation(context); + + // Add a runnable to the post animation ref counter to clear all the views + event.addPostAnimationCallback(new Runnable() { + @Override + public void run() { + // Start the dozer to trigger to trigger any UI that shows after a timeout + mUIDozeTrigger.startDozing(); + + // Update the focused state here -- since we only set the focused task without + // requesting view focus in onFirstLayout(), actually request view focus and + // animate the focused state if we are alt-tabbing now, after the window enter + // animation is completed + if (mFocusedTask != null) { + RecentsConfiguration config = Recents.getConfiguration(); + RecentsActivityLaunchState launchState = config.getLaunchState(); + setFocusedTask(mStack.indexOfStackTask(mFocusedTask), + false /* scrollToTask */, launchState.launchedWithAltTab); + } + } + }); + } } public final void onBusEvent(UpdateFreeformTaskViewVisibilityEvent event) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java index 1a6f1294f36e..d861d34fd2c9 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java @@ -33,7 +33,7 @@ import com.android.systemui.recents.Constants; import com.android.systemui.recents.Recents; import com.android.systemui.recents.events.EventBus; import com.android.systemui.recents.events.activity.HideRecentsEvent; -import com.android.systemui.recents.events.ui.DismissTaskViewEvent; +import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; import com.android.systemui.recents.events.ui.StackViewScrolledEvent; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.recents.misc.Utilities; @@ -367,7 +367,7 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback { // Re-enable touch events from this task view tv.setTouchEnabled(true); // Remove the task view from the stack - EventBus.getDefault().send(new DismissTaskViewEvent(tv.getTask(), tv)); + EventBus.getDefault().send(new TaskViewDismissedEvent(tv.getTask(), tv)); // Keep track of deletions by keyboard MetricsLogger.histogram(tv.getContext(), "overview_task_dismissed_source", Constants.Metrics.DismissSourceSwipeGesture); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java index 14909c50ef94..3f7b99de545e 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java @@ -47,6 +47,7 @@ import com.android.systemui.recents.RecentsConfiguration; import com.android.systemui.recents.events.EventBus; import com.android.systemui.recents.events.activity.LaunchTaskEvent; import com.android.systemui.recents.events.ui.DismissTaskViewEvent; +import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; import com.android.systemui.recents.misc.SystemServicesProxy; @@ -541,12 +542,14 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, void dismissTask() { // Animate out the view and call the callback final TaskView tv = this; - startDeleteTaskAnimation(new Runnable() { + DismissTaskViewEvent dismissEvent = new DismissTaskViewEvent(tv, mTask); + dismissEvent.addPostAnimationCallback(new Runnable() { @Override public void run() { - EventBus.getDefault().send(new DismissTaskViewEvent(mTask, tv)); + EventBus.getDefault().send(new TaskViewDismissedEvent(mTask, tv)); } - }, 0); + }); + EventBus.getDefault().send(dismissEvent); } /** -- 2.11.0