Skip to content

Commit

Permalink
Restore correct keyboard after Control/Meta shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
gurrhack committed Nov 2, 2015
1 parent 1208576 commit 1479134
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
18 changes: 14 additions & 4 deletions sys/android/src/com/tbd/NetHack/NH_State.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private enum CmdMode
private boolean mNumPad;
private boolean mIsMouseLocked;
private Hearse mHearse;
private SoftKeyboard.KEYBOARD mRegularKeyboard;

// ____________________________________________________________________________________
public NH_State(NetHack context)
Expand Down Expand Up @@ -171,6 +172,7 @@ public boolean handleKeyDown(char ch, int nhKey, int keyCode, Set<Input.Modifier
if(keyCode == KeyEvent.KEYCODE_BACK && isKeyboardMode())
{
hideKeyboard();
restoreRegularKeyboard();
return true;
}

Expand Down Expand Up @@ -216,6 +218,7 @@ else if(keyCode == KeyAction.Control || keyCode == KeyAction.Meta)
{
if(repeatCount == 0 && !Util.hasPhysicalKeyboard(mContext))
{
saveRegularKeyboard();
if(mMode != CmdMode.Keyboard)
mHideQuickKeyboard = true;
showKeyboard();
Expand Down Expand Up @@ -250,8 +253,7 @@ else if(keyCode == KeyAction.Control || keyCode == KeyAction.Meta)
{
if(mHideQuickKeyboard)
hideKeyboard();
else
setQwertyKeyboard();
restoreRegularKeyboard();
}

mHideQuickKeyboard = false;
Expand Down Expand Up @@ -606,9 +608,17 @@ public void setMetaKeyboard()
}

// ____________________________________________________________________________________
public void setQwertyKeyboard()
public void saveRegularKeyboard()
{
mRegularKeyboard = mKeyboard.getKeyboard();
}

// ____________________________________________________________________________________
public void restoreRegularKeyboard()
{
mKeyboard.setQwertyKeyboard();
if(mRegularKeyboard != null)
mKeyboard.setKeyboard(mRegularKeyboard);
mRegularKeyboard = null;
}

// ____________________________________________________________________________________
Expand Down
25 changes: 14 additions & 11 deletions sys/android/src/com/tbd/NetHack/SoftKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ public void setMetaKeyboard()
setKeyboard(KEYBOARD.META);
}

// ____________________________________________________________________________________
public void setQwertyKeyboard()
{
setKeyboard(KEYBOARD.QWERTY);
}

// ____________________________________________________________________________________
public void setCtrlKeyboard()
{
Expand Down Expand Up @@ -147,10 +141,13 @@ public void onKey(int primaryCode, int[] keyCodes)
break;

case Keyboard.KEYCODE_SHIFT:
mCurrent = KEYBOARD.QWERTY;
mKeyboardView.setKeyboard(mQwertyKeyboard);
mIsShifted = !mIsShifted;
mKeyboardView.setShifted(mIsShifted);
if(mQwertyKeyboard != null)
{
mCurrent = KEYBOARD.QWERTY;
mKeyboardView.setKeyboard(mQwertyKeyboard);
mIsShifted = !mIsShifted;
mKeyboardView.setShifted(mIsShifted);
}
break;

case Keyboard.KEYCODE_CANCEL:
Expand Down Expand Up @@ -178,7 +175,7 @@ public void onKey(int primaryCode, int[] keyCodes)
}

// ____________________________________________________________________________________
private void setKeyboard(KEYBOARD name)
public void setKeyboard(KEYBOARD name)
{
mCurrent = name;
Keyboard keyboard = null;
Expand All @@ -204,6 +201,12 @@ private void setKeyboard(KEYBOARD name)
}
}

// ____________________________________________________________________________________
public KEYBOARD getKeyboard()
{
return mCurrent;
}

// ____________________________________________________________________________________
private void setShift(Keyboard keyboard, boolean on)
{
Expand Down

0 comments on commit 1479134

Please sign in to comment.