Android Question GestureDetector Disabling Panel_Touch?

mmieher

Active Member
Licensed User
Longtime User
I am having trouble with GestureDetector. I stripped down my project to the code below to demonstrate.

The first time I touch either of the panels, the GDPanel_Touch event is fired. However, after
touching both pictures ONCE, the GDPanel_Touch event is only fired the last panel in the view.

If I comment out the GD.SetOnGestureListener, then the GDPanel_Touch event is fired as expected.

The Gesture_onClick event is behaving the same way.

I know one of you Guru's will have the answer!

Marc

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim PicPanel As Panel
  
    Dim GD As GestureDetector
    Dim GDPanel(10) As Panel    '    panels of pictures or documents
    Dim GDIndex As Int
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("CustComp3")
  
    GDPanel(0).Initialize("GDPanel")
    GDPanel(0).Tag = "0"
    PicPanel.AddView(GDPanel(0),10dip,10dip,140dip,135dip)
    GDPanel(0).SetBackgroundImage(LoadBitmapResize(File.DirAssets,"CashCow.jpg",140dip,135dip,False))
  
    GDPanel(1).Initialize("GDPanel")
    GDPanel(1).Tag = "1"
    PicPanel.AddView(GDPanel(1),210dip,10dip,140dip,135dip)
    GDPanel(1).SetBackgroundImage(LoadBitmapResize(File.DirAssets,"s-touchme.png",140dip,135dip,False))
End Sub

Sub GDPanel_Touch(Action As Int, X As Float, Y As Float)
  
    Try
        GD.RemoveGestureListener
    Catch
        Log("RemoveGestureListner Not On")
    End Try
  
    Dim pnl As Panel
    pnl = Sender
  
    GDIndex = pnl.Tag
  
    Log("GDPanel_Touch  TAG = " & pnl.Tag)
  
    GD.SetOnGestureListener(GDPanel(GDIndex), "Gesture")    '    IF I COMMENT OUT THIS LINE, PANEL_TOUCH IS FIRED NEXT TIME
  
End Sub

Sub Gesture_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)
  
    Try
        GD.RemoveGestureListener
    Catch
        Log("RemoveGestureListner Not On")
    End Try
  
    Dim pnl As Panel
    pnl = Sender
  
    Log("Gesture_onTouch  TAG = " & pnl.Tag)
  
    GDIndex = pnl.Tag
  
    GD.SetOnGestureListener(GDPanel(GDIndex), "Gesture")
  
    Return True
  
End Sub

Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
  
    Log("   onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
    GDPanel(GDIndex).Left = Max(0, Min(GDPanel(GDIndex).Left + deltaX, 100%x - GDPanel(GDIndex).Width))
    GDPanel(GDIndex).Top = Max(0, Min(GDPanel(GDIndex).Top + deltaY, 100%y - GDPanel(GDIndex).Height))
  
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

I have a related issue but want to avoid the ever so embarassing "Please start a new thread for this question."
 

mmieher

Active Member
Licensed User
Longtime User
Syd, changing to Return False makes things worse. Doing so caused the event to not fire at all on either panel after the panel was touched once.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
No luck, Syd. The _onTouch event only fires once for the second panel so I cannot detect it and execute your code.
 
Upvote 0
Top