I have to implement a two fingers tap.
For example I have a listView with multiple items, which already have a click listener for each row and touch listener. Now I have to do something if the user put two fingers on a row.
How can I do this?
Any suggestion is appreciated.
I believe just the gesture API only support single touch.
You basically have to override `onTouchEvent, and play with e.getPointerCount() and check the time between the ACTION_POINTER_DOWN and ACTION_POINTER_UP. You will probably also think about the case where the two touches actually do not come at the exact same time or leave the screen at the exact same time either.
Try this
Android multi-touch support
Or
http://www.rbgrn.net/content/367-source-code-to-multitouch-visible-test
android imageView: setting drag and pinch zoom parameters
This may help you.
Not sure what you mean by 2 fingers tap. If you mean a double tap (one finger, 2 taps) , I recommend this:
http://mobile.tutsplus.com/tutorials/android/android-gesture/
But if you are referring to 2 different fingers tapping once, would not recommend doing that a 2 finger tap because it goes against the Android design guidelines. If anything it is recommended to do a long press, which can easily be implemented overriding the onLongClick() method.
But if you really do not want to listen to me because you think I am stupid. You would essentially need to implement your own multi touch gesture. Here is one example:
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-2-building-the-touch-example/1763
FYI, please be aware of what android version you want to support.
Related
Is there documentation or an API that allows for an object to be flicked in a certain direction, such as a button? I've tried using 'drag & drop' to try and emulate this feature but not with the same results.
Here is an example: http://youtu.be/J-83lssy5kA?t=1m47s
Basically, you can see the guy flick the chat-head towards the close icon to close the chat. The same features are found in android launchers where you can flick to remove an icon fromthe home screen. Are those gestures custom built or is it an API, thanks.
The flick that you are talking about is called fling officially. Yes, you can handle fling events using the Android API by having your activity implement the GestureDetector.OnGestureListener interface. This interface will let you handle all the common gestures like scroll, long press, fling and so on. In your case, the onFling() method will be called.
However, in your case you only want the fling gesture in which case you will have to subclass GestureDetector.SimpleOnGestureListener and override methods selectively.
For more, please refer the docs: http://developer.android.com/training/gestures/detector.html
Yes I noticed this.
I recently tried to find a coding for the same but never could and lost interest. But this is what I feel is the solution:-
In a quick time interval find 2 points cordinates of that flicking action( drag)
Then project a third point according to the slope of this line equation.
Keep updating the position of the view you flicked while you make it travel slowly from point2 to projected point3 via may be a slow loop or timer
For slope you have
(y1-y2)/(x1-x2)
Does "ROBOTIUM " support 2 finger touch? Actually i want to write a testcase in which the user taps and hold one button and clicks on another button using other finger.
is that possible?
Actually, it's not supported. You can write enhancement here:
http://code.google.com/p/robotium/issues/list
It is possible, its not easy but its possible. You will need to MotionEvent which you can dispatch as per your need.
What is the best way to touch two buttons at the same time? I am working on an app that has buttons, like a D-pad and a jump button, to move your character around. Right now I am just using normal buttons and handling them with an OnClickListener. I am having problems when I am running and need to jump at the same time, or if I am running to the right, then want to go left without having to pick my finger up. I know this is possible because it works greats on game like Sonic CD and some others. Any help would be greatly appreciated.
OnClick fires only on release. Instead use the touch event handlers so that when they touch occurs, you get the events. However, note that not all devices have multitouch, and thus not all of them will be able to handle the double-touch case correctly. They will provide touch events, but not two of them. Also note that you may receive multiple "pointers" within a touch event, and will have to decide which is "yours" for each button if that matters.
Good day to all!
I'm trying to implement a voice over for Android (like iPhone), but a specific application (not the entire operating system)
Imagine a screen with six buttons, so they occupy the entire activity, distributed equally in size.
When I "walk" with my finger on the screen, I want to give focus to the button and capture the event when the button has focus and let the focus as well.
Conclusion: As I flick on the screen and if it is over a button, the focus button. if I continue to drag the finger, give the focus to another button without taking your finger off the screen.
Can anyone help me? Sorry for bad English.
I don't think you can use the Android Button class for this, but instead do a custom view, draw six rectangles, and write an onTouchEvent method that determines what sound to play based on where the user's finger is. See the Sudokuv4 example at http://pragprog.com/book/eband3/hello-android for some code you can use.
Well you have to know positions of buttons. You can use basic view functions to get positions (getLeft(), and so on...)
After that you have to implment onTouchListner for Activity. Within you have to check where Event.x and Event.y pointers are and set foucs to specified view. After pointers move from specified view you set focus to false.
Hi Here i want to solve the problem regarding multitouch in android. Is this possible to fire events of 2 buttons together if this is possible then how can i do this. please help regarding this. In my game application i want to do something after pressing two buttons together. How can i do this.
I don't think that it is possible to aggregate two events to a single one oob. But it shouldn't be to hard to determine if two buttons were pressed simultaneously by using a OnTouchListener you bind to the parent element of the two buttons.
When an event is thrown and the onTouch() method is called. You got a bunch of arguments related to the event, like what kind of event it was (Action_Down, Action_Move, Action_Up etc.). You also get the information if the action was performed by the first oder by the second finger so this should give you the option to decide whether both buttons were touched.
Here you can find a nice tutorial about multi touch support on Android.