Android Question Cross-platform grid code: B4A is not equal B4J

peacemaker

Expert
Licensed User
Longtime User
HI, All

The project is attached: the same code for B4J and B4A.
At start the objects are OK at 0.0 coords.
Under Windows B4J compilation works ideally (object moving along the grid), but under Android - objects are not fit a bit, if to move both objects and try to fit the circles.
Why ?
 

Attachments

  • TempDownload.png
    TempDownload.png
    22.7 KB · Views: 101
  • b4xVectEdit_v0.15.zip
    14.4 KB · Views: 110
  • TempDownload.png
    TempDownload.png
    24.4 KB · Views: 108
Last edited:

peacemaker

Expert
Licensed User
Longtime User
AutoScaleAll has no effect, commented or uncommented.

AutoScaleAll helps for sure. But, for my phone, seems, not ideally.
The MEMU Android emulator log:
Logger connected to: 127.0.0.1:21503
--------- beginning of system
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
GridSize = 7
1.5
1.5

PC Windows 10 log is:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
*** mainpage: B4XPage_Created
GridSize = 5
1.0
And they are OK now, looks the same.

But not at my phone with Scale = 2.8125 :)
My GridSize = 14 and Scale should be 14 / 5dip = 2.80, but here is 2.8125.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
My GridSize = 14 and Scale should be 14 / 5dip = 2.80, but here is 2.8125.
No !
GridSize = 5dip * 2.8125 = 14.063
But GridSize is an Int. therefore 14 !
Try to set GridSize As Float
Or, maybe,better set :
Private DownX, DownY As Int
And leave GridSize As Int
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
GridSize As Float

Even if
FLOAT:
Private Sub ApplyGrid (x As Float) As Float
    Dim res As Float = x
    If GridSize > 0 Then
        res = x - (x Mod GridSize)
    End If
    Return res
End Sub
, in B4J B4XView.Left and B4XView.Top coordinates are double, but B4A they are ... Int.

My another phone is Xiaomi Redmi Note 10 Pro (Android 13):

** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
GridSize = 13
2.75
2.75

But the same no good looking. OK, let's stop the topic.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, nothing new. Any coordinates in Android are Int, so any calculations are always rounded.
 
Upvote 0
Top