Fixed bug #4843 - Can not get the ime candidatelist like chinese/japaness input method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index f850b0a..df42416 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -102,6 +102,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
public static boolean mBrokenLibraries = true;
+ public static int mInputType = 1;
+
// Main components
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
@@ -1187,6 +1189,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
/**
* This method is called by SDL using JNI.
*/
+ public static int setInputType(int type) {
+ mInputType = type;
+ return 0;
+ }
+
+ /**
+ * This method is called by SDL using JNI.
+ */
public static Surface getNativeSurface() {
if (SDLActivity.mSurface == null) {
return null;
@@ -2182,7 +2192,14 @@ class DummyEdit extends View implements View.OnKeyListener {
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);
- outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+ if (SDLActivity.mInputType == 0) {
+ /* 0 normal: use input method */
+ outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
+ } else {
+ /* 1 password (default): can not use input method,just use english */
+ outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+ }
+
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
diff --git a/include/SDL_system.h b/include/SDL_system.h
index 433d0bf..52ec56f 100644
--- a/include/SDL_system.h
+++ b/include/SDL_system.h
@@ -395,6 +395,17 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permis
*/
extern DECLSPEC int SDLCALL SDL_AndroidShowToast(const char* message, int duration, int gravity, int xoffset, int yoffset);
+/* Set Android IME Input Type
+ * Call this method before calling SDL_StartTextInput()
+ *
+ * \param type
+ * 0 normal: use input method
+ * 1 password (default): can not use input method,just use english
+ *
+ * \returns 0 if success, -1 if any error occurs.
+ */
+extern DECLSPEC int SDLCALL SDL_AndroidSetInputType(int type);
+
#endif /* __ANDROID__ */
/* Platform specific functions for WinRT */
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 47e1ed6..88e028d 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -316,6 +316,7 @@ static jmethodID midShowToast;
static jmethodID midSendMessage;
static jmethodID midSetActivityTitle;
static jmethodID midSetCustomCursor;
+static jmethodID midSetInputType;
static jmethodID midSetOrientation;
static jmethodID midSetRelativeMouseEnabled;
static jmethodID midSetSystemCursor;
@@ -595,6 +596,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z");
midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass, "setActivityTitle","(Ljava/lang/String;)Z");
midSetCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setCustomCursor", "(I)Z");
+ midSetInputType = (*env)->GetStaticMethodID(env, mActivityClass, "setInputType", "(I)I");
midSetOrientation = (*env)->GetStaticMethodID(env, mActivityClass, "setOrientation","(IIZLjava/lang/String;)V");
midSetRelativeMouseEnabled = (*env)->GetStaticMethodID(env, mActivityClass, "setRelativeMouseEnabled", "(Z)Z");
midSetSystemCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setSystemCursor", "(I)Z");
@@ -625,6 +627,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
!midSendMessage ||
!midSetActivityTitle ||
!midSetCustomCursor ||
+ !midSetInputType ||
!midSetOrientation ||
!midSetRelativeMouseEnabled ||
!midSetSystemCursor ||
@@ -2453,6 +2456,14 @@ int SDL_AndroidShowToast(const char* message, int duration, int gravity, int xOf
return Android_JNI_ShowToast(message, duration, gravity, xOffset, yOffset);
}
+int SDL_AndroidSetInputType(int type)
+{
+ int result = 0;
+ JNIEnv *env = Android_JNI_GetEnv();
+ result = (*env)->CallStaticIntMethod(env, mActivityClass, midSetInputType, type);
+ return result;
+}
+
void Android_JNI_GetManifestEnvironmentVariables(void)
{
if (!mActivityClass || !midGetManifestEnvironmentVariables) {