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,282
  • Java source - GestureDetector.zip
    5.5 KB · Views: 1,329
Last edited:

TheMightySwe

Active Member
Licensed User
Longtime User
Sorry for the inconvenience. Skrill is probably something that I'll consider in the future. Fees are smaller than the Paypal ones.

I sent you a donation from a friend called Mikael V. How do i get the library? Do you sent it to the e-mail adress in the donation or to me?
 

TheMightySwe

Active Member
Licensed User
Longtime User
The most important is to have the reference of this button. Where it is declared does not matter. In Button_Click, for example, you can get a reference of the clicked button with Sender.

OK, I got it to work, but not as i want.

The button moves but only for a short distance.

This is how i did....

First I set the GestureListner here.

B4X:
Sub Item_Button_Edit_Down

    If DummyButton = Sender Then ' DummyButton is declared in Globals
        Return
    Else
        DummyButton = Sender
        GesturesAdministration.SetOnGestureListener(Sender,"ButtonMove")
    End If

End Sub


This is the onDrag

B4X:
Sub ButtonMove_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
    Log("  onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
   
    DummyButton.Left = Max(0, Min(DummyButton.Left + deltaX, 100%x - DummyButton.Width))
    DummyButton.Top = Max(0, Min(DummyButton.Top + deltaY, 100%y - DummyButton.Height))
    SaveButtonPlacement
   
End Sub

This is the log....

B4X:
  onDrag deltaX = -9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=75.0, y[0]=37.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33489274, downTime=33489141, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -6, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=54.0, y[0]=47.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33491505, downTime=33491386, deviceId=4, source=0x1002 }
  onDrag deltaX = -9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=44.0, y[0]=49.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33494347, downTime=33494213, deviceId=4, source=0x1002 }
  onDrag deltaX = 3, deltaY = -9, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=39.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33495477, downTime=33495328, deviceId=4, source=0x1002 }
  onDrag deltaX = 6, deltaY = -11, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=34.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33496489, downTime=33496325, deviceId=4, source=0x1002 }
  onDrag deltaX = 7, deltaY = -13, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=24.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33497396, downTime=33497202, deviceId=4, source=0x1002 }
  onDrag deltaX = 3, deltaY = -10, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=46.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33498481, downTime=33498288, deviceId=4, source=0x1002 }
  onDrag deltaX = -5, deltaY = -10, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=53.0, y[0]=46.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33500639, downTime=33500489, deviceId=4, source=0x1002 }
  onDrag deltaX = 14, deltaY = 0, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=42.0, y[0]=40.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33588716, downTime=33588344, deviceId=4, source=0x1002 }
  onDrag deltaX = 12, deltaY = 7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=36.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33590055, downTime=33589698, deviceId=4, source=0x1002 }
  onDrag deltaX = -9, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=45.0, y[0]=48.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33597845, downTime=33597680, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -8, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=54.0, y[0]=42.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33598915, downTime=33598782, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -11, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=52.0, y[0]=41.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33599957, downTime=33599823, deviceId=4, source=0x1002 }
  onDrag deltaX = -14, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=39.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=33602068, downTime=33601831, deviceId=4, source=0x1002 }
  onDrag deltaX = -10, deltaY = -4, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=48.0, y[0]=39.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33603065, downTime=33602946, deviceId=4, source=0x1002 }
  onDrag deltaX = -16, deltaY = -7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=41.0, y[0]=34.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33604047, downTime=33603943, deviceId=4, source=0x1002 }
  onDrag deltaX = -14, deltaY = -7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=57.0, y[0]=47.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33605088, downTime=33604954, deviceId=4, source=0x1002 }
  onDrag deltaX = -12, deltaY = -4, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=52.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33606887, downTime=33606798, deviceId=4, source=0x1002 }
  onDrag deltaX = 9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33750919, downTime=33750770, deviceId=4, source=0x1002 }
  onDrag deltaX = 15, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33750933, downTime=33750770, deviceId=4, source=0x1002 }

What am I missing?
 

Informatix

Expert
Licensed User
Longtime User
OK, I got it to work, but not as i want.

The button moves but only for a short distance.

This is how i did....

First I set the GestureListner here.

B4X:
Sub Item_Button_Edit_Down

    If DummyButton = Sender Then ' DummyButton is declared in Globals
        Return
    Else
        DummyButton = Sender
        GesturesAdministration.SetOnGestureListener(Sender,"ButtonMove")
    End If

End Sub


This is the onDrag

B4X:
Sub ButtonMove_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
    Log("  onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)

    DummyButton.Left = Max(0, Min(DummyButton.Left + deltaX, 100%x - DummyButton.Width))
    DummyButton.Top = Max(0, Min(DummyButton.Top + deltaY, 100%y - DummyButton.Height))
    SaveButtonPlacement

End Sub

This is the log....

B4X:
  onDrag deltaX = -9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=75.0, y[0]=37.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33489274, downTime=33489141, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -6, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=54.0, y[0]=47.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33491505, downTime=33491386, deviceId=4, source=0x1002 }
  onDrag deltaX = -9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=44.0, y[0]=49.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33494347, downTime=33494213, deviceId=4, source=0x1002 }
  onDrag deltaX = 3, deltaY = -9, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=39.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33495477, downTime=33495328, deviceId=4, source=0x1002 }
  onDrag deltaX = 6, deltaY = -11, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=34.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33496489, downTime=33496325, deviceId=4, source=0x1002 }
  onDrag deltaX = 7, deltaY = -13, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=24.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33497396, downTime=33497202, deviceId=4, source=0x1002 }
  onDrag deltaX = 3, deltaY = -10, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=46.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33498481, downTime=33498288, deviceId=4, source=0x1002 }
  onDrag deltaX = -5, deltaY = -10, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=53.0, y[0]=46.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33500639, downTime=33500489, deviceId=4, source=0x1002 }
  onDrag deltaX = 14, deltaY = 0, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=42.0, y[0]=40.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33588716, downTime=33588344, deviceId=4, source=0x1002 }
  onDrag deltaX = 12, deltaY = 7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=36.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33590055, downTime=33589698, deviceId=4, source=0x1002 }
  onDrag deltaX = -9, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=45.0, y[0]=48.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33597845, downTime=33597680, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -8, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=54.0, y[0]=42.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33598915, downTime=33598782, deviceId=4, source=0x1002 }
  onDrag deltaX = -11, deltaY = -11, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=52.0, y[0]=41.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33599957, downTime=33599823, deviceId=4, source=0x1002 }
  onDrag deltaX = -14, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=39.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=33602068, downTime=33601831, deviceId=4, source=0x1002 }
  onDrag deltaX = -10, deltaY = -4, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=48.0, y[0]=39.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33603065, downTime=33602946, deviceId=4, source=0x1002 }
  onDrag deltaX = -16, deltaY = -7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=41.0, y[0]=34.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33604047, downTime=33603943, deviceId=4, source=0x1002 }
  onDrag deltaX = -14, deltaY = -7, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=57.0, y[0]=47.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33605088, downTime=33604954, deviceId=4, source=0x1002 }
  onDrag deltaX = -12, deltaY = -4, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=52.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33606887, downTime=33606798, deviceId=4, source=0x1002 }
  onDrag deltaX = 9, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=56.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33750919, downTime=33750770, deviceId=4, source=0x1002 }
  onDrag deltaX = 15, deltaY = -5, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=62.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=33750933, downTime=33750770, deviceId=4, source=0x1002 }

What am I missing?
What you're trying to do cannot work because the touch event is handled by the button not by my library in your example. Bind the Gesture Detector to the view after creating it and handle only the events raised by the library.
In the Drag demo, replace Panel by Button for pnlGreen and that should work as expected.
 

TheMightySwe

Active Member
Licensed User
Longtime User
What you're trying to do cannot work because the touch event is handled by the button not by my library in your example. Bind the Gesture Detector to the view after creating it and handle only the events raised by the library.
In the Drag demo, replace Panel by Button for pnlGreen and that should work as expected.


OK, still same problem, all Button events are removed

Declaration is in Sub

B4X:
                    Dim Item_Button_Edit As Button
                    Item_Button_Edit.Initialize("Item_Button_Edit")
                   
                    Dim GesturesAdministration As GestureDetector
                    GesturesAdministration.SetOnGestureListener(Item_Button_Edit, "AdminGesture")

This is the movement code, basiclly cut and paste from your example.

B4X:
Sub AdminGesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)
    Return True
End Sub

Sub AdminGesture_onDown(X As Float, Y As Float, MotionEvent As Object)
    Log("  onDown x = " & X & ", y = " & Y & ", ev = " & MotionEvent)
End Sub

Sub AdminGesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)

    Log("  onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
   
    Dim ButtonToMove As Button
    ButtonToMove = Sender
   
    ButtonToMove.Left = Max(0, Min(ButtonToMove.Left + deltaX, 100%x - ButtonToMove.Width))
    ButtonToMove.Top = Max(0, Min(ButtonToMove.Top + deltaY, 100%y - ButtonToMove.Height))
    SaveButtonPlacement(ButtonToMove)

End Sub


Still the same

B4X:
onTouch action=0, x=26, y=31, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=26.0, y[0]=31.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68421804, downTime=68421804, deviceId=4, source=0x1002 }
  onDown x = 26, y = 31, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=26.0, y[0]=31.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68421804, downTime=68421804, deviceId=4, source=0x1002 }
onTouch action=2, x=38, y=30, ev=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=38.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68421968, downTime=68421804, deviceId=4, source=0x1002 }
  onDrag deltaX = 12, deltaY = -1, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=38.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68421968, downTime=68421804, deviceId=4, source=0x1002 }
onTouch action=3, x=196, y=79, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=196.0, y[0]=79.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=68422012, downTime=68421804, deviceId=4, source=0x1002 }
onTouch action=0, x=44, y=26, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=44.0, y[0]=26.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68428048, downTime=68428048, deviceId=4, source=0x1002 }
  onDown x = 44, y = 26, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=44.0, y[0]=26.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68428048, downTime=68428048, deviceId=4, source=0x1002 }
onTouch action=3, x=216, y=79, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=216.0, y[0]=79.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68428227, downTime=68428048, deviceId=4, source=0x1002 }
onTouch action=0, x=44, y=29, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=44.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68429090, downTime=68429090, deviceId=4, source=0x1002 }
  onDown x = 44, y = 29, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=44.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68429090, downTime=68429090, deviceId=4, source=0x1002 }
onTouch action=2, x=55, y=29, ev=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=55.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68429283, downTime=68429090, deviceId=4, source=0x1002 }
  onDrag deltaX = 11, deltaY = 0, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=55.0, y[0]=29.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68429283, downTime=68429090, deviceId=4, source=0x1002 }
onTouch action=3, x=222, y=76, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=222.0, y[0]=76.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=68429342, downTime=68429090, deviceId=4, source=0x1002 }
onTouch action=0, x=34, y=22, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=34.0, y[0]=22.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68430206, downTime=68430206, deviceId=4, source=0x1002 }
  onDown x = 34, y = 22, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=34.0, y[0]=22.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68430206, downTime=68430206, deviceId=4, source=0x1002 }
onTouch action=2, x=48, y=28, ev=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=48.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68430340, downTime=68430206, deviceId=4, source=0x1002 }
  onDrag deltaX = 14, deltaY = 6, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=48.0, y[0]=28.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68430340, downTime=68430206, deviceId=4, source=0x1002 }
onTouch action=3, x=234, y=84, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=234.0, y[0]=84.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=68430399, downTime=68430206, deviceId=4, source=0x1002 }
onTouch action=0, x=36, y=22, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=36.0, y[0]=22.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68431173, downTime=68431173, deviceId=4, source=0x1002 }
  onDown x = 36, y = 22, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=36.0, y[0]=22.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68431173, downTime=68431173, deviceId=4, source=0x1002 }
onTouch action=3, x=232, y=78, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=232.0, y[0]=78.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68431322, downTime=68431173, deviceId=4, source=0x1002 }
onTouch action=0, x=23, y=19, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=23.0, y[0]=19.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68432125, downTime=68432125, deviceId=4, source=0x1002 }
  onDown x = 23, y = 19, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=23.0, y[0]=19.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68432125, downTime=68432125, deviceId=4, source=0x1002 }
onTouch action=3, x=268, y=94, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=268.0, y[0]=94.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=68432602, downTime=68432125, deviceId=4, source=0x1002 }
onTouch action=0, x=68, y=36, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=68.0, y[0]=36.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434179, downTime=68434179, deviceId=4, source=0x1002 }
  onDown x = 68, y = 36, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=68.0, y[0]=36.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434179, downTime=68434179, deviceId=4, source=0x1002 }
onTouch action=1, x=68, y=36, ev=MotionEvent { action=ACTION_UP, id[0]=0, x[0]=68.0, y[0]=36.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434253, downTime=68434179, deviceId=4, source=0x1002 }
onTouch action=0, x=76, y=37, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=76.0, y[0]=37.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434283, downTime=68434283, deviceId=4, source=0x1002 }
  onDown x = 76, y = 37, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=76.0, y[0]=37.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434283, downTime=68434283, deviceId=4, source=0x1002 }
onTouch action=3, x=279, y=98, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=279.0, y[0]=98.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434477, downTime=68434283, deviceId=4, source=0x1002 }
onTouch action=0, x=100, y=36, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=100.0, y[0]=36.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434998, downTime=68434998, deviceId=4, source=0x1002 }
  onDown x = 100, y = 36, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=100.0, y[0]=36.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68434998, downTime=68434998, deviceId=4, source=0x1002 }
onTouch action=3, x=252, y=87, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=252.0, y[0]=87.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68435266, downTime=68434998, deviceId=4, source=0x1002 }
onTouch action=0, x=17, y=33, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=17.0, y[0]=33.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68435905, downTime=68435905, deviceId=4, source=0x1002 }
  onDown x = 17, y = 33, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=17.0, y[0]=33.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68435905, downTime=68435905, deviceId=4, source=0x1002 }
onTouch action=2, x=30, y=30, ev=MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=30.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68436174, downTime=68435905, deviceId=4, source=0x1002 }
  onDrag deltaX = 13, deltaY = -3, ev = MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=30.0, y[0]=30.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68436174, downTime=68435905, deviceId=4, source=0x1002 }
onTouch action=3, x=227, y=83, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=227.0, y[0]=83.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=68436233, downTime=68435905, deviceId=4, source=0x1002 }
onTouch action=0, x=27, y=32, ev=MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=27.0, y[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68436977, downTime=68436977, deviceId=4, source=0x1002 }
  onDown x = 27, y = 32, ev = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=27.0, y[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=68436977, downTime=68436977, deviceId=4, source=0x1002 }
onTouch action=3, x=242, y=77, ev=MotionEvent { action=ACTION_CANCEL, id[0]=0, x[0]=242.0, y[0]=77.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=68437275, downTime=68436977, deviceId=4, source=0x1002 }
 

Informatix

Expert
Licensed User
Longtime User
OK, still same problem, all Button events are removed

Declaration is in Sub

B4X:
                    Dim Item_Button_Edit As Button
                    Item_Button_Edit.Initialize("Item_Button_Edit")
                  
                    Dim GesturesAdministration As GestureDetector
                    GesturesAdministration.SetOnGestureListener(Item_Button_Edit, "AdminGesture")

This is the movement code, basiclly cut and paste from your example.

B4X:
Sub AdminGesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)
    Return True
End Sub

Sub AdminGesture_onDown(X As Float, Y As Float, MotionEvent As Object)
    Log("  onDown x = " & X & ", y = " & Y & ", ev = " & MotionEvent)
End Sub

Sub AdminGesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)

    Log("  onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
  
    Dim ButtonToMove As Button
    ButtonToMove = Sender
  
    ButtonToMove.Left = Max(0, Min(ButtonToMove.Left + deltaX, 100%x - ButtonToMove.Width))
    ButtonToMove.Top = Max(0, Min(ButtonToMove.Top + deltaY, 100%y - ButtonToMove.Height))
    SaveButtonPlacement(ButtonToMove)

End Sub

As I see only parts of your project, it is difficult to say what's wrong but something is wrong because my code works from Gingerbread to Kitkat without any issue (and I tried it with a button more than once).

What does this line do: SaveButtonPlacement(ButtonToMove)?
 

Informatix

Expert
Licensed User
Longtime User
The buttons are placed on a ScrollView2D if that is any help.
We found the culprit ! The ScrollView intercepts the touch events after a few pixels move (it waits until it is sure that's a known gesture, then it redirects all touch events to its own handlers). In this case, you have to disallow the touch interception (cf. this post) when you move the button.
 

TheMightySwe

Active Member
Licensed User
Longtime User
We found the culprit ! The ScrollView intercepts the touch events after a few pixels move (it waits until it is sure that's a known gesture, then it redirects all touch events to its own handlers). In this case, you have to disallow the touch interception (cf. this post) when you move the button.


I knew it was something simple like that, thanks a bunch!

Where should i put the Reflector code?
 
Top