Skip to content

Honor input_type Textinput property to choose the type of keyboard #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions recipes/android/src/android/_android.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,56 @@ 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()
# 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()
Expand Down
6 changes: 3 additions & 3 deletions recipes/android/src/android/_android_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions src/src/org/renpy/android/Hardware.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 12 additions & 4 deletions src/src/org/renpy/android/SDLSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -437,6 +446,7 @@ public static void setOpenFile(){
*/
public void onPause() {

this.closeSoftKeyboard();
synchronized (this) {
if (mPause == PAUSE_NONE) {
mPause = PAUSE_REQUEST;
Expand Down Expand Up @@ -476,6 +486,7 @@ public void onResume() {

public void onDestroy() {
Log.w(TAG, "onDestroy() called");
this.closeSoftKeyboard();
synchronized (this) {
this.notifyAll();

Expand All @@ -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.
Expand Down Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion src/templates/AndroidManifest.tmpl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<activity android:name="org.renpy.android.PythonActivity"
android:label="@string/iconName"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode|screenSize"
android:launchMode="singleTask"
android:process=":python"
android:screenOrientation="{{ args.orientation }}"
Expand Down