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







0 0
原创粉丝点击