您的位置:首页 > 移动开发 > Android开发

笔记:android4.3 添加清除最近使用应用按钮

2014-08-08 21:02 387 查看
在最近使用的界面添加一个按钮,

用来一健清除最近使用的应用。

patch如下:

.../res/layout-land/status_bar_recent_panel.xml    |   10 +++++++++-
.../res/layout/status_bar_recent_panel.xml         |   10 +++++++++-
packages/SystemUI/res/values-zh-rCN/strings.xml    |    1 +
packages/SystemUI/res/values/strings.xml           |    1 +
.../android/systemui/recent/RecentsActivity.java   |   16 +++++++++++++++-
.../recent/RecentsHorizontalScrollView.java        |   12 ++++++++++++
.../android/systemui/recent/RecentsPanelView.java  |    8 ++++++++
.../systemui/recent/RecentsVerticalScrollView.java |   12 ++++++++++++
8 files changed, 67 insertions(+), 3 deletions(-)

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 b06166d..1c2c377 100644
--- a/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout-land/status_bar_recent_panel.xml
@@ -61,5 +61,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
-
+    <Button
+        android:id="
4000
@+id/clear_app_all"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="bottom|center"
+        android:layout_gravity="bottom|center"
+        android:focusable="true"
+        android:clickable="true"
+        android:text="@string/clear_all_recent_apps" />
</com.android.systemui.recent.RecentsPanelView>
diff --git a/packages/SystemUI/res/layout/status_bar_recent_panel.xml b/packages/SystemUI/res/layout/status_bar_recent_panel.xml
index 305aaf2..0f2ef89 100644
--- a/packages/SystemUI/res/layout/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout/status_bar_recent_panel.xml
@@ -65,5 +65,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
-
+    <Button
+        android:id="@+id/clear_app_all"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:layout_gravity="bottom|center"
+        android:focusable="true"
+        android:clickable="true"
+        android:text="@string/clear_all_recent_apps" />
</com.android.systemui.recent.RecentsPanelView>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index 390dbc9..5fe2309 100644
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -217,4 +217,5 @@

<string name="task_manager_refresh">刷新</string>
<string name="task_manager_kill">清除</string>
+    <string name="clear_all_recent_apps">清除最近运行应用</string>
</resources>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 36e0f23..3ebc992 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -535,4 +535,5 @@

<string name="task_manager_refresh">Refresh</string>
<string name="task_manager_kill">Kill All</string>
+    <string name="clear_all_recent_apps">Clear All Recent Apps</string>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
index 5ee291b..3369488 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java
@@ -33,8 +33,10 @@ import com.android.systemui.R;
import com.android.systemui.statusbar.tablet.StatusBarPanel;

import java.util.List;
+import android.view.View.OnClickListener;
+import android.widget.Button;

-public class RecentsActivity extends Activity {
+public class RecentsActivity extends Activity implements OnClickListener {
public static final String TOGGLE_RECENTS_INTENT = "com.android.systemui.recent.action.TOGGLE_RECENTS";
public static final String PRELOAD_INTENT = "com.android.systemui.recent.action.PRELOAD";
public static final String CANCEL_PRELOAD_INTENT = "com.android.systemui.recent.CANCEL_PRELOAD";
@@ -49,6 +51,8 @@ public class RecentsActivity extends Activity {
private boolean mShowing;
private boolean mForeground;

+    Button mClearAllApp;
+
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -185,6 +189,9 @@ public class RecentsActivity extends Activity {
mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
mRecentsPanel.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

+        mClearAllApp = (Button) findViewById(R.id.clear_app_all);
+        mClearAllApp.setOnClickListener(this);
+
final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this);
recentTasksLoader.setRecentsPanel(mRecentsPanel, mRecentsPanel);
mRecentsPanel.setMinSwipeAlpha(
@@ -243,4 +250,11 @@ public class RecentsActivity extends Activity {
boolean isActivityShowing() {
return mShowing;
}
+
+    public void onClick(View v) {
+        if((mClearAllApp == v)){
+            mRecentsPanel.removeRecentAllViews();
+            dismissAndGoHome();
+        }
+    }
}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
index 217b7fd..fc6aa98 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
@@ -196,6 +196,18 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
mSwipeHelper.dismissChild(v, 0);
}

+    public void removeRecentAllViews() {
+        Log.d(TAG, "mLinearLayout count:" + mLinearLayout.getChildCount());
+        int count = mLinearLayout.getChildCount();
+        while (mLinearLayout.getChildCount() > 0) {
+            View v = mLinearLayout.getChildAt(0);
+            if (v == null || v.getTag() == null) {
+                continue;
+            }
+            onChildDismissed(v);
+        }
+    }
+
public void onChildDismissed(View v) {
addToRecycledViews(v);
mLinearLayout.removeView(v);
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index 8b69680..2dc68f3 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -99,6 +99,14 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
public void setCallback(RecentsCallback callback);
public void setMinSwipeAlpha(float minAlpha);
public View findViewForTask(int persistentTaskId);
+        public void removeRecentAllViews();
+    }
+
+    public void removeRecentAllViews() {
+        if (mRecentsContainer instanceof RecentsScrollView){
+            RecentsScrollView scrollView = (RecentsScrollView) mRecentsContainer;
+            scrollView.removeRecentAllViews();
+        }
}

private final class OnLongClickDelegate implements View.OnLongClickListener {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
index 403c643..b70e943 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
@@ -89,6 +89,18 @@ public class RecentsVerticalScrollView extends ScrollView
return null;
}

+    public void removeRecentAllViews() {
+        Log.d(TAG, "mLinearLayout count:" + mLinearLayout.getChildCount());
+        int count = mLinearLayout.getChildCount();
+        while (mLinearLayout.getChildCount() > 0) {
+            View v = mLinearLayout.getChildAt(0);
+            if (v == null || v.getTag() == null) {
+                continue;
+            }
+            onChildDismissed(v);
+        }
+    }
+
private void update() {
for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
View v = mLinearLayout.getChildAt(i);
--
1.7.9.5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android