Sub Activity_Create(FirstTime As Boolean)
Log(Activity.Height&" x "&Activity.Width)
Log("1dip "&1dip)
Log(GetDeviceLayoutValues)
Log(GetDeviceLayoutValues.ApproximateScreenSize)
result:
B4X:
2560 x 1440
1dip 1
1440 x 2560, scale = 4.0 (640 dpi)
4.589389937671455
how is it possible that GetDeviceLayoutValues returns correct values and 1dip is badly calculated?
PS. It happens on: Galaxy S7(Android 8), Galaxy A8(Android 8) and galaxy J5(Android 7), so it doesn't weem to be system or phone related problem.
Sub IntToDIP(Integer As Int) As Int
Dim r As Reflector
Dim scale As Float
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics"))
scale = r.GetField("density")
Dim DIP As Int
DIP = Integer * scale + 0.5
Return DIP
End Sub
Sub IntToDIP(Integer As Int) As Int
Dim r As Reflector
Dim scale As Float
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics"))
scale = r.GetField("density")
Dim DIP As Int
DIP = Integer * scale + 0.5
Return DIP
End Sub
Thank you, but where shoul I use it?
I use dip in the layouts all over the app,
and the problem is that sometimes it's calculated to 1, while normaly it shoud be 4 , when the app starts, checked with:
It could be used instead of Dip.
Unfortunately I can not tell you why it gives you wrong value to me never happened.
I can not tell you if the problem arises from the device or from the command.
However this method is very precise.
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
MyPanel.Width=IntToDIP(100)
End Sub
Sub IntToDIP(Integer As Int) As Int
Dim r As Reflector
Dim scale As Float
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics"))
scale = r.GetField("density")
Dim DIP As Int
DIP = Integer * scale + 0.5
Return DIP
End Sub
Make sure that there is no code in any of the Process_Globals subs other than variables declarations and assignments of primitive values. Don't use 'dip' units in Process_Globals.
I see how this can happen and I will make it more robust in the next version.
Erel -
If to follow your recomendations, do we need to worry anyway ? I never noticed something wrong with dips. Meanwhile I do not use layouts and do not use dip inside globals and process_globals.
I'll check that and report on friday, I have no access to B4A right now.
But to be honest, I always avoid using code in Process_Globals. Need to check anyway. Thanks
I just checked and didn't find any code other than declarations.
Just something like this in the Main:
B4X:
Sub Process_Globals
Public SubVer As String = "161018"
Dim pw As PhoneWakeState
Private xui As XUI
Private prevIntent As Intent
Private currentPage As Int
End Sub
and one assigment in Globals:
B4X:
Sub Globals
Dim ActivitySize As Int = GetDeviceLayoutValues.ApproximateScreenSize
I'm not sure if any of these can cause described issue...
Still not there, i'm checking spam as well.
I receive the 'new reply to watched thread' notifications as well as info about new B4A versions, so my email address should be ok.
I got the files. There is common created. in the unfiltered logs now.
I'll report it back if the issue appears or if it's ok, after some time of using my app.
Thanks for your help.
It's been a week since I compiled with new core libraries and installed on tree phones.
So far the described issue haven't appeared.
It looks that the change in core libraries solved it.
Thanks for help and please provide it with the new version.