panel touch action

derez

Expert
Licensed User
Longtime User
Using panel touch I get only action down event.
Using activity touch - all 3 events exist.

It might be related to consuming the events by return true or false - but I don't understand how it works.

Has anybody experienced it also ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this code:
B4X:
Sub Globals
   Dim p As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   p.Initialize("p")
   Activity.AddView(p, 0, 0, 100%x, 100%y)
End Sub
Sub p_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
   Select Action
      Case Activity.ACTION_DOWN
         Log("down")
      Case Activity.ACTION_MOVE
         Log("move")
      Case Activity.ACTION_UP
         Log("up")
   End Select
   Return True
End Sub
You should return True. Otherwise the panel just passes the event to the underlying view and no longer handles the current touch.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Erel
Thank you, it works.

Please note that while the down event is fired only on the panel area, the other two events are working also when going with the mouse/finger out of the panel area.

I attach here a piece of code and pictures which I used for vertical seekbar. The background image includes the gray part of the seekbar.

B4X:
Sub volPnl_Touch(Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Dim h As Double
volume.height = Max(Min(volpnl.Height - y, volpnl.Height),0)
volume.Top = 405 - volume.height
caret.top = volume.Top - caret.height/2
h = 1 - y/volpnl.Height
mp.SetVolume(h,h)
Return True
End Sub

notes: the panel covers the "seekbar" from top to bottom, the bottom in my app is 405. "volome" imageview holds the yellow bar and "caret" another imageview holding the knob.
The max-min line is to limit the volume size so it doesn't go beyond the 0-100% as a result of the abovementioned phenomena.
Other colors may be used of course.
 

Attachments

  • volb.png
    volb.png
    4.2 KB · Views: 1,159
  • caret.png
    caret.png
    3.3 KB · Views: 1,208
Last edited:
  • Like
Reactions: nyi
Upvote 0
Top