Hi,
For 1030 series, do you know if its possible to develop any action for datafield?
Best regards,
Oriol
Hi,
For 1030 series, do you know if its possible to develop any action for datafield?
Best regards,
Oriol
Yes. But only with edge touch devices.
Here's an ultra simple example. The view and delegate:
using Toybox.WatchUi; class tapDFView extends WatchUi.DataField { function initialize() { DataField.initialize(); } // other stuff } class tapDFDelegate extends WatchUi.BehaviorDelegate { function initialize() { BehaviorDelegate.initialize(); } function onTap(evt) { System.println("tap!"); return true; } }
AppBase:
using Toybox.Application; class tapDFApp extends Application.AppBase { function initialize() { AppBase.initialize(); } function onStart(state) { } function onStop(state) { } function getInitialView() { return [ new tapDFView(), new tapDFDelegate() ]; } }
Dear fellow developers and dear jim_m_58 (I found your snipped - thanks!)
I built a test datafield which should show a messagebox when the screen was clicked/tapped.
The tapEvent works, is detected and made visible by System.println().
My problem is:
I do not find a way to get the coordinates and a tapFlag I created to the function onUpdate(dc) in class TestTapEventView to draw the messagebox.
I tried various methods like function, public variables - but to no avail.
In my code snipped I try to get the variables from InputDelegate - which works, but the variables do not change after a dap-Event.
I would be very grateful if you can show me a way!
Thanks!
Here's my View and Delegate:
import Toybox.Activity; import Toybox.Graphics; import Toybox.Lang; import Toybox.WatchUi; //-------------------------------------------------------------- class InputDelegate extends WatchUi.BehaviorDelegate { public var tapX = 0; public var tapY = 0; public var tapFlag = false; function initialize() { BehaviorDelegate.initialize(); } function onTap(clickEvent) { var tapCoordinates = clickEvent.getCoordinates(); tapX = tapCoordinates[0]; tapY = tapCoordinates[1]; tapFlag = true; System.println(tapX + " " + tapY + " " + tapFlag); return true; } } //-------------------------------------------------------------- class TestTapEventView extends WatchUi.DataField { var mValue as String; function initialize() { DataField.initialize(); mValue = ""; } function compute(info as Activity.Info) as Void { //compute the message: mValue = "Text Message"; } function onUpdate(dc as Dc) as Void { //draw the messagebox when a tapEvent occured var tFlag = false; var tX = 0; var tY = 0; tX = InputDelegate.tapX; tY = InputDelegate.tapY; tFlag = InputDelegate.tapFlag; System.println(tX + " " + tY + " " + tFlag); if ( tFlag == true ) { dc.setColor(Graphics.COLOR_DK_BLUE, Graphics.COLOR_TRANSPARENT); dc.fillRectangle (10, 150, 260, 150); dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT); dc.drawText(140, 200 , Graphics.FONT_MEDIUM, mValue, Graphics.TEXT_JUSTIFY_CENTER); } } }
Try to change to static variables in InputDelegate, or pass the actual inputDelegate object to your view
Thanks!
I found that posting which explains your suggestion and it works now!
Is this also supposed to work when developing a "Data field" App type? I am trying to make it work, following your minimal example. But I do not see any response via System.println()
onTap is only available on some touch devices. What device are you trying?
I am trying to use it on the Garmin Edge 830 via the simulator in VS Code.
I copy/pasted the delegate I posted way back when, and added the delegate class in the return for getInitialView in AppBase, and it's working fine in the 6.4.2 Sim/SDK for an 830
function getInitialView() { return [ new tapDFView(), new tapDFDelegate() ]; }
Hmm, oke. So I cut out all my other code to see if this works. Now it does work. For some reason it is not working in combination with what I already setup in my datafield. I will dive into this and let you know once I found the problem.
Thanks already! :)
So it turned out that the issue was that I was using WatchUi.SimpleDataField instead of WatchUi.DataField. Clearly the onTap() function does not work with the SimpleDataField.