Well, I found that implementing the KeyboardView was going to be much more work than I thought it was worth. After taking a step back, I decided to implement something else entirely. Maybe it’s just lazyness, but to do it right, I would have needed to implement a whole Input Manager for the keyboard which I didn’t think was worth it.
Instead, I implemented a way for the engine to fire off an event that would start up an alert box on the android side for the user to type in whatever they want with the default Android keyboard. Once the alert box text entry is complete, the entire string is then returned to the caller so that they can do whatever they want with the text.
I have this working with Nifty textfields. Basically, when the text is returned to my screen controller, I then take the text and set the textfield text. I think this is probably better for a couple of reasons:
1. Users will use whatever keyboard they have defined
2. Every individual key code does not need to be implemented in JME since it just uses the resulting string
3. Future chat style implementations can also use this method to create strings to send over the network
Anyway, I’ll need another day or 2 to create the patch files, but the general changes are in:
AndroidHarness – creates the dialog box and returns the resulting text
SoftTextDialogInput – new interface for the engine to call to start the dialog box. This is currently located in package com.jme3.input so that it can be used for other platforms in the future (ie. iPhone, etc)
SoftTextDialogInputListener – new interface to send back the completed text
InputManager – added setters and getters for the SoftTextDialogInput class to use to create the dialog
AndroidInput – sets the SoftTextDialogInput in InputManager to AndroidHarness. Other platforms would set variable in InputManager to thier own implementations in their own contexts
As I said, I have it all working in a modified version of the engine. The user implentation is the following:
In the Nifty XML file, I have an onClick interaction defined to call a routine in the Screen Controller. In the Screen Controller, I have the following:
public void changeGravity() {
logger.log(Level.INFO,"changeGravity");
TextField textField = screen.findNiftyControl("txtGravity", TextField.class);
String initialValue = "";
if (textField != null) {
initialValue = textField.getText();
} else {
logger.log(Level.INFO, "textField is null getting initial value");
}
SoftTextDialogInput softTextDialogInput = app.getInputManager().getSoftTextDialogInput();
if (softTextDialogInput != null) {
logger.log(Level.INFO, "Requesting soft dialog input");
softTextDialogInput.requestDialog(SoftTextDialogInput.NUMERIC_ENTRY_DIALOG, "Gravity", initialValue, new SoftTextDialogInputListener() {
public void onSoftText(int action, String text) {
logger.log(Level.INFO, "onTextDialogDismissed: action: {0}, text: {1}",
new Object[]{action, text});
if (action == SoftTextDialogInputListener.COMPLETE) {
TextField textField = screen.findNiftyControl("txtGravity", TextField.class);
if (textField != null) {
textField.setText(text);
} else {
logger.log(Level.INFO, "textField is null in Results Listener");
}
}
}
});
} else {
logger.log(Level.INFO, "softTextDialogInput is null");
}
}
The above calls the Dialog creation interface and takes the returned text string and sets the TextField back in Nifty. No other user code is necessary.
@nehon I know it’s a lot to take in without playing with it, but let me know what you think.
EDIT: In case you’re wondering, this doesn’t affect the PC version. If the PC version is being executed, SoftTextDialogInput in InputManager is null and the code is skipped and the PC keyboard still works to set the text in the textfield.