Skip to content

Commit

Permalink
Merge pull request #115 from ShadyGeek/master
Browse files Browse the repository at this point in the history
FIXED ISSUE #25 : Enhancement: Do not output space when changing keyboard
  • Loading branch information
gazlaws-dev authored Feb 17, 2023
2 parents 15db69b + eeb8513 commit 44da283
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/src/main/java/com/gazlaws/codeboard/CodeBoardIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class CodeBoardIME extends InputMethodService
private Timer timerLongPress = null;
private KeyboardUiFactory mKeyboardUiFactory = null;
private KeyboardLayoutView mCurrentKeyboardLayoutView = null;
private boolean longPressedSpaceButton = false;

@Override
public void onKey(int primaryCode, int[] KeyCodes) {
Expand Down Expand Up @@ -272,8 +273,19 @@ public void onKey(int primaryCode, int[] KeyCodes) {
// }
}
if (ke != 0) {

Log.i(getClass().getSimpleName(), "onKey: keyEvent " + ke);
ic.sendKeyEvent(new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, ke, 0, meta));

/*
* The if statement was added in order to prevent the space button
* from having an action down event attached to it.
* Reason being that we first want to check
* whether the space button has been long pressed or not
* and afterwards produce the right output to the screen.
* TODO: Investigate whether KeyEvent.ACTION_UP is still required.
*/
if (primaryCode != 32) { ic.sendKeyEvent (new KeyEvent (0, 0, KeyEvent.ACTION_DOWN, ke, 0, meta)); }

ic.sendKeyEvent(new KeyEvent(0, 0, KeyEvent.ACTION_UP, ke, 0, meta));
} else {
//All non-letter characters are handled here
Expand Down Expand Up @@ -342,6 +354,21 @@ public void onViewClicked(boolean focusChanged) {
}

public void onRelease(int primaryCode) {

/*
* After the space button is released,
* we check whether it was long pressed or not.
* If it was, we don't do anything,
* but If it wasn't, we print a "space" to the screen.
*/
if ((primaryCode == 32) && (! longPressedSpaceButton)) {

InputConnection ic = getCurrentInputConnection ();
ic.commitText (String.valueOf ((char) primaryCode), 1);
}

longPressedSpaceButton = false;

clearLongPressTimer();
}

Expand Down Expand Up @@ -374,6 +401,9 @@ public void onKeyLongPress(int keyCode) {
}

if (keyCode == 32) {

longPressedSpaceButton = true;

InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
Expand Down

0 comments on commit 44da283

Please sign in to comment.