Class: Toybox.WatchUi.BehaviorDelegate

Overview

BehaviorDelegate handles behavior input events.

A BehaviorDelegate differs from an InputDelegate in that it acts upon device-independent behaviors, such as "next page" and "previous page" instead of device-specific button presses. For example, these behaviors might be mapped to swipe left and swipe right inputs on touch screen devices, while on non-touch screen devices these behaviors might be mapped to physical buttons.

Since BehaviorDelegate extends InputDelegate, so it can also act on basic inputs as well. If a BehaviorDelegate returns true for a function (indicating the input was used) then the InputDelegate function that corresponds to the behavior will not be called.

See Also:

Example:

using Toybox.System;
using Toybox.WatchUi;

class MyBehaviorDelegate extends BehaviorDelegate {
    // Detect Menu behavior
    function onMenu() {
        System.println("Menu behavior triggered");
        return false; // allow InputDelegate function to be called
    }
    // Detect Menu button input
    function onKey(keyEvent) {
        System.println(keyEvent.getKey()); // e.g. KEY_MENU = 7
        return true;
    }
}

Since:

API Level 1.0.0

Instance Method Summary collapse

Instance Method Details

initialize()

Constructor

Since:

API Level 1.0.0

onBack() as Lang.Boolean

Represents the Back behavior.

This is typically triggered by the back button (KEY_ESC).

Note:

Some devices interpret SWIPE_RIGHT SwipeEvents as KEY_ESC events. On these devices, returning false will cause onKey() to be called rather than onSwipe().

Returns:

Since:

API Level 1.0.0

onMenu() as Lang.Boolean

Represents the Menu behavior.

This is typically triggered by the menu button (KEY_MENU).

Returns:

Since:

API Level 1.0.0

onNextMode() as Lang.Boolean

Represents the Next behavior.

Returns:

Since:

API Level 1.0.0

onNextPage() as Lang.Boolean

Represents the Next Page behavior.

This is typically triggered by the down button (KEY_DOWN) or by a SWIPE_UP SwipeEvent on a touch screen.

Returns:

Since:

API Level 1.0.0

onPreviousMode() as Lang.Boolean

Represents the Previous Mode behavior.

Returns:

Since:

API Level 1.0.0

onPreviousPage() as Lang.Boolean

Represents the Previous Page behavior.

This is typically triggered by the up button (KEY_UP) or by a SWIPE_DOWN SwipeEvent on a touch screen.

Returns:

Since:

API Level 1.0.0

onSelect() as Lang.Boolean

Represents the Selection behavior.

This is typically triggered by the Start/Enter button (KEY_ENTER) or by a CLICK_TYPE_TAP ClickEvent on a touch screen.

Returns:

Since:

API Level 1.2.0


Generated Sep 23, 2024, 3:32:49 PM