Fixes to text input
This commit is contained in:
@@ -23,7 +23,7 @@ import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.view.View.OnKeyListener;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
@@ -218,11 +218,17 @@ public class MainActivity extends Activity {
|
||||
String text = _screenKeyboard.getText().toString();
|
||||
if( mGLView != null )
|
||||
{
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
mGLView.nativeTextInput( text.charAt(i), text.codePointAt(i) );
|
||||
synchronized(textInput) {
|
||||
textInput.addFirst(0); // Dummy keycode to skip first frame
|
||||
textInput.addFirst(0);
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
textInput.addLast((int)text.charAt(i));
|
||||
textInput.addLast((int)text.codePointAt(i));
|
||||
}
|
||||
textInput.addLast(13); // send return
|
||||
textInput.addLast(13);
|
||||
}
|
||||
mGLView.nativeTextInput( 13, 13 ); // Send return
|
||||
}
|
||||
_videoLayout.removeView(_screenKeyboard);
|
||||
_screenKeyboard = null;
|
||||
@@ -248,7 +254,10 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR))
|
||||
{
|
||||
mGLView.nativeTextInput( 8, 8 ); // send backspace keycode
|
||||
synchronized(textInput) {
|
||||
textInput.addLast(8); // send backspace keycode
|
||||
textInput.addLast(8);
|
||||
}
|
||||
return false; // and proceed to delete text in keyboard input field
|
||||
}
|
||||
return false;
|
||||
@@ -378,4 +387,6 @@ public class MainActivity extends Activity {
|
||||
public Settings.KeyEventsListener keyRemapTool = null;
|
||||
boolean _isPaused = false;
|
||||
|
||||
public LinkedList<Integer> textInput = new LinkedList<Integer> ();
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.lang.Thread;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import android.os.Build;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
abstract class DifferentTouchInput
|
||||
@@ -225,6 +226,18 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
mGlContextLost = false;
|
||||
Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics
|
||||
}
|
||||
|
||||
// Pass just one char per frame, many SDL games cannot handle multiple events in a single frame
|
||||
synchronized(context.textInput) {
|
||||
if( context.textInput.size() >= 2 )
|
||||
{
|
||||
if( context.textInput.getFirst() != 0 )
|
||||
nativeTextInput( context.textInput.getFirst(), context.textInput.get(1) );
|
||||
context.textInput.removeFirst();
|
||||
context.textInput.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -254,6 +267,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
private native void nativeDone();
|
||||
private native void nativeGlContextLost();
|
||||
public native void nativeGlContextRecreated();
|
||||
public static native void nativeTextInput( int ascii, int unicode );
|
||||
|
||||
private MainActivity context = null;
|
||||
private AccelerometerReader accelerometer = null;
|
||||
@@ -331,7 +345,6 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
|
||||
public static native void nativeMouse( int x, int y, int action, int pointerId, int pressure, int radius );
|
||||
public static native void nativeKey( int keyCode, int down );
|
||||
public static native void nativeTextInput( int ascii, int unicode );
|
||||
public static native void initJavaCallbacks();
|
||||
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeTextInput) ( JNIEnv* env, jobject thiz, jint ascii, jint unicode )
|
||||
JAVA_EXPORT_NAME(DemoRenderer_nativeTextInput) ( JNIEnv* env, jobject thiz, jint ascii, jint unicode )
|
||||
{
|
||||
SDL_ANDROID_MainThreadPushText(ascii, unicode);
|
||||
}
|
||||
@@ -1163,8 +1163,8 @@ extern void SDL_ANDROID_MainThreadPushText( int scancode, int unicode )
|
||||
nextEvent = getNextEvent();
|
||||
{
|
||||
SDL_Event * ev = &BufferedEvents[BufferedEventsEnd];
|
||||
ev->type = SDL_KEYUP;
|
||||
ev->key.state = SDL_PRESSED;
|
||||
ev->type = SDL_KEYDOWN;
|
||||
ev->key.state = SDL_RELEASED;
|
||||
ev->key.keysym.scancode = scancode;
|
||||
ev->key.keysym.sym = scancode;
|
||||
ev->key.keysym.mod = KMOD_NONE;
|
||||
|
||||
Reference in New Issue
Block a user