Skip to content

Commit

Permalink
Use virtual keys instead of position for navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
rkkr committed Jul 10, 2018
1 parent e65697a commit 8be3bd7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "rkr.simplekeyboard.inputmethod"
minSdkVersion 19
targetSdkVersion 27
versionCode 38
versionName "2.13"
versionCode 39
versionName "2.14"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public static int getCode(final String name) {
Constants.CODE_ACTION_PREVIOUS,
Constants.CODE_SHIFT_ENTER,
Constants.CODE_LANGUAGE_SWITCH,
Constants.CODE_LEFT,
Constants.CODE_RIGHT,
Constants.CODE_UNSPECIFIED,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
Expand Down Expand Up @@ -758,17 +758,10 @@ public boolean onCustomRequest(final int requestCode) {

@Override
public void onMovePointer(int steps) {
if (steps < 0) {
int availableCharacters = getCurrentInputConnection().getTextBeforeCursor(64, 0).length();
steps = availableCharacters < -steps ? -availableCharacters : steps;
}
else if (steps > 0) {
int availableCharacters = getCurrentInputConnection().getTextAfterCursor(64, 0).length();
steps = availableCharacters < steps ? availableCharacters : steps;
} else return;

int newPosition = mInputLogic.mConnection.mExpectedSelStart + steps;
getCurrentInputConnection().setSelection(newPosition, newPosition);
for (;steps < 0; steps++)
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT);
for (;steps > 0; steps--)
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT);
}

private boolean isShowingOptionDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ public static boolean isValidCoordinate(final int coordinate) {
public static final int CODE_SHIFT_ENTER = -11;
public static final int CODE_SYMBOL_SHIFT = -12;
// Code value representing the code is not specified.
public static final int CODE_LEFT = -13;
public static final int CODE_RIGHT = -14;
public static final int CODE_UNSPECIFIED = -15;
public static final int CODE_UNSPECIFIED = -13;

public static boolean isLetterCode(final int code) {
return code >= CODE_SPACE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp
// Shift + Enter is treated as a functional key but it results in adding a new
// line, so that does affect the contents of the editor.
break;
case Constants.CODE_LEFT:
sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT);
break;
case Constants.CODE_RIGHT:
sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT);
break;
default:
throw new RuntimeException("Unknown key code : " + event.mKeyCode);
}
Expand Down Expand Up @@ -531,7 +525,7 @@ private void resetEntireInputState(final int newSelStart, final int newSelEnd) {
*
* @param keyCode the key code to send inside the key event.
*/
private void sendDownUpKeyEvent(final int keyCode) {
public void sendDownUpKeyEvent(final int keyCode) {
final long eventTime = SystemClock.uptimeMillis();
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/xml/key_styles_common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,4 @@
latin:styleName="backFromMoreSymbolKeyStyle"
latin:keySpec="!text/keylabel_to_symbol|!code/key_shift"
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="leftKeyStyle"
latin:keySpec="&#x2190;|!code/key_left"
latin:keyActionFlags="isRepeatable|noKeyPreview" />
<key-style
latin:styleName="rightKeyStyle"
latin:keySpec="&#x2192;|!code/key_right"
latin:keyActionFlags="isRepeatable|noKeyPreview" />
</merge>

0 comments on commit 8be3bd7

Please sign in to comment.