From 84765b2f5ce515a721288dcd3638ee084d024199 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Mon, 2 Nov 2015 21:57:22 +0200 Subject: [PATCH] SDL: new API to show built-in SDL keyboard, fixed built-in QWERTY keyboard --- project/java/MainActivity.java | 98 ++++++++++++++----- project/java/Video.java | 7 +- .../application/hid-pc-keyboard/project.patch | 11 +-- project/jni/application/hid-pc-keyboard/src | 2 +- .../jni/sdl-1.2/include/SDL_screenkeyboard.h | 10 ++ .../src/video/android/SDL_androidvideo.c | 8 ++ .../jni/sdl-1.2/src/video/android/keymap.c | 3 + project/res/xml/qwerty.xml | 84 +++++++--------- project/res/xml/qwerty_alt.xml | 57 +++++++++++ project/res/xml/qwerty_alt_shift.xml | 57 +++++++++++ project/res/xml/qwerty_shift.xml | 53 ++++++++++ 11 files changed, 309 insertions(+), 81 deletions(-) create mode 100644 project/res/xml/qwerty_alt.xml create mode 100644 project/res/xml/qwerty_alt_shift.xml create mode 100644 project/res/xml/qwerty_shift.xml diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 156d17832..23d5e4959 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -487,9 +487,15 @@ public class MainActivity extends Activity cloudSave.onActivityResult(request, response, data); } - private int TextInputKeyboardList[] = { 0, R.xml.qwerty, R.xml.c64, R.xml.amiga, R.xml.atari800 }; + private int TextInputKeyboardList[][] = + { + { 0, R.xml.qwerty, R.xml.c64, R.xml.amiga, R.xml.atari800 }, + { 0, R.xml.qwerty_shift, R.xml.c64, R.xml.amiga, R.xml.atari800 }, + { 0, R.xml.qwerty_alt, R.xml.c64, R.xml.amiga, R.xml.atari800 }, + { 0, R.xml.qwerty_alt_shift, R.xml.c64, R.xml.amiga, R.xml.atari800 } + }; - public void showScreenKeyboardWithoutTextInputField() + public void showScreenKeyboardWithoutTextInputField(final int keyboard) { if( !keyboardWithoutTextInputShown ) { @@ -498,7 +504,7 @@ public class MainActivity extends Activity { public void run() { - if (Globals.TextInputKeyboard == 0) + if (keyboard == 0) { _inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); _inputManager.showSoftInput(mGLView, InputMethodManager.SHOW_FORCED); @@ -510,6 +516,8 @@ public class MainActivity extends Activity return; class BuiltInKeyboardView extends KeyboardView { + public boolean shift = false; + public boolean alt = false; public BuiltInKeyboardView(Context context, android.util.AttributeSet attrs) { super(context, attrs); @@ -526,35 +534,83 @@ public class MainActivity extends Activity } return false; } - public boolean onKeyDown(int keyCode, final KeyEvent event) + public boolean onKeyDown(int key, final KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) - return true; return false; } - public boolean onKeyUp(int keyCode, final KeyEvent event) + public boolean onKeyUp(int key, final KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) - { - showScreenKeyboardWithoutTextInputField(); // Hide keyboard - return true; - } return false; } + public void ChangeKeyboard() + { + int idx = (shift ? 1 : 0) + (alt ? 2 : 0); + setKeyboard(new Keyboard(MainActivity.this, TextInputKeyboardList[idx][keyboard])); + setPreviewEnabled(false); + setProximityCorrectionEnabled(false); + } } - BuiltInKeyboardView builtinKeyboard = new BuiltInKeyboardView(MainActivity.this, null); - builtinKeyboard.setKeyboard(new Keyboard(MainActivity.this, TextInputKeyboardList[Globals.TextInputKeyboard])); + final BuiltInKeyboardView builtinKeyboard = new BuiltInKeyboardView(MainActivity.this, null); + builtinKeyboard.setKeyboard(new Keyboard(MainActivity.this, TextInputKeyboardList[0][keyboard])); builtinKeyboard.setPreviewEnabled(false); builtinKeyboard.setProximityCorrectionEnabled(false); builtinKeyboard.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener() { public void onPress(int key) { + if (key == KeyEvent.KEYCODE_BACK) + return; + if (key < 0) + return; + if (key > 100000) + { + key -= 100000; + MainActivity.this.onKeyDown(KeyEvent.KEYCODE_SHIFT_LEFT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT)); + } MainActivity.this.onKeyDown(key, new KeyEvent(KeyEvent.ACTION_DOWN, key)); } public void onRelease(int key) { + if (key == KeyEvent.KEYCODE_BACK) + { + builtinKeyboard.setOnKeyboardActionListener(null); + showScreenKeyboardWithoutTextInputField(0); // Hide keyboard + return; + } + if (key == Keyboard.KEYCODE_SHIFT) + { + builtinKeyboard.shift = ! builtinKeyboard.shift; + if (builtinKeyboard.shift && !builtinKeyboard.alt) + MainActivity.this.onKeyDown(KeyEvent.KEYCODE_SHIFT_LEFT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT)); + else + MainActivity.this.onKeyUp(KeyEvent.KEYCODE_SHIFT_LEFT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT)); + builtinKeyboard.ChangeKeyboard(); + return; + } + if (key == Keyboard.KEYCODE_ALT) + { + builtinKeyboard.alt = ! builtinKeyboard.alt; + if (builtinKeyboard.alt) + MainActivity.this.onKeyUp(KeyEvent.KEYCODE_SHIFT_LEFT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT)); + else + builtinKeyboard.shift = false; + builtinKeyboard.ChangeKeyboard(); + return; + } + if (key < 0) + return; + + boolean shifted = false; + if (key > 100000) + { + key -= 100000; + shifted = true; + } + MainActivity.this.onKeyUp(key, new KeyEvent(KeyEvent.ACTION_UP, key)); + + if (shifted) + MainActivity.this.onKeyUp(KeyEvent.KEYCODE_SHIFT_LEFT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT)); } public void onText(CharSequence p1) {} public void swipeLeft() {} @@ -563,16 +619,6 @@ public class MainActivity extends Activity public void swipeUp() {} public void onKey(int p1, int[] p2) {} }); - /* - builtinKeyboard.addOnLayoutChangeListener(new View.OnLayoutChangeListener() - { - public void onLayoutChange (View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) - { - Log.i("SDL", "Built-in keyboard getTop " + top); - ((KeyboardView)v).setVerticalCorrection(top); - } - }); - */ _screenKeyboard = builtinKeyboard; FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM); _videoLayout.addView(_screenKeyboard, layout); @@ -606,7 +652,7 @@ public class MainActivity extends Activity { if(Globals.CompatibilityHacksTextInputEmulatesHwKeyboard) { - showScreenKeyboardWithoutTextInputField(); + showScreenKeyboardWithoutTextInputField(Globals.TextInputKeyboard); return; } if(_screenKeyboard != null) @@ -718,7 +764,7 @@ public class MainActivity extends Activity public void hideScreenKeyboard() { if( keyboardWithoutTextInputShown ) - showScreenKeyboardWithoutTextInputField(); + showScreenKeyboardWithoutTextInputField(Globals.TextInputKeyboard); if(_screenKeyboard == null || ! (_screenKeyboard instanceof EditText)) return; diff --git a/project/java/Video.java b/project/java/Video.java index eb5e1cf0c..61f600381 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -763,7 +763,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer public void showScreenKeyboardWithoutTextInputField() // Called from native code { - context.showScreenKeyboardWithoutTextInputField(); + context.showScreenKeyboardWithoutTextInputField(Globals.TextInputKeyboard); + } + + public void showInternalScreenKeyboard(int keyboard) // Called from native code + { + context.showScreenKeyboardWithoutTextInputField(keyboard); } public void showScreenKeyboard(final String oldText, int unused) // Called from native code diff --git a/project/jni/application/hid-pc-keyboard/project.patch b/project/jni/application/hid-pc-keyboard/project.patch index 602a3ce19..08a461c9e 100644 --- a/project/jni/application/hid-pc-keyboard/project.patch +++ b/project/jni/application/hid-pc-keyboard/project.patch @@ -1,13 +1,12 @@ --- a/project/AndroidManifest.xml 2014-11-24 19:30:31.003274516 +0200 +++ b/project/AndroidManifest.xml 2014-11-24 19:30:33.547274398 +0200 -@@ -28,7 +28,9 @@ +@@ -45,6 +45,9 @@ + + - - -- + + + - - + + diff --git a/project/jni/application/hid-pc-keyboard/src b/project/jni/application/hid-pc-keyboard/src index aebafa772..773eead64 160000 --- a/project/jni/application/hid-pc-keyboard/src +++ b/project/jni/application/hid-pc-keyboard/src @@ -1 +1 @@ -Subproject commit aebafa77217b909d4f3c119aa73b3ee2c9b03ebf +Subproject commit 773eead644903773feab629376c145fcc922f51b diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index 9a8240c96..6ddaf5f7b 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -117,6 +117,16 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleScreenKeyboardTextInput(const char /* Show only the bare Android QWERTY keyboard without any text input field, so it won't cover the screen */ extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput(void); +typedef enum +{ + SDL_KEYBOARD_QWERTY = 1, + SDL_KEYBOARD_COMMODORE = 2, + SDL_KEYBOARD_AMIGA = 3, + SDL_KEYBOARD_ATARI800 = 4, +} SDL_InternalKeyboard_t; +/* Show internal keyboard, built into SDL */ +extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleInternalScreenKeyboard(SDL_InternalKeyboard_t keyboard); + /* Show Android QWERTY keyboard, and pass entered text back to application in a buffer, using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size - this call will block until user typed all text. */ diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 99ad652e2..85504cdcc 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -72,6 +72,7 @@ static jobject JavaRenderer = NULL; static jmethodID JavaSwapBuffers = NULL; static jmethodID JavaShowScreenKeyboard = NULL; static jmethodID JavaToggleScreenKeyboardWithoutTextInput = NULL; +static jmethodID JavaToggleInternalScreenKeyboard = NULL; static jmethodID JavaHideScreenKeyboard = NULL; static jmethodID JavaIsScreenKeyboardShown = NULL; static jmethodID JavaSetScreenKeyboardHintMessage = NULL; @@ -238,6 +239,12 @@ int SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput(void) return 1; } +int SDL_ANDROID_ToggleInternalScreenKeyboard(SDL_InternalKeyboard_t keyboard) +{ + (*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaToggleInternalScreenKeyboard, (jint)keyboard ); + return 1; +} + #if SDL_VERSION_ATLEAST(1,3,0) #else extern int SDL_Flip(SDL_Surface *screen); @@ -333,6 +340,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t JavaSwapBuffers = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "swapBuffers", "()I"); JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;I)V"); JavaToggleScreenKeyboardWithoutTextInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboardWithoutTextInputField", "()V"); + JavaToggleInternalScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showInternalScreenKeyboard", "(I)V"); JavaHideScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "hideScreenKeyboard", "()V"); JavaIsScreenKeyboardShown = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "isScreenKeyboardShown", "()I"); JavaSetScreenKeyboardHintMessage = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setScreenKeyboardHintMessage", "(Ljava/lang/String;)V"); diff --git a/project/jni/sdl-1.2/src/video/android/keymap.c b/project/jni/sdl-1.2/src/video/android/keymap.c index 467f7621a..de9d26a71 100644 --- a/project/jni/sdl-1.2/src/video/android/keymap.c +++ b/project/jni/sdl-1.2/src/video/android/keymap.c @@ -241,6 +241,9 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap) keymap[KEYCODE_BUTTON_14] = SDL_KEY(N); keymap[KEYCODE_BUTTON_15] = SDL_KEY(O); keymap[KEYCODE_BUTTON_16] = SDL_KEY(P); + keymap[KEYCODE_MEDIA_TOP_MENU] = SDL_KEY(MENU); + keymap[KEYCODE_TV_CONTENTS_MENU] = SDL_KEY(MENU); + keymap[KEYCODE_TV_MEDIA_CONTEXT_MENU] = SDL_KEY(MENU); keymap[KEYCODE_MOUSE_LEFT] = SDL_KEY(MOUSE_LEFT); keymap[KEYCODE_MOUSE_MIDDLE] = SDL_KEY(MOUSE_MIDDLE); diff --git a/project/res/xml/qwerty.xml b/project/res/xml/qwerty.xml index de8cf2d9e..ff78c6512 100644 --- a/project/res/xml/qwerty.xml +++ b/project/res/xml/qwerty.xml @@ -6,58 +6,48 @@ android:verticalGap="0px" android:keyHeight="10%p"> - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - + + + + + + + + diff --git a/project/res/xml/qwerty_alt.xml b/project/res/xml/qwerty_alt.xml new file mode 100644 index 000000000..f7219b05a --- /dev/null +++ b/project/res/xml/qwerty_alt.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/project/res/xml/qwerty_alt_shift.xml b/project/res/xml/qwerty_alt_shift.xml new file mode 100644 index 000000000..1fc702c93 --- /dev/null +++ b/project/res/xml/qwerty_alt_shift.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/project/res/xml/qwerty_shift.xml b/project/res/xml/qwerty_shift.xml new file mode 100644 index 000000000..396a3ae43 --- /dev/null +++ b/project/res/xml/qwerty_shift.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +