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

Commit 4e56c93b authored by Konsta's avatar Konsta Committed by Bruno Martins
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 271eae23
Loading
Loading
Loading
Loading
+33 −0
Original line number Original line Diff line number Diff line
@@ -418,6 +418,11 @@ public class InputMethodService extends AbstractInputMethodService {
    final Insets mTmpInsets = new Insets();
    final Insets mTmpInsets = new Insets();
    final int[] mTmpLocation = new int[2];
    final int[] mTmpLocation = new int[2];


    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 -> {
    final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> {
        if (isExtractViewShown()) {
        if (isExtractViewShown()) {
            // In true fullscreen mode, we just say the window isn't covering
            // In true fullscreen mode, we just say the window isn't covering
@@ -817,6 +822,9 @@ public class InputMethodService extends AbstractInputMethodService {
            service.getContentResolver().registerContentObserver(
            service.getContentResolver().registerContentObserver(
                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD),
                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD),
                    false, observer);
                    false, observer);
            service.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(Settings.System.VOLUME_KEY_CURSOR_CONTROL),
                    false, observer);
            return observer;
            return observer;
        }
        }


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

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


        @Override
        @Override
@@ -916,6 +927,8 @@ public class InputMethodService extends AbstractInputMethodService {
        super.onCreate();
        super.onCreate();
        mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        mSettingsObserver = SettingsObserver.createAndRegister(this);
        mSettingsObserver = SettingsObserver.createAndRegister(this);
        mVolumeKeyCursorControl = Settings.System.getInt(getContentResolver(),
                Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
        // If the previous IME has occupied non-empty inset in the screen, we need to decide whether
        // If the previous IME has occupied non-empty inset in the screen, we need to decide whether
        // we continue to use the same size of the inset or update it
        // we continue to use the same size of the inset or update it
        mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0);
        mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0);
@@ -2222,6 +2235,22 @@ public class InputMethodService extends AbstractInputMethodService {
            }
            }
            return false;
            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);
        return doMovementKey(keyCode, event, MOVEMENT_DOWN);
    }
    }


@@ -2272,6 +2301,10 @@ public class InputMethodService extends AbstractInputMethodService {
                return handleBack(true);
                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);
        return doMovementKey(keyCode, event, MOVEMENT_UP);
    }
    }


+9 −0
Original line number Original line Diff line number Diff line
@@ -4094,6 +4094,15 @@ public final class Settings {
         * the setting value. See an example above.
         * the setting value. See an example above.
         */
         */
        /**
          * 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";
        /**
        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
         * keys and easy to update.