From c0bb0bd5e78e1db5096c634168ead11b402d1789 Mon Sep 17 00:00:00 2001 From: qua-non Date: Tue, 1 Oct 2013 23:55:07 +0530 Subject: [PATCH 1/4] Honor `input_type` Textinput setting to choose the type of keyboard displayed for the TextInput --- recipes/android/src/android/_android.pyx | 6 +++--- recipes/android/src/android/_android_jni.c | 6 +++--- src/src/org/renpy/android/Hardware.java | 16 ++++++++++++++-- src/src/org/renpy/android/SDLSurfaceView.java | 16 ++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/recipes/android/src/android/_android.pyx b/recipes/android/src/android/_android.pyx index fa34db2a94..679348cb8f 100644 --- a/recipes/android/src/android/_android.pyx +++ b/recipes/android/src/android/_android.pyx @@ -167,11 +167,11 @@ def get_dpi(): # Soft keyboard. -cdef extern void android_show_keyboard() +cdef extern void android_show_keyboard(int) cdef extern void android_hide_keyboard() -def show_keyboard(): - android_show_keyboard() +def show_keyboard(input_type): + android_show_keyboard(input_type) def hide_keyboard(): android_hide_keyboard() diff --git a/recipes/android/src/android/_android_jni.c b/recipes/android/src/android/_android_jni.c index f4cc50f4fe..ee0c3c2ff3 100644 --- a/recipes/android/src/android/_android_jni.c +++ b/recipes/android/src/android/_android_jni.c @@ -129,7 +129,7 @@ int android_get_dpi(void) { return (*env)->CallStaticIntMethod(env, cls, mid); } -void android_show_keyboard(void) { +void android_show_keyboard(int input_type) { static JNIEnv *env = NULL; static jclass *cls = NULL; static jmethodID mid = NULL; @@ -139,11 +139,11 @@ void android_show_keyboard(void) { aassert(env); cls = (*env)->FindClass(env, "org/renpy/android/Hardware"); aassert(cls); - mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "()V"); + mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "(I)V"); aassert(mid); } - (*env)->CallStaticVoidMethod(env, cls, mid); + (*env)->CallStaticVoidMethod(env, cls, mid, (jint) input_type); } void android_hide_keyboard(void) { diff --git a/src/src/org/renpy/android/Hardware.java b/src/src/org/renpy/android/Hardware.java index f87527bfe3..01ed712bcf 100644 --- a/src/src/org/renpy/android/Hardware.java +++ b/src/src/org/renpy/android/Hardware.java @@ -8,6 +8,7 @@ import android.hardware.SensorManager; import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.EditorInfo; import android.view.View; import java.util.List; @@ -21,7 +22,6 @@ import android.net.NetworkInfo; - /** * Methods that are expected to be called via JNI, to access the * device's non-screen hardware. (For example, the vibration and @@ -168,8 +168,20 @@ public static int getDPI() { /** * Show the soft keyboard. */ - public static void showKeyboard() { + public static void showKeyboard(int input_type) { + //Log.i("python", "hardware.Java show_keyword " input_type); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + + SDLSurfaceView vw = (SDLSurfaceView) view; + + int inputType = input_type; + + if (vw.inputType != inputType){ + vw.inputType = inputType; + imm.restartInput(view); + } + imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); } diff --git a/src/src/org/renpy/android/SDLSurfaceView.java b/src/src/org/renpy/android/SDLSurfaceView.java index b92dfcbe8d..4b47028527 100644 --- a/src/src/org/renpy/android/SDLSurfaceView.java +++ b/src/src/org/renpy/android/SDLSurfaceView.java @@ -275,6 +275,9 @@ private void printConfig(EGL10 egl, EGLDisplay display, // Have we started yet? public boolean mStarted = false; + // what is the textinput type while calling the keyboard + public int inputType = EditorInfo.TYPE_CLASS_TEXT; + // Is Python ready to receive input events? static boolean mInputActivated = false; @@ -429,6 +432,12 @@ public static void setOpenFile(){ } } + + public void closeSoftKeyboard(){ + // close the IME overlay(keyboard) + Hardware.hideKeyboard(); + } + /** * Inform the view that the activity is paused. The owner of this view must * call this method when the activity is paused. Calling this method will @@ -437,6 +446,7 @@ public static void setOpenFile(){ */ public void onPause() { + this.closeSoftKeyboard(); synchronized (this) { if (mPause == PAUSE_NONE) { mPause = PAUSE_REQUEST; @@ -476,6 +486,7 @@ public void onResume() { public void onDestroy() { Log.w(TAG, "onDestroy() called"); + this.closeSoftKeyboard(); synchronized (this) { this.notifyAll(); @@ -484,9 +495,6 @@ public void onDestroy() { return; } - // close the IME overlay(keyboard) - InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - inputMethodManager.hideSoftInputFromInputMethod(this.getWindowToken(), 0); // application didn't leave, give 10s before closing. // hopefully, this could be enough for launching the on_stop() trigger within the app. @@ -1050,7 +1058,7 @@ public boolean onKeyPreIme(int keyCode, final KeyEvent event){ @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { // setting inputtype to TYPE_CLASS_TEXT is necessary for swiftkey to enable - outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT; + outAttrs.inputType = inputType; // ask IME to avoid taking full screen on landscape mode outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; return new BaseInputConnection(this, false){ From cfda3e6363594a5c1da74bcc592994abab9c3d36 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 14 Oct 2013 07:43:49 +0200 Subject: [PATCH 2/4] listen to screenSize to not crash during orientation changes (fix buildozer orientation). fixes #148 --- src/templates/AndroidManifest.tmpl.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/AndroidManifest.tmpl.xml b/src/templates/AndroidManifest.tmpl.xml index de942dcae1..729886a7af 100644 --- a/src/templates/AndroidManifest.tmpl.xml +++ b/src/templates/AndroidManifest.tmpl.xml @@ -15,7 +15,7 @@ Date: Tue, 1 Oct 2013 23:55:07 +0530 Subject: [PATCH 3/4] Honor `input_type` Textinput setting to choose the type of keyboard displayed for the TextInput --- recipes/android/src/android/_android.pyx | 6 +++--- recipes/android/src/android/_android_jni.c | 6 +++--- src/src/org/renpy/android/Hardware.java | 16 ++++++++++++++-- src/src/org/renpy/android/SDLSurfaceView.java | 16 ++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/recipes/android/src/android/_android.pyx b/recipes/android/src/android/_android.pyx index fa34db2a94..679348cb8f 100644 --- a/recipes/android/src/android/_android.pyx +++ b/recipes/android/src/android/_android.pyx @@ -167,11 +167,11 @@ def get_dpi(): # Soft keyboard. -cdef extern void android_show_keyboard() +cdef extern void android_show_keyboard(int) cdef extern void android_hide_keyboard() -def show_keyboard(): - android_show_keyboard() +def show_keyboard(input_type): + android_show_keyboard(input_type) def hide_keyboard(): android_hide_keyboard() diff --git a/recipes/android/src/android/_android_jni.c b/recipes/android/src/android/_android_jni.c index f4cc50f4fe..ee0c3c2ff3 100644 --- a/recipes/android/src/android/_android_jni.c +++ b/recipes/android/src/android/_android_jni.c @@ -129,7 +129,7 @@ int android_get_dpi(void) { return (*env)->CallStaticIntMethod(env, cls, mid); } -void android_show_keyboard(void) { +void android_show_keyboard(int input_type) { static JNIEnv *env = NULL; static jclass *cls = NULL; static jmethodID mid = NULL; @@ -139,11 +139,11 @@ void android_show_keyboard(void) { aassert(env); cls = (*env)->FindClass(env, "org/renpy/android/Hardware"); aassert(cls); - mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "()V"); + mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "(I)V"); aassert(mid); } - (*env)->CallStaticVoidMethod(env, cls, mid); + (*env)->CallStaticVoidMethod(env, cls, mid, (jint) input_type); } void android_hide_keyboard(void) { diff --git a/src/src/org/renpy/android/Hardware.java b/src/src/org/renpy/android/Hardware.java index f87527bfe3..01ed712bcf 100644 --- a/src/src/org/renpy/android/Hardware.java +++ b/src/src/org/renpy/android/Hardware.java @@ -8,6 +8,7 @@ import android.hardware.SensorManager; import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.EditorInfo; import android.view.View; import java.util.List; @@ -21,7 +22,6 @@ import android.net.NetworkInfo; - /** * Methods that are expected to be called via JNI, to access the * device's non-screen hardware. (For example, the vibration and @@ -168,8 +168,20 @@ public static int getDPI() { /** * Show the soft keyboard. */ - public static void showKeyboard() { + public static void showKeyboard(int input_type) { + //Log.i("python", "hardware.Java show_keyword " input_type); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + + SDLSurfaceView vw = (SDLSurfaceView) view; + + int inputType = input_type; + + if (vw.inputType != inputType){ + vw.inputType = inputType; + imm.restartInput(view); + } + imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); } diff --git a/src/src/org/renpy/android/SDLSurfaceView.java b/src/src/org/renpy/android/SDLSurfaceView.java index b92dfcbe8d..4b47028527 100644 --- a/src/src/org/renpy/android/SDLSurfaceView.java +++ b/src/src/org/renpy/android/SDLSurfaceView.java @@ -275,6 +275,9 @@ private void printConfig(EGL10 egl, EGLDisplay display, // Have we started yet? public boolean mStarted = false; + // what is the textinput type while calling the keyboard + public int inputType = EditorInfo.TYPE_CLASS_TEXT; + // Is Python ready to receive input events? static boolean mInputActivated = false; @@ -429,6 +432,12 @@ public static void setOpenFile(){ } } + + public void closeSoftKeyboard(){ + // close the IME overlay(keyboard) + Hardware.hideKeyboard(); + } + /** * Inform the view that the activity is paused. The owner of this view must * call this method when the activity is paused. Calling this method will @@ -437,6 +446,7 @@ public static void setOpenFile(){ */ public void onPause() { + this.closeSoftKeyboard(); synchronized (this) { if (mPause == PAUSE_NONE) { mPause = PAUSE_REQUEST; @@ -476,6 +486,7 @@ public void onResume() { public void onDestroy() { Log.w(TAG, "onDestroy() called"); + this.closeSoftKeyboard(); synchronized (this) { this.notifyAll(); @@ -484,9 +495,6 @@ public void onDestroy() { return; } - // close the IME overlay(keyboard) - InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - inputMethodManager.hideSoftInputFromInputMethod(this.getWindowToken(), 0); // application didn't leave, give 10s before closing. // hopefully, this could be enough for launching the on_stop() trigger within the app. @@ -1050,7 +1058,7 @@ public boolean onKeyPreIme(int keyCode, final KeyEvent event){ @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { // setting inputtype to TYPE_CLASS_TEXT is necessary for swiftkey to enable - outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT; + outAttrs.inputType = inputType; // ask IME to avoid taking full screen on landscape mode outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; return new BaseInputConnection(this, false){ From b5db42cf2fdc24b3167d74a726f5f0077819b49c Mon Sep 17 00:00:00 2001 From: qua-non Date: Wed, 30 Oct 2013 14:02:40 +0530 Subject: [PATCH 4/4] move selelection of keyboard type to android module --- recipes/android/src/android/_android.pyx | 49 +++++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/recipes/android/src/android/_android.pyx b/recipes/android/src/android/_android.pyx index 679348cb8f..20973efb89 100644 --- a/recipes/android/src/android/_android.pyx +++ b/recipes/android/src/android/_android.pyx @@ -170,8 +170,53 @@ def get_dpi(): cdef extern void android_show_keyboard(int) cdef extern void android_hide_keyboard() -def show_keyboard(input_type): - android_show_keyboard(input_type) +# Flags for input_type, for requesting a particular type of keyboard +#android FLAGS +TYPE_CLASS_DATETIME = 4 +TYPE_CLASS_NUMBER = 2 +TYPE_NUMBER_VARIATION_NORMAL = 0 +TYPE_NUMBER_VARIATION_PASSWORD = 16 +TYPE_CLASS_TEXT = 1 +TYPE_TEXT_FLAG_AUTO_COMPLETE = 65536 +TYPE_TEXT_FLAG_AUTO_CORRECT = 32768 +TYPE_TEXT_FLAG_NO_SUGGESTIONS = 524288 +TYPE_TEXT_VARIATION_EMAIL_ADDRESS = 32 +TYPE_TEXT_VARIATION_NORMAL = 0 +TYPE_TEXT_VARIATION_PASSWORD = 128 +TYPE_TEXT_VARIATION_POSTAL_ADDRESS = 112 +TYPE_TEXT_VARIATION_URI = 16 +TYPE_CLASS_PHONE = 3 + +def show_keyboard(target, input_type): + if input_type == 'text': + _input_type = TYPE_CLASS_TEXT + elif input_type == 'number': + _input_type = TYPE_CLASS_NUMBER + elif input_type == 'url': + _input_type = \ + TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_URI + elif input_type == 'mail': + _input_type = \ + TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS + elif input_type == 'datetime': + _input_type = TYPE_CLASS_DATETIME + elif input_type == 'tel': + _input_type = TYPE_CLASS_PHONE + elif input_type == 'address': + _input_type = TYPE_TEXT_VARIATION_POSTAL_ADDRESS + + if target.password: + if _input_type == TYPE_CLASS_TEXT: + _input_type |= TYPE_TEXT_VARIATION_PASSWORD + elif _input_type == TYPE_CLASS_NUMBER: + _input_type |= TYPE_NUMBER_VARIATION_PASSWORD + + if not target.keyboard_suggestions: + if _input_type == TYPE_CLASS_TEXT: + _input_type = TYPE_CLASS_TEXT | \ + TYPE_TEXT_FLAG_NO_SUGGESTIONS + + android_show_keyboard(_input_type) def hide_keyboard(): android_hide_keyboard()