onSwipe() on a widget doesn't work for S62

With S62, I cannot make onSwipe() work in my widget on simulator.( I have not tried it on real watch.)

A break point at the function doesn't hit at all.

If I swipe up<<>>down the widget is terminated.

If I change device to S70, it will work.

If I change App Type to Watch App in manifest, it wil also work. This issue happens with combination S62 with Widget.

Here are the code of app and delegate

using Toybox.System;
using Toybox.WatchUi;

class WidgetTestDelegate extends WatchUi.BehaviorDelegate  {
    
        //! Constructor
    public function initialize() {
        BehaviorDelegate.initialize();

    }
    
    function onKey(keyEvent) {
        var event=keyEvent.getKey();
        System.println("key");         // e.g. KEY_MENU = 7
        return true;
    }

    function onTap(clickEvent) {
        var event=clickEvent.getType();
        System.println(clickEvent.getCoordinates()); // e.g. [36, 40]
      //  System.println(clickEvent.getType());        // CLICK_TYPE_TAP = 0

        return true;
    }

    function onSwipe(swipeEvent) {
        var event=swipeEvent.getDirection();
        System.println("swipe"); // e.g. SWIPE_DOWN = 2
        return true;
    }
}

import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;

class WidgetTestApp extends Application.AppBase {

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

    // onStart() is called on application start up
    function onStart(state as Dictionary?) as Void {
    }

    // onStop() is called when your application is exiting
    function onStop(state as Dictionary?) as Void {
    }

    // Return the initial view of your application here
    function getInitialView() as [Views] or [Views, InputDelegates] {
    //    return [ new WidgetTestView() ];

        var view =  new WidgetTestView();
        var delegate =new WidgetTestDelegate();
        
        return [view, delegate];
    }

}

function getApp() as WidgetTestApp {
    return Application.getApp() as WidgetTestApp;
}

  • Looks like a s62 doesn't support glances and on a real watch, up/down is how you move between different widgets, so in the sim, your widget terminates with either

    in your code, you can use

    var sSettings=Sys.getDeviceSettings();
    fromGlance=false;
    if(sSettings has :isGlanceModeEnabled) {
        fromGlance=sSettings.isGlanceModeEnabled;
    }

    To see if you were started from a glance or not.

    What you can do if a device doesn't have glances is to push a second view, and have it's delegate handle up/down, or if you are using this to change pages in your app, don't use up/down, but maybe onSelect to rotate through the screens instead

  • Thank you for educating me.

    I will try to use second view.

  • You do want to have getGlanceView in the AppBase.  On some devices you app wont show in the glance loop without a glance view.

  • It sounds that it is better not to use swipe operation in my widget UI since I would like to make my codes simple.

    thank you for the info.

  • To see if you were started from a glance or not.

    Once again, that code does not determine whether the app was started from a glance or not, it determines whether the device supports glances, and if so, whether glances are enabled. In other words, there’s a 3rd possibility other than “app was started as a widget” and “app was started from its glance” (see below.)

    For this use case it works, but that’s the wrong way to describe what the code does. A better description might be that the code determines whether the app was *not* launched as a widget. (If glances are supported and enabled, then it’s not possible for an app to be launched as a widget.)

    For further context, on devices that support super apps (which is any watch with CIQ >= 4), it’s possible for an app to be launched either from a glance or from the app/activity launcher, and in that case, it would be completely different code to “see if you were started from a glance or not”.

    There’s actually 3 possibilities, for an app which has a glance view, has an app type of widget specified in the manifest, and runs on both older and newer devices:

    1) app is launched as a widget

    2) app is launched from its glance

    3) app is launched from the app/activity list

    The code above does not distinguish between cases 2 and 3, so again, it’s not accurate to say it’s “to see if you were started from a glance or not”. It may very well be that the dev doesn’t care about distinguishing between 2 and 3, but that’s not a good reason to describe things inaccurately.

    If you want to literally determine whether an app was started from a glance (in a way that distinguishes between 2 and 3), this code could work:

    // this example code assumes the app type is “widget” (so older devices
    // treat it as a widget/glance), and that getGlanceView() is implemented
    enum {
        APP_STARTED_AS_WIDGET,
        APP_STARTED_FROM_GLANCE,
        APP_STARTED_FROM_APP_LIST
    };
    
    var appStartType = APP_STARTED_AS_WIDGET;
    
    function onStart(state as Lang.Dictionary or Null) as Void {
        var deviceSettings = System.getDeviceSettings();
        var ciqMajorVersion = settings.monkeyVersion[0];
        if (ciqMajorVersion >= 4) {
            // device supports super apps, so this app could have been launched
            // from either a glance or the app list.
            // note that in real-world testing, launchedFromGlance
            // is actually not present when the app is started from the app list,
            // as opposed to being false.
            // this is why we check the CIQ version to determine super app support
            if (state != null && state.get(:launchedFromGlance) == true) {
                appStartType = APP_STARTED_FROM_GLANCE;
            } else {
                appStartType = APP_STARTED_FROM_APP_LIST;
            }   
        } else {
            // this is an old device which doesn’t support super apps.
            // it may or may not support glances (if not, then it only supports true widgets).
            // if it supports glances, it may or may not support disabling glances 
    	    if (deviceSettings has :isGlanceModeEnabled && deviceSettings.isGlanceModeEnabled) {
    	        appStartType = APP_STARTED_FROM_GLANCE;
    	    } else {
                appStartType = APP_STARTED_AS_WIDGET;
            }
        }
    }

  • Have you ever actually used this on a range of devices?

    I have a number of apps that do exactly as I described.