mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-28 18:15:37 -05:00
Merge pull request #497 from yueyuzhao/issue/494-soft-keyboard-no-hides
Android: Fix soft keyboard hides too quickly
This commit is contained in:
commit
3c18ba8dad
1 changed files with 17 additions and 5 deletions
|
@ -545,12 +545,20 @@ public class ScratchJrActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Height of the status bar at the top of the screen
|
* Height of the status bar at the top of the screen
|
||||||
|
* We should always know the status bar height even if
|
||||||
|
* the status bar is not visible at all.
|
||||||
|
* See https://stackoverflow.com/a/14213035
|
||||||
*/
|
*/
|
||||||
private int getStatusBarHeight() {
|
private int getStatusBarHeight() {
|
||||||
Rect rectangle= new Rect();
|
int result = 0;
|
||||||
Window window= getWindow();
|
int resourceId = getResources().getIdentifier(
|
||||||
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
|
"status_bar_height",
|
||||||
int result = rectangle.top;
|
"dimen",
|
||||||
|
"android"
|
||||||
|
);
|
||||||
|
if (resourceId > 0) {
|
||||||
|
result = getResources().getDimensionPixelSize(resourceId);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,7 +624,11 @@ public class ScratchJrActivity
|
||||||
animator.start();
|
animator.start();
|
||||||
_currentAnimator = animator;
|
_currentAnimator = animator;
|
||||||
}
|
}
|
||||||
} else if (currentVisibleHeight > _priorVisibleHeight) {
|
} else if (currentVisibleHeight > _priorVisibleHeight + getStatusBarHeight()) {
|
||||||
|
// The status bar will be hidden ONE second after the keyboard is shown,
|
||||||
|
// on some devices like SM-T280, the `currentVisibleHeight` will increase
|
||||||
|
// by the status bar height, we don't want it to infect the keyboard.
|
||||||
|
// -- Yueyu Zhao
|
||||||
// Keyboard probably just became hidden
|
// Keyboard probably just became hidden
|
||||||
|
|
||||||
// Reset pan
|
// Reset pan
|
||||||
|
|
Loading…
Reference in a new issue