FIT2081 Lecture Notes - Lecture 10: Sqlite, Move, Methamphetamine
View.setOnTouchListener(new View.OnTouchListener()
!"#$%&"'()*+",-(*.//%&0"#.'+(1
onTouch(View v, MotionEvent event)
2$33.1"4+.&"$"'()*+".5.&'"%/"1%/,$'*+.1"'("$"View
§
6.')-&"true %7"%&'.-./'.1"%&"/)8/.9).&'".5.&'/"%&"'+."0./')-.
:..,"*$33%&0"onTouch $/"3(&0"$/"'+."0./')-."0(./
§
§
6.')-&"false %7"(&3;"%&'.-./'.1"%&"'+."7%-/'"<(4&
=-"%7"$*'%(&"'$>./",3$*."%&"$",3$*."(&/*-..&";()?-."&('"
%&'.-./'.1"%&
§
§
○
MotionEvent
=8@.*'")/.1"'("-.,(-'"#(5.#.&'".5.&'/
A
2$&"+(31".%'+.-"$8/(3)'.B-.3$'%5."#(5.#.&'/"$&1"('+.-"1$'$C"1.,.&1%&0"
(&"1.5%*."';,.
A
getActionMasked()
A
!"-.')-&/"#$/>.1"$*'%(&"8.%&0",.-7(-#.1C"4%'+()'",(%&'.-"%&1.D"%&7(
6.')-&/"%&1.D"$//(*%$'.1"4%'+",(%&'.-"$*'%(&/
○
E/."/4%'*+F*$/."(&"'+%/"-.')-&"5$3).
○
G+-.."';,./"(7"'()*+".5.&'/H
I8)%3'F%&"/'$'%*"5$3)./"$**.//.1"1%-.*'3;"7-(#"MotionEvent '+$'"*$&"
1.'.*'")/.-"'()*+J
ACTION_DOWN
onTouch .D.*)'./"(&*.".$*+"'%#."$"7%&0.-B#()/."0(./"1(4&
§
2$,')-."1(4&?/"D"$&1";"$&1"/$5."7(-"4+.&"),"(**)-/
2$&"1.'.-#%&."*+$&0."%&"D"$&1";"8.'4..&"1(4&"$&1"),
K
L3/("&..1"'(",(/%'%(&"1-$0"1-$4"/+$,.
K
M'(-."%&"mLastTouchX $&1"mLastTouchY
N..1"'("8."*3$//"3.5.3"/("'+.;"()'3%5."/.,$-$'."
onTouch .D.*)'%(&/
®
K
§
○
ACTION_MOVE I(&3;"O%&.C"&('"2%-*3.B6.*'J
(&G()*+".D.*)'./"-.,.$'.13;"I4%'+"+%0+./'"7-.9).&*;"=M"*$&"
#$&$0.J"$/"$"7%&0.-B#()/."#(5./"$7'.-"1(4&"$&1"),
§
P$*+"'%#."'+%/"-)&/C"MQO%'."18"%/"),1$'.1"F*3.$-3;" $"8%0"1-$%&"
(&"1.5%*."-./()-*./
23.$-3;"&('"8./'"$,,-($*+"'(",-(83.#
K
§
N("&..1"ACTION_POINTER_MOVE 8.*$)/.H
ACTION_MOVE 4(->/"/%#%3$-3;"'("$&"$--$;"(7",(%&'.-/C"
/("4."*$&".$/%3;"%'.-$'."'+-()0+"$33"'+.".5.&'/"$&1"
-.'-%.5."'+."1.'$%3/"(7".$*+"(&.C")/%&0"8%1%-.*'%(&$3"
#$,,%&0"8.'4..&"'+."R<"$&1"'+."%&1.D"(7".$*+",(%&'.-"
(findPointerIndex(firstPointerId))S
K
§
○
ACTION_UP I2%-*3.B6.*'C"&('"O%&.J
onTouch .D.*)'./"(&*.".$*+"'%#."$"7%&0.-B#()/."0(./"),
§
2$,')-."),?/"D"$&1";
§
E/."mLastTouchX $&1"mLastTouchY '("*$3*)3$'."*+$&0./"
8.'4..&"1(4&"$&1"),".5.&'"I1TC"1UJ"
§
storeShape(selectedShapeDrawing, downX,
downY, dX, dY)
M'(-./"$"/+$,."4%'+"'+./.",$-$#/"%&'("MQO%'."18
R&'("$"*(&'.&'V$3)./"(8@"4+%*+"%/"'+.&"%&/.-'.1"
%&'("26"$&1"/'(-.1"%&"18"'("8."1%/,3$;.1
®
K
§
○
ACTION_POINTER_DOWN
=**)-/"4+.&"'+.-."%/"#(-."'+$&"(&.",(%&'.-"(&"'+."/*-..&"$'"$&;"
0%5.&"'%#.
○
=**)-/"7(-"$33"('+.-",(%&'.-/"$,$-'"7-(#"'+."7%-/'B,-%#$-;",(%&'.-
○
A
ACTION_POINTER_UP
=**)-/"4+.&"'+.-."%/"#(-."'+$&"(&.",(%&'.-"(&"'+."/*-..&"$'"$&;"
0%5.&"'%#.
○
=**)-/"7(-"$33"('+.-",(%&'.-/"$,$-'"7-(#"'+."7%-/'B,-%#$-;",(%&'.-
○
A
2(##(&WL*'%(&/WM')1.&'
2(##(&L*'%(&M%#,3.
How$do$you$set$up$a$View$so$touch$events$on$it$can$be$detected$and$
responded$to?
L7'.-"0%5%&0"'+."V%.4"$&"R<"/("%'"*$&"8."-.7.-.&*.1C"/.'"$"&.4"
V%.4S(&G()*+O%/'.&.-IJ"*(&'$%&%&0"$"#.'+(1"(&G()*+"4%'+"X",$-$#.'.-/C"'+."
V%.4"$&1"$"Y('%(&P5.&'S
public boolean onTouch(View v, MotionEvent ev)
G+%/"#.'+(1"*(&'$%&/"/4%'*+F*$/."4%'+"'+."'+-.."*$/./"$//(*%$'.1"4%'+"'()*+"
.5.&'/"I<=ZNC"Y=VPC"E[JS"G+./."$-."8)%3'F%&"/'$'%*"5$3)./"$**.//.1"1%-.*'3;"
7-(#"'+."Y('%(&P5.&'"*3$//"'+$'"*$&"1.'.*'")/.-"'()*+S
Y('%(&"*$&"8."'-$*>.1")/%&0"8)%3'F%&"#.'+(1/"0.'TIJ $&1"0.'UIJ '+$'"1.'.*'"'+."
$D%/"5$3)./"7(-"'+.",(%&'.-S
Why$does$a$pointer$have$an$index$and$id?
R&1.D"$33(4/".5.-;",(%&'.-"'("8."$**.//.1"7-(#"'+."$--$;"%'"%/"/'(-.1"%&S
G+."R<"%1.&'%7%./"$&1"-.#.#8.-/".$*+"/,.*%7%*",(%&'.-"$/"3(&0"$/"'+$'",(%&'.-"%/"
(&"'+."/*-..&S
Under$typical$drag-draw$use,$which$case's$code$would$get$executed$the$most?
ACTION_MOVE 4()31"8.".D.*)'.1"'+."#(/'S
G+%/"'-$*>/"'+."\1-$00%&0\",$-'"(7"1-$0F1-$4")/.S
G;,%*$33;"ACTION_DOWN $&1"ACTION_UP (&3;".D.*)'."(&*.",.-",(%&'.-C"/%&*."
ACTION_DOWN (&3;"(**)-/"(&*."I'+."7%-/'"'%#."'+.",(%&'.-"%/"1.'.*'.1"(&"'+."
/*-..&JC"$&1"ACTION_UP (&3;"(**)-/"(&*."I'+."7%-/'"'%#."'+.",(%&'.-"*$&"&("
3(&0.-"8."1.'.*'.1"(&"'+."/*-..&JS
Explain$what$ACTION_MOVE does$when$you$draw$freehand$circle.
R'"1-$4/"$"3%&."*(&/%/'%&0"(7"/#$33"7%33.1"*%-*3./"(7"-$1%)/"]"I%S.S"1('/J"$3(&0"'+."
$D%/",(%&'/"'+.")/.-"1-$0/"'+.",(%&'.-"$*-(//S
How$does$this$code$store$a$shape$whose$position$and$size$are$based$on$a$
finger$drag?
R&"'+."ACTION_UP *$/.C"dX -.,-./.&'/"'+."1%77.-.&*."%&"DF$D%/"5$3)./"7-(#"'+."
7%-/'"%&/'$&*."'+.",(%&'.-"4$/"1(4&"(&"'+."/*-..&"$&1"'+."%&/'$&*."'+.",(%&'.-"
4$/"),"(77"'+."/*-..&C"$&1"dY /%#%3$-".D*.,'"7(-";F$D%/"%&/'.$1"(7"DF$D%/S"G+./."
'4("5$3)./"*(#."'(0.'+.-"'("7(-#"'+."/%^."(7"'+."1-$4&"/+$,.S
[$//%&0"'+./."5$3)./"%&'("M'(-.M+$,.C"$3(&0"4%'+"mLastTouchX $&1"
mLastTouchY 4+%*+"0%5."'+.",(/%'%(&"(7"'+."1-$4&"/+$,.C"/'(-./"'+."/+$,."
%&'("$"ContentValues (8@.*'"4+%*+"%/"'+.&"%&/.-'.1"%&'("'+."26"$&1"'+)/"
/'(-.1"%&"'+."18"'("8."1%/,3$;.1S
Week$10
G)./1$;C" X_"Y$;"X`ab
aaH`c
Document Summary
= main touch processing method ontouch(view v, motionevent event) Called when a touch event is dispatched to a view. Return true if interested in subsequent events in the gesture. Keep calling ontouch as long as the gesture goes. Return false if only interested in the first down. Or if action takes place in a place onscreen you"re not interested in. Can hold either absolute/relative movements and other data, depending on device type getactionmasked() = returns masked action being performed, without pointer index info. Three types of touch events: (built-in static values accessed directly from motionevent that can detect user touch) Action_down ontouch executes once each time a finger/mouse goes down. Capture down"s x and y and save for when up occurs. Can determine change in x and y between down and up. Need to be class level so they outlive separate ontouch executions.