34
34
import android .util .Log ;
35
35
import android .view .SurfaceHolder ;
36
36
import android .view .SurfaceView ;
37
- import android .opengl .GLSurfaceView ;
38
37
import android .view .MotionEvent ;
39
38
import android .view .KeyEvent ;
39
+ import android .view .inputmethod .EditorInfo ;
40
+ import android .view .inputmethod .InputMethodManager ;
41
+ import android .view .inputmethod .InputConnection ;
42
+ import android .view .inputmethod .BaseInputConnection ;
43
+ import android .opengl .GLSurfaceView ;
40
44
import android .net .Uri ;
41
45
import android .os .PowerManager ;
42
46
53
57
54
58
55
59
public class SDLSurfaceView extends SurfaceView implements SurfaceHolder .Callback , Runnable {
56
- private static String TAG = "SDLSurface" ;
60
+ private static String TAG = "SDLSurface" ;
57
61
private final String mVertexShader =
58
62
"uniform mat4 uMVPMatrix;\n " +
59
63
"attribute vec4 aPosition;\n " +
@@ -272,6 +276,9 @@ private void printConfig(EGL10 egl, EGLDisplay display,
272
276
// Is Python ready to receive input events?
273
277
static boolean mInputActivated = false ;
274
278
279
+ // Is Composing text being repeated?
280
+ static boolean mComposingText = false ;
281
+
275
282
// The number of times we should clear the screen after swap.
276
283
private int mClears = 2 ;
277
284
@@ -463,6 +470,11 @@ public void onDestroy() {
463
470
Log .d (TAG , "onDestroy() app already leaved." );
464
471
return ;
465
472
}
473
+
474
+ // close the IME overlay(keyboard)
475
+ InputMethodManager inputMethodManager = (InputMethodManager )getContext ().getSystemService (Context .INPUT_METHOD_SERVICE );
476
+ inputMethodManager .hideSoftInputFromInputMethod (this .getWindowToken (), 0 );
477
+
466
478
467
479
// application didn't leave, give 10s before closing.
468
480
// hopefully, this could be enough for launching the on_stop() trigger within the app.
@@ -865,6 +877,7 @@ public int swapBuffers() {
865
877
866
878
private static final int INVALID_POINTER_ID = -1 ;
867
879
private int mActivePointerId = INVALID_POINTER_ID ;
880
+ private static String mCompText = "" ;
868
881
869
882
@ Override
870
883
public boolean onTouchEvent (final MotionEvent event ) {
@@ -959,7 +972,7 @@ public boolean onKeyUp(int keyCode, final KeyEvent event) {
959
972
return super .onKeyUp (keyCode , event );
960
973
}
961
974
}
962
-
975
+
963
976
@ Override
964
977
public boolean onKeyMultiple (int keyCode , int count , KeyEvent event ){
965
978
String keys = event .getCharacters ();
@@ -972,32 +985,76 @@ public boolean onKeyMultiple(int keyCode, int count, KeyEvent event){
972
985
// but it my cause some odd behaviour
973
986
keyCode = 45 ;
974
987
}
975
-
976
- if (mInputActivated ){
988
+ if (mInputActivated && event .getAction () == KeyEvent .ACTION_MULTIPLE ){
977
989
keys .getChars (0 , keys .length (), keysBuffer , 0 );
990
+ if (mComposingText == true ){
991
+ mComposingText = false ;
992
+ this .mCompText = keys ;
993
+ }else if (this .mCompText .equals (keys )){
994
+ // skip on composing text
995
+ this .mCompText = "" ;
996
+ return true ;
997
+ }
998
+
978
999
for (char c : keysBuffer ){
979
1000
//Log.i("python", "Char from multiply " + (int) c);
980
1001
// Calls both up/down events to emulate key pressing
981
1002
nativeKey (keyCode , 1 , (int ) c );
982
1003
nativeKey (keyCode , 0 , (int ) c );
983
1004
}
1005
+ return true ;
1006
+ }else {
1007
+ return super .onKeyMultiple (keyCode , count , event );
984
1008
}
985
-
986
- return true ;
987
1009
}
988
1010
989
1011
@ Override
990
1012
public boolean onKeyPreIme (int keyCode , final KeyEvent event ){
991
- Log .i ("python" , String .format ("key up %d" , keyCode ));
992
- if (mInputActivated && nativeKey (keyCode , 1 , event .getUnicodeChar ())) {
993
- return false ;
994
- } else {
995
- return super .onKeyDown (keyCode , event );
996
- }
1013
+ //Log.i("python", String.format("key pre ime %d", keyCode));
1014
+ if (mInputActivated ){
1015
+ switch (event .getAction ()) {
1016
+ case KeyEvent .ACTION_DOWN :
1017
+ return onKeyDown (keyCode , event );
1018
+ case KeyEvent .ACTION_UP :
1019
+ return onKeyUp (keyCode , event );
1020
+ case KeyEvent .ACTION_MULTIPLE :
1021
+ return onKeyMultiple (
1022
+ keyCode ,
1023
+ event .getRepeatCount (),
1024
+ event );
1025
+ }
1026
+ return false ;
1027
+ }
1028
+ return super .onKeyPreIme (keyCode , event );
997
1029
}
998
-
1030
+
1031
+ @ Override
1032
+ public InputConnection onCreateInputConnection (EditorInfo outAttrs ) {
1033
+ outAttrs .inputType = EditorInfo .TYPE_NULL ;
1034
+ return new BaseInputConnection (this , false ) {
1035
+
1036
+ @ Override
1037
+ public boolean setComposingText (CharSequence text ,
1038
+ int newCursorPosition ) {
1039
+ commitText (text , 0 );
1040
+ mComposingText = true ;
1041
+ sendKeyEvent (
1042
+ new KeyEvent (
1043
+ KeyEvent .ACTION_DOWN ,
1044
+ KeyEvent .KEYCODE_SPACE ));
1045
+ sendKeyEvent (
1046
+ new KeyEvent (
1047
+ KeyEvent .ACTION_UP ,
1048
+ KeyEvent .KEYCODE_SPACE ));
1049
+ //Log.i("Python:", String.format("set Composing Text %s", mComposingText));
1050
+ return true ;
1051
+ }
1052
+ };
1053
+ }
1054
+
999
1055
static void activateInput () {
1000
1056
mInputActivated = true ;
1057
+ mComposingText = false ;
1001
1058
}
1002
1059
1003
1060
static void openUrl (String url ) {
0 commit comments