Skip to content

Commit

Permalink
Make compatible with older versions of cordova-android. (Fixes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Jul 16, 2015
1 parent c86bf5a commit c570ddc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/android/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.view.View;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -13,14 +14,22 @@ public class Keyboard extends CordovaPlugin {
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Activity activity = this.cordova.getActivity();
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);


View view;
try {
view = (View)webView.getClass().getMethod("getView").invoke(webView);
}
catch (Exception e){
view = (View)webView;
}

if("show".equals(action)){
imm.showSoftInput(webView.getView(), 0);
imm.showSoftInput(view, 0);
callbackContext.success();
return true;
}
else if("hide".equals(action)){
imm.hideSoftInputFromWindow(webView.getView().getWindowToken(), 0);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
callbackContext.success();
return true;
}
Expand Down

0 comments on commit c570ddc

Please sign in to comment.