Android Training Lesson 12: FPT Software
Android Training Lesson 12: FPT Software
Android Training Lesson 12: FPT Software
ANDROID TRAINING
LESSON 12
Version 0.1
• Gestures
• Built-in gesture detectors
• Handling Common Single-Touch Gestures
• Handling Common Multi-Touch Gestures
• In the onCreate() method we load the library and add the GestureOverlayView to
the listener:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
• Implementation of onGesturePerformed(),
when the listener is triggered, a list of
predictions and a score is returned, each with
the name you entered earlier in the Gesture
Builder.
if ("open".equalsIgnoreCase(result)) {
Toast.makeText(this, "Opening the document", Toast.LENGTH_LONG).show();
} else if ("save".equalsIgnoreCase(result)) {
Toast.makeText(this, "Saving the document", Toast.LENGTH_LONG).show();
}
}
}
• GestureDetector
– A GestureDetector is an Android class that can
take motion events, do some mathematical magic
to determine what they are, and then delegate
calls to a GestureListener object as specific gesture
or other motion callbacks.
private class GestureListener implements GestureDetector.OnGestureListene
r, GestureDetector.OnDoubleTapListener {
PlayAreaView view;
public GestureListener(PlayAreaView view) {
this.view = view;
}
}
• OnDoubleTapListener
– onSingleTapConfirmed: Called when a single-tap
event occurs.
– onDoubleTap: Called when a double-tap event
occurs.
– onDoubleTapEvent: Called when an event within a
double-tap gesture occurs, including any down,
move, or up MotionEvent.
• ScaleGestureDetector
– Detects transformation gestures involving more than one
pointer ("multitouch") using the supplied MotionEvents.
• This class should only be used with MotionEvents
reported via touch. To use this class:
– Create an instance of the ScaleGestureDetector for your
View
– overriding the onTouchEvent(MotionEvent) method to
pass the MotionEvent objects to the gesture detector
• ScaleGestureDetector.OnScaleGestureListener
callback will notify users when a particular
gesture event has occurred.
– onScale(ScaleGestureDetector detector) Responds
to scaling events for a gesture in progress.
– onScaleBegin(ScaleGestureDetector detector)
Responds to the beginning of a scaling gesture.
– onScaleEnd(ScaleGestureDetector detector)
Responds to the end of a scale gesture.