Download Map Compare

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
09/02/2016
Map
•
•
•
•
Android’s “Touch Mode”
Single touch
Multitouch
Touch gestures
© Scott MacKenzie
18
Compare
Single touch:
Multitouch:
© Scott MacKenzie
19
1
09/02/2016
Multitouch Summary (1)
• If fingers always left the tablet in the reverse order from touching, multitouch would be simple
• Of course, there is no guarantee that finger events will be so orderly
• To manage touch events for multiple fingers, each finger touch point (also called a pointer) has both an index and an identifier.
© Scott MacKenzie
20
Multitouch Summary (2)
• When a finger, or pointer, first touches the display surface, it is assigned an identifier (id)
• The id will not change for the duration of the movement associated with that finger
• However, the index of the finger/pointer might change from one touch event to the next
• This is simply an artefact of the possibility of multiple fingers touching and leaving the display surface and in any order
© Scott MacKenzie
21
2
09/02/2016
Multitouch Summary (3)
• As noted in the MotionEvent API, “the number of pointers only ever changes by one as individual pointers go up and down.”
• The index of the changed pointer is retrieved from the MotionEvent object ( me) by
int pointerIndex = me.getActionIndex();
• The id is retrieved by
int pointerId = me.getPointerId(pointerIndex);
22
© Scott MacKenzie
Demo_Multitouch
Esc
Let’s have a look.
© Scott MacKenzie
23
3
09/02/2016
What is Where!
Demo Touch
Demo Ink
Demo Multitouch
DemoTouchActivity.java
DemoInkActivity.java
DemoMultitouchActivity.java
Activity
Activity
Activity
onTouch
onTouch
onTouch
PaintPanel.java
PaintPanel.java
View
View
PaintPanel
View
Demo Scale
DemoScaleActivity.java
PaintPanel.java
Activity
View
Coming Up…
onTouchEvent
© Scott MacKenzie
24
Map
•
•
•
•
Android’s “Touch Mode”
Single touch
Multitouch
Touch gestures
© Scott MacKenzie
25
4
09/02/2016
Android Touch “Gestures”
• Question:
– Is it possible to detect high‐level finger actions, such as double tap, flick, drag, pinch, etc.?
• Answer: – Yes (of course) … but how?
• Two approaches:
– Roll your own (use a touch listener in combination with MotionEvent, state variables, timers, etc.) – Use Android’s gesture detector classes
© Scott MacKenzie
26
Android Touch “Gestures”
• Question:
– Is it possible to detect high‐level finger actions, such as double tap, flick, drag, pinch, etc.?
• Answer: – Yes (of course) … but how?
• Two approaches:
– Roll your own (use a touch listener in combination with MotionEvent, state variables, timers, etc.) – Use Android’s gesture detector classes
© Scott MacKenzie
27
5
09/02/2016
1‐Finger ( ) Gestures
Touch
Long
press
Swipe or
drag
Long press
drag
Double
touch
Double touch
drag
(click)
http://developer.android.com/design/patterns/gestures.html
© Scott MacKenzie
28
Android’s GestureDetector Class
(single touch)
• From the API:
– Detects various gestures and events using the supplied MotionEvents
• Programming approach:
– Extend the “convenience” class…
GestureDetector.SimpleOnGestureListener
… and implement methods of interest
© Scott MacKenzie
29
6
09/02/2016
GestureDetector.SimpleOnGestureListener
a “convenience” class
30
© Scott MacKenzie
Minimum Implementation
Note: We are handing touch events in the view, not in the activity.
© Scott MacKenzie
31
7
09/02/2016
2‐finger ( ) Gestures
Pinch
open
Pinch
closed
(click)
http://developer.android.com/design/patterns/gestures.html
© Scott MacKenzie
32
Android’s ScaleGestureDetector Class
(multitouch)
• From the API:
– Detects scaling transformation gestures using the supplied MotionEvents
• Programming approach:
– Extend the “convenience” class…
ScaleGestureDetector.SimpleOnScaleGestureListener
… and implement methods of interest
© Scott MacKenzie
33
8
09/02/2016
ScaleGestureDetector.SimpleOnScaleGestureListener
a “convenience” class
Notes:
• The listener methods above receive a ScaleGestureDetector
object. • This is different from the listener methods in GestureDetector.SimpleOnGestureListener, which receive a MotionEvent object.
• What methods are available with ScaleGestureDetector? (next slide)
© Scott MacKenzie
34
ScaleGestureDetector
© Scott MacKenzie
35
9
09/02/2016
Minimum Implementation
36
© Scott MacKenzie
Demo Scale
Esc
Let’s have a look.
Note: See PaintPanel class in Demo Scale
© Scott MacKenzie
37
10
09/02/2016
Homework
• The usual… 
• In particular,
– Download, import, run Demo_TiltBall
– Uses a sensor for orientation/acceleration
– Make sure it runs properly on your device
– Required for Lab #4
© Scott MacKenzie
38
Thank You
© Scott MacKenzie
39
11