aboutsummaryrefslogtreecommitdiffstats
path: root/Android/src
diff options
context:
space:
mode:
Diffstat (limited to 'Android/src')
-rw-r--r--Android/src/org/apache/cordova/plugins/SoftKeyBoard.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/Android/src/org/apache/cordova/plugins/SoftKeyBoard.java b/Android/src/org/apache/cordova/plugins/SoftKeyBoard.java
new file mode 100644
index 0000000..18940e1
--- /dev/null
+++ b/Android/src/org/apache/cordova/plugins/SoftKeyBoard.java
@@ -0,0 +1,46 @@
+package org.apache.cordova.plugins;
+
+import org.json.JSONArray;
+import android.content.Context;
+import android.view.inputmethod.InputMethodManager;
+import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.CallbackContext;
+
+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() {
+ // if more than 100 pixels, its probably a keyboard...
+ int heightDiff = webView.getRootView().getHeight() - webView.getHeight();
+ return (100 < heightDiff);
+}
+
+@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;
+ }
+}
+}