Usage

Build a Custom Setting Dialog is easy. Here is how to use them

Basic

The basic flow is this:

The Setting Dialog is shown on the screen. After pressing Save, the setting is saved so that you can get the same value when reopen the Setting.

Then for every View that is not an TextView, a Variable with the same name as the Key (more on that below) is automatically created or reassign if the Variable already exists.

Which means you can use whatever the user input as a Variable in any part of the macro.

The Key

For example if we make an EditText and we want to save what the user entered. How do we load it back? We assign the value with a Key to identify it and use the Key to retrieve its value.

After we load the value, we create a Variable with the same name as the Key so we can reference the value from any part of the macros.

As you can guess at this point, the Key must also follow Variable naming rules.

How to show the Dialog

You can show the Dialog when the macro started using the "Show at start up" in the Option of Setting Builder.

You can manually open it by going to the Setting tab in Play Mode and click on Custom Settings.

Or you can show it anytime by calling Setting.show() in code.

Example

We make a simple macro with only one Click:

Simple Macro One Click

Then we make a Setting with one EditText. The Key is repeat:

EditText simple

This is how it looks like:

Simple Dialog

Then we change the Repeat of the Click to repeat which is the Key we used earlier

Simple Dialog

Of course we make sure to turn "Show at start up" on.

Now if we enter 6 the Click will repeat 6 times, if we enter 9 it will repeat 9 times and that's nice.

Code Equivalent

    //Get the SettingBuilder
    var builder = Setting.builder()

    //Add the EditText
    builder.add("repeat", EditText().text("3").method(1).hint("Repeat").helper("Enter the number of repeat"))

    //Build the dialog
    var dialog = builder.build()

    //Show it
    var result = dialog.show()

    if (result) {
        //user press save
        //get the value back and assign to a variable
        var repeat = Setting.get("repeat")
    } else {
        //user press cancel
    }
    

© 2021 - Macrorify by KoK-CODE