Multitouch and gesture detection part 2
In my previous article I showed how to create a simple class that handles the basic gesture events such as ACTION_DOWN, ACTION_MOVE, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP. Combinations of these, you can implement all of touch gesture stuffs thats you need in your work with a touch screen phone.
Handling multitouch
Create a boolean member variable in your MultitouchView class that stores the actual multitouch event. Name it isMultiTouch.
- private boolean isMultiTouch = false;
- {...}
The variable's default value is false, because the basic touch event isn't multitouch until the user touches the screen with a second, third non-primary-finger.
In my last tutorial I wrote, the ACTION_POINTER_DOWN action called, when the user touches the screen with a second finger.
- case MotionEvent.ACTION_POINTER_DOWN:
- {
- Log.e( "Multitouch", "Action pointer down" );
- isMultiTouch =true;
- break;
- }
You have to set the isMultiTouch variable back to false when the ACTION_POINTER_UP action called. The bits in ACTION_POINTER_ID_MASK indicate which pointer changed.
Swipe detection
For swipe detection you have to set a minimal swipe lenght with a member (final) variable.
- private static final int SWIPE_MIN_LENGHT = 100;
Lesser lenght may cause the system detects swipe gesture instead of point action. Longer lenght may cause the system detects point gesture instead of swipe action. I think 100 is a good choice.
Multitouch detection by time
If you want to detect swipe gesture with multitouch the above example isn't good, because you must touch the screen with the same time and that is hard. I set a minimal time interval thats handles the time between the first and the second finger touch the screen. You have to create long a variable to store the first finger's touch time in ms.
- private static final long MULTITOUCH_DELAY = 500;
- private long mTouchStart;
500 ms is enough time to touch with the second finger.
- case MotionEvent.ACTION_DOWN:
- {
- break;
- }
Set the value when ACTION_DOWN called.
Now calculate with those two variables the multitouch value.
- case MotionEvent.ACTION_POINTER_DOWN:
- {
- Log.e( "Multitouch", "Action pointer down" );
- break;
- }
Within a half seconds the application wait for a non primary finger's touch.
That's it, feel free to comment.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
12 years 4 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
12 years 4 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
12 years 4 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
12 years 4 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
12 years 4 weeks ago
Poll
Useful resources
Android Development Projects
- App Development
- Telegram bulk messages sender
- Photo Editing Application
- React Native Developer - part time basis
- Locket App Copy
- Courier app $150 only
- Mobile Application Development - IOS and Android (Rewards for sharing brand ads on social media)
- Android app for sms
- Fitness app project for sale online
- io developer