笔记:android4.3 添加清除最近使用应用按钮
2014-08-08 21:02
387 查看
在最近使用的界面添加一个按钮,
用来一健清除最近使用的应用。
patch如下:
用来一健清除最近使用的应用。
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一键清除最近应用按钮
- Android 程式开发:(四)使用Intent调用“内置”应用 —— 4.4添加Category属性
- 在Android应用中使用SQLite数据库(传智播客视频笔记)
- android应用开发笔记---SQLite使用
- Android笔记之:App应用之启动界面SplashActivity的使用
- android应用开发揭秘examples_04-10笔记(AutoCompleteTextView和MultiAutoCompleteTextView使用)
- android应用开发笔记---常用控件使用方法
- android应用开发笔记---_Handler的使用
- android应用开发揭秘examples_04-08笔记(CheckBox的使用)
- android应用开发揭秘例4-3笔记(TextView的使用)
- android应用开发揭秘examples_04-17笔记(Gallery的使用)
- 在Android应用中使用Pull解析XML文件(传智播客视频笔记)
- Android应用中使用ListView实现数据列表显示(传智播客视频笔记)
- android应用开发揭秘例example4-7笔记(RadioGroup和RadioButton的使用与改进)
- 瓦片地图学习笔记一 编辑器使用及地图添加,对象层应用
- 在Android应用中使用Pull解析XML文件(传智播客视频笔记)
- Android应用中使用GridView实现数据网格显示(传智播客视频笔记)
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- android应用开发揭秘examples_04-16笔记(ImageButton的使用)
- android应用开发揭秘examples_04-09笔记(Spinner的使用,略有修改)