Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Programming Actions

Adrián Rivero edited this page May 5, 2017 · 9 revisions

Actions can be easily programmed, here is shown an action to Wait for a specific amount of time, before executing the next actions:

@ActionFor(value = "Wait")
public class WaitActionHolder  {

    private CountDownTimer countDownTimer;
    private long countDownTime;

    void init(long countDownTime) {
        this.countDownTime = countDownTime;
    }

    void build(final Runnable Finished, final Runnable Ticked) {
        countDownTimer = new CountDownTimer(countDownTime, 100) {

            @Override
            public void onTick(long millisUntilFinished) {
                if (Ticked != null) Ticked.run();
            }

            @Override
            public void onFinish() {
                if (Finished != null) Finished.run();
            }
        };
    }

    void execute() {
        countDownTimer.start();
    }
}

In the code, this action will be called simply like this:

void waitAndDoSomething() {
    $Wait(2500);
    doSomething();
}

Action Life Cycle

Each action should have the following methods:

  • init: It is where the action should be initialized, can have any number of parameters.
  • build: It is call to build the actions. It's parameters are the Events that the action can trigger.
  • execute: It is called to execute the action. This method should have no parameter.

It is recommended to declare this methods as protected (or without modifier) in order to avoid showing this methods to the user.

Parameters Annotations

Processors

The actions can have a processor to interpret the action and crate a more complex code from it.

Ex. [Recollect] (https://github.com/smaugho/declex/blob/master/declex-api/src/com/dspot/declex/api/action/builtin/RecollectActionHolder.java) and its processor RecollectActionProcessor

See Also: