|
1 | 1 | package com.ionic.keyboard; |
2 | 2 |
|
| 3 | +import org.apache.cordova.CallbackContext; |
3 | 4 | import org.apache.cordova.CordovaInterface; |
4 | 5 | import org.apache.cordova.CordovaPlugin; |
5 | 6 | import org.apache.cordova.CordovaWebView; |
| 7 | +import org.apache.cordova.PluginResult.Status; |
| 8 | +import org.json.JSONArray; |
| 9 | +import org.json.JSONException; |
6 | 10 |
|
| 11 | +import android.content.Context; |
7 | 12 | import android.graphics.Rect; |
8 | 13 | import android.util.DisplayMetrics; |
9 | 14 | import android.view.View; |
10 | 15 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
| 16 | +import android.view.inputmethod.InputMethodManager; |
11 | 17 |
|
12 | 18 | public class IonicKeyboard extends CordovaPlugin{ |
13 | 19 |
|
@@ -55,6 +61,26 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH |
55 | 61 | rootView.getViewTreeObserver().addOnGlobalLayoutListener(list); |
56 | 62 | } |
57 | 63 |
|
| 64 | + public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { |
| 65 | + if ("close".equals(action)) { |
| 66 | + cordova.getThreadPool().execute(new Runnable() { |
| 67 | + public void run() { |
| 68 | + //http://stackoverflow.com/a/7696791/1091751 |
| 69 | + InputMethodManager inputManager = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
| 70 | + View v = cordova.getActivity().getCurrentFocus(); |
| 71 | + |
| 72 | + if (v == null) { |
| 73 | + callbackContext.error("No current focus"); |
| 74 | + } |
| 75 | + inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); |
| 76 | + callbackContext.success(); // Thread-safe. |
| 77 | + } |
| 78 | + }); |
| 79 | + return true; |
| 80 | + } |
| 81 | + return false; // Returning false results in a "MethodNotFound" error. |
| 82 | + } |
58 | 83 |
|
59 | 84 |
|
60 | 85 | } |
| 86 | + |
0 commit comments