cse4443 – mobile user interfaces€¦ · indentifier vs. index • when a finger, or pointer,...
TRANSCRIPT
Scott MacKenzieYork University
CSE4443 – Mobile User Interfaces
© Scott MacKenzie
(Part 1)
Concepts
© Scott MacKenzie 2
Touch Multitouch
Preface - Terminology
• Android documentation uses the term “gesture” for touch interaction
• That’s fine, but…• We’ll also discuss gestural input in a different
context later (unistroke recognition)
© Scott MacKenzie 3
Map
• Android’s “Touch Mode”• Single touch• Multitouch• Touch gestures
© Scott MacKenzie 4
Map
• Android’s “Touch Mode”• Single touch• Multitouch• Touch gestures
© Scott MacKenzie 5
Key vs. Touch Input
• Consider three input scenarios:– Physical keys
• UI widgets acquire and reveal focus• Users navigate with keys or a trackball, then select
– Touch• UI widgets do not acquire and reveal focus• “Direct input” touch to select
– Hybrid (keys + touch)• Do widgets need to acquire and reveal focus?
© Scott MacKenzie 6
Examples
Key vs. Touch Input
• Consider three input scenarios:– Physical keys
• UI widgets acquire and reveal focus• Users navigate with keys, then select
– Touch• UI widgets do not acquire and reveal focus• “Direct input” touch to select
– Hybrid (keys + touch)• Do widgets need to acquire and reveal focus?
© Scott MacKenzie 7
Hybrid Example
• HTC Dream (aka T1-Mobile G1)– 1st Android phone (2008)– Input via physical keys, trackball, or touch
© Scott MacKenzie 8
Android’s Touch Mode
• For apps to work well on hybrid devices, the Android platform defines “touch mode”
• Normal mode– Widgets acquire and reveal focus (key input)
• Touch mode– Widgets do not acquire and reveal focus (touch input)
• Mode transitions (next slide)
© Scott MacKenzie 9
Input Mode Transitions
© Scott MacKenzie 10
Normalmode
Touchmode
User touchesscreen
User presses key
Keyinteraction
Touch interaction
Touch Mode Explained
© Scott MacKenzie 11http://developer.android.com/guide/topics/ui/ui-events.html#TouchMode
Android Buttons and Touch Mode
• Android buttons:– Not focusable in touch mode– Fire click events when touched
• Writing code for Android buttons:– Do attach a click listener– Do not attach a touch listener
• Examples:
© Scott MacKenzie 12
Demo_Android Demo_Layout Demo_Buttons
Map
• Android’s “Touch Mode”• Single touch• Multitouch• Touch gestures
© Scott MacKenzie 13
Handling Touch Events
© Scott MacKenzie 14
True = the event has been consumed (no further processing is necessary)False = not consumed (further processing is necessary)
The MotionEvent Object
• Carries information about the touch event• Action codes (retrieved via getAction):
– ACTION_DOWN finger touch– ACTION_MOVE finger movement – ACTION_UP finger lift– Etc.
• Retrieve values using get-methods:– getX, getY, getEventTime, getPressure, etc.
• Note: A finger is called a “pointer” in the Android documentation
© Scott MacKenzie 15
Demo_Touch
© Scott MacKenzie 16
EscLet’s have a look.
Demo_Ink
© Scott MacKenzie 17
EscLet’s have a look.
Drawing with digital ink on a canvas
Touch Mode Buttons
Map
• Android’s “Touch Mode”• Single touch• Multitouch• Touch gestures
© Scott MacKenzie 18
Compare
© Scott MacKenzie 19
Single touch:
Multitouch:
Multitouch Summary
• 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
Indentifier vs. Index
• 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
Changing Touch Points
• 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
• The id is retrieved by
© Scott MacKenzie 22
int pointerIndex = me.getActionIndex();
int pointerId = me.getPointerId(pointerIndex);
Demo_Multitouch
© Scott MacKenzie 23
EscLet’s have a look.
Thank You
24© Scott MacKenzie