Merge "Removing duplicated code in Recents"
diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
index b72294b..4fb90cb 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
@@ -58,10 +58,10 @@
                 Resources res = mContext.getResources();
                 float statusBarHeight = res.getDimensionPixelSize(
                         com.android.internal.R.dimen.status_bar_height);
-                Bundle replyData = msg.getData().getParcelable("replyData");
-                mSingleCountFirstTaskRect = replyData.getParcelable("singleCountTaskRect");
+                Bundle replyData = msg.getData().getParcelable(KEY_CONFIGURATION_DATA);
+                mSingleCountFirstTaskRect = replyData.getParcelable(KEY_SINGLE_TASK_STACK_RECT);
                 mSingleCountFirstTaskRect.offset(0, (int) statusBarHeight);
-                mMultipleCountFirstTaskRect = replyData.getParcelable("multipleCountTaskRect");
+                mMultipleCountFirstTaskRect = replyData.getParcelable(KEY_MULTIPLE_TASK_STACK_RECT);
                 mMultipleCountFirstTaskRect.offset(0, (int) statusBarHeight);
             }
         }
@@ -93,12 +93,20 @@
         }
     }
 
-    final static int MSG_UPDATE_FOR_CONFIGURATION = 0;
-    final static int MSG_UPDATE_TASK_THUMBNAIL = 1;
-    final static int MSG_PRELOAD_TASKS = 2;
-    final static int MSG_CANCEL_PRELOAD_TASKS = 3;
-    final static int MSG_CLOSE_RECENTS = 4;
-    final static int MSG_TOGGLE_RECENTS = 5;
+    final public static int MSG_UPDATE_FOR_CONFIGURATION = 0;
+    final public static int MSG_UPDATE_TASK_THUMBNAIL = 1;
+    final public static int MSG_PRELOAD_TASKS = 2;
+    final public static int MSG_CANCEL_PRELOAD_TASKS = 3;
+    final public static int MSG_CLOSE_RECENTS = 4;
+    final public static int MSG_TOGGLE_RECENTS = 5;
+
+    final public static String EXTRA_ANIMATING_WITH_THUMBNAIL = "recents.animatingWithThumbnail";
+    final public static String KEY_CONFIGURATION_DATA = "recents.data.updateForConfiguration";
+    final public static String KEY_WINDOW_RECT = "recents.windowRect";
+    final public static String KEY_SYSTEM_INSETS = "recents.systemInsets";
+    final public static String KEY_SINGLE_TASK_STACK_RECT = "recents.singleCountTaskRect";
+    final public static String KEY_MULTIPLE_TASK_STACK_RECT = "recents.multipleCountTaskRect";
+
 
     final static int sMinToggleDelay = 425;
 
@@ -195,8 +203,8 @@
             // Try and update the recents configuration
             try {
                 Bundle data = new Bundle();
-                data.putParcelable("windowRect", rect);
-                data.putParcelable("systemInsets", new Rect(0, statusBarHeight, 0, 0));
+                data.putParcelable(KEY_WINDOW_RECT, rect);
+                data.putParcelable(KEY_SYSTEM_INSETS, new Rect(0, statusBarHeight, 0, 0));
                 Message msg = Message.obtain(null, MSG_UPDATE_FOR_CONFIGURATION, 0, 0);
                 msg.setData(data);
                 msg.replyTo = mMessenger;
@@ -226,8 +234,7 @@
                 return null;
             }
 
-            Bitmap thumbnail = ssp.getTaskThumbnail(t.persistentId);
-            return thumbnail;
+            return ssp.getTaskThumbnail(t.persistentId);
         }
         return null;
     }
@@ -365,12 +372,12 @@
 
             ActivityOptions opts = ActivityOptions.makeThumbnailScaleDownAnimation(mStatusBarView,
                     thumbnail, taskRect.left, taskRect.top, null);
-            startAlternateRecentsActivity(opts);
+            startAlternateRecentsActivity(opts, true);
         } else {
             ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
                     R.anim.recents_from_launcher_enter,
                     R.anim.recents_from_launcher_exit);
-            startAlternateRecentsActivity(opts);
+            startAlternateRecentsActivity(opts, false);
         }
 
         Console.logTraceTime(Constants.DebugFlags.App.TimeRecentsStartup,
@@ -379,11 +386,12 @@
     }
 
     /** Starts the recents activity */
-    void startAlternateRecentsActivity(ActivityOptions opts) {
+    void startAlternateRecentsActivity(ActivityOptions opts, boolean animatingWithThumbnail) {
         Intent intent = new Intent(sToggleRecentsAction);
         intent.setClassName(sRecentsPackage, sRecentsActivity);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+        intent.putExtra(EXTRA_ANIMATING_WITH_THUMBNAIL, animatingWithThumbnail);
         if (opts != null) {
             mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(
                     UserHandle.USER_CURRENT));
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Constants.java b/packages/SystemUI/src/com/android/systemui/recents/Constants.java
index 26446cf..cde17f5e 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Constants.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Constants.java
@@ -96,8 +96,8 @@
         }
 
         public static class TaskView {
-            public static final boolean AnimateFrontTaskIconOnEnterRecents = true;
-            public static final boolean AnimateFrontTaskIconOnLeavingRecents = true;
+            public static final boolean AnimateFrontTaskBarOnEnterRecents = true;
+            public static final boolean AnimateFrontTaskBarOnLeavingRecents = true;
         }
     }
 }
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index 64c67b1..f61c28c 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -73,7 +73,12 @@
     };
 
     /** Updates the set of recent tasks */
-    void updateRecentsTasks() {
+    void updateRecentsTasks(Intent launchIntent) {
+        // Update the configuration based on the launch intent
+        RecentsConfiguration config = RecentsConfiguration.getInstance();
+        config.launchedWithThumbnailAnimation = launchIntent.getBooleanExtra(
+                AlternateRecentsComponent.EXTRA_ANIMATING_WITH_THUMBNAIL, false);
+
         RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
         SpaceNode root = loader.reload(this, Constants.Values.RecentsTaskLoader.PreloadFirstTasksCount);
         ArrayList<TaskStack> stacks = root.getStacks();
@@ -137,7 +142,7 @@
         setContentView(mContainerView);
 
         // Update the recent tasks
-        updateRecentsTasks();
+        updateRecentsTasks(getIntent());
     }
 
     @Override
@@ -157,7 +162,7 @@
         RecentsConfiguration.reinitialize(this);
 
         // Update the recent tasks
-        updateRecentsTasks();
+        updateRecentsTasks(intent);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
index 017581a..21460bb 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
@@ -41,6 +41,8 @@
     public int filteringNewViewsMinAnimDuration;
     public int taskBarEnterAnimDuration;
 
+    public boolean launchedWithThumbnailAnimation;
+
     /** Private constructor */
     private RecentsConfiguration() {}
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
index 96fbf30..f78a999 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java
@@ -51,14 +51,14 @@
         Context context = mContext.get();
         if (context == null) return;
 
-        if (msg.what == RecentsService.MSG_UPDATE_RECENTS_FOR_CONFIGURATION) {
+        if (msg.what == AlternateRecentsComponent.MSG_UPDATE_FOR_CONFIGURATION) {
             RecentsTaskLoader.initialize(context);
             RecentsConfiguration.reinitialize(context);
 
             try {
                 Bundle data = msg.getData();
-                Rect windowRect = (Rect) data.getParcelable("windowRect");
-                Rect systemInsets = (Rect) data.getParcelable("systemInsets");
+                Rect windowRect = data.getParcelable(AlternateRecentsComponent.KEY_WINDOW_RECT);
+                Rect systemInsets = data.getParcelable(AlternateRecentsComponent.KEY_SYSTEM_INSETS);
 
                 // Create a dummy task stack & compute the rect for the thumbnail to animate to
                 TaskStack stack = new TaskStack(context);
@@ -73,7 +73,8 @@
                 tsv.computeRects(windowRect.width(), windowRect.height() - systemInsets.top, 0);
                 tsv.boundScroll();
                 transform = tsv.getStackTransform(0, tsv.getStackScroll());
-                replyData.putParcelable("singleCountTaskRect", new Rect(transform.rect));
+                replyData.putParcelable(AlternateRecentsComponent.KEY_SINGLE_TASK_STACK_RECT,
+                        new Rect(transform.rect));
 
                 // Also calculate the target task rect when there are multiple tasks
                 stack.addTask(new Task());
@@ -81,19 +82,20 @@
                 tsv.setStackScrollRaw(Integer.MAX_VALUE);
                 tsv.boundScroll();
                 transform = tsv.getStackTransform(1, tsv.getStackScroll());
-                replyData.putParcelable("multipleCountTaskRect", new Rect(transform.rect));
+                replyData.putParcelable(AlternateRecentsComponent.KEY_MULTIPLE_TASK_STACK_RECT,
+                        new Rect(transform.rect));
 
-                data.putParcelable("replyData", replyData);
+                data.putParcelable(AlternateRecentsComponent.KEY_CONFIGURATION_DATA, replyData);
                 Message reply = Message.obtain(null,
-                        RecentsService.MSG_UPDATE_RECENTS_FOR_CONFIGURATION, 0, 0);
+                        AlternateRecentsComponent.MSG_UPDATE_FOR_CONFIGURATION, 0, 0);
                 reply.setData(data);
                 msg.replyTo.send(reply);
             } catch (RemoteException re) {
                 re.printStackTrace();
             }
-        } else if (msg.what == RecentsService.MSG_CLOSE_RECENTS) {
+        } else if (msg.what == AlternateRecentsComponent.MSG_CLOSE_RECENTS) {
             // Do nothing
-        } else if (msg.what == RecentsService.MSG_TOGGLE_RECENTS) {
+        } else if (msg.what == AlternateRecentsComponent.MSG_TOGGLE_RECENTS) {
             // Send a broadcast to toggle recents
             Intent intent = new Intent(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY);
             intent.setPackage(context.getPackageName());
@@ -113,11 +115,6 @@
     final static String ACTION_FINISH_RECENTS_ACTIVITY = "action_finish_recents_activity";
     final static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity";
 
-    // XXX: This should be getting the message from recents definition
-    final static int MSG_UPDATE_RECENTS_FOR_CONFIGURATION = 0;
-    final static int MSG_CLOSE_RECENTS = 4;
-    final static int MSG_TOGGLE_RECENTS = 5;
-
     Messenger mSystemUIMessenger = new Messenger(new SystemUIMessageHandler(this));
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
index a0e5b6a..21e2c1d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
@@ -43,7 +43,13 @@
         ArrayList<Task> prevFilteredTasks = new ArrayList<Task>(mFilteredTasks);
         mFilter = filter;
         updateFilteredTasks();
-        return !prevFilteredTasks.equals(mFilteredTasks);
+        if (!prevFilteredTasks.equals(mFilteredTasks)) {
+            return true;
+        } else {
+            // If the tasks are exactly the same pre/post filter, then just reset it
+            mFilter = null;
+            return false;
+        }
     }
 
     /** Removes the task filter and returns the previous touch state */
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 141d870..ec28379 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -277,7 +277,7 @@
                 Constants.DebugFlags.App.TimeRecentsLaunchKey, "onTaskLaunched");
 
         // Launch the app right away if there is no task view, otherwise, animate the icon out first
-        if (tv == null || !Constants.Values.TaskView.AnimateFrontTaskIconOnLeavingRecents) {
+        if (tv == null || !Constants.Values.TaskView.AnimateFrontTaskBarOnLeavingRecents) {
             post(launchRunnable);
         } else {
             tv.animateOnLeavingRecents(launchRunnable);
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 ce0d91f..728aaad 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
@@ -563,8 +563,9 @@
             requestSynchronizeStackViewsWithModel();
             synchronizeStackViewsWithModel();
 
-            // Animate the icon of the first task view
-            if (Constants.Values.TaskView.AnimateFrontTaskIconOnEnterRecents) {
+            // Animate the task bar of the first task view
+            if (config.launchedWithThumbnailAnimation &&
+                    Constants.Values.TaskView.AnimateFrontTaskBarOnEnterRecents) {
                 TaskView tv = (TaskView) getChildAt(getChildCount() - 1);
                 if (tv != null) {
                     tv.animateOnEnterRecents();