summaryrefslogtreecommitdiff
path: root/navit/android/src/org/navitproject
diff options
context:
space:
mode:
authormvglasow <michael -at- vonglasow.com>2015-11-15 23:05:24 +0100
committermvglasow <michael -at- vonglasow.com>2016-02-24 09:43:46 +0100
commit0c0697760bb9b78013812ee816a30c7af148520d (patch)
treea6f237d502db69ace0fe65611474c5f4a66db8e7 /navit/android/src/org/navitproject
parent6e8450f7ce39f4c713bcbd8368e1b25d32f98283 (diff)
downloadnavit-0c0697760bb9b78013812ee816a30c7af148520d.tar.gz
Fix:gui_internal:Further native keyboard refinements
Allow graphics plugin to specify size occupied by keyboard Create placeholder for Android keyboard Show Android keyboard in landscape mode Skip keyboard logic if hardware keyboard is present on Android Add some documentation and comments Signed-off-by: mvglasow <michael -at- vonglasow.com>
Diffstat (limited to 'navit/android/src/org/navitproject')
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java70
-rw-r--r--navit/android/src/org/navitproject/navit/NavitGraphics.java1
2 files changed, 65 insertions, 6 deletions
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index 78476758c..0242d95bf 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -116,6 +116,20 @@ public class Navit extends Activity
public static final String NAVIT_PREFS = "NavitPrefs";
Boolean isFullscreen = false;
+
+ /**
+ * @brief A Runnable to restore soft input when the user returns to the activity.
+ *
+ * An instance of this class can be passed to the main message queue in the Activity's
+ * {@code onRestore()} method.
+ */
+ private class SoftInputRestorer implements Runnable {
+ public void run() {
+ Navit.this.showNativeKeyboard();
+ }
+ }
+
+
public void removeFileIfExists(String source) {
File file = new File(source);
@@ -445,6 +459,21 @@ public class Navit extends Activity
Log.e("Navit", "timestamp for navigate_to expired! not using data");
}
}
+ Log.d(TAG, "onResume");
+ /* FIXME this doesn't work */
+ if (show_soft_keyboard_now_showing)
+ this.showNativeKeyboard();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ Log.d(TAG, "onPause");
+ if (show_soft_keyboard_now_showing) {
+ Log.d(TAG, "onPause:hiding soft input");
+ this.hideNativeKeyboard();
+ show_soft_keyboard_now_showing = true;
+ }
}
private void parseNavigationURI(String schemeSpecificPart) {
@@ -651,10 +680,38 @@ public class Navit extends Activity
*
* @return {@code true} if an input method is going to be displayed, {@code false} if not
*/
- public boolean showNativeKeyboard() {
- // TODO determine if we need on-screen input
- mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT);
- return true;
+ public int showNativeKeyboard() {
+ /*
+ * Apologies for the huge mess that this function is, but Android's soft input API is a big
+ * nightmare. Its devs have mercifully given us an option to show or hide the keyboard, but
+ * there is no reliable way to figure out if it is actually showing, let alone how much of the
+ * screen it occupies, so our best bet is guesswork.
+ */
+ Configuration config = getResources().getConfiguration();
+ if ((config.keyboard == Configuration.KEYBOARD_QWERTY) && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))
+ /* physical keyboard present, exit */
+ return 0;
+
+ /* Use SHOW_FORCED here, else keyboard won't show in landscape mode */
+ mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED);
+ show_soft_keyboard_now_showing = true;
+
+ /*
+ * Crude way to estimate the height occupied by the keyboard: for AOSP on KitKat and Lollipop it
+ * is about 62-63% of available screen width (in portrait mode) but no more than slightly above
+ * 46% of height (in landscape mode).
+ */
+ Display display_ = getWindowManager().getDefaultDisplay();
+ int width_ = display_.getWidth();
+ int height_ = display_.getHeight();
+ int maxHeight = height_ * 47 / 100;
+ int inputHeight = width_ * 63 / 100;
+ if (inputHeight > (maxHeight))
+ inputHeight = maxHeight;
+
+ /* the receiver isn't going to fire before the UI thread becomes idle, well after this method returns */
+ Log.d(TAG, "showNativeKeyboard:return (assuming true)");
+ return inputHeight;
}
@@ -662,10 +719,11 @@ public class Navit extends Activity
* @brief Hides the native keyboard or other input method.
*/
public void hideNativeKeyboard() {
- mgr.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
+ mgr.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
+ show_soft_keyboard_now_showing = false;
}
-
+
void setDestination(float latitude, float longitude, String address) {
Toast.makeText( getApplicationContext(),getString(R.string.address_search_set_destination) + "\n" + address, Toast.LENGTH_LONG).show(); //TRANS
diff --git a/navit/android/src/org/navitproject/navit/NavitGraphics.java b/navit/android/src/org/navitproject/navit/NavitGraphics.java
index 005f79bf2..de7c41863 100644
--- a/navit/android/src/org/navitproject/navit/NavitGraphics.java
+++ b/navit/android/src/org/navitproject/navit/NavitGraphics.java
@@ -738,6 +738,7 @@ public class NavitGraphics
frameLayout.addView(statusTintView);
activity.setContentView(frameLayout);
+
view.requestFocus();
}
else