Skip to content
Browse files

Frameworks: Option to control cursor in text fields using volume keys…

… (1/2)

This feature is moved to framework so it also works with third party keyboards.
Patch Set 3: Added missin @hide statements

Change-Id: I8e20240e7bee5351ab20bb3d701eb95a5fd3e112
  • Loading branch information...
1 parent 0ff9628 commit f237ca20ef07c7040dce0d84e2348ec337b55562 @KonstaT KonstaT committed with Gerrit Code Review
View
44 core/java/android/inputmethodservice/InputMethodService.java
@@ -247,6 +247,20 @@
*/
public static final int IME_VISIBLE = 0x2;
+ int mVolumeKeyCursorControl = 0;
+ /**
+ * @hide
+ */
+ public static final int VOLUME_CURSOR_OFF = 0;
+ /**
+ * @hide
+ */
+ public static final int VOLUME_CURSOR_ON = 1;
+ /**
+ * @hide
+ */
+ public static final int VOLUME_CURSOR_ON_REVERSE = 2;
+
InputMethodManager mImm;
int mTheme = 0;
@@ -1735,6 +1749,26 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
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);
}
@@ -1780,7 +1814,15 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
&& !event.isCanceled()) {
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);
}
View
9 core/java/android/provider/Settings.java
@@ -2777,6 +2777,15 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
*/
public static final String UI_FORCE_OVERFLOW_BUTTON = "ui_force_overflow_button";
+ /**
+ * 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";
+
/**
* Show the pending notification counts as overlays on the status bar

0 comments on commit f237ca2

Please sign in to comment.
Something went wrong with that request. Please try again.