Android多點(diǎn)觸控技術(shù)解析_第1頁
Android多點(diǎn)觸控技術(shù)解析_第2頁
Android多點(diǎn)觸控技術(shù)解析_第3頁
Android多點(diǎn)觸控技術(shù)解析_第4頁
Android多點(diǎn)觸控技術(shù)解析_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、android多點(diǎn)觸控技術(shù)解析android multi-touch technology1 introductionandroid multi一touch in essence need lcd drive and support on the program itself design, currently on the market htc, motorola and samsung and other well-known manufacturers as long as use the principle of capacitance screen touch phone can s

2、upport multi一touch multitouch technology, for the web zooming, gestures from a better user experience events are on the android platform using the motionevent object is hem died, such as when they begin to touch trigger action down, while mobile operati ng for action move, finally let go of the fin

3、ger trigger action_up event of course, there is a user,s no-rule action that might trigger the action_cancel action.it is important to note that android's multitouch functionality will need to run more than version 2.0 of androidfirs t an droid development net remind everybody multi-touch lcd dr

4、iver and application software two support is needed to achieve, so some older, such as android 2.0 or listed in north america before mobile phones may not be able to support multitouch on firmware, because apple patents in europe and the asia-pacific region of the android 2.0 after the new version o

5、f the firmware are already in the screen driver support, and simulator also cannot achieve multi-touch teststep 21) the first case is the ontouchevent method in the activity directly.for the parameter motionevent for the ontouchevent method, we can handle the details of the multi-touch approach, for

6、 examplean event getaction () / / gets a touch action such as acti0n_d0wnevent getpointercount () ; / / the number of touch points, such as 2, may be two fingers pressing the screen simultaneouslyevent getpointerld (nid); / / for the details of each touch point, we can use a loop to execute the getp

7、ointerld method to get the indexevent getx (nid) ; / / get the x position of the nid touch pointevent gety (nid); / / get the y position of the nid touchevent getpressure (nid); / / lcds can sense the pressure of the user's fingers, of course, depending on the driver and the physical hardwareeve

8、nt getdowntime () / / press start timeevent geteventtime()/ / the end of the eventevent geteventtime () 一 event getdowntime ();/ in total, it will take time2) the second is to achieve a ontouchlistener method, to set up the view of the listener attribute, then implement the ontouch (view view, motio

9、nevent event) method, can obtain the touch-screen induction eventsin this case, there are two parameters can be used to get control of the touch, these two parameters are: motionevent getaction ()and motionevent action_mask, the former is used for the single point touch, which is used for multi-touc

10、h, for single point touch, by the motionevent getaction () can get the following events: acti0n_d0wn, acti0n_up, with multi-touch, by motionevent. action_mask, we can get: acti0n_p0inter_d0wn, action_pointer_up, is a constant in the motionevent, can be called directly. while some constants are singl

11、e and multi-point, such as acti0n_m0ve, you must mark the difference between a single point and multi-touch when pressed.3) note: runs in ontouchevent (motionevent event) here you can use the event getactionmasked () is used for multi-touch testing point and in no event in 1. 6 and 2. 1. the getacti

12、onmasked () this approach, in fact he is the event the getaction () & motionevent. action_mask encapsulation.3 casescase a公共類的multitouchactivity擴(kuò)展了活動“顏色:# 008000;”當(dāng)活動第一次創(chuàng)建時(shí),> / * *被調(diào)用。* / / span >< span 風(fēng)格二"顏色:# 008000; > 0verride < / span > 公共空間 oncreate (包 savedlnstances

13、tate) super oncreate(savedlnstancestate);setcontentview(r. layout, main);< span 風(fēng)格二顏色:# 008000:> ©override < / span > 公共布爾 ontouchevent (motionevent 事件)int action 二 eventgetaction();開關(guān)(行動)案例 motionevent. act 10n_p01 nter_ 1 _d0wn:showmessage("第一個(gè)手指按下”);打破;案例 motionevent. action

14、_pointer_1_up: showmessage( “第一個(gè)手指抬起”);打破; 案例 motionevent. acti0n_p0inter_2_d0wn: showmessage("第二個(gè)手指按下”);打破;案例 motionevent. acti0n_p0inter_2_up: showmessage( “第二個(gè)手指抬起”);打破;案例 motionevent. acti0n_p0inter_3_d0wn: showmessage("笫三個(gè)手指按下”);打破;案例 motionevent. acti0n_p0inter_3_up: showmessage( “笫三

15、個(gè)手指抬起”);打破;返回true;私人空間 showmessage (string s) 烤面包片二 toast. maketext (getapplicationcontext (), s,toast. length_short);toast show ();實(shí)測效果如下:情況一:手指1按下沒有出現(xiàn)提示;手抬指1起也沒有出現(xiàn)提示;這是 很顯然的,因?yàn)檫@吋產(chǎn)生的消息是acti0n_d0wn和acti0n_upo情況二:手指1按下沒有提示;手指2按下出現(xiàn)手指2按下的提示;手 指2抬起出現(xiàn)手指2抬起的提示。情況三:手指1按下沒有提示;手指2按下出現(xiàn)提示;這時(shí)手指1提起 出現(xiàn)手指1提起的提示;手指

16、1按下出現(xiàn)手指1按下的提示;情況四:大家可以放三個(gè)手指去嘗試下,看看android是怎樣產(chǎn)生這 些消息的。根據(jù)實(shí)驗(yàn)的結(jié)果,可以得到一句話:當(dāng)屏幕上有一個(gè)手指時(shí)可以完美 的產(chǎn)生2點(diǎn)觸摸的消息;當(dāng)屏幕上有2個(gè)手指吋可以完美的產(chǎn)生3點(diǎn) 觸摸消息,以此類推。所謂的完美就是指你能正確的得到到底是 那個(gè)手指進(jìn)行了操作。案例二公共類 pointer2drawactivity 擴(kuò)展活動實(shí)現(xiàn) ontouchlistener / *當(dāng)活動第一次創(chuàng)建時(shí)調(diào)用。* /imageview imgview;位圖的位圖;帆布畫布;油漆涂料;©override公共空間 oncreate (包 savedlnstanc

17、estate) super oncreate(savedlnstancestate);setcontentview(r. layout .main);findviewbyid(r.id imgview =(imageview)oimgview);顯示 cunrentdisplay 二 getwindowmanager () getdefaultdisplay ();浮動 dw 二 currentdisplay. getwidtho ;浮動 dh 二 currentdisplay. getheight ();位圖二bitmap. createbitmap(dw(int), (int)dh, co

18、nfig. argb_8888);帆布二新畫布(位圖);涂二 new ();paint setcolor(color green);paint. setstrokewidth (浮動)10. 00) ;/ /設(shè)置筆刷大小,自己的屏 幕太犀利了imgview. setlinagebitmap (位圖);imgview. setontouchlistener (這個(gè));©override公共布爾ontouch(視圖v, motionevent事件)int pointercount 二 eventgetpointercount ();int pointerld 二 0;&motio

19、nevent int action = (event. getactiono。action_mask)% 5;/ /統(tǒng)一單點(diǎn)和多點(diǎn)開關(guān)(行動) 案例 motionevent. action down:如果(pointercount > 1) pointerld=(event. getactiono&motionevent. action_pointer_id_mask)> > >motionevent. acti0n_p01nter_id_shift;打破;案例 motionevent. acti0n_m0ve:如果(pointercount 二二 2) 浮動

20、x 二 event. getx(l);浮動 y - event. gety (1);canvas drawpoint (int) x, y (int),油漆);imgview. invalidate。;打破;案例 motionevent. action_up:打破;返回true;案例三公共類 gameview2x 擴(kuò)展 gameview 實(shí)現(xiàn) surfaceholdero 回調(diào) 私人olddist浮動;私有的 pointf midpoint = new pointf();私有布爾 iszoom 二 false;公共 gameview2x(上下文上下文,attributeset attrs) 超

21、級(上下文,attrs);公共布爾 ontouchevent (motionevent 事件)切換(event getaction()& motionevent action_mask) 案例 motionevent. acti0n_d0wn: super actiondown(事件);打破;案例 motionevent. action_pointer_up: iszoom 二 false;打破;/ * * api原文是一個(gè)非主指針下降了。*翻譯過來就是:非第一個(gè)點(diǎn)按下* /案例 motionevent. acti0n_p0inter_d0wn: olddist二間距(事件);中點(diǎn)(中

22、點(diǎn)、事件);iszoom 二 true;打破;case motionevent actionmove:if (iszoom) float newdist 二 spacing (event);/ * * indicates that the new distance is greater than the distance between the two fingers* (+ 10 pixels are used to delay amplification, or move a little bit more pixels, zoom in, and feel too fast)* /if

23、(newdist + 10 > olddist) getgamethread () getgamedraw ()(int) midpointgetgamethread () getgamedraw () getgamedraw ()./ * * indicates that the new distance is smaller than the distance between the two fingers* /if (newdist + 10 < olddist) getgamethread (). get gamedraw (). setiszoom ()gamedraw.

24、 newx 二 0;gamedraw. newy 二 0;super actionmove (event);break;return true;private float spacing (motionevent event)float x 二 event getx (0) 一 event getx (1);float y 二 event gety (0) -event gety (1);return floatmath, sqrt (x * x + y * y)"'private void midpoint,float x 二 event getx (0) + event

25、getx (1);float y 二 event gety (0) + event gety (1);point. set (x / 2, y / 2);case 4 (image enlargement and reduction)the public class 'touchactivity extends activity'privatestaticfinalintnone 二 0;privatestaticfinalintmove 二 1;privatestaticfinalintzoom 二 2;privatestaticfinalintrotation 二priva

26、te int mode 二 none;private matrix matrix 二 new matrix ();private matrix savedmatrix 二 new matrix ();private pointf start 二 new pointf ();private pointf mid 二 new pointf ();private float s = 0;private float olddistance;private int rotate 二 none; overridepublic void oncreate (bundle savedlnstancestate

27、)super oncreate (savedlnstancestate);the setcontentview (r 1 ayout main);so, imageview, imageview 二(imageview) findviewbyld;imageview setontouchlistener (new ontouchlistener () overridepublic boolean the ontouch (view view,motionevent 事件)imageview imageview 二(imageview)視圖;開關(guān)(event. getactiono&mo

28、tionevent. action_mask) 案例 motionevent. acti0n_d0wn:savedmatrix. set (矩陣);event gety start set (event getx()();模式=移動;旋轉(zhuǎn)二沒有;打破;案例 motionevent. acti0n_up:案例 motionevent. action_pointer_up:模式二沒有;打破;案例 motionevent. acti0n_p0inter_d0wn:olddistance =(浮動)math. sqrt (event. getx(o)-event. getx(l)* (event. g

29、etx(0)-ev ent. getx(l) +(event. gety(0)-event. gety(1)*(event. gety(0)-ev ent. gety(1);if(olddistance > lof) savedmatrix. set (矩陣); mid. set (event. getx(o)+ event. getx(l)/ 2, (event. gety (0) + event. gety (1)/ 2);模式二放大;案例 motionevent. acti0nj10ve:如果(模式二=)如果(旋轉(zhuǎn)二二none) savedmatrix. set (矩陣);even

30、t gety mid set (event getx()();旋轉(zhuǎn)二旋轉(zhuǎn);其他matrix set(savedmatrix);雙 a 二 math atan(mid y-start y)/(mid x-start x);雙 b 二 math. atan (event gety()一mid y)/(event getx()一mid. x); 如果(b - a < math) o pi / 2 &b -一個(gè)數(shù)學(xué)。(n / 18) | | (b + math.pi)% matho pi - a數(shù)學(xué)。pi / 2 &(b + math pi)% matho pi - a數(shù)學(xué)。n/ 18) 0. 9 matrix. postscale (浮動),0. 9 (浮動);else if (a - b < math)。pi / 2 & a - b >數(shù)學(xué)。(n / 18) | | (a + math pi)% matho pi - b數(shù)學(xué)。pi / 2 &(a + math pi)% matho p

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論