android一键清除最近应用按钮

diff --git a/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml b/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
index 0c0be29..2675a4c 100644
--- a/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
@@ -57,6 +57,15 @@
 
     </FrameLayout>
 
+ <Button
+          android:text="@string/one_key_clean"
+  android:id = "@+id/one_key_clear" 
+  android:layout_alignParentBottom="true"
+  android:layout_marginTop="450dp"
+                   android:layout_width="match_parent"
+                   android:layout_height="wrap_content" />
+
+
     <include layout="@layout/status_bar_no_recent_apps"
         android:id="@+id/recents_no_apps"
         android:layout_width="match_parent"
diff --git a/packages/SystemUI/res/layout/status_bar_recent_panel.xml b/packages/SystemUI/res/layout/status_bar_recent_panel.xml
index 2f3968d..9665268 100644
--- a/packages/SystemUI/res/layout/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout/status_bar_recent_panel.xml
@@ -32,6 +32,7 @@
         android:background="@drawable/status_bar_recents_background"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+ android:layout_marginBottom="130dp"
         android:layout_alignParentBottom="true">
 
         <com.android.systemui.recent.RecentsVerticalScrollView
@@ -59,7 +60,15 @@
 
         </com.android.systemui.recent.RecentsVerticalScrollView>
 
-    </FrameLayout>
+ </FrameLayout>
+
+ <Button
+ android:text="@string/one_key_clean"
+ android:id = "@+id/one_key_clear"
+ android:layout_alignParentBottom="true"
+ android:layout_marginTop="880dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
 
     <include layout="@layout/status_bar_no_recent_apps"
         android:id="@+id/recents_no_apps"
diff --git a/packages/SystemUI/res/values-in/strings.xml b/packages/SystemUI/res/values-in/strings.xml
index 0893599..f55816c 100644
--- a/packages/SystemUI/res/values-in/strings.xml
+++ b/packages/SystemUI/res/values-in/strings.xml
@@ -20,6 +20,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="app_label" msgid="7164937344850004466">"Sistem UI"</string>
+ <string name="one_key_clean">Kunci untuk menghapus</string>
+ <string name="cleaning">jelas dalam ...</string>
     <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Bersihkan"</string>
     <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Hapus dari daftar"</string>
     <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Info apl"</string>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index 8b4ac30..0eff18c 100755
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -20,6 +20,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="app_label" msgid="7164937344850004466">"系统用户界面"</string>
+ <string name="one_key_clean">一键清除</string>
+ <string name="cleaning">清除中 ...</string>
     <string name="status_bar_clear_all_button" msgid="7774721344716731603">"清除"</string>
     <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"从列表中删除"</string>
     <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"应用信息"</string>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 371f1ab..59d3e67 100755
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -19,6 +19,8 @@
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <!-- Name of the status bar as seen in the applications info settings page. [CHAR LIMIT=12] -->
     <string name="app_label">System UI</string>
+    <string name="one_key_clean">Clean all</string>
+    <string name="cleaning">Cleaning up ...</string>
 
     <!-- The text for the button in the notification window-shade that clears
          all of the currently visible notifications. [CHAR LIMIT=10]-->
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
index 09a7a5e..c55ab52 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
@@ -28,6 +28,10 @@ import android.os.UserHandle;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.WindowManager;
+import android.util.Log;
+import android.widget.Button;
+import android.os.Handler;
+import android.os.Message;
 
 import com.android.systemui.R;
 import com.android.systemui.statusbar.StatusBarPanel;
@@ -175,11 +179,35 @@ public class RecentsActivity extends Activity {
         finish();
     }
 
+ private Handler mHandler=new Handler(){
+ @Override
+ public void handleMessage(Message msg) {
+ finish();
+ }
+ };
+
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         getWindow().addPrivateFlags(
                 WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR);
         setContentView(R.layout.status_bar_recent_panel);
+
+ final Button button=(Button) findViewById(R.id.one_key_clear);
+        button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ RecentsPanelView recentsPanelView=new RecentsPanelView(RecentsActivity.this,null,0);
+ recentsPanelView.delAllRecentTask(RecentsActivity.this);
+ button.setText(getResources().getString(R.string.cleaning));
+ mHandler.sendEmptyMessageDelayed(0,500);
+
+ }
+ });
+
+
+
+
         mRecentsPanel = (RecentsPanelView) findViewById(R.id.recents_root);
         mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
         mRecentsPanel.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index 788e843..f14b975 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -810,4 +810,27 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
         }
         mRecentsContainer.drawFadedEdges(canvas, left, right, top, bottom);
     }
+
+
+   public  void delAllRecentTask(Context context){
+
+        final ActivityManager am =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
+
+        mRecentTaskDescriptions = new  ArrayList<TaskDescription>();
+        mRecentTaskDescriptions=mRecentTasksLoader.getLoadedTasks();
+ if(mRecentTaskDescriptions!=null){
+
+ if (am != null) {
+ for(TaskDescription recent :mRecentTaskDescriptions){
+ am.removeTask(recent.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
+ setContentDescription(mContext.getString(R.string.accessibility_recents_item_dismissed, recent.getLabel()));
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
+ setContentDescription(null);
+ }
+ dismissAndGoBack();
+ }
+
+ }
+ }
+
 }

猜你喜欢

转载自blog.csdn.net/xiaoyaoli123456/article/details/77908340