Adam: I have done the work of merging my work with the current MOAI 1.2 release, you can see it here:https://github.com/seclorum/moai-dev/
This is working - but only if your Android package is named "at/allaboutapps/test/moaikeyboard" ..
So what I need to do (before I submit a pull request to merge with mainline moai-dev) is replace the code on line #38 here (as well as everywhere else the classpath is hardcoded):https://github.com/seclorum/moai-dev/bl ... ndroid.cpp
.. with some sort of generic way of getting the package class path, so that instead of having a hard-coded:
- Code: Select all
jclass moai = env->FindClass ( "at/allaboutapps/test/moaikeyboard/MoaiActivity" );
.. I replace that "at/allaboutapps/test/moaikeyboard" bit with the "get current class path for the outer activity that is using this JNI call" code.
Trouble is, I am currently not sure how to do that. Anyone got any ideas? This is the last thing I need to do (plus a few comment cleanups, plus add a sample to the archive) before I do the pull request. I know a few of you are waiting for this, so if anyone has any ideas - please let me know and I'll give it a lot of attention to get this pull request made.
(In the meantime, if anyone desperately needs Android keyboard support - simply clone my repo, and change those hard-coded paths to whatever your package name is, and you should find that it works quite well..)
CAVEAT: Keyboard type switching is currently not implemented (i.e. changing to a numpad keyboard, or numeric, or ascii, etc.) This is something in the TODO.
EDIT: One more thing that needs to be done - make the same changes to make-host.bat that I made to make-host.sh in order to properly handle packagename replacement when creating a new Android host folder. I don't have a Windows machine, so I can't test this - so if someone else wants to do that work it would be very much appreciated, and please do a pull request so I can merge it before submitting it to mainline moai-dev ..
EDIT+1: I just wanted to describe this work to newcomers. The purpose of this code is to have a working MOAIKeyboardAndroid object within MOAI - equivalent to the existing MOAIKeyboardIOS object. The way the MOAIKeyboardIOS object works is that NSTextFieldDelegate is used to 'hook' into the keyboard input and provide the host client with a means of trapping keyboard events - so that live entry can occur in the MOAI host, each letter pressed results in a notification, etc.
On Android, I have implemented it in a similar way - albeit with the added complication of having JNI->Dalvik->LUA-VM paths to deal with. The Android host sources were modified to include an extension to LinearLayout, called LinearLayoutIMETrap, and the main layout now has a hidden EditText view - the main MOAI GL View still exists, and still takes over the whole screen, except that there is now another layout hidden off-screen which includes a real EditText. The advantage to this - in frameworks like moaigui, the keyboard/input/field updates inherit the behaviour of the native EditText view.
When MOAIKeyboardAndroid.showKeyboard() is called, the Android host pops up the soft keyboard, and input focus is set on the hidden EditText. All keypresses are trapped through the LinearLayoutIMETrap, so that we can catch BACK button presses (necessary!), and then dispatched through the NDK, into the Lua VM, for handling by whatever keypress handler has been assigned in the Lua side of things. PHEW!
It actually works very well, and is what we ended up using for Android keyboard support in some of our apps. The only thing is, I can't comfortably submit a pull request for inclusion in mainline moai-dev until I solve the classpath issue described above, so if anyone has any ideas .. please let me know. I'd be happy to move on from all this and to see this code included in moai-dev mainline, if its qualified ..
ALSO: I would like to add an example to the moaigui layouts that shows how to use this properly on both iOS and Android. One thing that is interesting is that the callbacks can be set up in moaigui (not sure about hanappe) so that when the keyboard is popped up, the screen offset can be adjusted so that the currently edited text field can always be visible .. this results in a very nice looking GUI-style app, but may not be clear to newcomers .. so I will add a sample as soon as I get the rest of the code submitted for inclusion in mainline moai-dev ..