Fixed bug 1614 - SDL for Android does not implement TextInput API
Andrey Isakov 2012-10-03 08:30:25 PDT I've found out in the process of porting one OS project to Android/SDL2 that there is no support for TextInput events/APIs on Android. So I implemented some kind of initial support of that feature, and at the very least it seems to work fine with latin chars input with soft and hardware keyboards on my Moto Milestone2. I've also tried playing around with more complex IMEs, like japanese, logging the process and it seemed to work too. I'm not sure since the app itself I am working on does not have support for non-latin input. The main point of the patch is to place a fake input view in the region specified by SDL_SetTextInputRect and create a custom InputConnection for it. The reason to make it a separate view is to support Android's pan&scan on input feature properly. For details please refer to http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html Even though the manual states that SetTextInputRect is used to determine the IME variants position, I thought this would be a proper use for this too.
This commit is contained in:
parent
a2a3c4ae55
commit
e6c0215444
7 changed files with 274 additions and 5 deletions
|
@ -321,6 +321,27 @@ Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
Android_StartTextInput(_THIS)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
Android_JNI_ShowTextInput(&videodata->textRect);
|
||||
}
|
||||
|
||||
#define COMMAND_TEXTEDIT_HIDE 3
|
||||
void
|
||||
Android_StopTextInput(_THIS)
|
||||
{
|
||||
Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
|
||||
}
|
||||
|
||||
void
|
||||
Android_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
videodata->textRect = *rect;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -32,4 +32,8 @@ extern int Android_HideScreenKeyboard(_THIS, SDL_Window * window);
|
|||
extern int Android_ToggleScreenKeyboard(_THIS, SDL_Window * window);
|
||||
extern SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window * window);
|
||||
|
||||
extern void Android_StartTextInput(_THIS);
|
||||
extern void Android_StopTextInput(_THIS);
|
||||
extern void Android_SetTextInputRect(_THIS, SDL_Rect *rect);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -87,17 +87,24 @@ Android_CreateDevice(int devindex)
|
|||
{
|
||||
printf("Creating video device\n");
|
||||
SDL_VideoDevice *device;
|
||||
SDL_VideoData *data;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
if (!device) {
|
||||
SDL_OutOfMemory();
|
||||
if (device) {
|
||||
SDL_free(device);
|
||||
}
|
||||
return (0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
|
||||
if (!data) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device->driverdata = data;
|
||||
|
||||
/* Set the function pointers */
|
||||
device->VideoInit = Android_VideoInit;
|
||||
device->VideoQuit = Android_VideoQuit;
|
||||
|
@ -132,6 +139,11 @@ Android_CreateDevice(int devindex)
|
|||
device->GetClipboardText = Android_GetClipboardText;
|
||||
device->HasClipboardText = Android_HasClipboardText;
|
||||
|
||||
/* Text input */
|
||||
device->StartTextInput = Android_StartTextInput;
|
||||
device->StopTextInput = Android_StopTextInput;
|
||||
device->SetTextInputRect = Android_SetTextInputRect;
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define _SDL_androidvideo_h
|
||||
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_rect.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
|
||||
/* Called by the JNI layer when the screen changes size or format */
|
||||
|
@ -31,6 +32,11 @@ extern void Android_SetScreenResolution(int width, int height, Uint32 format);
|
|||
|
||||
/* Private display data */
|
||||
|
||||
typedef struct SDL_VideoData
|
||||
{
|
||||
SDL_Rect textRect;
|
||||
} SDL_VideoData;
|
||||
|
||||
extern int Android_ScreenWidth;
|
||||
extern int Android_ScreenHeight;
|
||||
extern Uint32 Android_ScreenFormat;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue