diff options
| author | Konsta <konsta09@gmail.com> | 2022-09-10 21:24:42 +0300 |
|---|---|---|
| committer | Semavi Ulusoy <doc.divxm@gmail.com> | 2022-10-21 15:38:41 +0300 |
| commit | 0ca3fae944776458109ecdd231d75af76d86ce9f (patch) | |
| tree | 27670e34db304b84c884edad7323fc0d31c41614 /core/java/android/inputmethodservice/InputMethodService.java | |
| parent | 4df50d318423a5b24930d0eb780099c46e00ffd8 (diff) | |
Framework: Volume key cursor control
This feature is moved to framework so it also works with third
party keyboards.
Change-Id: I8e20240e7bee5351ab20bb3d701eb95a5fd3e112
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 8e67705c5cf0..c0f6f2615234 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -626,6 +626,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) { @@ -1397,6 +1402,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; } @@ -1437,6 +1445,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 @@ -1502,6 +1513,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); mHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean( com.android.internal.R.bool.config_hideNavBarForKeyboard); @@ -3048,6 +3061,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); } @@ -3098,6 +3127,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); } |
