From 2f06d51ac9e427ef0ade09ef4f6bbb659d05edf8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 11 Aug 2012 10:15:59 -0700 Subject: [PATCH] Fixed bug 1564 - SDL has no function to open a screen keyboard on Android. Philipp Wiesemann implemented a general on-screen keyboard API for SDL, and I switched iOS code over to use it. --- README.iOS | 10 +- .../Demos/Demos.xcodeproj/project.pbxproj | 30 +++--- Xcode-iOS/Demos/src/keyboard.c | 15 +-- .../TestiPhoneOS.xcodeproj/project.pbxproj | 98 +++++++++---------- android-project/AndroidManifest.xml | 3 + .../src/org/libsdl/app/SDLActivity.java | 30 +++++- include/SDL_keyboard.h | 72 ++++++++++++++ include/SDL_system.h | 15 +-- src/core/android/SDL_android.cpp | 15 +++ src/core/android/SDL_android.h | 3 + src/video/SDL_sysvideo.h | 7 ++ src/video/SDL_video.c | 45 +++++++++ src/video/android/SDL_androidkeyboard.c | 34 +++++++ src/video/android/SDL_androidkeyboard.h | 6 ++ src/video/android/SDL_androidvideo.c | 7 ++ src/video/uikit/SDL_uikitvideo.m | 5 + src/video/uikit/SDL_uikitview.h | 7 ++ src/video/uikit/SDL_uikitview.m | 51 ++++------ test/checkkeys.c | 10 +- 19 files changed, 332 insertions(+), 131 deletions(-) diff --git a/README.iOS b/README.iOS index cf5eb677a..3ec1e0f86 100644 --- a/README.iOS +++ b/README.iOS @@ -78,15 +78,15 @@ Finally, if your application completely redraws the screen each frame, you may f Notes -- Keyboard ============================================================================== -SDL for iPhone contains several additional functions related to keyboard visibility. These functions are not part of the SDL standard API, but are necessary for revealing and hiding the iPhone's virtual onscreen keyboard. +The SDL keyboard API has been extended to support on-screen keyboards: -int SDL_iPhoneKeyboardShow(SDL_Window * window) +int SDL_ShowScreenKeyboard(SDL_Window * window) -- reveals the onscreen keyboard. Returns 0 on success and -1 on error. -int SDL_iPhoneKeyboardHide(SDL_Window * window) +int SDL_HideScreenKeyboard(SDL_Window * window) -- hides the onscreen keyboard. Returns 0 on success and -1 on error. -SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) +SDL_bool SDL_IsScreenKeyboardShown(SDL_Window * window) -- returns whether or not the onscreen keyboard is currently visible. -int SDL_iPhoneKeyboardToggle(SDL_Window * window) +int SDL_ToggleScreenKeyboard(SDL_Window * window) -- toggles the visibility of the onscreen keyboard. Returns 0 on success and -1 on error. ============================================================================== diff --git a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj index 503b2c835..13c951f19 100755 --- a/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Demos/Demos.xcodeproj/project.pbxproj @@ -15,12 +15,12 @@ FD15FD6B0E086911003BDF25 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; FD15FD6C0E086911003BDF25 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDB96ED30DEFC9C700FAF19F /* OpenGLES.framework */; }; FD15FD6D0E086911003BDF25 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDB96EDF0DEFC9DC00FAF19F /* QuartzCore.framework */; }; - FD1B48DD0E313255007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; - FD1B49980E313261007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; - FD1B499C0E313269007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; - FD1B499E0E31326C007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; - FD1B49A00E313270007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; - FD1B49A20E313273007AB34E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; + FD1B48DD0E313255007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; + FD1B49980E313261007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; + FD1B499C0E313269007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; + FD1B499E0E31326C007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; + FD1B49A00E313270007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; + FD1B49A20E313273007AB34E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; FD5F9CE80E0E0741008E885B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; FD5F9CE90E0E0741008E885B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; FD5F9CEA0E0E0741008E885B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; @@ -56,7 +56,7 @@ FDB651FA0E43D1F300F688B5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = FD925B180E0F276600E92347 /* Icon.png */; }; FDB651FB0E43D1F300F688B5 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = FD787AA00E22A5CC003E8E36 /* Default.png */; }; FDB651FD0E43D1F300F688B5 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FD77A0060E26BC0500F39101 /* common.c */; }; - FDB652000E43D1F300F688B5 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL.a */; }; + FDB652000E43D1F300F688B5 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B489E0E313154007AB34E /* libSDL2.a */; }; FDB652020E43D1F300F688B5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; FDB652030E43D1F300F688B5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; FDB652040E43D1F300F688B5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; @@ -215,7 +215,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B48DD0E313255007AB34E /* libSDL.a in Frameworks */, + FD1B48DD0E313255007AB34E /* libSDL2.a in Frameworks */, FDF0D7AB0E12D53800247964 /* CoreAudio.framework in Frameworks */, FDF0D7AC0E12D53800247964 /* AudioToolbox.framework in Frameworks */, 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, @@ -230,7 +230,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B49980E313261007AB34E /* libSDL.a in Frameworks */, + FD1B49980E313261007AB34E /* libSDL2.a in Frameworks */, FDF0D7A90E12D53500247964 /* CoreAudio.framework in Frameworks */, FDF0D7AA0E12D53500247964 /* AudioToolbox.framework in Frameworks */, FD15FD690E086911003BDF25 /* Foundation.framework in Frameworks */, @@ -245,7 +245,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B499C0E313269007AB34E /* libSDL.a in Frameworks */, + FD1B499C0E313269007AB34E /* libSDL2.a in Frameworks */, FDF0D7A70E12D53200247964 /* CoreAudio.framework in Frameworks */, FDF0D7A80E12D53200247964 /* AudioToolbox.framework in Frameworks */, FD5F9CEB0E0E0741008E885B /* OpenGLES.framework in Frameworks */, @@ -260,7 +260,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDB652000E43D1F300F688B5 /* libSDL.a in Frameworks */, + FDB652000E43D1F300F688B5 /* libSDL2.a in Frameworks */, FDB652020E43D1F300F688B5 /* Foundation.framework in Frameworks */, FDB652030E43D1F300F688B5 /* UIKit.framework in Frameworks */, FDB652040E43D1F300F688B5 /* CoreGraphics.framework in Frameworks */, @@ -275,7 +275,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B499E0E31326C007AB34E /* libSDL.a in Frameworks */, + FD1B499E0E31326C007AB34E /* libSDL2.a in Frameworks */, FDF0D7950E12D52900247964 /* CoreAudio.framework in Frameworks */, FDF0D7960E12D52900247964 /* AudioToolbox.framework in Frameworks */, FDC202E60E107B1200ABAC90 /* Foundation.framework in Frameworks */, @@ -290,7 +290,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B49A20E313273007AB34E /* libSDL.a in Frameworks */, + FD1B49A20E313273007AB34E /* libSDL2.a in Frameworks */, FDC52ED40E2843D6008D768C /* Foundation.framework in Frameworks */, FDC52ED50E2843D6008D768C /* UIKit.framework in Frameworks */, FDC52ED60E2843D6008D768C /* CoreGraphics.framework in Frameworks */, @@ -305,7 +305,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FD1B49A00E313270007AB34E /* libSDL.a in Frameworks */, + FD1B49A00E313270007AB34E /* libSDL2.a in Frameworks */, FDF0D69C0E12D05400247964 /* Foundation.framework in Frameworks */, FDF0D69D0E12D05400247964 /* UIKit.framework in Frameworks */, FDF0D69E0E12D05400247964 /* CoreGraphics.framework in Frameworks */, @@ -607,7 +607,7 @@ FD1B489E0E313154007AB34E /* libSDL.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; - path = libSDL.a; + path = libSDL2.a; remoteRef = FD1B489D0E313154007AB34E /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c index c0df5b62b..df4b6e1c6 100644 --- a/Xcode-iOS/Demos/src/keyboard.c +++ b/Xcode-iOS/Demos/src/keyboard.c @@ -12,13 +12,6 @@ static SDL_Texture *texture; /* texture where we'll hold our font */ -/* iPhone SDL addition keyboard related function definitions */ -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window); -extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * - window); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window); - /* function declarations */ void cleanup(void); void drawBlank(int x, int y); @@ -296,14 +289,10 @@ main(int argc, char *argv[]) /* draw our updates to the screen */ SDL_RenderPresent(renderer); break; -#ifdef __IPHONEOS__ case SDL_MOUSEBUTTONUP: - /* mouse up toggles onscreen keyboard visibility - this function is available ONLY on iPhone OS - */ - SDL_iPhoneKeyboardToggle(window); + /* mouse up toggles onscreen keyboard visibility */ + SDL_ToggleScreenKeyboard(window); break; -#endif } } cleanup(); diff --git a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj index 68d408b86..1993661b1 100755 --- a/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 046CEF7713254F23007AD51D /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; - 046CEF7B13254F23007AD51D /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + 046CEF7B13254F23007AD51D /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; 046CEF7C13254F23007AD51D /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; 046CEF7D13254F23007AD51D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; 046CEF7E13254F23007AD51D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -17,7 +17,7 @@ 046CEF8113254F23007AD51D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; }; 046CEF8213254F23007AD51D /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; }; 046CEF8A13254F63007AD51D /* testgesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 046CEF8913254F63007AD51D /* testgesture.c */; }; - 047A63E213285C3200CD7973 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + 047A63E213285C3200CD7973 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; 047A63E313285C3200CD7973 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; 047A63E413285C3200CD7973 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; 047A63E513285C3200CD7973 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -27,7 +27,7 @@ 047A63E913285C3200CD7973 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; }; 047A63F113285CD100CD7973 /* checkkeys.c in Sources */ = {isa = PBXBuildFile; fileRef = 047A63F013285CD100CD7973 /* checkkeys.c */; }; 56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; - 56ED0502118A8FE400A56AA6 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + 56ED0502118A8FE400A56AA6 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; 56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; 56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; 56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -38,7 +38,7 @@ 56ED0511118A904200A56AA6 /* testpower.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED0510118A904200A56AA6 /* testpower.c */; }; AAE7DEDC14CBB1E100DF1A0E /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; AAE7DEDE14CBB1E100DF1A0E /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A7840E2D0F1F00EA573E /* common.c */; }; - AAE7DEE114CBB1E100DF1A0E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + AAE7DEE114CBB1E100DF1A0E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; AAE7DEE214CBB1E100DF1A0E /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; AAE7DEE314CBB1E100DF1A0E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; AAE7DEE414CBB1E100DF1A0E /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -51,7 +51,7 @@ AAE7DFA014CBB54E00DF1A0E /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; AAE7DFA114CBB54E00DF1A0E /* sample.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AADE0E2D33C100EA573E /* sample.bmp */; }; AAE7DFA314CBB54E00DF1A0E /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A7840E2D0F1F00EA573E /* common.c */; }; - AAE7DFA614CBB54E00DF1A0E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + AAE7DFA614CBB54E00DF1A0E /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; AAE7DFA714CBB54E00DF1A0E /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; AAE7DFA814CBB54E00DF1A0E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; AAE7DFA914CBB54E00DF1A0E /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -112,24 +112,24 @@ FDAAC62A0E2D5960001DB1D8 /* testgles.c in Sources */ = {isa = PBXBuildFile; fileRef = FDAAC6290E2D5960001DB1D8 /* testgles.c */; }; FDAAC6390E2D59BE001DB1D8 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; }; FDAAC7780E2D7024001DB1D8 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A7840E2D0F1F00EA573E /* common.c */; }; - FDBDE57C0E313445006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5810E313465006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5850E313495006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE58C0E3134F3006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE59B0E31356A006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE59F0E31358D006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5A90E3135C0006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5AE0E3135E6006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5B60E3135FE006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5BC0E31364D006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5C20E313663006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5C60E3136F1006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5C80E313702006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5CA0E313712006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5CC0E31372B006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5CE0E31373E006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDBDE5D40E313789006BAC0B /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; - FDC42FF40F0D866D009C87E1 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; }; + FDBDE57C0E313445006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5810E313465006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5850E313495006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE58C0E3134F3006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE59B0E31356A006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE59F0E31358D006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5A90E3135C0006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5AE0E3135E6006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5B60E3135FE006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5BC0E31364D006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5C20E313663006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5C60E3136F1006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5C80E313702006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5CA0E313712006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5CC0E31372B006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5CE0E31373E006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDBDE5D40E313789006BAC0B /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; + FDC42FF40F0D866D009C87E1 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL2.a */; }; FDC42FF60F0D866D009C87E1 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; }; FDC42FF70F0D866D009C87E1 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; }; FDC42FF80F0D866D009C87E1 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; }; @@ -322,7 +322,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 046CEF7B13254F23007AD51D /* libSDL.a in Frameworks */, + 046CEF7B13254F23007AD51D /* libSDL2.a in Frameworks */, 046CEF7C13254F23007AD51D /* AudioToolbox.framework in Frameworks */, 046CEF7D13254F23007AD51D /* QuartzCore.framework in Frameworks */, 046CEF7E13254F23007AD51D /* OpenGLES.framework in Frameworks */, @@ -337,7 +337,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 047A63E213285C3200CD7973 /* libSDL.a in Frameworks */, + 047A63E213285C3200CD7973 /* libSDL2.a in Frameworks */, 047A63E313285C3200CD7973 /* AudioToolbox.framework in Frameworks */, 047A63E413285C3200CD7973 /* QuartzCore.framework in Frameworks */, 047A63E513285C3200CD7973 /* OpenGLES.framework in Frameworks */, @@ -352,7 +352,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5810E313465006BAC0B /* libSDL.a in Frameworks */, + FDBDE5810E313465006BAC0B /* libSDL2.a in Frameworks */, FDA8A89F0E2D111A00EA573E /* AudioToolbox.framework in Frameworks */, FDA8A8A00E2D111A00EA573E /* QuartzCore.framework in Frameworks */, FDA8A8A10E2D111A00EA573E /* OpenGLES.framework in Frameworks */, @@ -367,7 +367,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 56ED0502118A8FE400A56AA6 /* libSDL.a in Frameworks */, + 56ED0502118A8FE400A56AA6 /* libSDL2.a in Frameworks */, 56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */, 56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */, 56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */, @@ -382,7 +382,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - AAE7DEE114CBB1E100DF1A0E /* libSDL.a in Frameworks */, + AAE7DEE114CBB1E100DF1A0E /* libSDL2.a in Frameworks */, AAE7DEE214CBB1E100DF1A0E /* AudioToolbox.framework in Frameworks */, AAE7DEE314CBB1E100DF1A0E /* QuartzCore.framework in Frameworks */, AAE7DEE414CBB1E100DF1A0E /* OpenGLES.framework in Frameworks */, @@ -397,7 +397,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - AAE7DFA614CBB54E00DF1A0E /* libSDL.a in Frameworks */, + AAE7DFA614CBB54E00DF1A0E /* libSDL2.a in Frameworks */, AAE7DFA714CBB54E00DF1A0E /* AudioToolbox.framework in Frameworks */, AAE7DFA814CBB54E00DF1A0E /* QuartzCore.framework in Frameworks */, AAE7DFA914CBB54E00DF1A0E /* OpenGLES.framework in Frameworks */, @@ -412,7 +412,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5850E313495006BAC0B /* libSDL.a in Frameworks */, + FDBDE5850E313495006BAC0B /* libSDL2.a in Frameworks */, FDA8AAB10E2D330F00EA573E /* AudioToolbox.framework in Frameworks */, FDA8AAB20E2D330F00EA573E /* QuartzCore.framework in Frameworks */, FDA8AAB30E2D330F00EA573E /* OpenGLES.framework in Frameworks */, @@ -427,7 +427,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE58C0E3134F3006BAC0B /* libSDL.a in Frameworks */, + FDBDE58C0E3134F3006BAC0B /* libSDL2.a in Frameworks */, FDAAC3C30E2D47E6001DB1D8 /* AudioToolbox.framework in Frameworks */, FDAAC3C40E2D47E6001DB1D8 /* QuartzCore.framework in Frameworks */, FDAAC3C50E2D47E6001DB1D8 /* OpenGLES.framework in Frameworks */, @@ -442,7 +442,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE59B0E31356A006BAC0B /* libSDL.a in Frameworks */, + FDBDE59B0E31356A006BAC0B /* libSDL2.a in Frameworks */, FDAAC5910E2D5429001DB1D8 /* AudioToolbox.framework in Frameworks */, FDAAC5920E2D5429001DB1D8 /* QuartzCore.framework in Frameworks */, FDAAC5930E2D5429001DB1D8 /* OpenGLES.framework in Frameworks */, @@ -457,7 +457,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE59F0E31358D006BAC0B /* libSDL.a in Frameworks */, + FDBDE59F0E31358D006BAC0B /* libSDL2.a in Frameworks */, FDAAC5BF0E2D55B5001DB1D8 /* AudioToolbox.framework in Frameworks */, FDAAC5C00E2D55B5001DB1D8 /* QuartzCore.framework in Frameworks */, FDAAC5C10E2D55B5001DB1D8 /* OpenGLES.framework in Frameworks */, @@ -472,7 +472,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE57C0E313445006BAC0B /* libSDL.a in Frameworks */, + FDBDE57C0E313445006BAC0B /* libSDL2.a in Frameworks */, FDAAC61C0E2D5914001DB1D8 /* AudioToolbox.framework in Frameworks */, FDAAC61D0E2D5914001DB1D8 /* QuartzCore.framework in Frameworks */, FDAAC61E0E2D5914001DB1D8 /* OpenGLES.framework in Frameworks */, @@ -487,7 +487,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDC42FF40F0D866D009C87E1 /* libSDL.a in Frameworks */, + FDC42FF40F0D866D009C87E1 /* libSDL2.a in Frameworks */, FDC42FF60F0D866D009C87E1 /* AudioToolbox.framework in Frameworks */, FDC42FF70F0D866D009C87E1 /* QuartzCore.framework in Frameworks */, FDC42FF80F0D866D009C87E1 /* OpenGLES.framework in Frameworks */, @@ -502,7 +502,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5A90E3135C0006BAC0B /* libSDL.a in Frameworks */, + FDBDE5A90E3135C0006BAC0B /* libSDL2.a in Frameworks */, FDD2C1000E2E4F4B00B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C1010E2E4F4B00B7A85F /* QuartzCore.framework in Frameworks */, FDD2C1020E2E4F4B00B7A85F /* OpenGLES.framework in Frameworks */, @@ -517,7 +517,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5AE0E3135E6006BAC0B /* libSDL.a in Frameworks */, + FDBDE5AE0E3135E6006BAC0B /* libSDL2.a in Frameworks */, FDD2C1770E2E52C000B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C1780E2E52C000B7A85F /* QuartzCore.framework in Frameworks */, FDD2C1790E2E52C000B7A85F /* OpenGLES.framework in Frameworks */, @@ -532,7 +532,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5B60E3135FE006BAC0B /* libSDL.a in Frameworks */, + FDBDE5B60E3135FE006BAC0B /* libSDL2.a in Frameworks */, FDD2C19B0E2E534F00B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C19C0E2E534F00B7A85F /* QuartzCore.framework in Frameworks */, FDD2C19D0E2E534F00B7A85F /* OpenGLES.framework in Frameworks */, @@ -547,7 +547,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5BC0E31364D006BAC0B /* libSDL.a in Frameworks */, + FDBDE5BC0E31364D006BAC0B /* libSDL2.a in Frameworks */, FDD2C4540E2E773800B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C4550E2E773800B7A85F /* QuartzCore.framework in Frameworks */, FDD2C4560E2E773800B7A85F /* OpenGLES.framework in Frameworks */, @@ -562,7 +562,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5C20E313663006BAC0B /* libSDL.a in Frameworks */, + FDBDE5C20E313663006BAC0B /* libSDL2.a in Frameworks */, FDD2C4720E2E77D700B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C4730E2E77D700B7A85F /* QuartzCore.framework in Frameworks */, FDD2C4740E2E77D700B7A85F /* OpenGLES.framework in Frameworks */, @@ -577,7 +577,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5C60E3136F1006BAC0B /* libSDL.a in Frameworks */, + FDBDE5C60E3136F1006BAC0B /* libSDL2.a in Frameworks */, FDD2C5010E2E7F4800B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C5020E2E7F4800B7A85F /* QuartzCore.framework in Frameworks */, FDD2C5030E2E7F4800B7A85F /* OpenGLES.framework in Frameworks */, @@ -592,7 +592,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5C80E313702006BAC0B /* libSDL.a in Frameworks */, + FDBDE5C80E313702006BAC0B /* libSDL2.a in Frameworks */, FDD2C51F0E2E807600B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C5200E2E807600B7A85F /* QuartzCore.framework in Frameworks */, FDD2C5210E2E807600B7A85F /* OpenGLES.framework in Frameworks */, @@ -607,7 +607,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5CA0E313712006BAC0B /* libSDL.a in Frameworks */, + FDBDE5CA0E313712006BAC0B /* libSDL2.a in Frameworks */, FDD2C5440E2E80E400B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C5450E2E80E400B7A85F /* QuartzCore.framework in Frameworks */, FDD2C5460E2E80E400B7A85F /* OpenGLES.framework in Frameworks */, @@ -622,7 +622,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5CC0E31372B006BAC0B /* libSDL.a in Frameworks */, + FDBDE5CC0E31372B006BAC0B /* libSDL2.a in Frameworks */, FDD2C57D0E2E8C7400B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C57E0E2E8C7400B7A85F /* QuartzCore.framework in Frameworks */, FDD2C57F0E2E8C7400B7A85F /* OpenGLES.framework in Frameworks */, @@ -637,7 +637,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5CE0E31373E006BAC0B /* libSDL.a in Frameworks */, + FDBDE5CE0E31373E006BAC0B /* libSDL2.a in Frameworks */, FDD2C5BB0E2E8CFC00B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C5BC0E2E8CFC00B7A85F /* QuartzCore.framework in Frameworks */, FDD2C5BD0E2E8CFC00B7A85F /* OpenGLES.framework in Frameworks */, @@ -652,7 +652,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FDBDE5D40E313789006BAC0B /* libSDL.a in Frameworks */, + FDBDE5D40E313789006BAC0B /* libSDL2.a in Frameworks */, FDD2C6EA0E2E959E00B7A85F /* AudioToolbox.framework in Frameworks */, FDD2C6EB0E2E959E00B7A85F /* QuartzCore.framework in Frameworks */, FDD2C6EC0E2E959E00B7A85F /* OpenGLES.framework in Frameworks */, @@ -711,7 +711,7 @@ FD1B48AD0E3131CA007AB34E /* Products */ = { isa = PBXGroup; children = ( - FD1B48B80E3131CA007AB34E /* libSDL.a */, + FD1B48B80E3131CA007AB34E /* libSDL2.a */, 0466EE7011E565E4000198A4 /* testsdl.app */, ); name = Products; @@ -1234,10 +1234,10 @@ remoteRef = 0466EE6F11E565E4000198A4 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - FD1B48B80E3131CA007AB34E /* libSDL.a */ = { + FD1B48B80E3131CA007AB34E /* libSDL2.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; - path = libSDL.a; + path = libSDL2.a; remoteRef = FD1B48B70E3131CA007AB34E /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; diff --git a/android-project/AndroidManifest.xml b/android-project/AndroidManifest.xml index 182232582..8fbb3e6af 100644 --- a/android-project/AndroidManifest.xml +++ b/android-project/AndroidManifest.xml @@ -3,6 +3,9 @@ package="org.libsdl.app" android:versionCode="1" android:versionName="1.0"> + + + diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 1cc17a9f7..8c85428ad 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -9,6 +9,7 @@ import android.app.*; import android.content.*; import android.view.*; +import android.view.inputmethod.InputMethodManager; import android.os.*; import android.util.Log; import android.graphics.*; @@ -106,13 +107,33 @@ protected void onDestroy() { } // Messages from the SDLMain thread - static int COMMAND_CHANGE_TITLE = 1; + static final int COMMAND_CHANGE_TITLE = 1; + static final int COMMAND_KEYBOARD_SHOW = 2; // Handler for the messages Handler commandHandler = new Handler() { + @Override public void handleMessage(Message msg) { - if (msg.arg1 == COMMAND_CHANGE_TITLE) { + switch (msg.arg1) { + case COMMAND_CHANGE_TITLE: setTitle((String)msg.obj); + break; + case COMMAND_KEYBOARD_SHOW: + InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); + if (manager != null) { + switch (((Integer)msg.obj).intValue()) { + case 0: + manager.hideSoftInputFromWindow(mSurface.getWindowToken(), 0); + break; + case 1: + manager.showSoftInput(mSurface, 0); + break; + case 2: + manager.toggleSoftInputFromWindow(mSurface.getWindowToken(), 0, 0); + break; + } + } + break; } } }; @@ -155,6 +176,10 @@ public static void setActivityTitle(String title) { mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); } + public static void sendMessage(int command, int param) { + mSingleton.sendCommand(command, Integer.valueOf(param)); + } + public static Context getContext() { return mSingleton; } @@ -590,4 +615,3 @@ public void onSensorChanged(SensorEvent event) { } } - diff --git a/include/SDL_keyboard.h b/include/SDL_keyboard.h index 16c33b59d..fc8abcc73 100644 --- a/include/SDL_keyboard.h +++ b/include/SDL_keyboard.h @@ -171,6 +171,78 @@ extern DECLSPEC void SDLCALL SDL_StopTextInput(void); */ extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect); +/** + * \brief Returns whether the platform has some screen keyboard support. + * + * \param window The window for which screen keyboard should be checked. + * + * \return SDL_TRUE if some keyboard support is available else SDL_FALSE. + * + * \note Not all screen keyboard functions are supported on all platforms. + * + * \sa SDL_ShowScreenKeyboard() + * \sa SDL_HideScreenKeyboard() + * \sa SDL_IsScreenKeyboardShown() + * \sa SDL_ToggleScreenKeyboard() + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(SDL_Window *window); + +/** + * \brief Requests to show a screen keyboard for given window. + * + * \param window The window for which screen keyboard should be shown. + * + * \return 0 if request will be processed or -1 on error (e.g. no support). + * + * \note Showing screen keyboards is asynchronous on some platforms. + * + * \sa SDL_HasScreenKeyboardSupport() + * \sa SDL_HideScreenKeyboard() + */ +extern DECLSPEC int SDLCALL SDL_ShowScreenKeyboard(SDL_Window *window); + +/** + * \brief Requests to hide a screen keyboard for given window. + * + * \param window The window for which screen keyboard should be shown. + * + * \return 0 if request will be processed or -1 on error (e.g. no support). + * + * \note Hiding screen keyboards is asynchronous on some platforms. + * + * \sa SDL_HasScreenKeyboardSupport() + * \sa SDL_ShowScreenKeyboard() + */ +extern DECLSPEC int SDLCALL SDL_HideScreenKeyboard(SDL_Window *window); + +/** + * \brief Requests to toggle a screen keyboard for given window. + * + * \param window The window for which screen keyboard should be toggled. + * + * \return 0 if request will be processed or -1 on error (e.g. no support). + * + * \note Showing and hiding screen keyboards is asynchronous on some platforms. + * + * \sa SDL_HasScreenKeyboardSupport() + * \sa SDL_IsScreenKeyboardShown() + */ +extern DECLSPEC int SDLCALL SDL_ToggleScreenKeyboard(SDL_Window * window); + +/** + * \brief Returns whether the screen keyboard is shown for given window. + * + * \param window The window for which screen keyboard should be queried. + * + * \return SDL_TRUE if screen keyboard is shown else SDL_FALSE. + * + * \note May always return SDL_FALSE on some platforms (not implemented there). + * + * \sa SDL_HasScreenKeyboardSupport() + * \sa SDL_ShowScreenKeyboard() + * \sa SDL_HideScreenKeyboard() + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL_system.h b/include/SDL_system.h index feb4d36c4..08dde6c40 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -30,6 +30,11 @@ #include "SDL_stdinc.h" +#if __IPHONEOS__ +#include "SDL_video.h" +#include "SDL_keyboard.h" +#endif + #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -40,15 +45,13 @@ extern "C" { #if __IPHONEOS__ -#include "SDL_video.h" - extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam); extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window); -extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window); +#define SDL_iPhoneKeyboardShow SDL_ShowScreenKeyboard +#define SDL_iPhoneKeyboardHide SDL_HideScreenKeyboard +#define SDL_iPhoneKeyboardToggle SDL_ToggleScreenKeyboard +#define SDL_iPhoneKeyboardIsShown SDL_IsScreenKeyboardShown #endif diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 116ffd502..1fe3e40a9 100755 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -735,6 +735,21 @@ extern "C" int Android_JNI_FileClose(SDL_RWops* ctx) return Android_JNI_FileClose(ctx, true); } +// sends message to be handled on the UI event dispatch thread +extern "C" int Android_JNI_SendMessage(int command, int param) +{ + JNIEnv *env = Android_JNI_GetEnv(); + if (!env) { + return -1; + } + jmethodID mid = env->GetStaticMethodID(mActivityClass, "sendMessage", "(II)V"); + if (!mid) { + return -1; + } + env->CallStaticVoidMethod(mActivityClass, mid, command, param); + return 0; +} + #endif /* __ANDROID__ */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index d0f761f4a..cd9a85052 100755 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -53,6 +53,9 @@ static void Android_JNI_ThreadDestroyed(void*); JNIEnv *Android_JNI_GetEnv(void); int Android_JNI_SetupThread(void); +// Generic messages +int Android_JNI_SendMessage(int command, int param); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus /* *INDENT-OFF* */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 61faa7c49..26e51ba22 100755 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -233,6 +233,13 @@ struct SDL_VideoDevice void (*StopTextInput) (_THIS); void (*SetTextInputRect) (_THIS, SDL_Rect *rect); + /* Screen keyboard */ + SDL_bool (*SDL_HasScreenKeyboardSupport) (_THIS, SDL_Window *window); + int (*SDL_ShowScreenKeyboard) (_THIS, SDL_Window *window); + int (*SDL_HideScreenKeyboard) (_THIS, SDL_Window *window); + int (*SDL_ToggleScreenKeyboard) (_THIS, SDL_Window *window); + SDL_bool (*SDL_IsScreenKeyboardShown) (_THIS, SDL_Window *window); + /* Clipboard */ int (*SetClipboardText) (_THIS, const char *text); char * (*GetClipboardText) (_THIS); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0778c233a..f40856959 100755 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2753,4 +2753,49 @@ SDL_SetTextInputRect(SDL_Rect *rect) } } +SDL_bool +SDL_HasScreenKeyboardSupport(SDL_Window *window) +{ + if (window && _this && _this->SDL_HasScreenKeyboardSupport) { + return _this->SDL_HasScreenKeyboardSupport(_this, window); + } + return SDL_FALSE; +} + +int +SDL_ShowScreenKeyboard(SDL_Window *window) +{ + if (window && _this && _this->SDL_ShowScreenKeyboard) { + return _this->SDL_ShowScreenKeyboard(_this, window); + } + return -1; +} + +int +SDL_HideScreenKeyboard(SDL_Window *window) +{ + if (window && _this && _this->SDL_HideScreenKeyboard) { + return _this->SDL_HideScreenKeyboard(_this, window); + } + return -1; +} + +int +SDL_ToggleScreenKeyboard(SDL_Window *window) +{ + if (window && _this && _this->SDL_ToggleScreenKeyboard) { + return _this->SDL_ToggleScreenKeyboard(_this, window); + } + return -1; +} + +SDL_bool +SDL_IsScreenKeyboardShown(SDL_Window *window) +{ + if (window && _this && _this->SDL_IsScreenKeyboardShown) { + return _this->SDL_IsScreenKeyboardShown(_this, window); + } + return SDL_FALSE; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index e4de1b965..597d371af 100755 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -178,6 +178,40 @@ Android_OnKeyUp(int keycode) return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode)); } +// has to fit Activity constant +#define COMMAND_KEYBOARD_SHOW 2 + +SDL_bool +Android_HasScreenKeyboardSupport(_THIS, SDL_Window * window) +{ + return Android_Window ? SDL_TRUE : SDL_FALSE; +} + +int +Android_ShowScreenKeyboard(_THIS, SDL_Window * window) +{ + return Android_Window ? Android_JNI_SendMessage(COMMAND_KEYBOARD_SHOW, 1) : -1; +} + +int +Android_HideScreenKeyboard(_THIS, SDL_Window * window) +{ + + return Android_Window ? Android_JNI_SendMessage(COMMAND_KEYBOARD_SHOW, 0) : -1; +} + +int +Android_ToggleScreenKeyboard(_THIS, SDL_Window * window) +{ + return Android_Window ? Android_JNI_SendMessage(COMMAND_KEYBOARD_SHOW, 2) : -1; +} + +SDL_bool +Android_IsScreenKeyboardShown(_THIS, SDL_Window * window) +{ + return SDL_FALSE; +} + #endif /* SDL_VIDEO_DRIVER_ANDROID */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidkeyboard.h b/src/video/android/SDL_androidkeyboard.h index df17cf1d1..c1f3b5263 100755 --- a/src/video/android/SDL_androidkeyboard.h +++ b/src/video/android/SDL_androidkeyboard.h @@ -26,4 +26,10 @@ extern void Android_InitKeyboard(); extern int Android_OnKeyDown(int keycode); extern int Android_OnKeyUp(int keycode); +extern SDL_bool Android_HasScreenKeyboardSupport(_THIS, SDL_Window * window); +extern int Android_ShowScreenKeyboard(_THIS, SDL_Window * window); +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); + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 047488c55..8095e5b4f 100755 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -119,6 +119,13 @@ Android_CreateDevice(int devindex) device->GL_SwapWindow = Android_GL_SwapWindow; device->GL_DeleteContext = Android_GL_DeleteContext; + /* Screen keyboard */ + device->SDL_HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport; + device->SDL_ShowScreenKeyboard = Android_ShowScreenKeyboard; + device->SDL_HideScreenKeyboard = Android_HideScreenKeyboard; + device->SDL_ToggleScreenKeyboard = Android_ToggleScreenKeyboard; + device->SDL_IsScreenKeyboardShown = Android_IsScreenKeyboardShown; + return device; } diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 420906aa9..9c724d7c8 100755 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -89,6 +89,11 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device) device->DestroyWindow = UIKit_DestroyWindow; device->GetWindowWMInfo = UIKit_GetWindowWMInfo; + device->SDL_HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport; + device->SDL_ShowScreenKeyboard = UIKit_ShowScreenKeyboard; + device->SDL_HideScreenKeyboard = UIKit_HideScreenKeyboard; + device->SDL_ToggleScreenKeyboard = UIKit_ToggleScreenKeyboard; + device->SDL_IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown; /* OpenGL (ES) functions */ device->GL_MakeCurrent = UIKit_GL_MakeCurrent; diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index b9aad299a..3b5e838c4 100755 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -60,6 +60,13 @@ - (void)hideKeyboard; - (void)initializeKeyboard; @property (readonly) BOOL keyboardVisible; + +SDL_bool UIKit_HasScreenKeyboardSupport(_THIS, SDL_Window *window); +int UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window); +int UIKit_HideScreenKeyboard(_THIS, SDL_Window *window); +int UIKit_ToggleScreenKeyboard(_THIS, SDL_Window *window); +SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window); + #endif @end diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index b6c4cf867..9c9362525 100755 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -343,7 +343,17 @@ - (BOOL)textFieldShouldReturn:(UITextField*)_textField return view; } -int SDL_iPhoneKeyboardShow(SDL_Window * window) +SDL_bool UIKit_HasScreenKeyboardSupport(_THIS, SDL_Window *window) +{ + SDL_uikitview *view = getWindowView(window); + if (view == nil) { + return SDL_FALSE; + } + + return SDL_TRUE; +} + +int UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window) { SDL_uikitview *view = getWindowView(window); if (view == nil) { @@ -354,7 +364,7 @@ int SDL_iPhoneKeyboardShow(SDL_Window * window) return 0; } -int SDL_iPhoneKeyboardHide(SDL_Window * window) +int UIKit_HideScreenKeyboard(_THIS, SDL_Window *window) { SDL_uikitview *view = getWindowView(window); if (view == nil) { @@ -365,7 +375,7 @@ int SDL_iPhoneKeyboardHide(SDL_Window * window) return 0; } -SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) +SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window) { SDL_uikitview *view = getWindowView(window); if (view == nil) { @@ -375,49 +385,22 @@ SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) return view.keyboardVisible; } -int SDL_iPhoneKeyboardToggle(SDL_Window * window) +int UIKit_ToggleScreenKeyboard(_THIS, SDL_Window *window) { SDL_uikitview *view = getWindowView(window); if (view == nil) { return -1; } - if (SDL_iPhoneKeyboardIsShown(window)) { - SDL_iPhoneKeyboardHide(window); + if (UIKit_IsScreenKeyboardShown(_this, window)) { + UIKit_HideScreenKeyboard(_this, window); } else { - SDL_iPhoneKeyboardShow(window); + UIKit_ShowScreenKeyboard(_this, window); } return 0; } -#else - -/* stubs, used if compiled without keyboard support */ - -int SDL_iPhoneKeyboardShow(SDL_Window * window) -{ - SDL_SetError("Not compiled with keyboard support"); - return -1; -} - -int SDL_iPhoneKeyboardHide(SDL_Window * window) -{ - SDL_SetError("Not compiled with keyboard support"); - return -1; -} - -SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) -{ - return 0; -} - -int SDL_iPhoneKeyboardToggle(SDL_Window * window) -{ - SDL_SetError("Not compiled with keyboard support"); - return -1; -} - #endif /* SDL_IPHONE_KEYBOARD */ #endif /* SDL_VIDEO_DRIVER_UIKIT */ diff --git a/test/checkkeys.c b/test/checkkeys.c index a30517b6e..421ede4a7 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -138,10 +138,6 @@ PrintText(char *text) SDL_Log("Text: %s", text); } -#if __IPHONEOS__ -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window); -#endif - int main(int argc, char *argv[]) { @@ -168,9 +164,11 @@ main(int argc, char *argv[]) #if __IPHONEOS__ /* Creating the context creates the view, which we need to show keyboard */ SDL_GL_CreateContext(window); - SDL_iPhoneKeyboardShow(window); #endif - + + if (SDL_HasScreenKeyboardSupport(window)) { + SDL_ShowScreenKeyboard(window); + } /* Watch keystrokes */ done = 0;