Finish all editor features
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_root"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/gdxDialogsEditTextInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:maxLength="15"
|
||||
>
|
||||
|
||||
<requestFocus />
|
||||
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_root"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gdxDialogsEnterTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
|
||||
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gdxDialogsEnterMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
|
||||
|
||||
/>
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/gdxDialogsEditTextInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:maxLength="15"
|
||||
>
|
||||
|
||||
<requestFocus />
|
||||
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -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(); } };
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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