SDL: SDL_ANDROID_GetScreenKeyboardTextInputAsync() for anychronous text input without buggy synthetic keypresses

This commit is contained in:
Sergii Pylypenko
2016-10-31 21:22:27 +02:00
parent 5e11dbbe7e
commit 1258d54afa
8 changed files with 50 additions and 12 deletions

View File

@@ -7,10 +7,10 @@ AppName="Ninslash"
AppFullName=ninslash.com
# Application version code (integer)
AppVersionCode=01910
AppVersionCode=01911
# Application user-visible version name (string)
AppVersionName="0.1.9.10 pre-alpha early access"
AppVersionName="0.1.9.11 pre-alpha early access"
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu

View File

@@ -128,10 +128,24 @@ typedef enum
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. */
using buffer contents as previous text (UTF-8 encoded), the buffer may be of any size.
This function will block until user typed all text. */
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSize);
typedef enum
{
SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS = 0,
SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED = 1,
} SDL_AndroidTextInputAsyncStatus_t;
/* 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 function will return immediately with return status SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS,
and will change the contents of the buffer in another thread. You then should call this function
with the same parameters, until it will return status SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED,
and only after this you can access the contents of the buffer. */
extern DECLSPEC SDL_AndroidTextInputAsyncStatus_t SDLCALL SDL_ANDROID_GetScreenKeyboardTextInputAsync(char * textBuf, int textBufSize);
/* Whether user redefined on-screen keyboard layout via SDL menu, app should not enforce it's own layout in that case */
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardRedefinedByUser(void);

View File

@@ -62,7 +62,7 @@ SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex)
if ( device ) {
SDL_memset(device, 0, sizeof (*device));
}
if ( (device == NULL) ) {
if ( device == NULL ) {
SDL_OutOfMemory();
if ( device ) {
SDL_free(device);

View File

@@ -42,6 +42,7 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_android.h"
#include "SDL_syswm.h"
#include "../SDL_sysvideo.h"
@@ -50,6 +51,7 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
#include "../SDL_sysvideo.h"
#include "SDL_androidvideo.h"
#include "SDL_androidinput.h"
#include "jniwrapperstuff.h"
@@ -264,7 +266,7 @@ extern int SDL_Flip(SDL_Surface *screen);
extern SDL_Surface *SDL_GetVideoSurface(void);
#endif
void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen)
void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen, int async)
{
JNIEnv *JavaEnv = GetJavaEnv();
@@ -307,6 +309,9 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
(*JavaEnv)->PopLocalFrame(JavaEnv, NULL);
}
if( async )
return;
while( !SDL_ANDROID_TextInputFinished )
SDL_Delay(100);
SDL_ANDROID_TextInputFinished = 0;
@@ -394,6 +399,7 @@ int SDL_ANDROID_SetApplicationPutToBackgroundCallback(
if( appRestoredCallback )
appRestoredCallback = appRestored;
return 0;
}
extern int SDL_ANDROID_SetOpenALPutToBackgroundCallback(
@@ -406,6 +412,7 @@ int SDL_ANDROID_SetOpenALPutToBackgroundCallback(
{
openALPutToBackgroundCallback = PutToBackground;
openALRestoredCallback = Restored;
return 0;
}
JNIEXPORT void JNICALL
@@ -458,6 +465,7 @@ int SDLCALL SDL_SetClipboardText(const char *text)
if( s )
(*JavaEnv)->DeleteLocalRef( JavaEnv, s );
(*JavaEnv)->PopLocalFrame(JavaEnv, NULL);
return 0;
}
char * SDLCALL SDL_GetClipboardText(void)
@@ -495,7 +503,7 @@ int SDLCALL SDL_HasClipboardText(void)
return ret;
}
JAVA_EXPORT_NAME(DemoRenderer_nativeClipboardChanged) ( JNIEnv* env, jobject thiz )
void JAVA_EXPORT_NAME(DemoRenderer_nativeClipboardChanged) ( JNIEnv* env, jobject thiz )
{
if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE )
{

View File

@@ -66,7 +66,7 @@ extern int SDL_ANDROID_ForceClearScreenRectAmount;
extern int SDL_ANDROID_ShowScreenUnderFinger;
extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnderFingerRectSrc;
extern int SDL_ANDROID_CallJavaSwapBuffers();
extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen);
extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen, int async);
extern void SDL_ANDROID_CallJavaHideScreenKeyboard();
extern void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint);
extern int SDL_ANDROID_IsScreenKeyboardShown();

View File

@@ -85,7 +85,7 @@ typedef struct
GLfloat h;
} GLTexture_t;
static GLTexture_t arrowImages[9];
static GLTexture_t arrowImages[12];
static GLTexture_t buttonAutoFireImages[MAX_BUTTONS_AUTOFIRE*2]; // These are not used anymore
static GLTexture_t buttonImages[MAX_BUTTONS*2];
static GLTexture_t mousePointer;
@@ -1171,6 +1171,7 @@ SDLKey SDL_ANDROID_GetScreenKeyboardButtonKey(int buttonId)
int SDL_ANDROID_SetScreenKeyboardShown(int shown)
{
touchscreenKeyboardShown = shown;
return 0;
};
int SDL_ANDROID_GetScreenKeyboardShown(void)
@@ -1215,16 +1216,28 @@ int SDL_ANDROID_ToggleScreenKeyboardTextInput(const char * previousText)
previousText = "";
strncpy(textIn, previousText, sizeof(textIn));
textIn[sizeof(textIn)-1] = 0;
SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0);
SDL_ANDROID_CallJavaShowScreenKeyboard(textIn, NULL, 0, 0);
return 1;
};
int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSize)
{
SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize);
SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize, 0);
return 1;
};
SDL_AndroidTextInputAsyncStatus_t SDLCALL SDL_ANDROID_GetScreenKeyboardTextInputAsync(char * textBuf, int textBufSize)
{
if( SDL_ANDROID_TextInputFinished )
{
SDL_ANDROID_TextInputFinished = 0;
SDL_ANDROID_IsScreenKeyboardShownFlag = 0;
return SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED;
}
SDL_ANDROID_CallJavaShowScreenKeyboard(textBuf, textBuf, textBufSize, 1);
return SDL_ANDROID_TEXTINPUT_ASYNC_IN_PROGRESS;
}
int SDLCALL SDL_HasScreenKeyboardSupport(void *unused)
{
return 1;

View File

@@ -5,6 +5,9 @@
#include <stdint.h>
#include <math.h>
#include <string.h> // for memset()
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "jniwrapperstuff.h"