Other Strange behaviour on panel touch event

udg

Expert
Licensed User
Hi all,

I am experiencing what seems a strange or unexpected behaviour on my Samsung Galaxy Tab 2 (GT-P5100) tablet.
Executing the following code it results always in whole values (both X and Y).
Only placing-moving-lifting a finger on the panel leads to decimal values on the UP action (Down stays integer). What happens on your devices and, most important, how do you explain this case?
B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim pnlTest As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   pnlTest.Initialize("test")
   Activity.AddView(pnlTest,10dip,10dip,200dip,200dip)
   pnlTest.Color = Colors.Red
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub test_Touch (Action As Int, X As Float, Y As Float)
  Select Action
  Case pnlTest.ACTION_DOWN
     Log("Down -> X: "&X&" Y: "&Y)
  Case pnlTest.ACTION_UP
     Log("UP -> X: "&X&" Y: "&Y)
  Case pnlTest.ACTION_MOVE
     Log("Moving -> X: "&X&" Y: "&Y)
  Case Else
     Log("other action")
  End Select
  Return True
End Sub

After a few touches here and there, my log results in:

B4X:
Down -> X: 97 Y: 74
UP -> X: 97 Y: 74
Down -> X: 170 Y: 169
UP -> X: 170 Y: 169
Down -> X: 50 Y: 159
UP -> X: 50 Y: 159
Down -> X: 133 Y: 197
Moving -> X: 138.03152465820313 Y: 183.91806030273438
Moving -> X: 143.3489227294922 Y: 171.96493530273438
Moving -> X: 147.5701141357422 Y: 166.64483642578125
Moving -> X: 148.5677032470703 Y: 163.8645782470703
Moving -> X: 149.5 Y: 162
Moving -> X: 150.2666778564453 Y: 160.46664428710938
UP -> X: 150.2666778564453 Y: 160.46664428710938
Down -> X: 154 Y: 52
UP -> X: 154 Y: 52
** Activity (main) Pause, UserClosed = true **

TIA for your help and comments.

udg

ps: btw, Panel documentation doesn't show "boolean" as the returning type for Touch function; should it be added in any case?
 
Last edited:

LucaMs

Expert
Licensed User
This is really strange, it probably just depends on the model of your device.
If so, you have no other solution than to cast the variables.

I want to add a strange behavior of my smartphone, both in this case and in other.

In this case, if I use your example maintaining the smartphone connected via USB, both in release and debug mode, I get even values 261 or 262 for Action! This does not happen when my smartphone is not connected to the PC.

I have not found an optimally USB driver for my device and this is the reason.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
ps: btw, Panel documentation doesn't show "boolean" as the returning type for Touch function; should it be added in any case?
No. There is no return value (there was in the past).

About the whole numbers. I don't have a good explanation for that however the numbers come from the native API directly.

I also recommend you to see this thread to understand how the touch event is delivered: http://www.basic4ppc.com/android/fo...touchevent-and-panel_touch.44711/#post-273217
 
Upvote 0

udg

Expert
Licensed User
Hi Luca,

thank you for your feedback.
Our findings seem to lead to an unpredictable numeric type for the coordinates served by the Touch function.
Maybe it is a problem/bug in Android itself while converting the X,Y values to whole numbers right after entering the function at least makes them consistent on all the devices.
Now my fear is: is this platform so unreliable not to be able to stay with consistent results even in its own coordinate system?

Edit: I just saw Erel's post and I'm going to study it.
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Hi Erel,

I was aware of the Reflection trick about the Touch event and used it with success before.
Do you recommend to stick with it and forget about panel_Touch?

For those who don't know what I'm talking about, it is:
B4X:
Dim r AsReflector
 r.Target = panel1
 r.SetOnTouchListener("Panel1_Touch") 'why reflection instead of the regular Panel_Touch event? Good question which deserves a forum thread of its own (not related to classes)...

Please have a more complete example here.

Umberto
 
Upvote 0

udg

Expert
Licensed User
does it matter if it is not rounded?

I guess it depends on its uses.
I discovered this issue while using my dgActionBar library to serve iconized options for a simple game. On my device everything worked as expected but others reported the "touch" event not working (so no options for them..).
The reason they found a not working event was that I required DOWN and UP values to be identical, and where decimals are served this is uncommon.

I understand that I could (and probably should) simply allow for a minimum difference between Down and Up values and still interpret it as a click on the icon, but the whole case surprised me. That's it.

Umberto
 
Upvote 0

sorex

Expert
Licensed User
is this the same issue that makes dragging an object the "normal" way shocky? like it loses contact due to the movement.
 
Upvote 0

udg

Expert
Licensed User
You forget that my hand is as still as the one of a neurosurgeon :)
And since we live in a tech society I could add as still as that of a robotic arm!
That means my Down and Up values will always be the same..no need for any "distance" factor yet.. eh eh

Seriously now, thanks for your support.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
You should definitely check for the distance and not rely on the same exact value.

B4X:
Dim Dist As Float = sqrt(Power(x - prevX, 2) + Power(y - prevY, 2))
If Dist < 10dip Then
Log("click")
End If


Yes, this was my first thought: it is not reasonable to think of touch a single pixel using a finger.

But using an emulator and a mouse, for example, you can (or simply those little pen of plastic we used in the past).

But the main point is really strange: receive INTs instead of FLOATs as parameters!!!

I think this is a problem of that tablet
 
Upvote 0

Beja

Expert
Licensed User
I I am not sure, but since you have initialized pnltest by just test, then how would you use a combination of both later?
 
Upvote 0

udg

Expert
Licensed User
Hi Beja,

I'm not sure to understand your question.
Pnltest is the only object involved and it is a panel.
test is the name I gave to its event in order to catch the touch event like test_Touch.
Naming that event "myevent", it would result in myevent_touch raised when a touch action is sensed on pnltest.

But I'm sure you know all this, so I definitely must have missed your point.

Umberto
 
Upvote 0
Top