OSDN Git Service

Moving more callbacks to animated events.
authorWinson <winsonc@google.com>
Tue, 5 Jan 2016 20:11:31 +0000 (12:11 -0800)
committerWinson <winsonc@google.com>
Wed, 6 Jan 2016 02:18:05 +0000 (18:18 -0800)
- 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

19 files changed:
packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java
packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java
packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java [moved from packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java with 94% similarity]
packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java
packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java [moved from packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java with 81% similarity]
packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java
packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java
packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java
packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java
packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java
packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java
packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java

index 57074df..0cfe076 100644 (file)
@@ -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);
     }
index 5f3e830..992afb4 100644 (file)
@@ -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;
+    }
+
 }
index b31f320..918875a 100644 (file)
@@ -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
 }
index 457d81e..21b9301 100644 (file)
@@ -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 (file)
index 0000000..3925ab1
--- /dev/null
@@ -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;
+    }
+
+}
@@ -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;
     }
 }
index 968890a..1165f4e 100644 (file)
@@ -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 (file)
index 0000000..7bd0958
--- /dev/null
@@ -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;
+    }
+}
index 9f3e9d5..df74018 100644 (file)
 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
index e0a2730..a91ea7e 100644 (file)
@@ -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
index 367f2e2..90eaca7 100644 (file)
@@ -30,8 +30,8 @@ import java.util.ArrayList;
 public class ReferenceCountedTrigger {
 
     int mCount;
-    ArrayList<Runnable> mFirstIncRunnables = new ArrayList<Runnable>();
-    ArrayList<Runnable> mLastDecRunnables = new ArrayList<Runnable>();
+    ArrayList<Runnable> mFirstIncRunnables = new ArrayList<>();
+    ArrayList<Runnable> mLastDecRunnables = new ArrayList<>();
     Runnable mErrorRunnable;
 
     // Convenience runnables
index 7f907ef..871afd9 100644 (file)
@@ -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<Task.TaskKey, RectF> 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;
index 0af7c1e..796556d 100644 (file)
@@ -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());
index c95c73b..9e9956e 100644 (file)
@@ -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);
index 9d391b0..901799e 100644 (file)
@@ -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;
         }
     }
index 94fae13..ba67ad8 100644 (file)
@@ -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) {
index 1a6f129..d861d34 100644 (file)
@@ -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);
index 14909c5..3f7b99d 100644 (file)
@@ -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);
     }
 
     /**