Android Question Question about ApproximateScreenSize

D

Deleted member 103

Guest
Hi,

I have 2 smartphone with 5 inch display, a samsung-s4 and a HTC-one-a9.
The ApproximateScreenSize and ExactSize functions show two different results.
Where can I get the info that the 2 devices have a 5 inch display?

Samsung-S4:
ApproximateScreenSize=4.589389937671455
ExactSize=4.675465685446727

HTC-one-A9:
ApproximateScreenSize=4.330415684434925
ExactSize=4.371859576504938

B4X:
Sub getDeviceSize As Double
    Dim lv As LayoutValues   
    lv = GetDeviceLayoutValues
    Log("ApproximateScreenSize=" & lv.ApproximateScreenSize)
   
    Log("ExactSize=" & ExactSize)
   
    Return lv.ApproximateScreenSize
End Sub

Sub ExactSize As Double
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    r.Target = r.RunMethod("getDisplayMetrics")
    Dim xdpi As Double = r.GetField("xdpi")
    Dim ydpi As Double = r.GetField("ydpi")
    Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))
End Sub
 
D

Deleted member 103

Guest
I know the 2 devices have a 5 inch display, the question is how can I ensure by code that the 2 also a 5 inch display.

HTC-one-A9:
GetDeviceLayoutValues.Height = 1080
GetDeviceLayoutValues.Width = 1776
 
Upvote 0
D

Deleted member 103

Guest
What is the output when you use GetDeviceLayoutValues.Height and GetDeviceLayoutValues.Width in the ExactSize sub instead of 100%y and 100%x?
ExactSize=4.691006343276494

B4X:
Sub ExactSize As Double
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    r.Target = r.RunMethod("getDisplayMetrics")
    Dim xdpi As Double = r.GetField("xdpi")
    Dim ydpi As Double = r.GetField("ydpi")
    'Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))

    Dim lv As LayoutValues
    lv = GetDeviceLayoutValues
    Return Sqrt(Power(lv.Width / xdpi, 2) + Power(lv.Height / ydpi, 2))
End Sub
 
Upvote 0
D

Deleted member 103

Guest
This is the closest that it will be. It probably doesn't include the soft keys bar.
My problem is that I have to define that a smartphone from 5 inches should have the same settings as a tablet.

B4X:
Sub IsTablet As Boolean
    If ExactSize > 4.69 Then '4.69 = 5 zoll ?
        '7'' or 10'' tablet
        Return True
    Else
        'phone
        Return False
    End If
End Sub

Sub ExactSize As Double
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod("getResources")
   r.Target = r.RunMethod("getDisplayMetrics")
   Dim xdpi As Double = r.GetField("xdpi")
   Dim ydpi As Double = r.GetField("ydpi")
   'Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))

   Dim lv As LayoutValues
   lv = GetDeviceLayoutValues
   Return Sqrt(Power(lv.Width / xdpi, 2) + Power(lv.Height / ydpi, 2))
End Sub
 
Upvote 0
Top