Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
How to use TapDetectionHelper in Java ME
When touch screen is tapped with finger it may generate lots of unnecessary noise (drag events) and also "pointer up" event might easily end up being too far away from "pointer down" coordinates. Many applications rely on "pointer up" and "pointer down" to occur within certain area in order to launch some functionality(e.g. selecting small links in Internet Browser). A new feature called TapDetectionHelper offers help for detecting taps in Canvas based Java applications. This article demonstrates how to use TapDetectionHelper.
- Coordinates are saved whenever "pointer down" event occurs
- Drag events are suppressed if they occure within predefined rect (and time) around the "pointer down" coordinates.
- default rectangle size is about 7mmx7mm
- default timeout is 500ms
- If finger is dragged outside of the rect, drag events will be passed normally to the MIDlet
- If timeout passes, drag events will be passed normally to the MIDlet
- If "pointer up" event occurs within rect/timeout, the "pointer up" coordinates will be set the same as "pointer down" coordinates
- The amount of the coming drag events might be unnecessarily high. By default the amount of these events are limited by using "drag event frequency limiter". The time between the events is not shorter than 50ms.
- By using JAD parameter setting Nokia-MIDlet-Tap-Detection-Options:0,0 MIDlet is able to get all the drag events generated by platform with higher frequency (no "drag event frequency limiter" is used).
- Note: the "drag event frequency limiter" is not available in the first Nokia N97 software versions (sw 10.x.x)
As a result finger touch events on small areas are detected more reliably. Note, that using TapDetectionHelper might make usability worse in painting or drawing applications. For such applications it is possible to disable the feature, as shown below.
It is possible to use JAD attribute "Nokia-MIDlet-Tap-Detection-Options" to alter the predefined suppressor values (i.e. 200twips, 500ms). Twip value is the distance from "pointer down" coordinates and rectangle can be calculated by multiplying this value with two. (1 twip = 1/1440 of an inch)
Nokia-MIDlet-Tap-Detection-Options:0,0 <- Disable the feature, All drag events will be passed to the MIDlet. No up-event coordinate switching will be done.
Nokia-MIDlet-Tap-Detection-Options:200,500 <- Same as default values. Rectangle size 400x400 twips (about 7mmx7mm). Timeout 500ms.
Nokia-MIDlet-Tap-Detection-Options:100,250 <- Rectangle size 200x200 twips. Timeout 250ms.
The screen has been touched on the red dot. Rectangle illustrates the safe area within where all drag events will be suppressed for 500ms. If "pointer up" occurs within red rectangle and within 500ms, it's coordinates will be set the same as "pointer down" coordinates. As a result accurate tapping/selecting small link has been made easier by TapDetectionHelper.