How to get full control of the touch screen from developer perspective?

Hey, I would like to create an app which will utilise the input on the touch screen given by the user. The problem is that when user swipes from left to right the app closes. I want to get rid of default behaviour of the application in which this swipe closes the app, since it interrupts my concept of using touch screen for the interface.

How can I do this?

  • Return true in the callback functions

  • You really can't.  On some devices/app types, a swipe from the left to the right is the same as pressing the back button and closes the app

  • As flocsy said, the normal way to do something like this would be to return true in the relevant callback function of the BehaviorDelegate, which means that your app handles the behavior and the default system action should not happen.

    In this case, you would return true in onBack(), which is triggered either by a right swipe or by pressing the LAP/BACK button (KEY_ESC). This would prevent the default system behavior of popping the current view (which closes the app if it's the top-level view), and you would be free to handle onBack however you want.

    However, this has an issue in practice. Once you return true in onBack(), the subsequent onSwipe() or onKey() handlers are not called, which means it's hard to distinguish a press of KEY_ESC from a right swipe. This may be an issue if you actually wanted to close the app / pop the view with a press of KEY_ESC and not a right swipe. However, onKeyPressed and onKeyReleased *are* still called even if onBack() returns true (this is understandaable, as onKeyPressed is called *before* onBack, since obviously the system has no way of knowing if you'll long-press the back button, in which case onBack() should *not* be called.)

    At this point, you might think to yourself, "ok, I'll continue to return false in onBack (or not override onBack), but I'll return true in onSwipe(SWIPE_RIGHT) and onKey(KEY_ESC). This will give me full control over the 'back behavior'!" And this sounds great on paper. Returning true in onSwipe(SWIPE_RIGHT)  and/or onKey(KEY_ESC) prevents the respective action from popping the view. So this way, it *seems* that you now have full control over right swipe / KEY_ESC.

    [1/3]

  • Unfortunately there are/were a couple of quirks in current watches like Forerunner 955 / 965 (and probably at least every other 5-button touchscreen watch of their generation):

    Bug 1) A right swipe from the left edge triggers onKey(KEY_ESC) and not onSwipe(SWIPE_RIGHT).

    This happens in both the simulator and a real fr955. This means that it's not possible to distinguish the 2 types of "back behaviors" (right swipe from left edge, and KEY_ESC), which makes it hard or impossible to handle the  button and the swipe in different ways.

    Bug 2) In the native UI (including native menus / CIQ Menu2), only a certain kind of right swipe triggers the "back behavior": right swipes which start from the left edge. Other right swipes do *not* trigger the back behavior, which is good, so that apps can use other right swipes for things like panning a chart. However, the problem is that on a real device, in CIQ only, *all* right swipes trigger the back behavior. This is different from the native UI, including CIQ Menu2.

    I just checked my fr955, which is on the current beta firmware (24.07):

    Bug 1) still exists :/. This means it's tough (or impossible!) for apps to handle a right swipe from the left edge differently from KEY_ESC (LAP/BACK button)

    Bug 2) is fixed! Only right swipes from the left edge trigger the back behavior, which means CIQ apps are free to use other right swipes for something else

    [2/3]

  • TL;DR

    To suppress the default "back" / "pop view" behaviour of right swipe (from left edge) you have a couple of choices:

    A) Implement onBack() and return true. This will not only prevent the current view from being popped, but it will also suppress the subsequent onSwipe(SWIPE_RIGHT) or onKey(KEY_ESC) handlers, which means that you cannot handle swipe right and LAP/BACK button in different ways, unless you rely on onKeyPressed/onKeyReleased to do so. [*]

    B) Return false in onBack() (or don't implement onBack), but handle onSwipe(SWIPE_RIGHT) and return true. Also, implement onKey(KEY_ESC) and return true. This is the perfect solution for you, except you will not be able to handle right swipe and KEY_ESC (LAP/BACK) differently, due to bug 1) above.

    [*] Due to bug 1) above, swipe right from left edge triggers KEY_ESC anyway, so there doesn't really seem to be any way at all to handle right swipe from left edge and LAP/BACK in different ways, unless this bug is resolved. Someone from the CIQ team said it's by design, so I guess it will never be resolved. I bet they did this on purpose because they *want* to make it hard (or impossible) for devs to suppress the back behavior for right swipe (from left edge) but not KEY_ESC. Maybe they got user complaints that right swipe from left edge didn't work in some CIQ apps.

    [3/3]