The ArrowKeys MIDlet contains one screen element, a StringItem
, that indicates the orientation of the device as a printed arrow
head (<, >, ^, or v). The received acceleration data from the accelerometer
sensor is translated first to key events and then to these arrows.
The following figure shows the main view of the MIDlet.
Figure: ArrowKeys main view
The MIDlet is a DataListener
and, as such, it implements
the DataListener.dataReceived
callback to receive
data from the accelerometer sensor. After setting the listener, the
MIDlet receives a notification every time the accelerometer sends
data.
The MIDlet converts the acceleration data to the following action events:
Canvas.LEFT
Canvas.RIGHT
Canvas.UP
Canvas.DOWN
The MIDlet converts the acceleration data by reading the acceleration
values from the x and y axes. The z axis does not affect the MIDlet,
and it is therefore ignored. The MIDlet compares the rotation values
of the x and y axes, and selects the larger one. The MIDlet performs
the actual comparison using the if(Math.abs(axis_x) > Math.abs(axis_y))
statement.
To prevent the device from changing the screen orientation, the
MIDlet uses the Nokia-MIDlet-App-Orientation: portrait
JAD attribute. It forces the device to remain in portrait mode regardless
of how the user turns it.
For instructions on how to implement the MIDlet, see section Implementation.