For information about the design and functionality of the MIDlet, see section Design.
To implement multipoint touch handling in the MIDlet:
Enable multipoint touch events on Symbian devices by setting the following attribute in the MIDlet JAD file:
Nokia-UI-Enhancement: EnableMultiPointTouchEvents
Multipoint touch events are enabled by default on Series 40 devices that support multipoint touch. This attribute value is therefore ignored on Series 40 devices.
Catch touch
events by overriding selected Canvas
methods. The getPointerEventId
method is used to track individual multipoint touch events through
the com.nokia.pointer.number
system property (see
the following step). Every event creates a new Point
instance whose state depends on the event type.
Note: The com.nokia.pointer.number
system property
is not supported on Series 40 devices, which means that the getPointerEventId
always returns 0
. The
multipoint touch implementation used in this example therefore does
not track individual multipoint touch events on Series 40 devices.
While the MIDlet nevertheless draws the worm-like animation for each
touch point normally, the animations are all drawn with the same color
(yellow, since that is the color for touch points whose ID is 0
). To track individual multipoint touch events on Series
40 devices, use the Multipoint Touch
API.
protected void pointerPressed(int x, int y) { int pointerId = this.getPointerEventId(); this.addPoint(pointerId, new Point(x, y, Point.PRESSED)); this.exitButtonPointerDown = this.exitButtonHitTest(x, y); this.inactivityCounter[pointerId] = 0; } protected void pointerDragged(int x, int y) { int pointerId = this.getPointerEventId(); this.addPoint(pointerId, new Point(x, y, Point.DRAGGED)); this.exitButtonPointerDown = this.exitButtonHitTest(x, y); this.inactivityCounter[pointerId] = 0; } protected void pointerReleased(int x, int y) { int pointerId = this.getPointerEventId(); this.addPoint(pointerId, new Point(x, y, Point.RELEASED)); if (this.exitButtonPointerDown && this.exitButtonHitTest(x, y)) { this.inactivityTimer.cancel(); Display.getDisplay(this.midlet).setCurrent(null); this.midlet.notifyDestroyed(); } else { this.exitButtonPointerDown = false; } this.inactivityCounter[pointerId] = 0; }
Obtain the pointer
number of the pointer that was the source of the event by calling
the System.getProperty("com.nokia.pointer.number")
method. This method exists only in the scope of the methods pointerPressed
, pointerDragged
, and pointerReleased
. Outside these methods, the returned value
is null
.
Note: On Series 40 devices,
this method always returns 0
. For more information,
see the preceding step.
private int getPointerEventId() { String idString = System.getProperty("com.nokia.pointer.number"); int id = 0; if (idString != null) { id = Integer.parseInt(idString); } return id; }
The currentPoints
array stores
the Points
:
private Point[][] currentPoints = new Point[6][25];
In conclusion, this example supports six simultaneous touches and
each of them can have a maximum of 25 circles drawn on the screen
to create the worm-like animation. When a point is created, it is
stored to the correct index of the currentPoints
array,
depending on the pointer number.