aMaze utilises three different gestures:
Double tap for toggling between the default and the user defined zoom
Pinch-to-zoom, and
tilting the phone to move the marble (accelerometer sensor)
Double tap detection is a custom solution, and it is very easy to implement: just listen to pointerPressed events, and if two of such events occur within the given short time frame and are close enough (in terms of coordinates) to each other, double tap has been detected. Here is a snippet from DoubleTapDetector.java:
if (currentTime - _lastTapTime < DOUBLE_TAP_TIMEOUT && Math.abs(_lastTapCoordinate[0] - x) < JITTER_THRESHOLD && Math.abs(_lastTapCoordinate[1] - y) < JITTER_THRESHOLD) { // Double tap! if (_listener != null) { // Notify the listener _listener.onDoubleTapDetected(); } ...
Pinch-to-zoom solution has been copied as-is from Series 40 UI Component Demos project into its own package, com.nokia.example.amaze.gestures.
The implementation for managing the accelerometer sensor is also re-used. It was originally implemented for Explonoid game example. See the implementation at com.nokia.example.amaze.sensors. In aMaze the InteractionManager class acts as the listener for the sensor implementation. The sensor readings are passed to onDataReceived() method:
/** * From AccelerationProvider.Listener. */ public void onDataReceived(double ax, double ay, double az) { if (_mazeCanvas.gameState() != MazeCanvas.ONGOING) { return; } if (_calibration == UNDEFINED) { // Do calibrate now based on the current reading if (_mazeCanvas.isPortrait()) { setCalibration(-ay); } else { setCalibration(-ax); } } if (_mazeCanvas.isPortrait()) { _ax = ax; _ay = ay + _calibration; } else { _ax = ax + _calibration; _ay = ay; } }
As seen in the snippet above, a calibration value is used on the Y axis for the accelerometer reading. This is done so that the game can also be played when the phone is being held normally (i.e., the phone does not need to lie on the table for horizontal zero level). For more information on sensors, see Mobile sensor API documentation.
For information about the design and functionality of the MIDlet, see Design.