自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Series40 設(shè)備上多點(diǎn)觸摸交互的處理

移動(dòng)開發(fā)
在 Java Runtime 2.0.0 for Series 40 版本中添加了對多點(diǎn)觸摸API的支持,那么本文的目的就是介紹如何使用多點(diǎn)觸摸API,處理交互的事件。

在 Java Runtime 2.0.0 for Series 40 版本中添加了對多點(diǎn)觸摸API的支持,那么本文的目的就是介紹如何使用多點(diǎn)觸摸API,處理交互的事件。

多點(diǎn)觸摸API允許在基于Canvas的MIDlet中處理多點(diǎn)觸摸事件,比如說GameCanvas, FullCanvas等,通過API我們可以注冊以便能夠接收到多點(diǎn)觸摸事件。

API介紹

每一個(gè)觸摸點(diǎn)是包括3個(gè)重要的數(shù)值:

一個(gè)唯一的ID

當(dāng)前的坐標(biāo)值,包括X, Y

當(dāng)前觸點(diǎn)的狀態(tài)

其中觸摸的狀態(tài)有3種:

POINTER_PRESSED

POINTER_DRAGGED

POINTER_RELEASED

多點(diǎn)觸摸的API很簡單,主要包括了下面的:

-MultipointTouch 該類主要用來訪問多個(gè)觸電的相關(guān)坐標(biāo),狀態(tài)等信息,設(shè)備所支持的觸點(diǎn)數(shù)等信息,綁定或移除多點(diǎn)觸摸監(jiān)聽者等。

-MultipointTouchListener 接收多點(diǎn)觸摸事件,并做出相應(yīng)處理。

API的使用

判斷當(dāng)前設(shè)備是否支持 MultiTouch API

Nokia SDK中提供了屬性com.nokia.mid.ui.multipointtouch.version 來獲取API版本信息。

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
}

如何獲取特定設(shè)備所支持的最大觸點(diǎn)數(shù)呢: 可以使用- MultipointTouch.getMaxPointers

獲取MultipointTouch實(shí)例

MultipointTouch mpt = MultipointTouch.getInstance();

為MIDlet注冊MultipointTouchListener

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

處理多點(diǎn)觸摸事件

從函數(shù)pointersChanged(int[] pointerIds)可以看出參數(shù)僅僅是一個(gè)觸摸點(diǎn)ID的數(shù)組,然后我們是通過ID值使用MultipointTouch來獲取觸點(diǎn)的相關(guān)信息。 

這里需要注意的,參數(shù)pointerIds 這個(gè)數(shù)組僅僅是包含了狀態(tài),位置有變化的觸摸點(diǎn)的ID,沒有變化的并不會被包含在該數(shù)組中。

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;
}
}
}

實(shí)例演示

MultiTouch Example pic 1.png 

責(zé)任編輯:Yeva 來源: NOKIA Developer
相關(guān)推薦

2012-12-14 15:28:25

2010-04-20 09:08:36

2009-04-14 08:14:09

AndroidGoogle移動(dòng)OS

2013-05-14 10:56:45

AIR Android多點(diǎn)觸摸

2012-12-14 14:48:01

諾基亞Series 40S40

2009-12-25 10:07:38

Linux系統(tǒng)多點(diǎn)觸摸

2009-02-17 20:21:20

Windows 7多點(diǎn)觸摸

2009-08-25 09:40:09

Windows 7多點(diǎn)觸摸

2013-01-25 15:13:58

Series 40S40

2009-09-22 15:47:11

2013-01-25 15:19:07

Series 40S40

2012-08-21 17:02:19

Office 2013觸摸

2010-04-20 15:36:01

Linux多點(diǎn)觸摸

2011-08-06 23:06:27

聯(lián)想一體機(jī)

2012-12-14 15:21:10

諾基亞Series 40S40

2009-09-01 08:44:35

Windows 7多點(diǎn)觸摸

2009-11-07 19:05:05

Windows 7多點(diǎn)觸摸

2013-01-25 13:44:52

諾基亞series 40

2013-05-14 11:08:23

AIR Android觸摸事件鼠標(biāo)事件

2013-01-25 15:04:30

S40Series 40
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號