其他分享
首页 > 其他分享> > Android5.1下拉状态栏新增截屏功能

Android5.1下拉状态栏新增截屏功能

作者:互联网

记录一下:直接上代码

diff --git a/alps/frameworks/base/packages/SystemUI/res/values-de/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-de/strings.xml
old mode 100644
new mode 100755
index fa87380..b3beba9
--- a/alps/frameworks/base/packages/SystemUI/res/values-de/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-de/strings.xml
@@ -362,4 +362,7 @@
     <string name="quick_settings_reset_confirmation_title" msgid="748792586749897883">"<xliff:g id="TILE_LABEL">%1$s</xliff:g> ausblenden?"</string>
     <string name="quick_settings_reset_confirmation_message" msgid="2235970126803317374">"Sie wird wieder eingeblendet, wenn Sie sie in den Einstellungen erneut aktivieren."</string>
     <string name="quick_settings_reset_confirmation_button" msgid="2660339101868367515">"Ausblenden"</string>
+	<!--add by frankchen start-->
+	<string name="screenshot">"Screenshots"</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values-es/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-es/strings.xml
old mode 100644
new mode 100755
index 4a05367..f3968b1
--- a/alps/frameworks/base/packages/SystemUI/res/values-es/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-es/strings.xml
@@ -362,4 +362,7 @@
     <string name="quick_settings_reset_confirmation_title" msgid="748792586749897883">"¿Ocultar <xliff:g id="TILE_LABEL">%1$s</xliff:g>?"</string>
     <string name="quick_settings_reset_confirmation_message" msgid="2235970126803317374">"Volverá a aparecer la próxima vez que actives esta opción en Ajustes."</string>
     <string name="quick_settings_reset_confirmation_button" msgid="2660339101868367515">"Ocultar"</string>
+	<!--add by frankchen start-->
+	<string name="screenshot">"Intercepción"</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values-fr/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-fr/strings.xml
old mode 100644
new mode 100755
index b67ced4..96f81bb
--- a/alps/frameworks/base/packages/SystemUI/res/values-fr/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-fr/strings.xml
@@ -362,4 +362,7 @@
     <string name="quick_settings_reset_confirmation_title" msgid="748792586749897883">"Masquer <xliff:g id="TILE_LABEL">%1$s</xliff:g> ?"</string>
     <string name="quick_settings_reset_confirmation_message" msgid="2235970126803317374">"Cet élément réapparaîtra la prochaine fois que vous l\'activerez dans les paramètres."</string>
     <string name="quick_settings_reset_confirmation_button" msgid="2660339101868367515">"Masquer"</string>
+	<!--add by frankchen start-->
+	<string name="screenshot">"Ecran"</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values-it/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-it/strings.xml
old mode 100644
new mode 100755
index 57ec46e..bb3bc83
--- a/alps/frameworks/base/packages/SystemUI/res/values-it/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-it/strings.xml
@@ -362,4 +362,7 @@
     <string name="quick_settings_reset_confirmation_title" msgid="748792586749897883">"Nascondere <xliff:g id="TILE_LABEL">%1$s</xliff:g>?"</string>
     <string name="quick_settings_reset_confirmation_message" msgid="2235970126803317374">"Verranno visualizzate di nuovo quando le riattiverai nelle impostazioni."</string>
     <string name="quick_settings_reset_confirmation_button" msgid="2660339101868367515">"Nascondi"</string>
+	<!--add by frankchen start-->
+	<string name="screenshot">"Schermi"</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index 319cf8f..bad232c
--- a/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -362,4 +362,7 @@
     <string name="quick_settings_reset_confirmation_title" msgid="748792586749897883">"要隐藏“<xliff:g id="TILE_LABEL">%1$s</xliff:g>”吗?"</string>
     <string name="quick_settings_reset_confirmation_message" msgid="2235970126803317374">"下次在设置中将其开启后,此快捷设置条目将会重新显示。"</string>
     <string name="quick_settings_reset_confirmation_button" msgid="2660339101868367515">"隐藏"</string>
+	<!--add by frankchen start-->
+	<string name="screenshot">截屏</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values/config.xml b/alps/frameworks/base/packages/SystemUI/res/values/config.xml
old mode 100644
new mode 100755
index 6515a2f..91ac9c6
--- a/alps/frameworks/base/packages/SystemUI/res/values/config.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values/config.xml
@@ -118,8 +118,13 @@
 
     <!-- The default tiles to display in QuickSettings -->
     <string name="quick_settings_tiles_default" translatable="false">
+        wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,takescreenshot,hotspot,audioprofile
+    </string>
+	<!-- frankchen
+	<string name="quick_settings_tiles_default" translatable="false">
         wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,hotspot,hotknot,audioprofile
     </string>
+	-->
 
     <!-- The tiles to display in QuickSettings -->
     <string name="quick_settings_tiles" translatable="false">default</string>
diff --git a/alps/frameworks/base/packages/SystemUI/res/values/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
old mode 100644
new mode 100755
index 5608bdb..26818ce
--- a/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
@@ -916,4 +916,8 @@
 
     <!-- Hide quick settings tile confirmation button -->
     <string name="quick_settings_reset_confirmation_button">Hide</string>
+	
+	<!--add by frankchen start-->
+	<string name="screenshot">ScreenShot</string>
+	<!--add by frankchen end-->
 </resources>
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/TakeScreenShotTitle.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/TakeScreenShotTitle.java
new file mode 100755
index 0000000..ce6e73a
--- /dev/null
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/TakeScreenShotTitle.java
@@ -0,0 +1,121 @@
+/*
+* Copyright (C) 2014 MediaTek Inc.
+* Modification based on code covered by the mentioned copyright
+* and/or permission notice(s).
+*/
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+package com.android.systemui.qs.tiles;
+ 
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.provider.Settings;
+import android.util.Log;
+import android.os.Handler ;
+import android.os.Message ;
+import android.os.Messenger ;
+import android.view.View;
+import android.view.ViewGroup;
+import java.lang.Exception ;
+import com.android.systemui.screenshot.* ;
+import com.android.systemui.R;
+import com.android.systemui.qs.QSTile.State;
+import com.android.systemui.qs.QSTile.BooleanState;
+import com.android.systemui.qs.QSDetailItems;
+import com.android.systemui.qs.QSDetailItems.Item;
+import com.android.systemui.qs.QSTile;
+import com.android.systemui.qs.QSTileView;
+import com.android.systemui.qs.SignalTileView;
+import com.android.systemui.statusbar.phone.QSTileHost;
+import com.android.systemui.statusbar.policy.NetworkController;
+import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
+import com.android.systemui.statusbar.policy.NetworkController.AccessPointController.AccessPoint;
+import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback;
+ 
+/** pang test Quick settings tile: TakeScreenShotTitle **/
+public class TakeScreenShotTitle extends QSTile<QSTile.BooleanState> {
+    private static final String TAG = "TakeScreenShotTile";  
+  
+    private static final int TAKE_SCREEN_SHOT_MESSAGE = 10000;  
+    private static GlobalScreenshot mScreenshot;  
+      
+    private int screen_icon = R.drawable.ic_qs_screenshot;
+  
+    public TakeScreenShotTitle(Host host) {  
+        super(host);  
+    }  
+  
+    @Override  
+    protected BooleanState newTileState() {  
+        return new BooleanState();  
+    }  
+  
+    @Override  
+    public void setListening(boolean listening) {  
+    }  
+ 
+ 
+  
+    @Override  
+    protected void handleClick() {  
+        mHost.startSettingsActivity(new Intent());  
+        Message msg = mHandler.obtainMessage(TAKE_SCREEN_SHOT_MESSAGE);  
+        mHandler.sendMessageDelayed(msg,1000);  
+    }  
+     
+    protected void handleLongClick() {  
+        mHost.startSettingsActivity(new Intent());  
+        Message msg = mHandler.obtainMessage(TAKE_SCREEN_SHOT_MESSAGE);  
+        mHandler.sendMessageDelayed(msg,1000);  
+    }  
+  
+    @Override  
+    protected void handleUpdateState(BooleanState state, Object arg) {  
+        state.label = mContext.getString(R.string.screenshot);  
+        state.visible = true;  
+        state.icon = ResourceIcon.get(screen_icon);  
+    }  
+  
+    Handler mHandler = new Handler() {  
+        public void handleMessage(Message msg) {  
+            switch (msg.what) {  
+            case TAKE_SCREEN_SHOT_MESSAGE:  
+ 
+                final Messenger callback = msg.replyTo;  
+                if (mScreenshot == null) {  
+                    mScreenshot = new GlobalScreenshot(mContext);  
+                }  
+                mScreenshot.takeScreenshot(new Runnable() {  
+                    @Override public void run() {  
+                        Message reply = Message.obtain(null, 1);  
+                        try {  
+                            if(callback != null){  
+                                callback.send(reply);  
+                            }  
+                        }catch(Exception e){  
+                        }  
+                    }  
+                }, msg.arg1 > 0, msg.arg2 > 0);  
+                break;                      
+            default:  
+                break;  
+            }  
+        }  
+    };  
+  
+}
\ No newline at end of file
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
old mode 100644
new mode 100755
index 10f8117..b207406
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -359,7 +359,8 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
  *   - what do we say in the Toast? Which icon do we get if the user uses another
  *     type of gallery?
  */
-class GlobalScreenshot {
+ //modify by frankchen class GlobalScreenshot -> public class GlobalScreenshot
+public class GlobalScreenshot {
     private static final String TAG = "GlobalScreenshot";
 
     private static final int SCREENSHOT_NOTIFICATION_ID = 789;
@@ -506,7 +507,8 @@ class GlobalScreenshot {
     /**
      * Takes a screenshot of the current display and shows an animation.
      */
-    void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
+	 //modify by frankchen void takeScreenshot -> public void takeScreenshot
+    public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
         // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
         // only in the natural orientation of the device :!)
         mDisplay.getRealMetrics(mDisplayMetrics);
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
old mode 100644
new mode 100755
index 355483b..8d2ebbc
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
@@ -83,6 +83,8 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+//add by frankchen
+import com.android.systemui.qs.tiles.TakeScreenShotTitle;
 
 /** Platform implementation of the quick settings tile host **/
 public class QSTileHost implements QSTile.Host {
@@ -326,6 +328,7 @@ public class QSTileHost implements QSTile.Host {
         else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this);
         else if (tileSpec.equals("rotation")) return new RotationLockTile(this);
         else if (tileSpec.equals("flashlight")) return new FlashlightTile(this);
+		else if(tileSpec.equals("takescreenshot")) return new TakeScreenShotTitle(this);//add by frankchen
         else if (tileSpec.equals("location")) return new LocationTile(this);
         // M: Remove CastTile when WFD is not support in quicksetting
         else if (tileSpec.equals("cast") && SIMHelper.isWifiDisplaySupport())

 

标签:alps,Android5.1,状态栏,frameworks,截屏,base,android,packages,SystemUI
来源: https://blog.csdn.net/Evahuangchen/article/details/101052907