use of playn.core.Keyboard in project playn by threerings.
the class GetTextTest method init.
@Override
public void init() {
String instructions = "Click one of the buttons below to display the text entry UI.";
ImageLayer instLayer = graphics().createImageLayer(formatText(instructions, false));
graphics().rootLayer().addAt(instLayer, 50, 50);
String last = storage().getItem("last_text");
if (last == null)
last = "...";
final ImageLayer outputLayer = graphics().createImageLayer(formatText(last, false));
graphics().rootLayer().addAt(outputLayer, 50, 150);
final Callback<String> onGotText = new Callback<String>() {
public void onSuccess(String text) {
outputLayer.setImage(formatText(text == null ? "canceled" : text, false));
if (text != null)
storage().setItem("last_text", text);
}
public void onFailure(Throwable cause) {
outputLayer.setImage(formatText(cause.getMessage(), false));
}
};
float x = 50;
for (final Keyboard.TextType type : Keyboard.TextType.values()) {
ImageLayer button = createButton(type.toString(), new Runnable() {
public void run() {
keyboard().getText(Keyboard.TextType.DEFAULT, "Enter " + type + " text:", "", onGotText);
}
});
graphics().rootLayer().addAt(button, x, 100);
x += button.width() + 10;
}
}
Aggregations