Overriding application icon with activity icon where available.

Change-Id: I03ee8f806b3853183db7f96e71f1684c72b79c57
diff --git a/packages/SystemUI/res/layout/recents_task_view.xml b/packages/SystemUI/res/layout/recents_task_view.xml
index 7f64032..4442bca 100644
--- a/packages/SystemUI/res/layout/recents_task_view.xml
+++ b/packages/SystemUI/res/layout/recents_task_view.xml
@@ -63,13 +63,6 @@
             android:maxLines="2"
             android:ellipsize="marquee"
             android:fadingEdge="horizontal" />
-        <ImageView
-            android:id="@+id/activity_icon"
-            android:layout_width="@dimen/recents_task_view_activity_icon_size"
-            android:layout_height="@dimen/recents_task_view_activity_icon_size"
-            android:layout_gravity="center_vertical|end"
-            android:padding="12dp"
-            android:visibility="invisible" />
     </com.android.systemui.recents.views.TaskBarView>
 </com.android.systemui.recents.views.TaskView>
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java
index fd0f6d1..da265e1 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java
@@ -415,7 +415,10 @@
             ActivityInfo info = ssp.getActivityInfo(t.baseIntent.getComponent(), t.userId);
             String activityLabel = (t.activityLabel == null ? ssp.getActivityLabel(info) :
                     t.activityLabel.toString());
-            Bitmap activityIcon = t.activityIcon;
+            BitmapDrawable activityIcon = null;
+            if (t.activityIcon != null) {
+                activityIcon = new BitmapDrawable(res, t.activityIcon);
+            }
             boolean isForemostTask = (i == (taskCount - 1));
 
             // Create a new task
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
index ff062f6c..1566a49 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
@@ -18,6 +18,7 @@
 
 import android.content.Intent;
 import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 
 
@@ -69,8 +70,8 @@
 
     public TaskKey key;
     public Drawable applicationIcon;
+    public Drawable activityIcon;
     public String activityLabel;
-    public Bitmap activityIcon;
     public Bitmap thumbnail;
     public boolean isActive;
     public int userId;
@@ -82,7 +83,7 @@
     }
 
     public Task(int id, boolean isActive, Intent intent, String activityTitle,
-                Bitmap activityIcon, int userId) {
+                BitmapDrawable activityIcon, int userId) {
         this.key = new TaskKey(id, intent, userId);
         this.activityLabel = activityTitle;
         this.activityIcon = activityIcon;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
index c9a6d67..124f11e 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskBarView.java
@@ -31,7 +31,6 @@
     Task mTask;
 
     ImageView mApplicationIcon;
-    ImageView mActivityIcon;
     TextView mActivityDescription;
 
     public TaskBarView(Context context) {
@@ -54,23 +53,22 @@
     protected void onFinishInflate() {
         // Initialize the icon and description views
         mApplicationIcon = (ImageView) findViewById(R.id.application_icon);
-        mActivityIcon = (ImageView) findViewById(R.id.activity_icon);
         mActivityDescription = (TextView) findViewById(R.id.activity_description);
     }
 
     /** Binds the bar view to the task */
     void rebindToTask(Task t, boolean animate) {
         mTask = t;
-        if (t.applicationIcon != null) {
+        // If an activity icon is defined, then we use that as the primary icon to show in the bar,
+        // otherwise, we fall back to the application icon
+        if (t.activityIcon != null) {
+            mApplicationIcon.setImageDrawable(t.activityIcon);
+        } else if (t.applicationIcon != null) {
             mApplicationIcon.setImageDrawable(t.applicationIcon);
-            mActivityDescription.setText(t.activityLabel);
-            if (t.activityIcon != null) {
-                mActivityIcon.setImageBitmap(t.activityIcon);
-                mActivityIcon.setVisibility(View.VISIBLE);
-            }
-            if (animate) {
-                // XXX: Investigate how expensive it will be to create a second bitmap and crossfade
-            }
+        }
+        mActivityDescription.setText(t.activityLabel);
+        if (animate) {
+            // XXX: Investigate how expensive it will be to create a second bitmap and crossfade
         }
     }
 
@@ -78,8 +76,6 @@
     void unbindFromTask() {
         mTask = null;
         mApplicationIcon.setImageDrawable(null);
-        mActivityIcon.setImageBitmap(null);
-        mActivityIcon.setVisibility(View.INVISIBLE);
         mActivityDescription.setText("");
     }
 }