behaviorDelegate and Vivoactive4

Hi all,

I surely miss something but don't find what...

I try to understand what function of a behaviorDelegate is called when I push the upper button of a vivoactive4. So I overload all functions of inputDelegate and behaviorDelegate and put a println.
But when I start the simulator and push the button : nothing in the log !!... Same for holding pressure on screen.

class APICallDelegate extends WatchUi.BehaviorDelegate {

    function initialize() {
        BehaviorDelegate.initialize();
    }

    function onKey(evt) {
        var key = evt.getKey();
        System.println("Evt = " + evt + ", key=" + key);      // e.g. CLICK_TYPE_TAP = 0
        return true;
    }

    function onTap(clickEvent) {
		System.println("arg1");
		if (Application.Properties.getValue("TapLaunch") || selected_action == null) {
			self.onKey(new Toybox.WatchUi.KeyEvent(KEY_ENTER, PRESS_TYPE_ACTION));
		}
        return true;
    }

function onNextMode() {
		System.println("arg3");
		return false;
	}
function onNextPage() {
		System.println("arg4");
		return false;
	}
function onPreviousMode() {
		System.println("arg5");
		return false;
	}
function onPreviousPage() {
		System.println("arg6");
		return false;
	}
function onSelect() {
		System.println("arg7");
		return false;
	}

function onKeyPressed(keyEvent) {
		System.println("arg8");
		return false;
	}
function onKeyReleased(keyEvent) {
		System.println("arg9");
		return false;
	}
function onRelease(clickEvent) {
		System.println("arg10");
		return false;
	}
function onSelectable(selectableEvent) {
		System.println("arg11");
		return false;
	}
function onSwipe(swipeEvent) {
		System.println("arg12");
		return false;
	}


	function onHold(clickEvent) {
		System.println("arg20");
		self.onMenu();

        return true;
	}
	
	function onMenu() {
		System.println("arg21");
        ...

        return true;
    }

	function onBack() {
		System.println("arg22");
    	System.exit();
    }

  • Try the input sample in the SDK. It will tell you about everything.

  • Maybe this is a dumb question, but how are you actually using the delegate?

    Are you passing it in to WatchUi.pushView() or AppBase.getInitialView()?

  • Hi,


    AppBase.getInitialView()

    If you ask, I guess it matter ? And you are right, the button work with another class that inherit of BehavoirDelegate() but which is passing to pushView().

    @jim, I test the example, it well I suppose, it call onKey(), but why it is not call in my case...

  • No, I was just curious.

    What's your initial view? Does APICallDelegate work with that other view that's pushed using pushView()?

  • You probably want to avoid onKeyPressed() and onKeyReleased(), and in most cases you probably want to return true in the callbacks.

    The exception would be onBack(), where if you return false, your app will exit (without calling exit())

    In gener, you may want to comment out some of the callbacks and work with a smaller set to get things going. And for other devices, things could get confusing as a screen hold on the va3 caused onMenu(), and a swipe to the right on the va3/va4/venu is also onBack.

  • Jim, it's obvious that the code I posted, is not the final code. Just the code I try to debug and understand why when I push the upper button on Vivoactive nothing append...
    That is why I declare all with a println to debug.  In my original code, I just keep blocks that are tabulated.

    FlowState, it's curious... yes my other class (that also extend BehaviorDelegate) work good. It is a very simple delegate for a view that just display a message. The delegate just pop the view regardless of the button or tap. Here is the code, and yes the wiew is popped when I push the upper button.

    class MessageDelegate extends WatchUi.BehaviorDelegate {
    
      function initialize() {
        BehaviorDelegate.initialize();
      }
    
      function onKey(t) {
    	WatchUi.popView(WatchUi.SLIDE_DOWN);
      }
    
      function onTap(t) {
    	WatchUi.popView(WatchUi.SLIDE_DOWN);
      }
    
      function onBack() {
    
      }
    
    }

    I create the behavior as : WatchUi.pushView(new MessageView(WatchUi.loadResource(Rez.Strings.ReleaseMessage)), new MessageDelegate(), WatchUi.SLIDE_UP);

    BUT, with my main view, the one I create in appbase.getInitialView().

    Even if I comment all functions except onKey() and onTap(), none function is called when I press the button...

  • And the crazy thing : it work with a tap on vivoactive 4, more, all is good with buttons of a Forerunner945 ...

  • A tap on a /va3/va4/venu triggers onSelect. 

    Touch vs button devices can be interesting,

    You can do many things with just

    onMenu()

    onBack()

    onSelect()

    onNextPage()

    onPreviousPage()

    and work fine on touch or button devices.

    You may need onKey() in some cases, like if you want the upper right button on the va4 or handle the lap key on edge devices.

  • Jim, press the button of Vivoactive4 doesn't trigger any function on my main BehaviorDelegate... But when I push another view with another BehaviorDelegate that have exactly the same functions, it trigger well ...
    I will send you a complete exemple. You will understand the issue.

  • Each view has it's own delegate, and that is assigned by way of the return in getInitalView, or when you push a view.

    You're doing a device app and not a widget, correct?  There is a big difference between the 2 as far as accepting input.