The TouchUtils class in the android documentation has functions like drag():
https://developer.android.com/reference/android/test/TouchUtils.html#drag(android.test.InstrumentationTestCase,%20float,%20float,%20float,%20float,%20int)
but they do not support multi touch gestures, like a two finger swipe.
Looking at the MotionEvent.obtain() methods, there does not seem to be any way of invoking a "virtual" multi touch event from a testcase.
Anyone has got it working?
Apparently there is no other way than to use the private function MotionEvent.obtainNano() to mock the multi touch events. Hopefully this will change in future versions.
Related
I want to generate a touch event via programming on the screen outside of my app. My app currently has a floating window. I am trying to make something like repetitouch
I used the Hover library to create a floating window to display some message and buttons. I tried following this answer but the Hover library doesn't provide me with any views to work on
[ when I try to use view.dispatchTouchEvent(motionEvent); ]
The ClassName.this, getView() and all don't work.
Is there any other floating window library which provides views after implementation so that I can generate touches via code.
Can I do this task using services? If yes, what should I use?
Updated:::::
Refer the following link that shows How to stimulate touch event in android
https://stackoverflow.com/a/23902985/9287163
(Hope you find it useful)
I found my solution. I used instrumentation.
InstrumentationObj.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x_coordinate, y_coordinate, 0));
Simple scenario - ScrollView hosting a single LinearLayout which has several children - the preferred pattern to allow a scroll enabled views in developing on Android.
I need to capture onScrollEvents, start, stop, etc. that are readily available and work very well if I use ListView/onScrollListener combination.
A dedicated widget for scrolling a view DOES NOT have the built-in capabilities to capture these events? Come On! I have tried OnTouchEvent listener, onGestureListener, etc - all work arounds and all meant for something else. What am I missing here?
Unfortunately, there is no pre-built way for getting these events. However, there are two workarounds:
Use a ListView instead
Build your own custom ScrollView with ScrollListener. This is not that hard to achieve and has been done before.
We have the Gallery, which support swiping.
We also have 3rd-party components that support pinch-to-zoom on ImageView, such as ImageViewTouch in ImageViewZoom.
Now I would like to combine them both.
The problem is that the swipe events get consumed by the ImageViewTouch and missed by the Gallery.
How can consume events by both components?
That would solve my problem, because, eventually, after a few events, each component will know how to react accordingly.
For example, if the first event is ACTION_DOWN, it can be part of a pinch-to-zoom or part of a swipe. Both components (Gallery and ImageViewTouch) should consume it in order to know what to do in following events.
I combined both components by changing some code in ImageViewZoom. The change was for the events to return a value if they were consumed by the ImageViewTouch. If so, than the event should not be passed to the gallery. If the event is not consumed by the ImageView, than the gallery should consume it (if it can).
There are still some small issues, but it's functional. Hopefully other people in the community can help.
Here's the fork on github: https://github.com/kilaka/ImageViewZoom
Thanks.
which function is used for keeping track of all user interactions in Android?
I have used the onuserinteraction() function, but that does not include touching the mouse.
It includes clicking the mouse or any key event.
So is there any function which keeps track of touching the mouse also?
Take a look at these links:
View.OnTouchListener
Learn Android Tutorial 1.32 – Android’s OnTouchListener and MotionEvent
I hope this helps you...
I dont think android has a "mouse". U can only use onClick listeners.
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.