2. Android touch basics
The Android standard View class support
touch events.
You can react to touch events in your
custom views and your activities.
Android supports multiple pointers, e.g.
fingers which are interacting with the
screen.
3. The base class for touch support is the
MotionEvent class which is passed to
Views via the onTouchEvent() method.
To react to touch events you override the
onTouchEvent() method.
4. Single touch
If single input is used you can use the
getX() and getY() methods to get the
current position of the first finger.
Via the getAction() method you receive
the action which was performed
5. The MotionEvent class provides the following
constants to determine the action which was
performed.
6. Demo
Using One Touch
Create custom View
Draw in it
Track touches points
Draw lines while move
8. Gestures
Android provides special types of touch
screen events such as pinch , double tap,
scrolls , long presses and flinch. These are
all known as gestures.
Android provides GestureDetector class
to receive motion events and tell us that
these events correspond to gestures or
not.
9. Using
you need to create an object of
GestureDetector and then extend
another class with
GestureDetector.SimpleOnGestureListener
to act as a listener.
10. Gestures Type
Touch
Long press
Swipe or drag
Long press drag
Double touch (Tap)
Pinch open / close
11. Where I can use onTouch
Listener
onTouchEvent (Activity Override)
onTouchEvent (CustomView Override)
onTouch(view.setOnTouchListener)