Skip to content

Commit 654ab99

Browse files
committed
ANDROID: de-bounce keypad show/hide
1 parent bd0272f commit 654ab99

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class MainActivity extends NativeActivity {
107107
private MediaPlayer _mediaPlayer = null;
108108
private LocationAdapter _locationAdapter = null;
109109
private TextToSpeechAdapter _tts;
110+
private Handler _keypadHandler = new Handler();
110111

111112
static {
112113
System.loadLibrary("smallbasic");
@@ -596,19 +597,24 @@ public void onClick(DialogInterface dialog, int which) {}
596597
public void showKeypad(final boolean show) {
597598
Log.i(TAG, "showKeypad: " + show);
598599
final View view = getWindow().getDecorView();
599-
final Activity activity = this;
600-
runOnUiThread(new Runnable() {
600+
_keypadHandler.removeCallbacksAndMessages(null);
601+
_keypadHandler.postDelayed(new Runnable() {
602+
@Override
601603
public void run() {
602-
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
603-
if (imm != null) {
604-
if (show) {
605-
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
606-
} else {
607-
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
604+
runOnUiThread(new Runnable() {
605+
public void run() {
606+
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
607+
if (imm != null) {
608+
if (show) {
609+
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
610+
} else {
611+
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
612+
}
613+
}
608614
}
609-
}
615+
});
610616
}
611-
});
617+
}, 100);
612618
}
613619

614620
public void showToast(final byte[] messageBytes) {

0 commit comments

Comments
 (0)