Android 12systemui手势截图代码
时间: 2024-04-06 10:12:32 浏览: 114
android截屏代码
4星 · 用户满意度95%
以下是 Android 12 SystemUI 中手势截图的相关代码:
1. 在 `PhoneWindowManager.java` 文件中添加以下方法:
```
private void handleThreeFingerGesture() {
mHasThreeFingerGesture = true;
if (mScreenshotChordEnabled && !mScreenOnFully && !mWindowManagerFuncs.isKeyguardLocked()) {
if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
// If the volume down button was already triggered, capture the screen now.
mVolumeDownKeyTriggered = false;
mPowerManagerWrapper.goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_GESTURE, 0);
takeScreenshot(true, true);
} else {
mVolumeDownKeyTriggered = true;
mVolumeDownKeyTime = SystemClock.uptimeMillis();
mVolumeDownKeyConsumedByGestures = true;
}
}
}
```
2. 在 `PhoneWindowManager.java` 文件的 `interceptMotionBeforeQueueingNonInteractive()` 方法中添加以下代码:
```
case MotionEvent.ACTION_POINTER_DOWN: {
final int pointerCount = motionEvent.getPointerCount();
if (pointerCount == 3) {
handleThreeFingerGesture();
}
break;
}
```
3. 在 `ScreenshotHelper.java` 文件中添加以下方法:
```
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
takeScreenshot(finisher, statusBarVisible, navBarVisible, false, true);
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast) {
// Call the takeScreenshot method with the necessary parameters.
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, null, true);
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean nonInteractive) {
// Call the appropriate method based on the value of nonInteractive parameter.
if (nonInteractive) {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop);
} else {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, false /* screenSecure */);
}
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure) {
// Call the takeScreenshot method with the necessary parameters.
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, true);
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure, boolean runnableFinisher) {
// Call the appropriate method based on the value of runnableFinisher parameter.
if (runnableFinisher) {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, true /* sensorShade */);
} else {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, false /* sensorShade */);
}
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure, boolean sensorShade) {
// Call the appropriate method based on the value of sensorShade parameter.
if (sensorShade) {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, true /* useSystemService */);
} else {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, false /* useSystemService */);
}
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure, boolean useSystemService) {
// Call the takeScreenshot method with the necessary parameters.
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, useSystemService, true /* showFlash */);
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure, boolean useSystemService, boolean showFlash) {
// Call the appropriate method based on the value of useSystemService parameter.
if (useSystemService) {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, showFlash, true /* useSecureFlag */);
} else {
takeScreenshot(finisher, statusBarVisible, navBarVisible, isPartial, showToast, crop, screenSecure, showFlash, false /* useSecureFlag */);
}
}
public void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, boolean isPartial, boolean showToast, Rect crop, boolean screenSecure, boolean showFlash, boolean useSecureFlag) {
// Get the DisplayManager instance and call the appropriate method based on the value of isPartial parameter.
final DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
if (displayManager == null) {
return;
}
if (isPartial) {
// Capture a partial screenshot.
capturePartialScreenshot(statusBarVisible, navBarVisible, finisher, showFlash, useSecureFlag);
} else {
// Capture a full screenshot.
final Display display = mContext.getDisplay();
final int rot = display == null ? Surface.ROTATION_0 : display.getRotation();
final int width = mDisplayMetrics.widthPixels;
final int height = mDisplayMetrics.heightPixels;
final int minLayer = HwFrameworkFactory.getHwNsdImpl().getMinLayer();
final SurfaceControl sc = SurfaceControl.screenshot(new Rect(), width, height, minLayer, rot);
if (sc == null) {
if (finisher != null) {
finisher.run();
}
return;
}
captureScreenshot(sc, finisher, showToast, showFlash, useSecureFlag, width, height, crop, statusBarVisible, navBarVisible, screenSecure);
}
}
```
以上是 Android 12 SystemUI 中手势截图的相关代码。
阅读全文