Navigation Menu

Skip to content

Commit

Permalink
volume rocker: volume key cursor control
Browse files Browse the repository at this point in the history
  • Loading branch information
rascarlo committed Nov 12, 2014
1 parent c123a0c commit b382699
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
45 changes: 43 additions & 2 deletions core/java/android/inputmethodservice/InputMethodService.java
Expand Up @@ -251,6 +251,20 @@ public class InputMethodService extends AbstractInputMethodService {
*/
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;
Expand Down Expand Up @@ -1803,6 +1817,26 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return true;
}
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);
}
Expand Down Expand Up @@ -1848,8 +1882,15 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.isTracking()
&& !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);
}

Expand Down
9 changes: 9 additions & 0 deletions core/java/android/provider/Settings.java
Expand Up @@ -2645,6 +2645,15 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String STATUS_BAR_NATIVE_BATTERY_PERCENTAGE = "status_bar_native_battery_percentage";

/**
* 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.
Expand Down

0 comments on commit b382699

Please sign in to comment.