Do not send Backspace keycode for text input invoked with SDL_ANDROID_GetScreenKeyboardTextInput()
This commit is contained in:
@@ -250,32 +250,26 @@ public class MainActivity extends Activity {
|
||||
mGLView.requestFocus();
|
||||
};
|
||||
|
||||
public void showScreenKeyboard(final String oldText)
|
||||
public void showScreenKeyboard(final String oldText, boolean sendBackspace)
|
||||
{
|
||||
if(_screenKeyboard != null)
|
||||
return;
|
||||
class myKeyListener implements OnKeyListener
|
||||
{
|
||||
MainActivity _parent;
|
||||
myKeyListener(MainActivity parent) { _parent = parent; };
|
||||
boolean sendBackspace;
|
||||
myKeyListener(MainActivity parent, boolean sendBackspace) { _parent = parent; this.sendBackspace = sendBackspace; };
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event)
|
||||
{
|
||||
if ((event.getAction() == KeyEvent.ACTION_UP) && ((keyCode == KeyEvent.KEYCODE_ENTER) || (keyCode == KeyEvent.KEYCODE_BACK)))
|
||||
{
|
||||
_parent.hideScreenKeyboard();
|
||||
if(keyCode == KeyEvent.KEYCODE_ENTER)
|
||||
{
|
||||
synchronized(textInput)
|
||||
{
|
||||
//DemoRenderer.nativeTextInput( 13, 13 ); // send return
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR))
|
||||
if ((sendBackspace && event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR))
|
||||
{
|
||||
synchronized(textInput) {
|
||||
DemoRenderer.nativeTextInput( 8, 8 );
|
||||
DemoRenderer.nativeTextInput( 8, 8 ); // Send backspace to native code
|
||||
}
|
||||
return false; // and proceed to delete text in keyboard input field
|
||||
}
|
||||
@@ -283,7 +277,7 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
};
|
||||
_screenKeyboard = new EditText(this);
|
||||
_screenKeyboard.setOnKeyListener(new myKeyListener(this));
|
||||
_screenKeyboard.setOnKeyListener(new myKeyListener(this, sendBackspace));
|
||||
_screenKeyboard.setHint(R.string.text_edit_click_here);
|
||||
_screenKeyboard.setText(oldText);
|
||||
_videoLayout.addView(_screenKeyboard);
|
||||
|
||||
@@ -253,20 +253,22 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void showScreenKeyboard(final String oldText) // Called from native code
|
||||
public void showScreenKeyboard(final String oldText, int sendBackspace) // Called from native code
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public MainActivity parent;
|
||||
public String oldText;
|
||||
public boolean sendBackspace;
|
||||
public void run()
|
||||
{
|
||||
parent.showScreenKeyboard(oldText);
|
||||
parent.showScreenKeyboard(oldText, sendBackspace);
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.parent = context;
|
||||
cb.oldText = oldText;
|
||||
cb.sendBackspace = (sendBackspace != 0);
|
||||
context.runOnUiThread(cb);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
AppSettingVersion=17
|
||||
LibSdlVersion=1.2
|
||||
AppName="Ballfield"
|
||||
AppFullName=net.olofson.ballfield.v426
|
||||
AppFullName=net.olofson.ballfield
|
||||
ScreenOrientation=h
|
||||
InhibitSuspend=n
|
||||
AppDataDownloadUrl="Game data is 1 Mb|ballfield.zip"
|
||||
|
||||
@@ -64,6 +64,7 @@ static jmethodID JavaShowScreenKeyboard = NULL;
|
||||
static int glContextLost = 0;
|
||||
static int showScreenKeyboardDeferred = 0;
|
||||
static const char * showScreenKeyboardOldText = "";
|
||||
static int showScreenKeyboardSendBackspace = 0;
|
||||
int SDL_ANDROID_SmoothVideo = 0;
|
||||
int SDL_ANDROID_VideoMultithreaded = 0;
|
||||
|
||||
@@ -118,7 +119,7 @@ int SDL_ANDROID_CallJavaSwapBuffers()
|
||||
if( showScreenKeyboardDeferred )
|
||||
{
|
||||
showScreenKeyboardDeferred = 0;
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText) );
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText), showScreenKeyboardSendBackspace );
|
||||
}
|
||||
SDL_ANDROID_ProcessDeferredEvents();
|
||||
return 1;
|
||||
@@ -229,6 +230,7 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
|
||||
{
|
||||
showScreenKeyboardDeferred = 1;
|
||||
showScreenKeyboardOldText = oldText;
|
||||
showScreenKeyboardSendBackspace = 1;
|
||||
// Move mouse by 1 pixel to force screen update
|
||||
int x, y;
|
||||
SDL_GetMouseState( &x, &y );
|
||||
@@ -246,11 +248,12 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
|
||||
// Dirty hack: we may call (*JavaEnv)->CallVoidMethod(...) only from video thread
|
||||
showScreenKeyboardDeferred = 1;
|
||||
showScreenKeyboardOldText = oldText;
|
||||
showScreenKeyboardSendBackspace = 0;
|
||||
SDL_Flip(SDL_GetVideoSurface());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, oldText) );
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, oldText), 0 );
|
||||
|
||||
while( !textInputFinished )
|
||||
SDL_Delay(100);
|
||||
@@ -266,7 +269,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t
|
||||
|
||||
JavaRendererClass = (*JavaEnv)->GetObjectClass(JavaEnv, thiz);
|
||||
JavaSwapBuffers = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "swapBuffers", "()I");
|
||||
JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;)V");
|
||||
JavaShowScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboard", "(Ljava/lang/String;I)V");
|
||||
|
||||
ANDROID_InitOSKeymap();
|
||||
|
||||
|
||||
@@ -789,6 +789,8 @@ int SDL_ANDROID_GetScreenKeyboardSize()
|
||||
int SDL_ANDROID_ToggleScreenKeyboardTextInput(const char * previousText)
|
||||
{
|
||||
static char textIn[255];
|
||||
if( previousText == NULL )
|
||||
previousText = "";
|
||||
strncpy(textIn, previousText, sizeof(textIn));
|
||||
textIn[sizeof(textIn)-1] = 0;
|
||||
SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0);
|
||||
|
||||
Reference in New Issue
Block a user