Class: Toybox::WatchUi::BehaviorDelegate

Inherits:
InputDelegate show all

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.

Examples:

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;
    }
}

See Also:

  • System::InputDelegate

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from InputDelegate

onHold, onKey, onKeyPressed, onKeyReleased, onRelease, onSelectable, onSwipe, onTap

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Constructor Details

initializeBehaviorDelegate

Returns a new instance of BehaviorDelegate

Since:

  • 1.0.0


13410
13411
# File 'Monkeybrains.rb', line 13410

def initialize()
end

Instance Method Details

onBackToybox::Lang::Boolean

Represents the Back behavior.

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

Returns:

Since:

  • 1.0.0


13450
13451
# File 'Monkeybrains.rb', line 13450

def onBack()
end

onMenuToybox::Lang::Boolean

Represents the Menu behavior.

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

Returns:

Since:

  • 1.0.0


13441
13442
# File 'Monkeybrains.rb', line 13441

def onMenu()
end

onNextModeToybox::Lang::Boolean

Represents the Next behavior.

Returns:

Since:

  • 1.0.0


13456
13457
# File 'Monkeybrains.rb', line 13456

def onNextMode()
end

onNextPageToybox::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:

  • 1.0.0


13421
13422
# File 'Monkeybrains.rb', line 13421

def onNextPage()
end

onPreviousModeToybox::Lang::Boolean

Represents the Previous Mode behavior.

Returns:

Since:

  • 1.0.0


13462
13463
# File 'Monkeybrains.rb', line 13462

def onPreviousMode()
end

onPreviousPageToybox::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:

  • 1.0.0


13432
13433
# File 'Monkeybrains.rb', line 13432

def onPreviousPage()
end

onSelectToybox::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:

  • 1.2.0


13473
13474
# File 'Monkeybrains.rb', line 13473

def onSelect()
end