Processing of multi-touch interaction on the Series40 Device

Source: Internet
Author: User

Added support for multi-touch APIs in Java Runtime 2.0.0 for Series 40. The purpose of this article is to introduce how to use multi-touch APIs to handle interactive events.

The multi-touch API allows you to process multi-touch events in a Canvas-based MIDlet, such as GameCanvas and FullCanvas. You can register the API to receive multi-touch events.

API Introduction

Each touch point contains three important values:

A unique ID

Current coordinate value, including X and Y

Current contact status

There are three touch statuses:

POINTER_PRESSED

POINTER_DRAGGED

POINTER_RELEASED

The multi-touch API is very simple, mainly including the following:

-MultipointTouch is used to access the coordinates, status, and other information of Multiple electric shock events, as well as the number of contacts supported by the device, and to bind or remove a multi-touch listener.

-MultipointTouchListener receives and processes multi-point touch events.

Use of Apis

Determine whether the current device supports the MultiTouch API

The Nokia SDK provides the com. nokia. mid. ui. multipointtouch. version attribute to obtain API version information.

if (System.getProperty("com.nokia.mid.ui.multipointtouch.version") != null) {
// API is supported: Can implement multipoint touch functionality
} else {
// API is not supported: Cannot implement multipoint touch functionality
}

How can I obtain the maximum number of contacts supported by a specific device?-MultipointTouch. getMaxPointers can be used.

Obtain a MultipointTouch instance

MultipointTouch mpt = MultipointTouch.getInstance();

Register MultipointTouchListener for the MIDlet

public class MainCanvas extends Canvas implements MultipointTouchListener
{
public MainCanvas() {
// ...
mpt.addMultipointTouchListener(this);
}
......
}

Handling multi-touch events

From the function pointersChanged (int [] pointerIds), we can see that the parameter is only an array of touch point IDs, and then we use the ID value to obtain contact information using MultipointTouch.

Note that the parameter pointerIds array only contains the ID of the touch point with the changed status and position. The unchanged value is not included in the array.

public void pointersChanged(int[] pointerIds) {
for(int i=0; i<pointerIds.length; i++) { // Loop through the changed touch points
{
int pointerId = pointerIds[i]; // Get the touch point ID
int state = MultipointTouch.getState(pointerId); // Get the touch point state
// Get the touch point x and y coordinates
int x = MultipointTouch.getX(pointerId);
int y = MultipointTouch.getY(pointerId);

// Handle the UI update based on the touch point state, ID and coordinates
switch(state) {
case MultipointTouch.POINTER_PRESSED: // A new finger was pressed against the screen
drawTouch(pointerId, x, y); break;
case MultipointTouch.POINTER_DRAGGED: // A pressed finger was dragged over the screen
drawTouch(pointerId, x, y); break;
case MultipointTouch.POINTER_RELEASED: // A pressed finger was lifted from the screen
break;
}
}
}

Instance demo

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.