From 7bfae47d487ba362919c50f42f5388251b98cb40 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 Sep 2013 10:35:23 +0100 Subject: Allow details screen to scroll on Android This fixes #113 in that it means the user can move the screen to see what fields are available. Previously this was prevented by setting the adjustPan mode for the soft input mode which had fixed a bug with the keyboard not dismissing on transition. This has been resolved by adding a plugin for Android to control display of the soft keyboard and hiding the keyboard before navigation in the navigate method of FMSView. Sadly this then meant that the screen size was being measured *before* the keyboard was dismissed with the result that the screen transitioned too was incorrectly displayed. This was resolved by taking the screen height on start up, storing that as a property of the FMS global object and then using this property instead of measuring the screen size at the time of transition. The map has also been expanded to fill the whole screen rather than stopping at the bottom of the navigation bar as on Android when you scroll the screen the map does not scroll and the gap at the top was visible. --- .../org/apache/cordova/plugins/SoftKeyBoard.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Android/src/org/apache/cordova/plugins/SoftKeyBoard.java (limited to 'Android/src') 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; + } +} +} -- cgit v1.2.3