Hello all!
I am trying to get some help on how to determine a button state.
I have the button(s) setup in Layout.xml:
<layout id="RHButtonLayout">
<button x="60" y="55" width="100" height="100" behavior="onRHUp">
<state id="stateDefault" bitmap="@Drawables.RH_MuSelected" />
<state id="stateHighlighted" bitmap="@Drawables.RH_MuRegular" />
<state id="stateSelected" bitmap="@Drawables.RH_MuRegular" />
<state id="stateDisabled" color="Graphics.COLOR_BLACK" />
</button>
</layout>
in my View i have:
using Toybox.Graphics as Gfx;
using Toybox.WatchUi as Ui;
using Toybox.Lang as Lang;
using Toybox.System as Sys;
class ButtonView extends Ui.View {
var buttonlayout;
//! Constructor
public function initialize(index as Lang.Number) {
View.initialize();
buttonlayout = index;
}
public function onLayout(dc as Gfx.Dc) as Void {
if (buttonlayout == 0){
setLayout($.Rez.Layouts.RHButtonLayout(dc));
}
}
.
.
.
}
And for the Delegate:
class ButtonDelegate extends Ui.BehaviorDelegate {
//! Constructor
public function initialize() {
}
//! Vibrate on event
//! @return true if handled, false otherwise
public function onRHUp() as Lang.Boolean {
if (Att has :vibrate) {
var vibrateData = [new Att.VibeProfile(25, 100),
new Att.VibeProfile(50, 100),
new Att.VibeProfile(75, 100),
new Att.VibeProfile(100, 100),
new Att.VibeProfile(75, 100),
new Att.VibeProfile(50, 100),
new Att.VibeProfile(25, 100)] as Lang.Array<Att.VibeProfile>;
Att.vibrate(vibrateData);
}
return true;
}
This works great. The button is placed where I want it, it does vibrate (used as a test).
However I want it to function WHILE pressed.
How can I get the state of the press and act accordingly? (e.g. while selected, when released, etc.)
I also fail to understand how to make it selectable by default when defining the button in Layout.
I would like to be able to select between buttons using the up/down keys on the watch.
my Delegate extends WatchUi.BehaviorDelegate in this case. is this the correct use for a button delegate here? it seems to make it selectable i need to change this.
