Skip to content

Commit 9a4f62a

Browse files
committed
close keyboard when pausing
1 parent 4858289 commit 9a4f62a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

core/src/processing/core/PApplet.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ public class PApplet extends Object implements ActivityAPI, PConstants {
255255
*/
256256
protected boolean keyRepeatEnabled = false;
257257

258+
/**
259+
* Set to open when openKeyboard() is called, and used to close the keyboard when the sketch is
260+
* paused, otherwise it remains visible.
261+
*/
262+
boolean keyboardIsOpen = false;
263+
258264
///////////////////////////////////////////////////////////////
259265
// Permission handling
260266

@@ -2493,15 +2499,19 @@ public void openKeyboard() {
24932499
Context context = surface.getContext();
24942500
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
24952501
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
2502+
keyboardIsOpen = true;
24962503
}
24972504

24982505

24992506
public void closeKeyboard() {
2500-
Context context = surface.getContext();
2501-
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
2502-
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
2503-
if (parentLayout == -1) {
2504-
setFullScreenVisibility();
2507+
if (keyboardIsOpen) {
2508+
Context context = surface.getContext();
2509+
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
2510+
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
2511+
keyboardIsOpen = false;
2512+
if (parentLayout == -1) {
2513+
setFullScreenVisibility();
2514+
}
25052515
}
25062516
}
25072517

0 commit comments

Comments
 (0)