Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 55b96e41 authored by Jesse Chan's avatar Jesse Chan Committed by Michael Bestas
Browse files

Implement click to take partial screenshot [1/3]



Default to the old long press behaviour when the feature is enabled.

Change-Id: I5fc37f818b06db2bd2d315cffee2041a740781ed
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent aa225f7b
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_OTHER;
import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
import static android.view.WindowManagerGlobal.ADD_OKAY;
@@ -547,6 +548,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    private boolean mHandleVolumeKeysInWM;

    // Click volume down + power for partial screenshot
    boolean mClickPartialScreenshot;

    private boolean mPendingKeyguardOccluded;
    private boolean mKeyguardOccludedChanged;

@@ -818,6 +822,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CLICK_PARTIAL_SCREENSHOT), false, this,
                    UserHandle.USER_ALL);

            updateSettings();
        }
@@ -1585,9 +1592,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private long getScreenshotChordLongPressDelay() {
        long delayMs = DeviceConfig.getLong(
        // If click to partial screenshot is enabled, restore pre Android QPR1
        // default delay (500ms) in case SCREENSHOT_KEYCHORD_DELAY is shorter than it.
        long delayMs = Long.max(mClickPartialScreenshot ? 500 : 0, DeviceConfig.getLong(
                DeviceConfig.NAMESPACE_SYSTEMUI, SCREENSHOT_KEYCHORD_DELAY,
                ViewConfiguration.get(mContext).getScreenshotChordKeyTimeout());
                ViewConfiguration.get(mContext).getScreenshotChordKeyTimeout()));
        if (mKeyguardDelegate.isShowing()) {
            // Double the time it takes to take a screenshot from the keyguard
            return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * delayMs);
@@ -1601,7 +1610,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private void cancelPendingScreenshotChordAction() {
        boolean hadMessage = mHandler.hasMessages(MSG_SCREENSHOT_CHORD);
        mHandler.removeMessages(MSG_SCREENSHOT_CHORD);
        if (mClickPartialScreenshot && hadMessage) {
            mHandler.sendMessage(mHandler.obtainMessage(
                    MSG_SCREENSHOT_CHORD, TAKE_SCREENSHOT_SELECTED_REGION, SCREENSHOT_OTHER));
        }
    }

    private void cancelPendingAccessibilityShortcutAction() {
@@ -2585,6 +2599,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mTorchTimeout = LineageSettings.System.getIntForUser(
                    resolver, LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0,
                    UserHandle.USER_CURRENT);
            mClickPartialScreenshot = LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CLICK_PARTIAL_SCREENSHOT, 0,
                    UserHandle.USER_CURRENT) == 1;

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,