How to use TapDetectionHelper in Java ME
Article Metadata
Contents |
Overview
When touch screen is tapped with finger it may generate lots of unnecessary noice (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 occure 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.
Functionality
- 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.
Usage
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)
Examples
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.
Picture 1. Link selection situation in Opera Mini Browser. The screen has been touched on the red dot. Rectange illustrates the safe area within where all drag events will be suppressed for 500ms. If "pointer up" occurs within red rectange 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.
Picture 2. Default rectangle dimensions and JAD parameter twip usage.




29 Sep
2009
This article covers an interesting topic that is particularly relevant, given the recent rapid rise in the number of touch-screen devices Nokia is bringing to market. The article shows how tap detection options can be used to alter the way a midlet which makes use of a Canvas interprets tap events on touch-screen devices. Often when the user taps on the screen, there is a small difference between where they put the stylus (or their finger) on the screen and the co-ordinates where they lift it up. This may be entirely unintentional, but may be interpreted by the midlet as a drag event instead of a tap event. Also, it may lead to selection errors. Furthermore, unnecessarily many drag events can also be generated. This article shows how through the use of a simple property in the JAD file, we can address these problems. Basically, by setting the Nokia-MIDlet-Tap-Detection-Options in the JAD file, drag events which occur over a short time within a small area are suppressed and the pointer down and pointer up co-ordinates are set to be the same.
I wasn't aware of this feature (and the associated JAD property) until reading this article, so it made for very interesting reading. This is certainly likely to be of interest to those developing for touch-screen Nokia devices, as selection errors are pretty common on touch-screen devices for the reasons identified in this article. The concepts are nicely illustrated using graphical examples, and examples of setting the JAD option are also usefully provided (along with a discussion of how the different settings will affect midlet behavior).