Hey guys, after fighting for a few days I found something useful.
I have a panel with various ImageViews inside. I needed localized swiping and image tapping to work together nicely. After trying many things, this is what worked.
Add a panel, and it's touch event
Add the image views on top of the panel in the designer, set the parent to be the panel. Don't set an event name, we're gonna let the panels touch event figure out what to do.
Now we're gonna add the panel_Touch event:
If anyone has code to detect a LongClick that works reliably, please let me know so I can update my code as well. I'm assuming a timer would be necessary. Hope this helps you guys because it's been a real pain for me to figure this one out. The lesson is that views without an event specified pass touch events to the view below and that image views don't have Touch events but panels do. It also helps to keep it all in a panel so that the x/y coordinates are what's expected. This method works perfectly with the Picasso image loading library. The only other thing I'd like to figure out is getting a swipe looking animation to work with my scheme because since I have thousands of products I use the paging scheme rather than loading them all at once. Some sort of animation would be nice, currently I just clear the products and load another set.
I have a panel with various ImageViews inside. I needed localized swiping and image tapping to work together nicely. After trying many things, this is what worked.
Add a panel, and it's touch event
Add the image views on top of the panel in the designer, set the parent to be the panel. Don't set an event name, we're gonna let the panels touch event figure out what to do.
Now we're gonna add the panel_Touch event:
B4X:
Sub panel1_Touch (Action As Int, x As Float, Y As Float)
Select Action
Case Activity.ACTION_DOWN
startX = x
startY = Y
Case Activity.ACTION_UP
If Abs(Y - startY) > 10%y Then
Return
End If
If x - startX > 10%x Then
Log("swipe left")
Else If startX - x > 10%x Then
Log("swipe right")
Else
Log("Click")
For i = 0 To panel1.NumberOfViews-1
Dim v As View = panel1.GetView(i)
If GetType(v) = GetType(SomeImageViewObject) Then
If v.Left <= x AND v.Top <= Y AND v.Left+v.Width >= x AND v.Top+v.Height >= Y Then
Log("ImageView Clicked")
'I used the tag object to handle the click action, in my case displaying product details in another panel
End If
End If
Next
End If
End Select
If anyone has code to detect a LongClick that works reliably, please let me know so I can update my code as well. I'm assuming a timer would be necessary. Hope this helps you guys because it's been a real pain for me to figure this one out. The lesson is that views without an event specified pass touch events to the view below and that image views don't have Touch events but panels do. It also helps to keep it all in a panel so that the x/y coordinates are what's expected. This method works perfectly with the Picasso image loading library. The only other thing I'd like to figure out is getting a swipe looking animation to work with my scheme because since I have thousands of products I use the paging scheme rather than loading them all at once. Some sort of animation would be nice, currently I just clear the products and load another set.