Add clear all button to Recents Go

Add a button to clear all tasks to the recents Go layout and hook it up
to the model.

Bug: 114136250
Test: Open recents, hit clear all
Change-Id: Id67310ce88053528d372e4dc21e2b011ed957646
diff --git a/go/quickstep/res/drawable/clear_all_button.xml b/go/quickstep/res/drawable/clear_all_button.xml
new file mode 100644
index 0000000..acac32d
--- /dev/null
+++ b/go/quickstep/res/drawable/clear_all_button.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<shape
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="@color/clear_all_button_bg"/>
+    <corners android:radius="4dp"/>
+</shape>
diff --git a/go/quickstep/res/layout/icon_recents_root_view.xml b/go/quickstep/res/layout/icon_recents_root_view.xml
index ff3dcef9..fddb1d3 100644
--- a/go/quickstep/res/layout/icon_recents_root_view.xml
+++ b/go/quickstep/res/layout/icon_recents_root_view.xml
@@ -19,13 +19,31 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
-    <androidx.recyclerview.widget.RecyclerView
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/recent_task_recycler_view"
+    <LinearLayout
+        android:id="@+id/recent_task_content_view"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:scrollbars="none"
-        android:visibility="gone"/>
+        android:orientation="vertical"
+        android:visibility="gone">
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/recent_task_recycler_view"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:scrollbars="none"/>
+        <Button
+            android:id="@+id/clear_all_button"
+            android:layout_width="@dimen/clear_all_button_width"
+            android:layout_height="@dimen/clear_all_button_height"
+            android:layout_gravity="center_horizontal"
+            android:layout_marginVertical="@dimen/task_item_half_vert_margin"
+            android:background="@drawable/clear_all_button"
+            android:gravity="center"
+            android:text="@string/recents_clear_all"
+            android:textAllCaps="false"
+            android:textColor="@color/clear_all_button_text"
+            android:textSize="14sp"/>
+    </LinearLayout>
     <TextView
         android:id="@+id/recent_task_empty_view"
         android:layout_width="match_parent"
diff --git a/go/quickstep/res/values/colors.xml b/go/quickstep/res/values/colors.xml
new file mode 100644
index 0000000..ff9dc9c
--- /dev/null
+++ b/go/quickstep/res/values/colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<resources>
+    <color name="clear_all_button_bg">#FFDADCE0</color>
+    <color name="clear_all_button_text">#FF5F6368</color>
+</resources>
diff --git a/go/quickstep/res/values/dimens.xml b/go/quickstep/res/values/dimens.xml
index 7269704..e2fa387 100644
--- a/go/quickstep/res/values/dimens.xml
+++ b/go/quickstep/res/values/dimens.xml
@@ -20,4 +20,7 @@
     <dimen name="task_thumbnail_height">60dp</dimen>
     <dimen name="task_thumbnail_width">36dp</dimen>
     <dimen name="task_icon_size">36dp</dimen>
+
+    <dimen name="clear_all_button_width">106dp</dimen>
+    <dimen name="clear_all_button_height">36dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/go/quickstep/src/com/android/quickstep/TaskInputController.java b/go/quickstep/src/com/android/quickstep/TaskInputController.java
index 8433007..10de5c8 100644
--- a/go/quickstep/src/com/android/quickstep/TaskInputController.java
+++ b/go/quickstep/src/com/android/quickstep/TaskInputController.java
@@ -61,6 +61,14 @@
         mAdapter.notifyItemRemoved(position);
     }
 
-    // TODO: Implement "Clear all" and notify adapter that data has updated
-
+    /**
+     * Logic that occurs when clear all is triggered.
+     */
+    public void onClearAllClicked(View view) {
+        // TODO: Play an animation so transition is more natural.
+        int count = mAdapter.getItemCount();
+        ActivityManagerWrapper.getInstance().removeAllRecentTasks();
+        mLoader.clearAllTasks();
+        mAdapter.notifyItemRangeRemoved(0 /* positionStart */, count);
+    }
 }
diff --git a/go/quickstep/src/com/android/quickstep/TaskListLoader.java b/go/quickstep/src/com/android/quickstep/TaskListLoader.java
index e6d1a22..c86c24e 100644
--- a/go/quickstep/src/com/android/quickstep/TaskListLoader.java
+++ b/go/quickstep/src/com/android/quickstep/TaskListLoader.java
@@ -93,6 +93,13 @@
     }
 
     /**
+     * Clears the current task list.
+     */
+    void clearAllTasks() {
+        mTaskList.clear();
+    }
+
+    /**
      * Loads task content for a list of tasks, including the label, icon, and thumbnail. For content
      * that isn't cached, load the content asynchronously in the background.
      *
diff --git a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
index 504f640..94f3e66 100644
--- a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
+++ b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java
@@ -79,6 +79,7 @@
     private RecentsToActivityHelper mActivityHelper;
     private RecyclerView mTaskRecyclerView;
     private View mEmptyView;
+    private View mContentView;
 
     public IconRecentsView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -102,6 +103,7 @@
             helper.attachToRecyclerView(mTaskRecyclerView);
 
             mEmptyView = findViewById(R.id.recent_task_empty_view);
+            mContentView = findViewById(R.id.recent_task_content_view);
             mTaskAdapter.registerAdapterDataObserver(new AdapterDataObserver() {
                 @Override
                 public void onChanged() {
@@ -113,6 +115,9 @@
                     updateContentViewVisibility();
                 }
             });
+
+            View clearAllView = findViewById(R.id.clear_all_button);
+            clearAllView.setOnClickListener(mTaskInputController::onClearAllClicked);
         }
     }
 
@@ -162,11 +167,11 @@
     private void updateContentViewVisibility() {
         int taskListSize = mTaskLoader.getCurrentTaskList().size();
         if (mEmptyView.getVisibility() != VISIBLE && taskListSize == 0) {
-            crossfadeViews(mEmptyView, mTaskRecyclerView);
+            crossfadeViews(mEmptyView, mContentView);
             mActivityHelper.leaveRecents();
         }
-        if (mTaskRecyclerView.getVisibility() != VISIBLE && taskListSize > 0) {
-            crossfadeViews(mTaskRecyclerView, mEmptyView);
+        if (mContentView.getVisibility() != VISIBLE && taskListSize > 0) {
+            crossfadeViews(mContentView, mEmptyView);
         }
     }