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

Commit 457fc71

Browse files
committed
add close() for Android
1 parent 54c36d9 commit 457fc71

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/android/IonicKeyboard.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.ionic.keyboard;
22

3+
import org.apache.cordova.CallbackContext;
34
import org.apache.cordova.CordovaInterface;
45
import org.apache.cordova.CordovaPlugin;
56
import org.apache.cordova.CordovaWebView;
7+
import org.apache.cordova.PluginResult.Status;
8+
import org.json.JSONArray;
9+
import org.json.JSONException;
610

11+
import android.content.Context;
712
import android.graphics.Rect;
813
import android.util.DisplayMetrics;
914
import android.view.View;
1015
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
16+
import android.view.inputmethod.InputMethodManager;
1117

1218
public class IonicKeyboard extends CordovaPlugin{
1319

@@ -55,6 +61,26 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH
5561
rootView.getViewTreeObserver().addOnGlobalLayoutListener(list);
5662
}
5763

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+
}
5883

5984

6085
}
86+

0 commit comments

Comments
 (0)