Search in sources :

Example 1 with UITextField

use of org.robovm.apple.uikit.UITextField in project libgdx by libgdx.

the class IOSInput method createDefaultTextField.

private void createDefaultTextField() {
    textfield = new UITextField(new CGRect(10, 10, 100, 50));
    //Parameters
    // Setting parameters
    textfield.setKeyboardType(UIKeyboardType.Default);
    textfield.setReturnKeyType(UIReturnKeyType.Done);
    textfield.setAutocapitalizationType(UITextAutocapitalizationType.None);
    textfield.setAutocorrectionType(UITextAutocorrectionType.No);
    textfield.setSpellCheckingType(UITextSpellCheckingType.No);
    textfield.setHidden(true);
    // Text field needs to have at least one symbol - so we can use backspace
    textfield.setText("x");
    app.getUIViewController().getView().addSubview(textfield);
}
Also used : UITextField(org.robovm.apple.uikit.UITextField) CGRect(org.robovm.apple.coregraphics.CGRect)

Example 2 with UITextField

use of org.robovm.apple.uikit.UITextField in project libgdx by libgdx.

the class IOSInput method buildUIAlertView.

/** Builds an {@link UIAlertView} with an added {@link UITextField} for inputting text.
	 * @param listener Text input listener
	 * @param title Dialog title
	 * @param text Text for text field
	 * @return UiAlertView */
private UIAlertView buildUIAlertView(final TextInputListener listener, String title, String text, String placeholder) {
    delegate = new UIAlertViewDelegateAdapter() {

        @Override
        public void clicked(UIAlertView view, long clicked) {
            if (clicked == 0) {
                // user clicked "Cancel" button
                listener.canceled();
            } else if (clicked == 1) {
                // user clicked "Ok" button
                UITextField textField = view.getTextField(0);
                listener.input(textField.getText());
            }
            delegate = null;
        }

        @Override
        public void cancel(UIAlertView view) {
            listener.canceled();
            delegate = null;
        }
    };
    // build the view
    final UIAlertView uiAlertView = new UIAlertView();
    uiAlertView.setTitle(title);
    uiAlertView.addButton("Cancel");
    uiAlertView.addButton("Ok");
    uiAlertView.setAlertViewStyle(UIAlertViewStyle.PlainTextInput);
    uiAlertView.setDelegate(delegate);
    UITextField textField = uiAlertView.getTextField(0);
    textField.setPlaceholder(placeholder);
    textField.setText(text);
    return uiAlertView;
}
Also used : UIAlertView(org.robovm.apple.uikit.UIAlertView) UIAlertViewDelegateAdapter(org.robovm.apple.uikit.UIAlertViewDelegateAdapter) UITextField(org.robovm.apple.uikit.UITextField)

Example 3 with UITextField

use of org.robovm.apple.uikit.UITextField in project playn by threerings.

the class RoboKeyboard method getText.

@Override
public void getText(TextType textType, String label, String initVal, final Callback<String> callback) {
    UIAlertView view = new UIAlertView();
    if (label != null)
        view.setTitle(label);
    view.addButton("Cancel");
    view.addButton("OK");
    view.setAlertViewStyle(UIAlertViewStyle.PlainTextInput);
    final UITextField field = view.getTextField(0);
    field.setReturnKeyType(UIReturnKeyType.Done);
    if (initVal != null) {
        field.setText(initVal);
    }
    switch(textType) {
        case NUMBER:
            field.setKeyboardType(UIKeyboardType.NumberPad);
            break;
        case EMAIL:
            field.setKeyboardType(UIKeyboardType.EmailAddress);
            break;
        case URL:
            field.setKeyboardType(UIKeyboardType.URL);
            break;
        case DEFAULT:
            field.setKeyboardType(UIKeyboardType.Default);
            break;
    }
    // TODO: Customize these per getText() call?
    field.setAutocorrectionType(UITextAutocorrectionType.Yes);
    field.setAutocapitalizationType(UITextAutocapitalizationType.Sentences);
    // TODO: if nothing else, can do this one as a TextType
    field.setSecureTextEntry(false);
    view.setDelegate(new UIAlertViewDelegateAdapter() {

        public void clicked(UIAlertView view, long buttonIndex) {
            // Cancel is at button index 0
            platform.notifySuccess(callback, buttonIndex == 0 ? null : field.getText());
        }
    });
    view.show();
}
Also used : UIAlertView(org.robovm.apple.uikit.UIAlertView) UIAlertViewDelegateAdapter(org.robovm.apple.uikit.UIAlertViewDelegateAdapter) UITextField(org.robovm.apple.uikit.UITextField)

Aggregations

UITextField (org.robovm.apple.uikit.UITextField)3 UIAlertView (org.robovm.apple.uikit.UIAlertView)2 UIAlertViewDelegateAdapter (org.robovm.apple.uikit.UIAlertViewDelegateAdapter)2 CGRect (org.robovm.apple.coregraphics.CGRect)1