Android Question Detect left or right swipe over ACToolBarLight

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have a ACToolbar with a button, a label and a number of menu items with icons. I currently have 3 menu groups (will be a few more) and currently I change these by clicking the button or the label. This works well, but this is perhaps not according to the usual Android behaviour, so would like to try to change these groups with a swipe over the menubar. Left swipe for menu group down and right swipe for menu group up.
What would be the best/simplest way to do this?
I did try the GestureDetector library and this is quite simple, but wasn't quite reliable, maybe because I only did bind to the ACToolbar:

B4X:
GD.SetOnGestureListener(ActionBar, "Gesture")

Could I do this without an extra library, maybe with a panel overlaying the ACToolbar?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have a ACToolbar with a button, a label and a number of menu items with icons. I currently have 3 menu groups (will be a few more) and currently I change these by clicking the button or the label. This works well, but this is perhaps not according to the usual Android behaviour, so would like to try to change these groups with a swipe over the menubar. Left swipe for menu group down and right swipe for menu group up.
What would be the best/simplest way to do this?
I did try the GestureDetector library and this is quite simple, but wasn't quite reliable, maybe because I only did bind to the ACToolbar:

B4X:
GD.SetOnGestureListener(ActionBar, "Gesture")

Could I do this without an extra library, maybe with a panel overlaying the ACToolbar?

RBS

Maybe this link answers my question:

https://www.b4x.com/android/forum/t...pe-in-the-underlying-views.33948/#post-198793

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have a ACToolbar with a button, a label and a number of menu items with icons. I currently have 3 menu groups (will be a few more) and currently I change these by clicking the button or the label. This works well, but this is perhaps not according to the usual Android behaviour, so would like to try to change these groups with a swipe over the menubar. Left swipe for menu group down and right swipe for menu group up.
What would be the best/simplest way to do this?
I did try the GestureDetector library and this is quite simple, but wasn't quite reliable, maybe because I only did bind to the ACToolbar:

B4X:
GD.SetOnGestureListener(ActionBar, "Gesture")

Could I do this without an extra library, maybe with a panel overlaying the ACToolbar?

RBS

Got this kind of working, but swipe is still missed, so not 100% reliable.
I added the GestureDetector to all 3 controls, so the button, the label and the ACToolbar.

B4X:
Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
 
 Dim lSwipeInterval As Long
 
 'lSwipeTime is Private variable
 If lSwipeTime > 0 Then
  lSwipeInterval = DateTime.Now - lSwipeTime
  If lSwipeInterval < 100 Then
   General.RunLog("Gesture_onDrag, Return")
   Return
  End If
 End If

 'If the gesture is more horizontal than vertical and covered more than the minimal distance (10%x)...
 'If Abs(deltaX) > Abs(deltaY) And Abs(deltaX) > 10%x Then
 If Abs(deltaX) > Abs(deltaY) Then
  If deltaX > 0 Then
   General.RunLog("Gesture_onDrag, swipe to right")
   ChangeMenuGroup
  Else
   General.RunLog("Gesture_onDrag, swipe to left")
   ChangeMenuGroup
  End If
 End If
 
 lSwipeTime = DateTime.Now

End Sub

Any suggestions how to make this more reliable?

RBS
 
Upvote 0
Top