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

Unverified Commit 7c74380f 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 b3cb1a51
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -536,6 +536,11 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    private IBinder mCurHideInputToken;

    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);
        if (!mViewsCreated) {
@@ -1219,6 +1224,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;
        }

@@ -1259,6 +1267,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
@@ -1324,6 +1335,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);

        mIsAutomotive = isAutomotive();
        mAutomotiveHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean(
@@ -2683,6 +2696,22 @@ public class InputMethodService extends AbstractInputMethodService {
            }
            return false;
        }
        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);
    }

@@ -2733,6 +2762,10 @@ public class InputMethodService extends AbstractInputMethodService {
                return handleBack(true);
            }
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            return isInputViewShown() && mVolumeKeyCursorControl != VOLUME_CURSOR_OFF;
        }
        return doMovementKey(keyCode, event, MOVEMENT_UP);
    }

+9 −0
Original line number Diff line number Diff line
@@ -5165,6 +5165,15 @@ public final class Settings {
        @Readable
        public static final String MULTI_AUDIO_FOCUS_ENABLED = "multi_audio_focus_enabled";
        /**
         * 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
         */
        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