forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftKeyBoard.java
More file actions
54 lines (43 loc) · 1.72 KB
/
SoftKeyBoard.java
File metadata and controls
54 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.zenexity.SoftKeyBoardPlugin;
import org.json.JSONArray;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
public class SoftKeyBoard extends CordovaPlugin {
public SoftKeyBoard() {
}
public void showKeyBoard() {
InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(webView, 0);
}
public void hideKeyBoard() {
InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(webView.getWindowToken(), 0);
}
public boolean isKeyBoardShowing() {
int heightDiff = webView.getRootView().getHeight() - webView.getHeight();
return (100 < heightDiff); // if more than 100 pixels, its probably a keyboard...
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
if (action.equals("show")) {
this.showKeyBoard();
callbackContext.success("done");
return true;
}
else if (action.equals("hide")) {
this.hideKeyBoard();
callbackContext.success();
return true;
}
else if (action.equals("isShowing")) {
callbackContext.success(Boolean.toString(this.isKeyBoardShowing()));
return true;
}
else {
return false;
}
}
}