Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.

Commit 8007e89

Browse files
committed
more generic android
1 parent 90cec57 commit 8007e89

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/android/IonicKeyboard.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
2222

2323
final CordovaWebView appView = webView;
2424

25+
//http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
2526
final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
2627
OnGlobalLayoutListener list = new OnGlobalLayoutListener() {
2728
int previousHeightDiff = 0;
@@ -32,14 +33,14 @@ public void onGlobalLayout() {
3233
rootView.getWindowVisibleDisplayFrame(r);
3334

3435
int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);
35-
if (heightDiff > 200 && heightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard...
36+
if (heightDiff > 200 && heightDiff != previousHeightDiff) { // if more than 200 pixels, its probably a keyboard...
3637
int keyboardHeight = (int)(heightDiff / density);
37-
appView.sendJavascript("Keyboard.isVisible = true");
38-
appView.sendJavascript("cordova.fireWindowEvent('ionic.showkeyboard', { 'keyboardHeight':" + Integer.toString(keyboardHeight)+"});");
38+
appView.sendJavascript("cordova.plugins.Keyboard.isVisible = true");
39+
appView.sendJavascript("cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight':" + Integer.toString(keyboardHeight)+"});");
3940
}
4041
else if (heightDiff != previousHeightDiff && (previousHeightDiff - heightDiff) > 200){
41-
appView.sendJavascript("Keyboard.isVisible = false");
42-
appView.sendJavascript("cordova.fireWindowEvent('ionic.hidekeyboard')");
42+
appView.sendJavascript("cordova.plugins.Keyboard.isVisible = false");
43+
appView.sendJavascript("cordova.fireWindowEvent('native.hidekeyboard')");
4344
}
4445
previousHeightDiff = heightDiff;
4546
}

0 commit comments

Comments
 (0)