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

Commit 0755450e authored by Konsta's avatar Konsta Committed by Steve Kondik
Browse files

Framework: Volume key cursor control (1/2)

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

Change-Id: I8e20240e7bee5351ab20bb3d701eb95a5fd3e112
parent d06f8d6f
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -324,6 +324,11 @@ public class InputMethodService extends AbstractInputMethodService {
    final Insets mTmpInsets = new Insets();
    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 =
            new ViewTreeObserver.OnComputeInternalInsetsListener() {
        public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo info) {
@@ -1997,6 +2002,26 @@ public class InputMethodService extends AbstractInputMethodService {
            }
            return false;
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
            mVolumeKeyCursorControl = Settings.System.getInt(getContentResolver(),
                    Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
            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) {
            mVolumeKeyCursorControl = Settings.System.getInt(getContentResolver(),
                    Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
            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);
    }

@@ -2047,6 +2072,15 @@ public class InputMethodService extends AbstractInputMethodService {
                return handleBack(true);
            }
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            mVolumeKeyCursorControl = Settings.System.getInt(getContentResolver(),
                    Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
            if (isInputViewShown() && (mVolumeKeyCursorControl != VOLUME_CURSOR_OFF)) {
                return true;
            }
            return false;
        }
        return doMovementKey(keyCode, event, MOVEMENT_UP);
    }

+9 −0
Original line number Diff line number Diff line
@@ -3700,6 +3700,15 @@ public final class Settings {
         */
        public static final String DOUBLE_TAP_SLEEP_GESTURE = "double_tap_sleep_gesture";

        /**
          * 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
         * keys and easy to update.