A,frameworksasepackagesSystemUI esvaluesconfig.xml
添加: <bool name="quick_settings_show_screenshot">truebool>
B,frameworksasepackagesSystemUI esvaluesstrings.xml
添加:<string name="quick_settings_screen_shot_label">Screen shotstring>
C,frameworksasepackagesSystemUI esvalues-zh-rCNstrings.xml
添加:<string name="quick_settings_screen_shot_label" msgid="f9870466a61654f367d">屏幕截图string>
D,添加图标
①frameworksasepackagesSystemUI
esdrawable-hdpiic_qs_screen_shot.png
②frameworksasepackagesSystemUI
esdrawable-mdpiic_qs_screen_shot.png
③frameworksasepackagesSystemUI
esdrawable-xhdpiic_qs_screen_shot.png
E,添加单布局文件:
frameworksasepackagesSystemUI eslayoutquick_settings_tile_screen_shot.xml
xml version="1.0" encoding="utf-8"?> <TextViewxmlns:android="http://schemas.android.com/apk/res/android"style="@style/TextAppearance.QuickSettings.TileView"android:id="@+id/screen_shot_textview"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:gravity="center"android:drawableTop="@drawable/ic_qs_screen_shot"android:text="@string/quick_settings_screen_shot_label"/>
F,添加相应java代码:
frameworksasepackagesSystemUIsrccomandroidsystemuistatusbarphoneQuickSettings.java
import android.content.ServiceConnection;import android.os.IBinder;import android.os.Message;import android.os.Messenger;
再在addTemporaryTiles() 方法里面的最后添加相应代码:
///_1126/// screen shotQuickSettingsTileView ScreenShotTile = (QuickSettingsTileView)inflater.inflate(R.layout.quick_settings_tile, parent, false);ScreenShotTile.setContent(R.layout.quick_settings_tile_screen_shot, inflater);ScreenShotTile.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Log.i(TAG, "---------------------------------screen shot is clicked.");//takeScreenshot();mBar.collapseAllPanels(true);mHandler.removeCallbacks(mScreenshotClick);mHandler.postDelayed(mScreenshotClick, 500);}});if (mContext.getResources().getBoolean(R.bool.quick_settings_show_screenshot)) {parent.addView(ScreenShotTile);}
随后在外部添加相应调用代码:
/*******************_1126*********************************/// add by xxx, for screen shot in quick settings.private final Runnable mScreenshotClick = new Runnable() {public void run() {takeScreenshot();}};private final Object mScreenshotLock = new Object();private ServiceConnection mScreenshotConnection = null;private final Runnable mScreenshotTimeout = new Runnable() {@Override public void run() {synchronized (mScreenshotLock) {if (mScreenshotConnection != null) {mContext.unbindService(mScreenshotConnection);mScreenshotConnection = null;}}}};// Assume this is called from the Handler thread.private void takeScreenshot() {Log.i("bright", "start take screen shot.");synchronized (mScreenshotLock) {if (mScreenshotConnection != null) {return;}ComponentName cn = new ComponentName("com.android.systemui","com.android.systemui.screenshot.TakeScreenshotService");Intent intent = new Intent();intent.setComponent(cn);ServiceConnection conn = new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {synchronized (mScreenshotLock) {if (mScreenshotConnection != this) {return;}Messenger messenger = new Messenger(service);Message msg = Message.obtain(null, 1);final ServiceConnection myConn = this;Handler h = new Handler(mHandler.getLooper()) {@Overridepublic void handleMessage(Message msg) {synchronized (mScreenshotLock) {if (mScreenshotConnection == myConn) {mContext.unbindService(mScreenshotConnection);mScreenshotConnection = null;mHandler.removeCallbacks(mScreenshotTimeout);}}}};msg.replyTo = new Messenger(h);msg.arg1 = msg.arg2 = 1;try {messenger.send(msg);} catch (RemoteException e) {}}}@Overridepublic void onServiceDisconnected(ComponentName name) {}};if (mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE)) {mScreenshotConnection = conn;mHandler.postDelayed(mScreenshotTimeout, 10000);}}}/**************************************************/
系统编译后的最终效果如下图(找了个关于SIM的图标代替):
------------------------------------------------------------------------------------- -------------------------------------- -------------------------
参考:http://blog.csdn.net/yicao821/article/details/17416649