I have the following problem: I need to completely disable my own keyboard. The keyboard should only appear when calling show () and hide it when I call the close () function (this will be a button for the user to switch the keyboard). A keyboard that displays a click on a field and focus should be completely disabled.
In Stackoverflow, I found this: InputMethodManager im = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow (editText.getWindowToken (), 0);
So, I thought that in "Init" (line 52 in IonicKeyboard.java) I need to change it.
if ("init".equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { //new Logic on init View v = cordova.getActivity().getCurrentFocus(); ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0); DisplayMetrics dm = new DisplayMetrics(); cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); final float density = dm.density; //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView(); OnGlobalLayoutListener list = new OnGlobalLayoutListener() { int previousHeightDiff = 0; @Override public void onGlobalLayout() { Rect r = new Rect(); //r will be populated with the coordinates of your view that area still visible. rootView.getWindowVisibleDisplayFrame(r); PluginResult result; int heightDiff = rootView.getRootView().getHeight() - r.bottom; int pixelHeightDiff = (int)(heightDiff / density); if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard... String msg = "S" + Integer.toString(pixelHeightDiff); result = new PluginResult(PluginResult.Status.OK, msg); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){ String msg = "H"; result = new PluginResult(PluginResult.Status.OK, msg); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } previousHeightDiff = pixelHeightDiff; } }; rootView.getViewTreeObserver().addOnGlobalLayoutListener(list); PluginResult dataResult = new PluginResult(PluginResult.Status.OK); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } }); return true; } return false; // Returning false results in a "MethodNotFound" error. }
Unfortunately, this does not work at all ...
I think I need to change the close / show function, but I'm not quite sure what the correct code is, and I don't know if this change will affect other keyboard behavior. (But I mainly need Focus without a keyboard)
I also found this Cordova plugin
which looks very promising, but I decided to change it in the Ionic Keyboard Plugin, because I also need the same on Windows. Very happy if someone can help me here.
Regards Christopher
source share