Skip to content

Commit c0bb0bd

Browse files
committed
Honor input_type Textinput setting to choose the type of keyboard
displayed for the TextInput
1 parent e9f0e0d commit c0bb0bd

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

recipes/android/src/android/_android.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ def get_dpi():
167167

168168

169169
# Soft keyboard.
170-
cdef extern void android_show_keyboard()
170+
cdef extern void android_show_keyboard(int)
171171
cdef extern void android_hide_keyboard()
172172

173-
def show_keyboard():
174-
android_show_keyboard()
173+
def show_keyboard(input_type):
174+
android_show_keyboard(input_type)
175175

176176
def hide_keyboard():
177177
android_hide_keyboard()

recipes/android/src/android/_android_jni.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int android_get_dpi(void) {
129129
return (*env)->CallStaticIntMethod(env, cls, mid);
130130
}
131131

132-
void android_show_keyboard(void) {
132+
void android_show_keyboard(int input_type) {
133133
static JNIEnv *env = NULL;
134134
static jclass *cls = NULL;
135135
static jmethodID mid = NULL;
@@ -139,11 +139,11 @@ void android_show_keyboard(void) {
139139
aassert(env);
140140
cls = (*env)->FindClass(env, "org/renpy/android/Hardware");
141141
aassert(cls);
142-
mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "()V");
142+
mid = (*env)->GetStaticMethodID(env, cls, "showKeyboard", "(I)V");
143143
aassert(mid);
144144
}
145145

146-
(*env)->CallStaticVoidMethod(env, cls, mid);
146+
(*env)->CallStaticVoidMethod(env, cls, mid, (jint) input_type);
147147
}
148148

149149
void android_hide_keyboard(void) {

src/src/org/renpy/android/Hardware.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.hardware.SensorManager;
99
import android.util.DisplayMetrics;
1010
import android.view.inputmethod.InputMethodManager;
11+
import android.view.inputmethod.EditorInfo;
1112
import android.view.View;
1213

1314
import java.util.List;
@@ -21,7 +22,6 @@
2122
import android.net.NetworkInfo;
2223

2324

24-
2525
/**
2626
* Methods that are expected to be called via JNI, to access the
2727
* device's non-screen hardware. (For example, the vibration and
@@ -168,8 +168,20 @@ public static int getDPI() {
168168
/**
169169
* Show the soft keyboard.
170170
*/
171-
public static void showKeyboard() {
171+
public static void showKeyboard(int input_type) {
172+
//Log.i("python", "hardware.Java show_keyword " input_type);
173+
172174
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
175+
176+
SDLSurfaceView vw = (SDLSurfaceView) view;
177+
178+
int inputType = input_type;
179+
180+
if (vw.inputType != inputType){
181+
vw.inputType = inputType;
182+
imm.restartInput(view);
183+
}
184+
173185
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
174186
}
175187

src/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ private void printConfig(EGL10 egl, EGLDisplay display,
275275
// Have we started yet?
276276
public boolean mStarted = false;
277277

278+
// what is the textinput type while calling the keyboard
279+
public int inputType = EditorInfo.TYPE_CLASS_TEXT;
280+
278281
// Is Python ready to receive input events?
279282
static boolean mInputActivated = false;
280283

@@ -429,6 +432,12 @@ public static void setOpenFile(){
429432
}
430433
}
431434

435+
436+
public void closeSoftKeyboard(){
437+
// close the IME overlay(keyboard)
438+
Hardware.hideKeyboard();
439+
}
440+
432441
/**
433442
* Inform the view that the activity is paused. The owner of this view must
434443
* call this method when the activity is paused. Calling this method will
@@ -437,6 +446,7 @@ public static void setOpenFile(){
437446
*/
438447
public void onPause() {
439448

449+
this.closeSoftKeyboard();
440450
synchronized (this) {
441451
if (mPause == PAUSE_NONE) {
442452
mPause = PAUSE_REQUEST;
@@ -476,6 +486,7 @@ public void onResume() {
476486

477487
public void onDestroy() {
478488
Log.w(TAG, "onDestroy() called");
489+
this.closeSoftKeyboard();
479490
synchronized (this) {
480491
this.notifyAll();
481492

@@ -484,9 +495,6 @@ public void onDestroy() {
484495
return;
485496
}
486497

487-
// close the IME overlay(keyboard)
488-
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
489-
inputMethodManager.hideSoftInputFromInputMethod(this.getWindowToken(), 0);
490498

491499
// application didn't leave, give 10s before closing.
492500
// 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){
10501058
@Override
10511059
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
10521060
// setting inputtype to TYPE_CLASS_TEXT is necessary for swiftkey to enable
1053-
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
1061+
outAttrs.inputType = inputType;
10541062
// ask IME to avoid taking full screen on landscape mode
10551063
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
10561064
return new BaseInputConnection(this, false){

0 commit comments

Comments
 (0)