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

Unverified Commit c96ac1cc authored by Konsta's avatar Konsta Committed by Michael Bestas
Browse files

Framework: Volume key cursor control

This feature is moved to framework so it also works with third
party keyboards.

Change-Id: I8e20240e7bee5351ab20bb3d701eb95a5fd3e112
parent 4668026e
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -731,6 +731,11 @@ public class InputMethodService extends AbstractInputMethodService {
    @Nullable
    private ImeTracker.Token mCurStatsToken;

    int mVolumeKeyCursorControl;
    private static final int VOLUME_CURSOR_OFF = 0;
    private static final int VOLUME_CURSOR_ON = 1;
    private static final int VOLUME_CURSOR_ON_REVERSE = 2;

    final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> {
        onComputeInsets(mTmpInsets);
        mNavigationBarController.updateInsets(mTmpInsets);
@@ -1695,6 +1700,9 @@ public class InputMethodService extends AbstractInputMethodService {
            service.getContentResolver().registerContentObserver(
                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD),
                    false, observer);
            service.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(Settings.System.VOLUME_KEY_CURSOR_CONTROL),
                    false, observer);
            return observer;
        }

@@ -1735,6 +1743,9 @@ public class InputMethodService extends AbstractInputMethodService {
                // state as if configuration was changed.
                mService.resetStateForNewConfiguration();
            }

            mService.mVolumeKeyCursorControl = Settings.System.getInt(mService.getContentResolver(),
                    Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
        }

        @Override
@@ -1817,6 +1828,8 @@ public class InputMethodService extends AbstractInputMethodService {
        // cache preference so we don't have to read ContentProvider when IME is requested to be
        // shown the first time (cold start).
        mSettingsObserver.shouldShowImeWithHardKeyboard();
        mVolumeKeyCursorControl = Settings.System.getInt(getContentResolver(),
                Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);

        final boolean hideNavBarForKeyboard = getApplicationContext().getResources().getBoolean(
                com.android.internal.R.bool.config_hideNavBarForKeyboard);
@@ -3814,6 +3827,23 @@ public class InputMethodService extends AbstractInputMethodService {
            }
        }

        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
            if (isInputViewShown() && mVolumeKeyCursorControl != VOLUME_CURSOR_OFF) {
                sendDownUpKeyEvents(mVolumeKeyCursorControl == VOLUME_CURSOR_ON_REVERSE
                        ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT);
                return true;
            }
            return false;
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
            if (isInputViewShown() && mVolumeKeyCursorControl != VOLUME_CURSOR_OFF) {
                sendDownUpKeyEvents(mVolumeKeyCursorControl == VOLUME_CURSOR_ON_REVERSE
                        ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT);
                return true;
            }
            return false;
        }

        return doMovementKey(keyCode, event, MOVEMENT_DOWN);
    }

@@ -3906,6 +3936,11 @@ public class InputMethodService extends AbstractInputMethodService {
            }
        }

        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            return isInputViewShown() && mVolumeKeyCursorControl != VOLUME_CURSOR_OFF;
        }

        return doMovementKey(keyCode, event, MOVEMENT_UP);
    }

+10 −0
Original line number Diff line number Diff line
@@ -6514,6 +6514,16 @@ public final class Settings {
        public static final String SCREEN_FLASH_NOTIFICATION_COLOR =
                "screen_flash_notification_color_global";
        /**
         * Volume keys control cursor in text fields (default is 0)
         * 0 - Disabled
         * 1 - Volume up/down moves cursor left/right
         * 2 - Volume up/down moves cursor right/left
         * @hide
         */
        @Readable
        public static final String VOLUME_KEY_CURSOR_CONTROL = "volume_key_cursor_control";
        /**
         * IMPORTANT: If you add a new public settings you also have to add it to
         * PUBLIC_SETTINGS below. If the new setting is hidden you have to add