您的位置:首页 > 其它

增加截图功能

2016-12-29 14:20 225 查看

增加截图功能

------- frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_screenshot.png
------- frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
------- frameworks/base/packages/SystemUI/res/values-zh-rHK/strings.xml
------- frameworks/base/packages/SystemUI/res/values-zh-rTW/strings.xml
------- frameworks/base/packages/SystemUI/res/values/config.xml
------- frameworks/base/packages/SystemUI/res/values/strings.xml
------- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
------- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenShotTile.java
------- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
------- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
------- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/ScreenShotController.java
------- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/ScreenShotControllerImpl.java


--- frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_screenshot.png ---
new file mode 100644
index 0000000..2637b64
Binary files /dev/null and b/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_screenshot.png differ

------- frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml -------
index ef925f8..52293f2 100644
@@ -430,4 +430,5 @@
<string name="remove_from_settings_prompt" msgid="6069085993355887748">"要将系统界面调谐器从“设置”中移除,并停止使用所有相关功能吗?"</string>
<string name="utouu_status_bar_phone_going">通话中,点击返回通话</string>
<string name="utouu_status_bar_phone_going_in_lockscreen">通话中</string>
+  <string name="screenshot_title">"截图"</string>
</resources>


------- frameworks/base/packages/SystemUI/res/values-zh-rHK/strings.xml -------
index 6d76214..4971ef3 100644
@@ -430,4 +430,5 @@
<string name="remove_from_settings_prompt" msgid="6069085993355887748">"要從「設定」移除系統使用者介面調諧器,並停止其所有功能嗎?"</string>
<string name="utouu_status_bar_phone_going">通話中,點擊返回通話</string>
<string name="utouu_status_bar_phone_going_in_lockscreen">通話中</string>
+    <string name="screenshot_title">截圖</string>
</resources>


------- frameworks/base/packages/SystemUI/res/values-zh-rTW/strings.xml -------
index e0464b7..4bbed6d 100644
@@ -428,4 +428,5 @@
<string name="tuner_toast" msgid="603429811084428439">"恭喜!系統使用者介面調整精靈已新增到設定中"</string>
<string name="remove_from_settings" msgid="8389591916603406378">"從設定中移除"</string>
<string name="remove_from_settings_prompt" msgid="6069085993355887748">"要將系統使用者介面調整精靈從設定中移除,並停止使用所有相關功能嗎?"</string>
+    <string name="screenshot_title">截圖</string>
</resources>


----------- frameworks/base/packages/SystemUI/res/values/config.xml -----------
index 260d81b..02c6a11 100644
@@ -119,7 +119,7 @@

<!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false">
-        wifi,bt,inversion,dnd,cell,airplane,rotation,flashlight,location,cast,hotspot
+        wifi,bt,inversion,dnd,cell,airplane,rotation,flashlight,location,screenshot,hotspot
</string>

<!-- The tiles to display in QuickSettings -->


----------- frameworks/base/packages/SystemUI/res/values/strings.xml -----------
index 5fc7e5d..0e3c17a 100644
@@ -1121,7 +1121,7 @@
<string name="remove_from_settings_prompt">Remove System UI Tuner from Settings and stop using all of its features?"</string>
<string name="utouu_status_bar_phone_going">Calling. Click to return</string>
<string name="utouu_status_bar_phone_going_in_lockscreen">Calling</string>
-
+    <string name="screenshot_title">ScreenShot</string>
<string name="key_writer_test">加密芯片测试</string>
<string name="key_writer_string1">芯片是否写入KEY:</string>
<string name="key_writer_string2">NV中的KEY:</string>


-- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSTile.java --
index 5bad7e5..7e1a288 100644
@@ -41,7 +41,7 @@ import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.RotationLockController;
import com.android.systemui.statusbar.policy.ZenModeController;
-
+import com.android.systemui.statusbar.policy.ScreenShotController; //add
/// M: Add other tiles
import com.mediatek.systemui.statusbar.policy.AudioProfileController;
import com.mediatek.systemui.statusbar.policy.HotKnotController;
@@ -358,6 +358,9 @@ public abstract class QSTile<TState extends State> implements Listenable {
*/
AudioProfileController getAudioProfileController();

+        /// M: add screenshot in quick setting by Lee
+        ScreenShotController getScreenShotController();
+
public interface Callback {
void onTilesChanged();
}


---frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenShotTile.java
new file mode 100644
index 0000000..5080e91
@@ -0,0 +1,154 @@
+/*
+ * 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.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ComponentName;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.UserHandle;
+import android.os.RemoteException;
+import android.os.Message;
+import android.os.Messenger;
+
+import android.util.Log;
+
+import com.android.systemui.R;
+import com.android.systemui.qs.GlobalSetting;
+import com.android.systemui.qs.QSTile;
+import com.android.internal.logging.MetricsLogger;
+
+/** Quick settings tile: Airplane mode **/
+public class ScreenShotTile extends QSTile<QSTile.BooleanState> {
+
+    final Handler mHandler;
+
+    final Object mScreenshotLock = new Object();
+    ServiceConnection mScreenshotConnection = null;
+    final Host mHost;
+
+    public ScreenShotTile(Host host) {
+        super(host);
+        mHost = host;
+        mHandler = new Handler();
+    }
+
+    @Override
+    protected BooleanState newTileState() {
+        return new BooleanState();
+    }
+
+    @Override
+    public void handleClick() {
+        //Log.v("Lee", "handleClick() mHost="+mHost);
+        if (mHost != null) {
+            mHost.getScreenShotController().onCollapsePanels();
+        }
+        mHandler.postDelayed(mScreenshotRunnable, 1000);
+    }
+
+    @Override
+    protected void handleUpdateState(BooleanState state, Object arg) {
+        state.label = mContext.getString(R.string.screenshot_title);
+        state.visible = true;
+        state.icon =  ResourceIcon.get(R.drawable.ic_qs_screenshot);
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsLogger.QS_LOCATION;
+    }
+
+    @Override
+    public void setListening(boolean listening) {
+
+    }
+
+    private final Runnable mScreenshotRunnable = new Runnable() {
+        @Override
+        public void run() {
+            takeScreenshot();
+        }
+    };
+
+    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() {
+        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() {
+                @Override
+                public 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()) {
+                            @Override
+                            public void handleMessage(Message msg) {
+                                synchronized (mScreenshotLock) {
+                                    if (mScreenshotConnection == myConn) {
+                                        mContext.unbindService(mScreenshotConnection);
+                                        mScreenshotConnection = null;
+                                        mHandler.removeCallbacks(mScreenshotTimeout);
+                                    }
+                                }
+                            }
+                        };
+                        msg.replyTo = new Messenger(h);
+                        msg.arg1 = 1;
+                        msg.arg2 = 0;
+                        try {
+                            messenger.send(msg);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+                @Override
+                public void onServiceDisconnected(ComponentName name) {}
+            };
+            if (mContext.bindServiceAsUser(
+                    intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
+                mScreenshotConnection = conn;
+                mHandler.postDelayed(mScreenshotTimeout, 10000);
+            }
+        }
+    }
+}


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index c74d0c5..d1fb830 100644
@@ -152,9 +152,11 @@ import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.PreviewInflater;
import com.android.systemui.statusbar.policy.RotationLockControllerImpl;
import com.android.systemui.statusbar.policy.SecurityControllerImpl;
+import com.android.systemui.statusbar.policy.ScreenShotControllerImpl;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import com.android.systemui.statusbar.policy.ZenModeController;
+import com.android.systemui.statusbar.policy.ScreenShotController;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout.OnChildLocationsChangedListener;
import com.android.systemui.statusbar.stack.StackViewState;
@@ -291,6 +293,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
HotKnotControllerImpl mHotKnotController;
//add AudioProfile in quicksetting
AudioProfileControllerImpl mAudioProfileController;
+    /// M: add screenshot in quicksetting by Lee
+    ScreenShotControllerImpl mScreenShotControllerImpl;
// /@}
int mNaturalBarHeight = -1;

@@ -900,6 +904,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
SIMHelper.setContext(mContext);
// /@}

+        /// M: add screenshot in quicksetting by Lee
+        mScreenShotControllerImpl = new ScreenShotControllerImpl(this);
+        /// M: end by Lee
if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)) {
mRotationLockController = new RotationLockControllerImpl(mContext);
}
@@ -969,6 +976,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mHotKnotController,
/// M: add AudioProfile in quicksetting
mAudioProfileController
+                    /// M: add screenshot in quicksetting by Lee
+                    ,mScreenShotControllerImpl
);
mQSPanel.setHost(qsh);
mQSPanel.setTiles(qsh.getTiles());
@@ -3749,6 +3758,36 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
return false;
}

+    /// M: add screenshot in quicksetting by Lee
+    private static final int UPDATE_UI = 0x100;
+    Handler mHandlerUI = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            switch (msg.what) {
+                case UPDATE_UI:
+                    if (mNotificationPanel.isQsExpanded()) {
+                        //Log.e("Lee", "handleMessage() 111111");
+                        if (mNotificationPanel.isQsDetailShowing()) {
+                            mNotificationPanel.closeQsDetail();
+                        } else {
+                            mNotificationPanel.animateCloseQs();
+                        }
+                    }
+                    if (mState != StatusBarState.KEYGUARD && mState != StatusBarState.SHADE_LOCKED) {
+                        //Log.e("Lee", "handleMessage() 222222");
+                        animateCollapsePanels();
+                    }
+                    break;
+            }
+        }
+    };
+    public void collapsePanels() {
+        //Log.e("Lee", "collapsePanels()");
+        mHandlerUI.obtainMessage(UPDATE_UI).sendToTarget();
+    }
+    /// M: end by Lee
+
public boolean onSpacePressed() {
if (mScreenOn != null && mScreenOn
&& (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED)) {


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
index 1a86bc7..1f9285b 100644
@@ -38,6 +38,8 @@ import com.android.systemui.qs.tiles.HotspotTile;
import com.android.systemui.qs.tiles.IntentTile;
import com.android.systemui.qs.tiles.LocationTile;
import com.android.systemui.qs.tiles.RotationLockTile;
+import com.android.systemui.qs.tiles.ScreenShotTile;
+import com.android.systemui.statusbar.policy.ScreenShotController; //by Lee
import com.android.systemui.qs.tiles.WifiTile;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
@@ -69,7 +71,7 @@ import com.mediatek.systemui.statusbar.policy.AudioProfileController;
import com.mediatek.systemui.statusbar.policy.HotKnotController;
import com.mediatek.systemui.statusbar.util.SIMHelper;
// /@}
-
+import java.lang.Override;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -108,6 +110,9 @@ public class QSTileHost implements QSTile.Host, Tunable {
// /@}
private Callback mCallback;

+    /// M: added screenshot in quicksetting by Lee
+    private final ScreenShotController mScreenShotController;
+
public QSTileHost(Context context, PhoneStatusBar statusBar,
BluetoothController bluetooth, LocationController location,
RotationLockController rotation, NetworkController network,
@@ -119,7 +124,9 @@ public class QSTileHost implements QSTile.Host, Tunable {
// add HotKnot in quicksetting
HotKnotController hotknot,
// add AudioProfile in quicksetting
-            AudioProfileController audioprofile) {
+            AudioProfileController audioprofile
+           /// M: add screenshot by Lee
+            ,ScreenShotController screenShotController) {
// /@}
mContext = context;
mStatusBar = statusBar;
@@ -134,6 +141,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
mUserSwitcherController = userSwitcher;
mKeyguard = keyguard;
mSecurity = security;
+        mScreenShotController = screenShotController; //by Lee
/// M: Add extra tiles in quicksetting @{
// add HotKnot in quicksetting
mHotKnot = hotknot;
@@ -151,6 +159,22 @@ public class QSTileHost implements QSTile.Host, Tunable {
public void destroy() {
TunerService.get(mContext).removeTunable(this);
}
+    public QSTileHost(Context context, PhoneStatusBar statusBar,
+            BluetoothController bluetooth, LocationController location,
+            RotationLockController rotation, NetworkController network,
+            ZenModeController zen, HotspotController hotspot,
+            CastController cast, FlashlightController flashlight,
+            UserSwitcherController userSwitcher, KeyguardMonitor keyguard,
+            SecurityController security,
+            /// M: add HotKnot in quicksetting
+            HotKnotController hotknot,
+            /// M: add AudioProfile in quicksetting
+            AudioProfileController audioprofile
+            ) {
+        this(context, statusBar, bluetooth, location, rotation, network, zen, hotspot,
+                cast, flashlight, userSwitcher, keyguard, security, hotknot, audioprofile, null);
+    }
+    /// M: end

@Override
public void setCallback(Callback callback) {
@@ -259,6 +283,11 @@ public class QSTileHost implements QSTile.Host, Tunable {
}
// /@}

+    /// M: add screenshot in quicksetting
+    @Override
+    public ScreenShotController getScreenShotController() { return mScreenShotController; }
+    /// M: add screenshot in quicksetting
+
@Override
public void onTuningChanged(String key, String newValue) {
if (!TILES_SETTING.equals(key)) {
@@ -334,6 +363,9 @@ public class QSTileHost implements QSTile.Host, Tunable {
new ApnSettingsTile(this));
}
/// @}
+        /// M: added screenshot icon  {
+        else if (tileSpec.equals("screenshot")) return new ScreenShotTile(this);
+        /// @}
else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
}


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/ScreenShotController.java
new file mode 100644
index 0000000..c108ed4
@@ -0,0 +1,22 @@
+/*
+ * 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.statusbar.policy;
+
+public interface ScreenShotController {
+
+    void onCollapsePanels();
+
+}


frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/ScreenShotControllerImpl.java
new file mode 100644
index 0000000..fd8c861
@@ -0,0 +1,53 @@
+/*
+* 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.statusbar.policy;
+
+import android.content.Context;
+import android.util.Log;
+
+import com.android.systemui.statusbar.BaseStatusBar;
+import com.android.systemui.statusbar.phone.PhoneStatusBar;
+
+public class ScreenShotControllerImpl implements ScreenShotController {
+
+    private static final String TAG = "ScreenShotController";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+    private PhoneStatusBar phoneStatusBar;
+
+    public ScreenShotControllerImpl(BaseStatusBar statusBar) {
+        //Log.v("Lee", "ScreenShotControllerImpl()");
+        if (statusBar instanceof PhoneStatusBar) {
+            phoneStatusBar = (PhoneStatusBar) statusBar;
+        } else {
+            Log.e("Lee", "error in ScreenShotControllerImpl()");
+        }
+
+    }
+
+    @Override
+    public void onCollapsePanels() {
+        //Log.e("Lee", "onCollapsePanels()");
+        if (phoneStatusBar != null) {
+            phoneStatusBar.collapsePanels();
+        }
+    }
+
+}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: