Gestures and buttons/labels problem

dagnabitboy

Active Member
Licensed User
Longtime User
I have written code to detect various gestures on the screen; left, right, up, down, tap, tap-tap, short-press and long-press. There is a "debugging" label at the bottom of the screen I use to show the result of the gesture detection. works great. My problem comes when I add either buttons or labels to the screen, that are used to display a menu choice, which will be selected by an up or down gesture. I will then change the color of the button/panel to indicate the active menu item. Later TTS will speak the choice as well because this is an app for the blind/vision impaired. When the buttons/labels are on screen I cannot tap or gesture on the part of the screen they occupy if there is a handler for them. If I leave out the handler it works the way I want, but I'll need the handler because eventually I'll have modes for both sighted people and blind people. Sorry for my long winded explanation!! Thank you in advance for any help!

Here is the code:

'Activity module
Sub Process_Globals
Dim timer1 As Timer ' timer1 used to count screen taps within
Timer1.initialize("Timer1",100) ' 0.60 seconds.
End Sub

Sub Globals
Dim g As Gestures
Dim p1 As Panel
Dim label1 As Label
Dim tictimeNow, tictimeStart As Long
Dim tapDur As Float
Dim dstartX,dstartY,diffx,diffy,tapCounter,ticCounter As Int
' now we add stuff for a button array
Dim labelPTR As Label
Dim buttonID(16) As String
Dim menubtn(16) As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)

ticCounter=0
tapCounter=0

p1.Initialize("P1") ' init the panel to be used for gesture detection
p1.Color=Colors.black

label1.Initialize("label1") ' init lable 1
label1.Color=Colors.LightGray ' the label is used for debugging
label1.BringToFront ' the various routines.. they wouldn't
label1.TextColor=Colors.Black ' necessarily be part of any final code.


Activity.AddView(p1,0,0,100%x,100%y)
activity.AddView(label1,10dip,490dip,200dip,40dip)
activity.Title="menu test"

p1.SendToBack
g.SetOnTouchListener(p1,"pnl_gesture")

For i = 0 To 3
menubtn(i).Initialize("menubtn")
activity.AddView(menubtn(i),10dip,10dip+60dip*i,250dip,50dip)
menubtn(i).BringToFront
menubtn(i).TextColor=Colors.Black
Next
End Sub

Sub menubtn_Click
Return True
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Timer_Tick
ticCounter=ticCounter+1
End Sub

Sub pnl_gesture(o As Object,ptrID As Int,action As Int,x As Float,y As Float) As Boolean
Dim xx, yy, DX,DY As Int
xx=x
yy=y
If action = g.ACTION_DOWN Then
timer1.Enabled=True
tictimeStart=DateTime.Now
dstartX=xx
dstartY=yy
End If

If action = g.ACTION_UP Then
tictimeNow=DateTime.Now
dx=Abs(xx-dstartx)
dy=Abs(yy-dstarty)
label1.Text=""
tapDur=(tictimeNow-tictimeStart)/1000
If dy>dx Then
If yy>dstartY+25 Then
label1.Text="down"
End If

If dstartY>yy+25 Then
label1.Text="up"
End If
Else
If xx>dstartX+25 Then
label1.Text="right"
End If

If dstartx>xx+25 Then
label1.Text="left"
End If
End If
If dx<25 AND dy<25 Then
If tapdur>0.40 AND tapdur<1.00 Then
label1.Text="short press"
End If
If tapdur>1.00 AND tapdur< 2.0 Then
label1.Text="long press"
End If
If tapdur>0.01 AND tapdur<0.35 Then
tapCounter=tapCounter+1
End If
End If
End If
Return True
End Sub

Sub timer1_tick
ticCounter=ticCounter+1
If ticCounter=5 Then
timer1.Enabled=False
ticCounter=0
If tapCounter=1 Then
label1.Text="tap"
End If
If tapCounter=2 Then
label1.Text="tap-tap"
End If
If tapCounter=3 Then
timer1.Enabled=False
Activity.Finish
ExitApplication
End If
tapCounter=0
End If
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean

' following runs dialog box to ask if the user wants to quit, if yes(positive) then
' we exit the app, else we ignore the key and continue running the app.

If Keycode = KeyCodes.KEYCODE_BACK Then
Dim result As Int
result=Msgbox2("Do you really want to quit?", "Exit the program","Yes","","No",Null)
If result=DialogResponse.POSITIVE Then
timer1.Enabled=False
Activity.Finish
ExitApplication
Else
Return True
End If
End If

' KEYCODE_HOME doesn't seem to reach the APP on droidx.

' If Keycode = KeyCodes.KEYCODE_HOME Then
' label3.Text="home key"
' Return True
' End If

If Keycode = KeyCodes.KEYCODE_MENU Then
Return True
End If
End Sub
 

dagnabitboy

Active Member
Licensed User
Longtime User
Erel: Works like a charm! I brought the panel to the front, and sent the buttons to the back. With the panel set to colors.transparent I can still see the buttons and I can detect gestures on the entire screen. Disabling the panel, now the buttons are accessible. This is my first experience with programming objects, so it is initially mysterious but rewarding when I find the answer. Thanks again.
 
Upvote 0
Top