Added iOS text field dialog listener
This commit is contained in:
@@ -26,7 +26,7 @@ public class TextFieldDialogListener extends ClickListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void add(TextField field){
|
public static void add(TextField field){
|
||||||
add(field, 0, 15);
|
add(field, 0, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
//type - 0 is text, 1 is numbers, 2 is decimals
|
//type - 0 is text, 1 is numbers, 2 is decimals
|
||||||
|
|||||||
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#Sat Apr 28 09:57:33 EDT 2018
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
|
||||||
|
|||||||
@@ -4,16 +4,53 @@ import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
|
|||||||
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
|
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
|
||||||
import io.anuke.kryonet.KryoClient;
|
import io.anuke.kryonet.KryoClient;
|
||||||
import io.anuke.kryonet.KryoServer;
|
import io.anuke.kryonet.KryoServer;
|
||||||
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.ucore.scene.ui.TextField;
|
||||||
import org.robovm.apple.foundation.NSAutoreleasePool;
|
import org.robovm.apple.foundation.NSAutoreleasePool;
|
||||||
import org.robovm.apple.uikit.UIApplication;
|
import org.robovm.apple.uikit.UIApplication;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class IOSLauncher extends IOSApplication.Delegate {
|
public class IOSLauncher extends IOSApplication.Delegate {
|
||||||
@Override
|
@Override
|
||||||
protected IOSApplication createApplication() {
|
protected IOSApplication createApplication() {
|
||||||
Net.setClientProvider(new KryoClient());
|
Net.setClientProvider(new KryoClient());
|
||||||
Net.setServerProvider(new KryoServer());
|
Net.setServerProvider(new KryoServer());
|
||||||
|
|
||||||
|
Platform.instance = new Platform() {
|
||||||
|
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(Date date) {
|
||||||
|
return format.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(int number) {
|
||||||
|
return NumberFormat.getIntegerInstance().format(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDialog(TextField field) {
|
||||||
|
TextFieldDialogListener.add(field, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDialog(TextField field, int maxLength) {
|
||||||
|
TextFieldDialogListener.add(field, maxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLocaleName(Locale locale) {
|
||||||
|
return locale.getDisplayName(locale);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
|
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
|
||||||
return new IOSApplication(new Mindustry(), config);
|
return new IOSApplication(new Mindustry(), config);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,104 @@
|
|||||||
package io.anuke.mindustry;
|
package io.anuke.mindustry;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import io.anuke.ucore.scene.event.ClickListener;
|
||||||
|
import io.anuke.ucore.scene.event.InputEvent;
|
||||||
|
import io.anuke.ucore.scene.event.InputListener;
|
||||||
|
import io.anuke.ucore.scene.ui.TextField;
|
||||||
|
import org.robovm.apple.foundation.NSRange;
|
||||||
|
import org.robovm.apple.uikit.*;
|
||||||
|
import org.robovm.rt.bro.annotation.ByVal;
|
||||||
|
|
||||||
public class TextFieldDialogListener {
|
public class TextFieldDialogListener {
|
||||||
|
|
||||||
|
public static void add(TextField field, int maxLength){
|
||||||
|
field.addListener(new ClickListener(){
|
||||||
|
public void clicked(final InputEvent event, float x, float y){
|
||||||
|
show(field, maxLength);
|
||||||
|
event.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
field.addListener(new InputListener(){
|
||||||
|
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||||
|
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void show(TextField field, int maxLength){
|
||||||
|
|
||||||
|
UIAlertViewDelegateAdapter delegate = new UIAlertViewDelegateAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void didDismiss(UIAlertView alertView, long buttonIndex) {
|
||||||
|
if (buttonIndex == 1) {
|
||||||
|
UITextField textField = alertView.getTextField(0);
|
||||||
|
final String result = textField.getText();
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(() -> {
|
||||||
|
field.setText(result);
|
||||||
|
field.change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clicked(UIAlertView alertView, long buttonIndex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel(UIAlertView alertView) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void willPresent(UIAlertView alertView) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void didPresent(UIAlertView alertView) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void willDismiss(UIAlertView alertView, long buttonIndex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldEnableFirstOtherButton(UIAlertView alertView) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
String[] otherButtons = new String[1];
|
||||||
|
otherButtons[0] = "OK";
|
||||||
|
|
||||||
|
UIAlertView alertView = new UIAlertView("", "", delegate, "Cancel", otherButtons);
|
||||||
|
|
||||||
|
alertView.setAlertViewStyle(UIAlertViewStyle.PlainTextInput);
|
||||||
|
|
||||||
|
UITextField uiTextField = alertView.getTextField(0);
|
||||||
|
|
||||||
|
uiTextField.setDelegate(new UITextFieldDelegateAdapter() {
|
||||||
|
@Override
|
||||||
|
public boolean shouldChangeCharacters(UITextField textField, @ByVal NSRange nsRange, String additionalText) {
|
||||||
|
|
||||||
|
if (textField.getText().length() + additionalText.length() > maxLength) {
|
||||||
|
String oldText = textField.getText();
|
||||||
|
String newText = oldText + additionalText;
|
||||||
|
textField.setText(newText.substring(0, maxLength));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alertView.show();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user