Sub Class_Globals
....
....
Dim GD As GestureDetector, DiscardOtherGestures As Boolean, FilterMoveEvents As Boolean
End Sub
Public Sub Initialize (vCallback As Object, vEventName As String)
sv.Initialize2(0, "sv")
items.Initialize
panels.Initialize
dividerHeight = 2dip
EventName = vEventName
CallBack = vCallback
sv.Color = 0xFFD9D7DE 'this sets the dividers color
Dim r As Reflector
Dim idPressed As Int
idPressed = r.GetStaticField("android.R$drawable", "list_selector_background")
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
pressedDrawable = r.RunMethod2("getDrawable", idPressed, "java.lang.int")
DefaultTextColor = Colors.White
DefaultTextSize = 16
DefaultTextBackgroundColor = Colors.Black
DefaultTextBackground = Null
GD.SetOnGestureListener(sv, "Gesture")
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)
If FilterMoveEvents Then
If Action = GD.ACTION_MOVE Then
Log("[Filtered]")
Return True
Else
FilterMoveEvents = False
End If
End If
Return DiscardOtherGestures
End Sub
Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
Log(" onDrag deltaX=" & deltaX & ", deltaY=" & deltaY)
'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 And Not(FilterMoveEvents) Then
FilterMoveEvents = True 'We handle all the touch events with Action = Move so no vertical scrolling is possible
If deltaX > 0 Then
CallSubDelayed3(Me, "DisplayMsg", "Swipe to the right", deltaX)
Else
CallSubDelayed3(Me, "DisplayMsg", "Swipe to the left", -deltaX)
End If
End If
End Sub'
Sub Gesture_onScroll(distanceX As Float, distanceY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
Log(" onScroll distanceX = " & distanceX & ", distanceY = " & distanceY & ", ev1 = " & MotionEvent1 & ", ev2=" & MotionEvent2)
End Sub
Sub Gesture_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
Log(" onFling velocityX = " & velocityX & ", velocityY = " & velocityY & ", ev1 = " & MotionEvent1 & ", ev2 = " & MotionEvent2)
End Sub
Sub DisplayMsg(Text As Object, Distance As Object)
Log(Text & ": " & NumberFormat(Distance, 1, 0) & " pixels")
Msgbox(Text & ": " & NumberFormat(Distance, 1, 0) & " pixels", Text)
End Sub
Sub CB_Discard_CheckedChange(Checked As Boolean)
DiscardOtherGestures = Checked
End Sub
...