Triggers & Actions is a module provided by CG Client API combined with CG Server API. The module goes beyond the basic act of presenting widgets, and is intend to be used mostly by developers, although some exposure may be available for end users. The module provides developers with the ability to define rules by which certain trigger invoke certain action on a given condition.
CG lets developers set Triggers and Actions conditions for manipulating widgets. Trigger is related with given state of an application in which some action need to be applied. Action is the actual operation that needs to be applied on one or more widget.
For example a scheduler mechanism can be used as the trigger got setting a flag on widget that indicate if a widget can be presented or not, so that widget will be presented on a Glass only for some specific period of time.
Triggers and actions can involve also interaction with Linkage Graph but this is not a must. Trigger and actions can be set programmatically for any set of widgets selected by a program. Using the Linkage Graph a user (or a program) can set triggers and actions for related widgets. For example: creating hierarchy of presentation between widgets on the same Glass. Widget-B can be presented only if Widget-A was previously presented, and Widget-C can be presented only if Widget-B was first presented and so on.
The mechanism has three stages:
- A rule needs to be defined. The rule determines a trigger type (source) and the condition on which this trigger will act of selected action. So we have the trigger type, the state and the action.
- The state need to be checked repeatedly against rule settings
- Once state of trigger source match the defined condition the action is fired.
Type of triggers
- Scheduler: action will be triggered on pre defined times or periodically each given amount of predefined time.
- Software state: on some state an action will be invoked
- Widget state: a state of one widget is used as the trigger for setting and action on other widget.
Type of actions
- Visual changes, for example: Hide/Show widget, Change theme or style, Set text color
- Widget content, for example: clear content, Set fixed content, Switch the content based on condition
- Widget operation: perform some operation, for example send notification.
- Run some code