Programmatically pass (or delay) touch event to panel...?

PaulR

Active Member
Licensed User
Longtime User
I am working on an app with a custom GUI, controlled with multi-touches via the Gestures library. I have a three finger swipe gesture to scroll through screens.

On one screen I have standard UI elements, at the moment ListViews.

My issue is that I want to be able to delay passing touch events through to the panel containing the ListView.

ie when a touch is made on the panel containing the ListViews I need to be able to wait until I am sure that the first touch is not part of a multi-touch gesture, and only then allow it to pass to the ListView.

Any ideas would be much appreciated...
 

Informatix

Expert
Licensed User
Longtime User
I am working on an app with a custom GUI, controlled with multi-touches via the Gestures library. I have a three finger swipe gesture to scroll through screens.

On one screen I have standard UI elements, at the moment ListViews.

My issue is that I want to be able to delay passing touch events through to the panel containing the ListView.

ie when a touch is made on the panel containing the ListViews I need to be able to wait until I am sure that the first touch is not part of a multi-touch gesture, and only then allow it to pass to the ListView.

Any ideas would be much appreciated...

A touch event is a very generic event. What do you want to do exactly ? Delay a click ? Delay the scrolling events ?

Basically, to prevent a ListView from intercepting the Touch events, you have to use the Reflection library (put this code in your panel touch handler):
B4X:
Dim r As Reflector
r.Target = your_listview
r.RunMethod2("requestDisallowInterceptTouchEvent", True, "java.lang.boolean")
When you want to let the events pass, let the ListView intercept the events.
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Thanks for the replies gentlemen....

What I am exactly looking to achieve is the ability to have a 3 finger screen change gesture working over standard GUI elements like a ListView.

So when the first touch happens I will set a timer for X milliseconds to see whether any additional touches happen. If there are no more touches then the first touch is passed to the View. edit: and all further moves and action up are then passed (I am detecting touches with the Gestures library over the entire screen size).

So (I think) I cannot simply prevent the ListView from intercepting touch events because when I re-enable it the event has already been consumed by the Gestures.SetOnTouchListener event sub.

I see from Stack Overflow that it is possible to store/create a MotionEvent and pass it to the onTouchEvent method of the View which would be perfect (well passing it to the parent panel of the views would be 100% perfect).

Would creating a MotionEvent object be possible with the Reflection library?
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Would creating a MotionEvent object be possible with the Reflection library?
I will answer for my own library because I know it well, of course. So, with Gesture Detector (but I think that works also with Gestures), you can pass a MotionEvent to another view this way:
B4X:
Sub GD_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object)
   Dim r As Reflector
   r.Target = your_view
   r.RunMethod4("onTouchEvent", Array As Object(MotionEvent), Array As String("android.view.MotionEvent"))
End Sub
Beware: the X and Y positions, included in the MotionEvent data, are relatives to the top left corner of the view that first receives the event. So, if your destination view has a different size, you'll get shifted positions.
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Unfortunately the Gestures library does not expose the raw MotionEvent like your library does so I think I'll (under)use your library to store and send the first touches.

Thanks very much for the assistance! :)
 
Upvote 0

nicholas.jj.taylor

Member
Licensed User
Longtime User
I will answer for my own library because I know it well, of course. So, with Gesture Detector (but I think that works also with Gestures), you can pass a MotionEvent to another view this way:
B4X:
Sub GD_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object)
   Dim r As Reflector
   r.Target = your_view
   r.RunMethod4("onTouchEvent", Array As Object(MotionEvent), Array As String("android.view.MotionEvent"))
End Sub
Beware: the X and Y positions, included in the MotionEvent data, are relatives to the top left corner of the view that first receives the event. So, if your destination view has a different size, you'll get shifted positions.

Is there a way to use this method to temporarily prevent a ScrollView from scrolling?

I'm asking in connection to my thread here:
http://www.b4x.com/forum/basic4andr...nature-box-within-scroll-view.html#post174277
 
Upvote 0
Top