Skip to content

Commit 2da7d84

Browse files
committed
initial attempt at swiping support
1 parent 3d2b706 commit 2da7d84

File tree

1 file changed

+71
-14
lines changed

1 file changed

+71
-14
lines changed

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

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
import android.util.Log;
3535
import android.view.SurfaceHolder;
3636
import android.view.SurfaceView;
37-
import android.opengl.GLSurfaceView;
3837
import android.view.MotionEvent;
3938
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;
4044
import android.net.Uri;
4145
import android.os.PowerManager;
4246

@@ -53,7 +57,7 @@
5357

5458

5559
public class SDLSurfaceView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
56-
private static String TAG = "SDLSurface";
60+
private static String TAG = "SDLSurface";
5761
private final String mVertexShader =
5862
"uniform mat4 uMVPMatrix;\n" +
5963
"attribute vec4 aPosition;\n" +
@@ -272,6 +276,9 @@ private void printConfig(EGL10 egl, EGLDisplay display,
272276
// Is Python ready to receive input events?
273277
static boolean mInputActivated = false;
274278

279+
// Is Composing text being repeated?
280+
static boolean mComposingText = false;
281+
275282
// The number of times we should clear the screen after swap.
276283
private int mClears = 2;
277284

@@ -463,6 +470,11 @@ public void onDestroy() {
463470
Log.d(TAG, "onDestroy() app already leaved.");
464471
return;
465472
}
473+
474+
// close the IME overlay(keyboard)
475+
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
476+
inputMethodManager.hideSoftInputFromInputMethod(this.getWindowToken(), 0);
477+
466478

467479
// application didn't leave, give 10s before closing.
468480
// hopefully, this could be enough for launching the on_stop() trigger within the app.
@@ -865,6 +877,7 @@ public int swapBuffers() {
865877

866878
private static final int INVALID_POINTER_ID = -1;
867879
private int mActivePointerId = INVALID_POINTER_ID;
880+
private static String mCompText = "";
868881

869882
@Override
870883
public boolean onTouchEvent(final MotionEvent event) {
@@ -959,7 +972,7 @@ public boolean onKeyUp(int keyCode, final KeyEvent event) {
959972
return super.onKeyUp(keyCode, event);
960973
}
961974
}
962-
975+
963976
@Override
964977
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event){
965978
String keys = event.getCharacters();
@@ -972,32 +985,76 @@ public boolean onKeyMultiple(int keyCode, int count, KeyEvent event){
972985
// but it my cause some odd behaviour
973986
keyCode = 45;
974987
}
975-
976-
if (mInputActivated){
988+
if (mInputActivated && event.getAction() == KeyEvent.ACTION_MULTIPLE){
977989
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+
978999
for(char c: keysBuffer){
9791000
//Log.i("python", "Char from multiply " + (int) c);
9801001
// Calls both up/down events to emulate key pressing
9811002
nativeKey(keyCode, 1, (int) c);
9821003
nativeKey(keyCode, 0, (int) c);
9831004
}
1005+
return true;
1006+
}else {
1007+
return super.onKeyMultiple(keyCode, count, event);
9841008
}
985-
986-
return true;
9871009
}
9881010

9891011
@Override
9901012
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);
9971029
}
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+
9991055
static void activateInput() {
10001056
mInputActivated = true;
1057+
mComposingText = false;
10011058
}
10021059

10031060
static void openUrl(String url) {

0 commit comments

Comments
 (0)