summaryrefslogtreecommitdiff
path: root/core/java/android/inputmethodservice/InputMethodService.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java33
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);
}