Android Question TOUCH_ACTION_MOVE alternatives?

JeffT

Member
Licensed User
Im trying to develop a canvas (panel/B4Xview) which has a grid
When the pointer is dragged across the grid, each square will change color.. like a bitmap icon editor.

When detecting TOUCH_ACTION_MOVE events, I get a bunch of them, then inexplicable pauses.
This means that I cannot fill a row of squares by dragging the pointer.. some are missed.

I have read in other posts that 'too many events' may be happening, and to try handling 'every 5'
That's not the issue, and it makes things worse if I skip additional messages in this way
Even if I log every received event, there are gaps in the events, and moving the pointer slowly is sometimes not enough.. events just stop happening, leaving gaps of an inch or so on screen.

It may be my low-end Android tablet, but since my potential users may have similar tablets, it has to work for them.
Games work fine , after all

What can be done to improve this?


In the Touch event , I have only this code:
B4X:
    Dim thex As Int =Floor(X/ squaresize)
    Dim they As Int =Floor(y/ squaresize)
'lastx and lasty are global properties

If  ( lastx <> thex Or lasty <> they ) Then   'this is to prevent drawing if we are still 'in' the previous square

'rct is a rect

                        rct.Initialize (thex*squaresize,they * squaresize, thex*squaresize+ squaresize,they * squaresize+ squaresize)
                        mycanvas.DrawRect (rct, thecolor,True,1)
    
end if

lastx = thex
lasty = they
mycanvas.invalidate
 

JeffT

Member
Licensed User
Here we are, @Erel . stripped to the basics, logging turned off.
try drawing a circle freehand.

So far I have been testing in debug mode using B4Bridge on a tablet.
 

Attachments

  • grid example.zip
    448.6 KB · Views: 258
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I downloaded your project, but the B4XMainPage.pas file is missing so I could not run it. I coded my own equivalent, and added some counters ...
B4X:
Sub base_Touch (Action As Int, X As Float, Y As Float)
    If isOutsideCell(X, Y) Then drawCell(X, Y)
End Sub

Sub isOutsideCell(x As Float, y As Float) As Boolean
    Return ((x < cell.Left) Or (X > cell.Right) Or (y < cell.Top) Or (y > cell.Bottom))
End Sub

Sub drawCell(x As Float, y As Float)
    cell.Left = Floor(x / size) * size
    cell.Right = cell.Left + size
    cell.Top = Floor(y / size ) * size
    cell.Bottom = cell.Top + size
    cvs.DrawRect(cell, xui.Color_Red, True, 0)
    cvs.Invalidate
End Sub
The results looked reasonable, but it was possible to "draw" fast enough to leave occasional gaps. This is on a two-year old Google Pixel with Android 10. The counters indicated that cell drawing was able to keep up with the rate of incoming events, but the incoming events were not always able to keep up with the finger movement. So if you want to draw a continuous line then you will have to interpolate between the events and add additional cells. The speed of drawing is not the problem - it is the rate at which the events are posted, it seems to me.

[EDIT : I have added my project]
 

Attachments

  • GridTrace.zip
    9.3 KB · Views: 224
Last edited:
Upvote 0

JeffT

Member
Licensed User
Thanks for looking into that Brian
Not sure what happened to the bas file, but your code isnt that for removed from mine.
I agree.. I just don't think the events fire quite fast enough
I'd rather have too many and ignore some than miss a few, but hey ho.
I can say it is faster in release build, and I'm using a £66 Chinese 10inch thing for testing, which I would expect to plod along.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
it does seem faster when not in a B4XPage environment
There is no such thing 'B4XPage environment'. There is nothing special in projects based on B4XPages and the performance will be identical.
You should never test performance in debug mode.

Use File - Export as zip to create a zip file with all modules.
B4A doesn't filter any event. All touch events will be raised and handled.
 
Upvote 0
Top