MultiTouchAndGestures

MultiTouchAndGestures - Touch& Gestures  ...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Touch & Gestures   MotionEvents   Touch Handling   Gestures   Represents a movement in an input device reading   e.g., pen, trackball, mouse, finger   Records event’s time, action, pressure, location, source, and more.   Some common MotionEvent actions   ACTION_DOWN   ACTION_UP   ACTION_POINTER_DOWN   ACTION_POINTER_UP   ACTION_MOVE   Some useful MotionEvent methods   getPointerCount()   getActionIndex()   getActionMasked()   getX()   getY()   View.onTouchEvent() delivers MotionEvent to the View being touched   If subclassing, onTouchEvent(), return true if the MotionEvent has been consumed; false otherwise   View.OnTouchListener defines touch event callback methods   onTouch() called when user performs a touch event, such as pressing, releasing or dragging an item on the screen   Should return true if it has consumed the event   View.setOnTouchListener() registers listener for Touch callbacks   1 ­touch – each touch is a single event   Process ACTION_DOWN, ACTION_MOVE & ACTION_UP independently   2+ ­touch – multiple touches combined to form a gesture   Identify & process combinations of touches such as ACTION_DOWN, followed by ACTION_POINTER_DOWN   Some common Gestures can be recognized by GestureDetectors ▪  E.g., double tap, fling, confirmed single tap, etc. #1 touch #2 touch #1 lift #2 lift Action ACTION_DOWN ACTION_MOVE ACTION_POINTER_DOWN ACTION_MOVE ACTION_MOVE ACTION_POINTER_UP ACTION_UP ID 0 0 1 0 0 0 1 #1 touch #2 touch #2 lift #1 lift Action ACTION_DOWN ACTION_MOVE ACTION_POINTER_DOWN ACTION_MOVE ACTION_MOVE ACTION_POINTER_UP ACTION_UP ID 0 0 1 0 0 1 0 #1 touch #2 touch #3 touch #2 lift #1 lift #3 lift Action ACTION_DOWN ACTION_POINTER_DOWN ACTION_POINTER_DOWN ACTION_MOVE ACTION_POINTER_UP ACTION_POINTER_UP ACTION_UP ID 0 1 2 0 1 0 2 public class IndicateTouchLocationActivity extends Activity { public void onCreate(Bundle savedInstanceState) { … final FrameLayout frame = … frame.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int actionCode = event.getActionMasked(); for (int i = 0; i < event.getPointerCount(); i++) { switch (actionCode) { case /* interesting motion event */ : { // make a view showing touch location frame.addView(/* new view */); … public class ViewFlipperTestActivity extends Activity { private ViewFlipper mFlipper; private int mCurrentLayoutState; private GestureDetector gd; public void onCreate(Bundle savedInstanceState) { … mFlipper = (ViewFlipper) findViewById(R.id.view_flipper); mCurrentLayoutState = 0; …. … gd = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { public boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (velocityX <  ­10.0f) { /* change view */ } return true; } }); } public boolean onTouchEvent(MotionEvent event) { return gd.onTouchEvent(event); }   GestureBuilder allows developers to create & save custom gestures   GestureLibraries supports loading custom gestures & recognizing then at runtime   GestureOverlayView intercepts user gestures and invokes application code to handle them   Comes bundled with emulator   Stores gestures to /mnt/sdcard/gestures   Copy this file to /res/raw directory   View intercepts gestures   Invokes OnGesturePerformedListener public class GesturesActivity extends Activity implements OnGesturePerformedListener { private GestureLibrary mLibrary; public void onCreate(Bundle savedInstanceState) { … mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures); if (!mLibrary.load()) { finish(); } GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); gestures.addOnGesturePerformedListener(this); … } … … public void onGesturePerformed( GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = mLibrary.recognize(gesture); if (predictions.size() > 0) { Prediction prediction = predictions.get(0); if (prediction.score > 1.0) { // Check prediction.name and take appropriate action } } } }   TouchIndicateTouchLocation   TouchGestureViewFlipper   TouchGestures ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern