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?
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
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
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