×

Adding pinch gesture

In addition to the Gesture API features that were supported by the touch and type platform, full touch platform supports pinch gesture.

For more information on gesture events, see Using gestures and also refer the ImageViewer example to learn how multipoint touch interaction is added.

class myClass extends GameCanvas implements GestureListener {

/**
     	 * Initializes gestures and set it to receive gesture events
     	 */
public void initializeGesture() {

        /**
         * Set the listener to register events for ImageCanvas (this,) and
         * register the GestureListener for the UI element (,this)
         */
        GestureRegistrationManager.setListener(this, this);

        /**
         * Create an interactive zone and set it to receive taps
         */
GestureInteractiveZone myGestureZone = new GestureInteractiveZone(GestureInteractiveZone.GESTURE_PINCH);

        /**
         * Set the location (relative to the container) and size of the
         * interactive zone:
         */
        myGestureZone.setRectangle(0, 0, getWidth(), getHeight());

        /**
         * Register the interactive zone for GestureCanvas (this)
         */
        GestureRegistrationManager.register(this, myGestureZone);
    }

/**
     * Defines the gestureAction method for the class. This method is called
     * every time a gesture event occurs for a UI element that uses
     * GestureListener. The method is called with all the information related to
     * the gesture event.
     */
public void gestureAction(Object arg0, GestureInteractiveZone arg1, GestureEvent gestureEvent) {

        switch (gestureEvent.getType()) {

            /**
             * This gesture event is supported from Java Runtime 2.0.0 for
             * Series 40 onwards. Receives pinch events and check the pinch
             * distance change to scale the current image.
             */
            case GestureInteractiveZone.GESTURE_PINCH:
                if (gestureEvent.getPinchDistanceChange() < 0) {
                    scaleImage(-0.1f);
                } else if (gestureEvent.getPinchDistanceChange() > 0) {
                    scaleImage(0.1f);
                }
                repaint();
                break;

            default:
                break;
        }

    }

Last updated 9 October 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×