Android源代码在长按home键添加一键清除当前任务
来源:互联网 发布:高清混合矩阵价格 编辑:程序博客网 时间:2024/05/22 15:36
主要修改一个布局文件:/frameworks/base/packages/SystemUI/res/layout/status_bar_recent_panel.xml
一个java文件:/frameworks/base/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
布局文件作如下更改,主要添加一个按钮。
<com.android.systemui.recent.RecentsPanelView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:id="@+id/recents_root" android:layout_height="match_parent" android:layout_width="match_parent" android:foreground="@drawable/bg_protect" systemui:recentItemLayout="@layout/status_bar_recent_item" > <span style="color:#ff0000;"><RelativeLayout</span> android:id="@+id/recents_bg_protect" android:background="@drawable/status_bar_recents_background" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="true"> <com.android.systemui.recent.RecentsVerticalScrollView android:id="@+id/recents_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginEnd="0dp" android:divider="@null" android:stackFromBottom="true" android:fadingEdge="vertical" android:scrollbars="none" android:fadingEdgeLength="@dimen/status_bar_recents_scroll_fading_edge_length" android:layout_gravity="bottom|start" <span style="color:#ff0000;">android:layout_above="@+id/clean_all_recent_apps"</span> android:clipToPadding="false" android:clipChildren="false"> <LinearLayout android:id="@+id/recents_linear_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:fitsSystemWindows="true" android:clipToPadding="false" android:clipChildren="false"> </LinearLayout> </com.android.systemui.recent.RecentsVerticalScrollView> <span style="color:#ff0000;"><Button android:id="@+id/clean_all_recent_apps" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20dp" android:text="@string/status_bar_no_recent_apps" android:gravity="center" android:layout_alignParentBottom="true" /></span><span style="color:#ff0000;"> </RelativeLayout></span> <include layout="@layout/status_bar_no_recent_apps" android:id="@+id/recents_no_apps" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="invisible" /></com.android.systemui.recent.RecentsPanelView>
java文件作如下修改,做出按钮的响应和删除所有任务的功能,在新线程中执行,避免影响主线程,并延时动态效果处理。
protected void onFinishInflate() { super.onFinishInflate(); mRecentsContainer = (RecentsScrollView) findViewById(R.id.recents_container); mRecentsContainer.setOnScrollListener(new Runnable() { public void run() { // need to redraw the faded edges invalidate(); } }); mListAdapter = new TaskDescriptionAdapter(mContext); mRecentsContainer.setAdapter(mListAdapter); mRecentsContainer.setCallback(this); mRecentsScrim = findViewById(R.id.recents_bg_protect); mRecentsNoApps = findViewById(R.id.recents_no_apps); //The Clean All Button Handle mClearRecent = (Button)findViewById(R.id.clean_all_recent_apps); if(mClearRecent != null) { mCleanAllHandler = new CleanAllRecentsHandler(); mClearRecent.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new Thread(new CleanAllRecentsThread()).start(); } }); } if (mRecentsScrim != null) { mHighEndGfx = ActivityManager.isHighEndGfx(); if (!mHighEndGfx) { mRecentsScrim.setBackground(null); } else if (mRecentsScrim.getBackground() instanceof BitmapDrawable) { // In order to save space, we make the background texture repeat in the Y direction ((BitmapDrawable) mRecentsScrim.getBackground()).setTileModeY(TileMode.REPEAT); } } } class CleanAllRecentsThread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout); mCurRecentID = -1; if (mLinearLayout != null) { Log.i(VIEW_LOG_TAG, "ChildCount" + mLinearLayout.getChildCount()); int count = mLinearLayout.getChildCount(); for(int i = count - 1; i >= 0; i--){ mCurRecentID = i; Message msg = new Message(); mCleanAllHandler.sendMessage(msg); try { Thread.sleep(300); } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } } }else { Log.i(VIEW_LOG_TAG, "LinearLayout is null"); } } } class CleanAllRecentsHandler extends Handler{ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub if (mCurRecentID < 0) { return; } View view = mLinearLayout.getChildAt(mCurRecentID); ((ViewGroup) mRecentsContainer).removeViewInLayout(view); super.handleMessage(msg); } }
刷入手机的命令:
编译:./mk -t -o=USE_CCACHE=1,TARGET_BUILD_VARIANT=user m05 mm frameworks/base/packages/SystemUI/
./mk -t -o=USE_CCACHE=1,TARGET_BUILD_VARIANT=user m05 mm frameworks/base/
push到手机:adb remount
adb push out/target/product/m05/system/priv-app/SystemUI.odex system/priv-app/
adb push out/target/product/m05/system/priv-app/SystemUI.apk system/priv-app/
adb push out/target/product/m05/system/framework/framework.odex system/framework
adb push out/target/product/m05/system/framework/framework2.odex system/framework
adb push out/target/product/m05/system/framework/framework2.jar system/framework
adb push out/target/product/m05/system/framework/framework.jar system/framework
adb reboot
- Android源代码在长按home键添加一键清除当前任务
- 长按home键显示当前任务
- android长按home键源码分析以及模拟长按home事件--弹出近期任务
- android长按home键源码分析以及模拟长按home事件--弹出近期任务.
- 怎么样清除android手机长按home键后,出现的最近运行的6个任务中的指定一个的图标
- android长按home键流程
- android长按home键流程
- android长按home键流程
- android长按home键流程 .
- Android中屏蔽 电源键长按、Home键、Home长按
- Android中屏蔽 电源键长按、Home键、Home长按
- Android 长按home键强制关闭应用后,在哪里执行退出应用?
- 模拟长按Home键
- 【android】仿照长按home键 恢复后台运行程序
- android 修改statusbar(一)添加home back menu键
- android 修改statusbar(一)添加home back menu键
- 长按Home键显示的8个近期任务问题
- Android | 设置按home键之后是否销毁当前Activity
- ICON的设计很重要
- Ubuntu系统下搭建lnmp环境
- Android应用开发中如何使用RSA加密算法对数据进行校验
- Linux下卸载oracle_RAC
- Cocos2d Box2d 物理引擎实现愤怒的小鸟
- Android源代码在长按home键添加一键清除当前任务
- 归并排序及其空间复杂度的思考
- android之cpu使用率曲线效果的实现!
- Xcode常用快捷键
- A + B
- JDK7动态方法调用
- 5分钟 学会Git
- 几种servlet页面跳转方式。
- Box2d Physics封装,碰撞检测,随笔