B4A Library [Lib] Gesture Detector

This library adds the detection of standard gestures (press, single-tap, double-tap, long tap, drag, scroll, fling, pinch, rotation) to B4A. Instead of using the Touch events to figure out what the user really did, now you just set 15 different listeners with one line of code and you get the gestures as events with all the useful values (scrolling distance, fling velocity, pinch variation, rotation angle...).
With this library, you can also know easily the pressure or the size of a touch event.

It works with any view.

Note: you have to create an instance of GestureDetector (with Dim) for each view you want to bind to the detector with SetOnGestureListener.

v2.2:
- Freeware.

v2.3:
- I fixed an issue with the boolean value returned by the OnTouch event with some views (e.g. ListView or ScrollView);
- I added a new demo (GD_SwipeLV);
- The OnDown event is now raised before OnDoubleTap.

v2.4:
- I fixed an issue when a view is dragged after one of the pointer is up (delta values were computed according to the pointer 0, not to the remaining pointer).

Incompatible with Android versions < 2.
 

Attachments

  • GestureDetector v2.4.zip
    35.3 KB · Views: 3,316
  • Java source - GestureDetector.zip
    5.5 KB · Views: 1,355
Last edited:

postasat

Active Member
Licensed User
Longtime User
Not always detect horizontal "fling" (maybe the problem is that my scrollview contains lot of "panel" with data), but the functionality seems perfect.

Thank you.

B4X:
Sub Globals
Dim Gesture1 As GestureDetector

Sub Activity_Create
Gesture1.SetOnGestureListener(scvMain,"Gesture1")

Sub Gesture1_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
'if horizontal speed is low, I'm scrolling vertical, I pass the event to scrollview (scvMain)
If Abs(velocityX) > positive_speed Then
'if I have a vertical scroll from right to left
    If velocityX < negative_speed Then
            Button1_click
    Else    'from left to right
            Button2_click
    End If
End If
End Sub

Sub Gesture1_onTouch(Action AsInt, X AsFloat, Y AsFloat, MotionEvent AsObject) AsBoolean
     Return False
End Sub
 

Informatix

Expert
Licensed User
Longtime User
Not always detect horizontal "fling" (maybe the problem is that my scrollview contains lot of "panel" with data), but the functionality seems perfect.

Thank you.

B4X:
Sub Globals
Dim Gesture1 As GestureDetector

Sub Activity_Create
Gesture1.SetOnGestureListener(scvMain,"Gesture1")

Sub Gesture1_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
'if horizontal speed is low, I'm scrolling vertical, I pass the event to scrollview (scvMain)
If Abs(velocityX) > positive_speed Then
'if I have a vertical scroll from right to left
    If velocityX < negative_speed Then
            Button1_click
    Else    'from left to right
            Button2_click
    End If
End If
End Sub

Sub Gesture1_onTouch(Action AsInt, X AsFloat, Y AsFloat, MotionEvent AsObject) AsBoolean
     Return False
End Sub
onFling is for fling gestures. To detect all swipe gestures, use also onScroll.
 

postasat

Active Member
Licensed User
Longtime User
Is it possible with onScroll to know the direction of the swipe/scroll ?
(left to right or right to left)
 

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

is there any limitations on what you can do in a event. I update a Button background in onDoubleTap event and it crashes without errormessage on the "End Sub" line.

B4X:
Sub ButtonAdminGesture_onDoubleTap(X As Float, Y As Float, MotionEvent As Object)

    If Debug Then Log("ButtonAdminGesture_onDoubleTap(MotionEvent=" & MotionEvent & ")")

    Dim ButtonToEdit As Button
    ButtonToEdit = Sender
   
    Dim ThisTag As FunctionTag
    ThisTag.Initialize
    ThisTag = ButtonToEdit.Tag
    Administration.ItemButtonSettings(ButtonToEdit,ThisTag.ID)
    Buttons.UpdateItemButtonFromSender(ButtonToEdit)
    DoEvents
   
End Sub


The "Buttons.UpdateItemButtonFromSender(ButtonToEdit)" is just a change of button background.
 

Informatix

Expert
Licensed User
Longtime User
Hi,

is there any limitations on what you can do in a event. I update a Button background in onDoubleTap event and it crashes without errormessage on the "End Sub" line.

B4X:
Sub ButtonAdminGesture_onDoubleTap(X As Float, Y As Float, MotionEvent As Object)

    If Debug Then Log("ButtonAdminGesture_onDoubleTap(MotionEvent=" & MotionEvent & ")")

    Dim ButtonToEdit As Button
    ButtonToEdit = Sender
  
    Dim ThisTag As FunctionTag
    ThisTag.Initialize
    ThisTag = ButtonToEdit.Tag
    Administration.ItemButtonSettings(ButtonToEdit,ThisTag.ID)
    Buttons.UpdateItemButtonFromSender(ButtonToEdit)
    DoEvents
  
End Sub


The "Buttons.UpdateItemButtonFromSender(ButtonToEdit)" is just a change of button background.
DoEvents is not welcome in a touch event (same thing for MsgBox). If you absolutely need it, place it in a different sub and call this sub with CallSubDelayed.
Little hint: it's better to write Dim ButtonToEdit As Button = Sender on one line. That avoids allocating memory for a new button (not used since Sender is assigned to the variable).
 

TheMightySwe

Active Member
Licensed User
Longtime User
Actually was the doevents just to test if there was any other events in the que that crashed the app seperate from this so that is not in the code usually. ;)

I'll try the CallSubDelayed approach.

Thanks
 

TheMightySwe

Active Member
Licensed User
Longtime User
Is there any good way to use onRotate with a view and "setRotation"?

B4X:
    Dim jo = ViewToRotate As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))
 

Informatix

Expert
Licensed User
Longtime User
Is there any good way to use onRotate with a view and "setRotation"?

B4X:
    Dim jo = ViewToRotate As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))
Replace the code of the GestureDetector_Drag demo by this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text = "Rotate the green ball with your fingers."
    lbl.TextColor = Colors.White
    lbl.TextSize = 18
    Activity.AddView(lbl, 15dip, 15dip, 100%x-30dip, 60dip)
   
    pnlGreen.Initialize("")
    pnlGreen.SetBackgroundImage(LoadBitmap(File.DirAssets, "greenball.png"))
    Activity.AddView(pnlGreen, 30dip, 70dip, 100dip, 100dip)
    GD.SetOnGestureListener(Activity, "Gesture")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Gesture_onRotation(Degrees As Double, MotionEvent As Object)
    Dim jo = pnlGreen As JavaObject
    Dim Angle As Float = Degrees
    jo.RunMethod("setRotation", Array As Object(Angle))
End Sub
The important thing here is to convert the angle from Double to Float (Java is not as permissive with types as Basic4Android).
 

Informatix

Expert
Licensed User
Longtime User
How do i "getRotation" from the Sender? Searched the forum and cant find it.
From the Sender ? I don't understand what you're trying to do. If you want to rotate the view by x degrees, x being the delta between the actual angle of fingers and the previous angle, then add x to your setRotation value (you can store this value in a global variable, or retrieve it from the view with getRotation; use a variable if you're not familiar with calling Java functions with JO). It's basic maths and basic programming so I probably missed something in your explanation.
 

TheMightySwe

Active Member
Licensed User
Longtime User
I'm doing a map over a room, and the tables and chairs are Buttons thith images of furniture from above that needs to be rotated, when i use Gesture it seems just spinn.

It seems to add the angle from the previous posision so it just keeps going around even if my fingers at still.

My knowledge of JO are very limited. Never worked with it except when i cut and pasted some code.
 

Informatix

Expert
Licensed User
Longtime User
I'm doing a map over a room, and the tables and chairs are Buttons thith images of furniture from above that needs to be rotated, when i use Gesture it seems just spinn.

It seems to add the angle from the previous posision so it just keeps going around even if my fingers at still.

My knowledge of JO are very limited. Never worked with it except when i cut and pasted some code.
Post your code if you want some help because if the view rotates when your fingers are still, there's a programming error somewhere (no event is raised by GD when the angle does not change). In the main demo of the library, you can read on screen the value returned by the event.
 

TheMightySwe

Active Member
Licensed User
Longtime User
The code is yours code exact but i use the Sender to get the button to rotate.

B4X:
Sub TableGesture_onRotation(Degrees As Double, MotionEvent As Object)
   
    If Debug Then Log("TableGesture_onRotation(Degrees = " & Degrees & ", MotionEvent=" & MotionEvent & ")")
   
    Dim TableToRotate As Button
    TableToRotate = Sender
   
    Dim Angle As Float = Degrees
    Dim jo = TableToRotate As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))

End Sub


Here is the logfile, i press on the bottom left and the top right corners, and the image rotate like a propeller.

B4X:
TableGesture_onPointerDown(MotionEvent=MotionEvent { action=ACTION_POINTER_DOWN(1), id[0]=0, x[0]=19.6875, y[0]=145.39063, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=132.1875, y[1]=27.421875, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=174910109, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.35930578606862, MotionEvent=MotionEvent { action=ACTION_POINTER_DOWN(1), id[0]=0, x[0]=19.6875, y[0]=145.39063, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=132.1875, y[1]=27.421875, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=0, eventTime=174910109, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.4336084732027947, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.363449, y[0]=85.571266, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.0662, y[1]=81.48121, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910411, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.442476810653865, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.798882, y[0]=147.25356, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.4866, y[1]=28.743988, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174910428, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.4846978789451746, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.575539, y[0]=85.83004, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06396, y[1]=81.58872, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910478, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.48283888349723, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.728836, y[0]=147.59044, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.53227, y[1]=28.791702, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910545, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.3879757942283937, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.40554, y[0]=85.601654, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.0628, y[1]=81.6409, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910711, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.42454142122849, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.859005, y[0]=147.03058, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.44576, y[1]=28.701405, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910729, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.5034223108301956, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.576134, y[0]=85.8604, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06445, y[1]=81.56554, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910840, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.312365247110016, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.723703, y[0]=146.92517, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.54901, y[1]=28.8092, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910893, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.312904685421457, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.80608, y[0]=85.17627, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06738, y[1]=81.42053, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174910924, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.446491881531315, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.311441, y[0]=147.55661, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.3785, y[1]=28.631424, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911029, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.2135906243218515, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.682587, y[0]=85.062775, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06384, y[1]=81.59392, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911079, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.3601831890107, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=20.074017, y[0]=147.26149, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.28937, y[1]=28.538979, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911112, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.1758490003072182, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-9.757538, y[0]=84.84488, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06616, y[1]=81.482346, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911194, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.27613198344365, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=19.828321, y[0]=147.09966, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.25546, y[1]=28.503883, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911272, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.2798452767636581, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-10.27433, y[0]=85.045296, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06827, y[1]=81.37368, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911346, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.32356607639368, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=19.725096, y[0]=147.59904, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.34885, y[1]=28.600632, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911421, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.1764757655986535, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-10.672386, y[0]=84.818146, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.0671, y[1]=81.43501, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911446, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.3900924131775, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=19.530916, y[0]=147.88626, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.25603, y[1]=28.50447, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911579, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.0835377907279446, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-11.0139885, y[0]=84.64324, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06538, y[1]=81.521, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911630, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.26239719472853, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=19.339973, y[0]=147.3806, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.17242, y[1]=28.418152, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911640, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.0439686277376032, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-10.925407, y[0]=84.36258, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.0686, y[1]=81.35594, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911713, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.367864443394375, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=19.06278, y[0]=148.0365, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.1368, y[1]=28.38144, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911808, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.0931274212775381, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-11.376961, y[0]=84.649086, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.06598, y[1]=81.49227, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174911840, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.34544497802226, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=18.68332, y[0]=148.43251, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=133.18106, y[1]=28.427052, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174911917, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.9809754570103297, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-11.738125, y[0]=83.951385, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=155.24892, y[1]=78.17558, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174911978, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.53506668598391, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=17.334866, y[0]=146.97542, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=132.15381, y[1]=25.8331, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912023, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.8570762227210662, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-11.90863, y[0]=83.4811, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=155.18134, y[1]=78.06347, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912047, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.71544231276491, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=17.154846, y[0]=147.49104, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=131.81383, y[1]=25.752167, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912080, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.9046123288734185, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-12.15321, y[0]=83.51296, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.86566, y[1]=77.958916, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912084, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.570927402879306, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=16.692383, y[0]=147.42537, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=131.8302, y[1]=25.794228, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912113, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -1.948268755717073, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-12.500725, y[0]=83.6527, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.51297, y[1]=77.97143, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174912163, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.46705373932083, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=16.26007, y[0]=147.55959, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=131.54588, y[1]=26.213509, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174912174, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -2.038352980169377, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-12.86911, y[0]=83.745766, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.4653, y[1]=77.79017, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912230, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.34140296720259, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=15.834679, y[0]=147.64336, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=131.6304, y[1]=26.294617, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912243, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -2.1208209921088144, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=-13.415161, y[0]=83.61465, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=154.2492, y[1]=77.40566, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=2, eventTime=174912313, downTime=174910109, deviceId=9, source=0x1002 })
TableGesture_onRotation(Degrees = -46.38309857814087, MotionEvent=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=15.574013, y[0]=147.74033, toolType[0]=TOOL_TYPE_FINGER, id[1]=1, x[1]=131.2392, y[1]=26.351643, toolType[1]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=2, historySize=1, eventTime=174912317, downTime=174910109, deviceId=9, source=0x1002 })
 

Informatix

Expert
Licensed User
Longtime User
The code is yours code exact but i use the Sender to get the button to rotate.

B4X:
Sub TableGesture_onRotation(Degrees As Double, MotionEvent As Object)
  
    If Debug Then Log("TableGesture_onRotation(Degrees = " & Degrees & ", MotionEvent=" & MotionEvent & ")")
  
    Dim TableToRotate As Button
    TableToRotate = Sender
  
    Dim Angle As Float = Degrees
    Dim jo = TableToRotate As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))

End Sub


Here is the logfile, i press on the bottom left and the top right corners, and the image rotate like a propeller.
Each instance of GestureDetector is bound to a view so I don't really understand why you need to know who sent the event. That cannot be another view that the one you bound to GD. If you share the GD among different views, it's a mistake. 1 GD = 1 View.
 

TheMightySwe

Active Member
Licensed User
Longtime User
Each instance of GestureDetector is bound to a view so I don't really understand why you need to know who sent the event. That cannot be another view that the one you bound to GD. If you share the GD among different views, it's a mistake. 1 GD = 1 View.

The views and gesturedetectors are made programaticlly depending on data in a database, there can be 50 different views and i only want to rotate the one i have my fingers on.

And it works fine with all the other events.
 
Last edited:
Top