Search in sources :

Example 1 with TextField

use of io.anuke.ucore.scene.ui.TextField in project Mindustry by Anuken.

the class AndroidLauncher method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.useImmersiveMode = true;
    Platform.instance = new Platform() {

        DateFormat format = SimpleDateFormat.getDateTimeInstance();

        @Override
        public boolean hasDiscord() {
            return isPackageInstalled("com.discord");
        }

        @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, int length) {
            TextFieldDialogListener.add(field, 0, length);
        }

        @Override
        public String getLocaleName(Locale locale) {
            return locale.getDisplayName(locale);
        }

        @Override
        public void openDonations() {
            showDonations();
        }

        @Override
        public void requestWritePerms() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, WRITE_REQUEST_CODE);
                } else {
                    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, WRITE_REQUEST_CODE);
                    }
                    if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, WRITE_REQUEST_CODE);
                    }
                }
            }
        }

        @Override
        public ThreadProvider getThreadProvider() {
            return new DefaultThreadImpl();
        }

        @Override
        public boolean isDebug() {
            return false;
        }

        @Override
        public byte[] getUUID() {
            try {
                String s = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
                int len = s.length();
                byte[] data = new byte[len / 2];
                for (int i = 0; i < len; i += 2) {
                    data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
                }
                return data;
            } catch (Exception e) {
                Settings.defaults("uuid", "");
                String uuid = Settings.getString("uuid");
                if (uuid.isEmpty()) {
                    byte[] result = new byte[8];
                    new Random().nextBytes(result);
                    uuid = new String(Base64Coder.encode(result));
                    Settings.putString("uuid", uuid);
                    Settings.save();
                    return result;
                }
                return Base64Coder.decode(uuid);
            }
        }
    };
    if (doubleScaleTablets && isTablet(this.getContext())) {
        Unit.dp.addition = 0.5f;
    }
    config.hideStatusBar = true;
    Net.setClientProvider(new KryoClient());
    Net.setServerProvider(new KryoServer());
    initialize(new Mindustry(), config);
}
Also used : Locale(java.util.Locale) Platform(io.anuke.mindustry.io.Platform) KryoServer(io.anuke.kryonet.KryoServer) DefaultThreadImpl(io.anuke.kryonet.DefaultThreadImpl) Date(java.util.Date) AndroidApplicationConfiguration(com.badlogic.gdx.backends.android.AndroidApplicationConfiguration) Random(java.util.Random) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TextField(io.anuke.ucore.scene.ui.TextField) ThreadProvider(io.anuke.mindustry.core.ThreadHandler.ThreadProvider) KryoClient(io.anuke.kryonet.KryoClient)

Example 2 with TextField

use of io.anuke.ucore.scene.ui.TextField in project Mindustry by Anuken.

the class UI method showTextInput.

public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer<String> confirmed) {
    new Dialog(title, "dialog") {

        {
            content().margin(30).add(text).padRight(6f);
            TextField field = content().addField(def, t -> {
            }).size(170f, 50f).get();
            field.setTextFieldFilter((f, c) -> field.getText().length() < 12 && filter.acceptChar(f, c));
            Platform.instance.addDialog(field);
            buttons().defaults().size(120, 54).pad(4);
            buttons().addButton("$text.ok", () -> {
                confirmed.accept(field.getText());
                hide();
            }).disabled(b -> field.getText().isEmpty());
            buttons().addButton("$text.cancel", this::hide);
        }
    }.show();
}
Also used : TextField(io.anuke.ucore.scene.ui.TextField) Settings(io.anuke.ucore.core.Settings) TooltipManager(io.anuke.ucore.scene.ui.TooltipManager) Skin(io.anuke.ucore.scene.Skin) Gdx(com.badlogic.gdx.Gdx) TextFieldFilter(io.anuke.ucore.scene.ui.TextField.TextFieldFilter) Graphics(io.anuke.ucore.core.Graphics) Locale(java.util.Locale) Colors(com.badlogic.gdx.graphics.Colors) Dialog(io.anuke.ucore.scene.ui.Dialog) Vars.control(io.anuke.mindustry.Vars.control) Interpolation(com.badlogic.gdx.math.Interpolation) Unit(io.anuke.ucore.scene.ui.layout.Unit) Mathf(io.anuke.ucore.util.Mathf) Vars(io.anuke.mindustry.Vars) io.anuke.mindustry.ui.fragments(io.anuke.mindustry.ui.fragments) Core(io.anuke.ucore.core.Core) Platform(io.anuke.mindustry.io.Platform) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) Draw(io.anuke.ucore.graphics.Draw) Consumer(io.anuke.ucore.function.Consumer) Listenable(io.anuke.ucore.function.Listenable) MapEditorDialog(io.anuke.mindustry.mapeditor.MapEditorDialog) SceneModule(io.anuke.ucore.modules.SceneModule) Keys(com.badlogic.gdx.Input.Keys) Actions(io.anuke.ucore.scene.actions.Actions) io.anuke.ucore.scene.builders.build(io.anuke.ucore.scene.builders.build) Timers(io.anuke.ucore.core.Timers) io.anuke.mindustry.ui.dialogs(io.anuke.mindustry.ui.dialogs) Dialog(io.anuke.ucore.scene.ui.Dialog) MapEditorDialog(io.anuke.mindustry.mapeditor.MapEditorDialog) TextField(io.anuke.ucore.scene.ui.TextField)

Example 3 with TextField

use of io.anuke.ucore.scene.ui.TextField in project Mindustry by Anuken.

the class ChatFragment method setup.

private void setup() {
    fieldlabel.setStyle(new LabelStyle(fieldlabel.getStyle()));
    fieldlabel.getStyle().font = font;
    fieldlabel.setStyle(fieldlabel.getStyle());
    chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
    chatfield.setTextFieldFilter((field, c) -> field.getText().length() < maxLength);
    chatfield.getStyle().background = null;
    chatfield.getStyle().fontColor = Color.WHITE;
    chatfield.getStyle().font = skin.getFont("default-font-chat");
    chatfield.setStyle(chatfield.getStyle());
    Platform.instance.addDialog(chatfield, maxLength);
    bottom().left().marginBottom(offsety).marginLeft(offsetx * 2).add(fieldlabel).padBottom(4f);
    add(chatfield).padBottom(offsety).padLeft(offsetx).growX().padRight(offsetx).height(28);
    if (Vars.android) {
        marginBottom(105f);
        marginRight(240f);
    }
    if (Vars.android) {
        addImageButton("icon-arrow-right", 14 * 2, this::toggle).size(46f, 51f).visible(() -> chatOpen).pad(2f);
    }
}
Also used : TextField(io.anuke.ucore.scene.ui.TextField) LabelStyle(io.anuke.ucore.scene.ui.Label.LabelStyle)

Aggregations

TextField (io.anuke.ucore.scene.ui.TextField)3 Platform (io.anuke.mindustry.io.Platform)2 Locale (java.util.Locale)2 Gdx (com.badlogic.gdx.Gdx)1 Keys (com.badlogic.gdx.Input.Keys)1 AndroidApplicationConfiguration (com.badlogic.gdx.backends.android.AndroidApplicationConfiguration)1 Color (com.badlogic.gdx.graphics.Color)1 Colors (com.badlogic.gdx.graphics.Colors)1 Interpolation (com.badlogic.gdx.math.Interpolation)1 Align (com.badlogic.gdx.utils.Align)1 DefaultThreadImpl (io.anuke.kryonet.DefaultThreadImpl)1 KryoClient (io.anuke.kryonet.KryoClient)1 KryoServer (io.anuke.kryonet.KryoServer)1 Vars (io.anuke.mindustry.Vars)1 Vars.control (io.anuke.mindustry.Vars.control)1 ThreadProvider (io.anuke.mindustry.core.ThreadHandler.ThreadProvider)1 MapEditorDialog (io.anuke.mindustry.mapeditor.MapEditorDialog)1 io.anuke.mindustry.ui.dialogs (io.anuke.mindustry.ui.dialogs)1 io.anuke.mindustry.ui.fragments (io.anuke.mindustry.ui.fragments)1 Core (io.anuke.ucore.core.Core)1