Hi all,
I'm in the process to port an old B4A lib of mine to B4J. Unfortunately, it uses the Reflection library to compute the display metrics of the device it runs on.
How could I translate the following sub to B4J? Thank you.
I'm in the process to port an old B4A lib of mine to B4J. Unfortunately, it uses the Reflection library to compute the display metrics of the device it runs on.
How could I translate the following sub to B4J? Thank you.
B4X:
'returns Display metrics in inches or millimeters
Private Sub getDisplayMetrics(Xaxis As Boolean, UnitInches As Boolean) As Float
Dim xdpi, ydpi As Float
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
xdpi=r.GetField("xdpi") 'is xdpi an int or a float?
ydpi=r.GetField("ydpi")
If Xaxis Then
If UnitInches Then Return xdpi Else Return dpi2dpmm(xdpi)
Else
If UnitInches Then Return ydpi Else Return dpi2dpmm(ydpi)
End If
End Sub