Finish all editor features
This commit is contained in:
@@ -15,6 +15,7 @@ import android.os.Bundle;
|
||||
import android.telephony.TelephonyManager;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class AndroidLauncher extends AndroidApplication{
|
||||
@@ -47,6 +48,11 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW, marketUri );
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDialog(TextField field){
|
||||
TextFieldDialogListener.add(field);
|
||||
}
|
||||
};
|
||||
|
||||
Mindustry.donationsCallable = new Callable(){ @Override public void run(){ showDonations(); } };
|
||||
|
||||
135
android/src/io/anuke/mindustry/AndroidTextFieldDialog.java
Normal file
135
android/src/io/anuke/mindustry/AndroidTextFieldDialog.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.text.InputFilter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class AndroidTextFieldDialog{
|
||||
private Activity activity;
|
||||
private EditText userInput;
|
||||
private AlertDialog.Builder builder;
|
||||
private TextPromptListener listener;
|
||||
private boolean isBuild;
|
||||
|
||||
public AndroidTextFieldDialog() {
|
||||
this.activity = (Activity)Gdx.app;
|
||||
load();
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog show() {
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gdx.app.error("Android Dialogs", AndroidTextFieldDialog.class.getSimpleName() + " now shown.");
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private AndroidTextFieldDialog load() {
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
|
||||
LayoutInflater li = LayoutInflater.from(activity);
|
||||
|
||||
View promptsView = li.inflate(getResourceId("gdxdialogs_inputtext", "layout"), null);
|
||||
|
||||
alertDialogBuilder.setView(promptsView);
|
||||
|
||||
userInput = (EditText) promptsView.findViewById(getResourceId("gdxDialogsEditTextInput", "id"));
|
||||
|
||||
alertDialogBuilder.setCancelable(false);
|
||||
builder = alertDialogBuilder;
|
||||
|
||||
isBuild = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Wait till TextPrompt is built.
|
||||
while (!isBuild) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getResourceId(String pVariableName, String pVariableType) {
|
||||
try {
|
||||
return activity.getResources().getIdentifier(pVariableName, pVariableType, activity.getPackageName());
|
||||
} catch (Exception e) {
|
||||
Gdx.app.error("Android Dialogs", "Cannot find resouce with name: " + pVariableName
|
||||
+ " Did you copy the layouts to /res/layouts and /res/layouts_v14 ?");
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setText(CharSequence value) {
|
||||
userInput.append(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setCancelButtonLabel(CharSequence label) {
|
||||
builder.setNegativeButton(label, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setConfirmButtonLabel(CharSequence label) {
|
||||
builder.setPositiveButton(label, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (listener != null && !userInput.getText().toString().isEmpty()) {
|
||||
listener.confirm(userInput.getText().toString());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setTextPromptListener(TextPromptListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setInputType(int type) {
|
||||
userInput.setInputType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidTextFieldDialog setMaxLength(int length) {
|
||||
userInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(length) });
|
||||
return this;
|
||||
}
|
||||
|
||||
public static interface TextPromptListener{
|
||||
public void confirm(String text);
|
||||
}
|
||||
|
||||
}
|
||||
71
android/src/io/anuke/mindustry/TextFieldDialogListener.java
Normal file
71
android/src/io/anuke/mindustry/TextFieldDialogListener.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import android.text.InputType;
|
||||
import io.anuke.mindustry.AndroidTextFieldDialog.TextPromptListener;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.utils.ChangeListener;
|
||||
import io.anuke.ucore.scene.utils.ClickListener;
|
||||
|
||||
public class TextFieldDialogListener extends ClickListener{
|
||||
private TextField field;
|
||||
private int type;
|
||||
private int max;
|
||||
|
||||
public static void add(TextField field, int type, int max){
|
||||
field.addListener(new TextFieldDialogListener(field, type, max));
|
||||
field.addListener(new InputListener(){
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void add(TextField field){
|
||||
add(field, 0, 15);
|
||||
}
|
||||
|
||||
//type - 0 is text, 1 is numbers, 2 is decimals
|
||||
public TextFieldDialogListener(TextField field, int type, int max){
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public void clicked(final InputEvent event, float x, float y){
|
||||
|
||||
if(Gdx.app.getType() == ApplicationType.Desktop) return;
|
||||
|
||||
AndroidTextFieldDialog dialog = new AndroidTextFieldDialog();
|
||||
|
||||
dialog.setTextPromptListener(new TextPromptListener(){
|
||||
public void confirm(String text){
|
||||
field.clearText();
|
||||
field.appendText(text);
|
||||
field.fire(new ChangeListener.ChangeEvent());
|
||||
Gdx.graphics.requestRendering();
|
||||
}
|
||||
});
|
||||
|
||||
if(type == 0){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}else if(type == 1){
|
||||
dialog.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
}else if(type == 2){
|
||||
dialog.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
}
|
||||
|
||||
dialog.setConfirmButtonLabel("OK").setText(field.getText());
|
||||
dialog.setCancelButtonLabel("Cancel");
|
||||
dialog.setMaxLength(max);
|
||||
dialog.show();
|
||||
event.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user