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.

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

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

    Try reading my comment carefully.

    On devices with CIQ < 4 (no super apps, but glances may be supported), yes isGlanceModeEnabled will determine whether a widget was started as full-screen widget or a glance, as you described.

    On devices with CIQ >= 4 (super apps, no full-screen widgets), isGlanceModeEnabled will always be true, and cannot distinguish between the case where a device app is launched as a glance and the case where it's launched from the app list. If I launch a device app from the app list on such a device, isGlanceModeEnabled will still be true, but nobody would say "the app was started from a glance" in this case.

    I know what you meant, but the problem is that you're not describing it properly. In general, isGlanceModeEnabled determines whether an app was not launched as a widget (EDIT: this isn't quite right either - see below), not whether it was launched as a glance. If a dev doesn't care about distinguishing between the case where a device app is launched as a glance or from the app list, then your advice is perfectly sound. If they do care, then it's misleading.

    Why do you think onStart()'s state parameter literally has a key called :launchedFromGlance, if isGlanceModeEnabled is enough to determine whether an app was "started from a glance or not."

    It should also be intuitive that DeviceSettings.isGlanceModeEnabled is not going to change based on whether a user chooses to launch a device app from a glance or from the app list (on a CIQ 4+ device), since it's a setting, not a state.

  • If it's launched as an app and not from a glace, this works fine, as you can use up/down when launched that way.  And all devices with super apps have glances.

    Maybe you should just try it yourself.

  • TL;DR in this case isGlanceModeEnabled tells you what OP wants, but there are other cases where a dev might actually want to tell the difference between a device app w/glance view being launched as a glance or from the app list. One example could be a device app that optionally supports recording - in this case, recording should probably be disabled if the app is launched from a glance. isGlanceModeEnabled does not help here, as device apps with glance views (that can be launched either from the glance list or app list) are only supported on CIQ 4+ devices, and isGlanceModeEnabled is always true on CIQ 4+ devices (as they do not support full-screen widgets at all.)

    So it's misleading to say DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not" without qualifying the statement, as if it applies in all cases.

    Garmin must have added :launchedFromGlance to AppBase.onStart()'s state parameter for a reason - they must think *somebody* might care. (unfortunately it's only available on CIQ 4+ devices, so older devices still have to use isGlanceModeEnabled.)

    If it's launched as an app and not from a glace, this works fine, as you can use up/down when launched that way

    I addressed this already:

    If a dev doesn't care about distinguishing between the case where a device app is launched as a glance or from the app list, then your advice is perfectly sound. If they do care, then it's misleading.

    That doesn't mean that DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not." That would only be true if you focus on one special case (a CIQ widget on CIQ < 4 device), and you disregard other cases (because to you, it doesn't ever matter whether a super app was started from glance or app list). This is similar to the advice you always give about handling float temperature values with the conversion from C to F - it ignores the real case where an app doesn't need to do that conversion because it's displaying C.

    And all devices with super apps have glances

    Yeah, I realize that. Maybe you're just really bad at reading comprehension.

    Maybe you should just try it yourself.

    I have tried it myself (on devices without glances, with full-screen widgets and glances, and only glances), and your response ("all devices with super apps have glances") only confirms my point that you failed to understand what I said (multiple times, no matter how many or few words I used.)

    Multiple times, you said that DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not." It's a very simple statement, but it's not true in all cases. Just because you don't care about the other cases doesn't make your statement correct.

    On a CIQ 4+ device, as we both know, device apps with a glance view can be started from either the glance list or the app list. If I start such an app from the app list, clearly it was not started from a glance, yet isGlanceModeEnabled is always true for CIQ 4+ devices. Therefore, isGlanceModeEnabled does not always tell you whether an app was "started from a glance or not." I don't know how much simpler it can be.

    If the dev doesn't care about the distinction between starting an app from the glance list and the app list, then it's fine. It's still not correct to say that DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not." Words have meanings.

    To be fair, it's not really true that DeviceSettings.isGlanceModeEnabled tells you whether an app was not started as a full-screen widget, either. So that was a poor choice of words on my part, too.

    So I'll be very clear and precise (you already know all of this):

    - isGlanceModeEnabled is documented as follows: "Indicates if widget glances are enabled on the device." Note that it's not documented as "indicates whether apps are started from a glance or not."

    - CIQ < 4 devices:

    - support full-screen widgets, glances, or both (in this case glances can be turned on or off in a setting which corresponds to isGlanceModeEnabled). (depends on how old the device is and what firmware it has)

    - isGlanceModeEnabled may or may not be present. When it's false (or not present), that indicates that a CIQ widget will be launched as a full-screen widget, and when it's true, that indicates that a CIQ widget will be launched as a glance. Just as you said. But only in this case.

    - CIQ >= 4 devices

    - do not support full-screen widgets, do support glances, and do support super apps (which means that CIQ widgets will be built as device apps, and device apps support glance views). Obviously there is no setting to turn off glances (which is why isGlanceModeEnabled is always true)

    - a device app which has a glance view can be launched from either the glance list or the activity/app list

    - isGlanceModeEnabled is always true, therefore isGlanceModeEnabled doesn't give the dev any information about whether a device app with glance view was launched as a glance or launched from the activity/app list. Again, if you (or OP) don't care about that distinction, it's fine. But that doesn't mean that DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not." in all cases.

    To put it differently (focusing on isGlanceModeEnabled):

    - isGlanceModeEnabled - not present or false (CIQ < 4 only): CIQ widget launches as full-screen widget

    - isGlanceModeEnabled - true: On CIQ < 4, CIQ widget launches as glance. On CIQ >= 4, CIQ device app can be launched either as glance (if glance view implemented) or from app list. (On CIQ >= 4, an app with a type of "widget" in the manifest is compiled as a device app.)

    In conclusion, you can't just say DeviceSettings.isGlanceModeEnabled tells you whether an app was "started from a glance or not" without qualifying that statement. It's just imprecise communication and sloppy thinking. It's expecting the reader to know what you mean instead of clearly communicating. But if they already knew what you mean, they wouldn't be asking in the first place.

    You may not care about the case that a CIQ 4+ device app with glance view is opened from the app list, OP may not care, but if someone else who does care reads what you said (multiple times), they might get the wrong impression and think that they can just look at DeviceSettings.isGlanceModeEnabled, and not :launchedFromGlance in onStart()'s state variable. Again, if nobody cares about the case where a device app with glance view is opened from the app list, why did garmin implement :launchedFromGlance?

    I'm also pretty sure that there was a thread where someone just asked about this in a generic way ("how do I know if my app was started as a glance?") and you answered with "isGlanceModeEnabled", even though they said nothing about input or up/down buttons. Tellingly, someone else mentioned :launchedFromGlance.

    as you can use up/down when launched that way.

    Yeah, that's the concern here, but the input available on the initial view is not the only conceivable reason to know whether an app was launched from the glance list. You are assuming that, because it's the topic of discussion here (fair enough) and because it's clearly the only reason that you are interested in. Same as you only ever consider displaying Fahrenheit (and not Celsius) because you live in America, and you don't consider people who live elsewhere.

    For example, I'm pretty sure that device apps launched from the glance list are still not allowed to record activities (definitely not if an activity is currently in progress). So a dev which implements a device app which has an optional recording feature, and which also has a glance view, would definitely want to know whether their app was launched from the glance list or the app list. If it's launched from a glance, I think they would want to hide or disable the recording feature. If it's launched from the app list, the recording feature would be enabled.

  • If you spent less time writing posts and more time trying things that addressed the OP's question, you might be happier, and wouldn't try to insert words in other people's mouth, as you were caught by Travis just yesterday.