Hi Erel, you are the best, even at the weekend.
This problem becomes a research project for me, but now I feel myself like an expert and I will share the result with our community:
There is a 'normal' orientation (rotation) for a device. By holding the device in this orientation, the function DisplayGetRotation() returns 0.
Turning the device left (counter clockwise) it returns 1, turning it right (clockwise) returns 3 and upside down it returns 2.
The 'normal' orientation of a phone is portrait, for a tablet it is landscape.
With the function GetDeviceType() the type phone, tablet or watch can be detected.
'**************************************************************
'* Returns the type of the device
'* 0 = phone, 1=tablet, 2=watch
'*
Sub GetDeviceType As Int
Dim LayVal As LayoutValues = GetDeviceLayoutValues
Dim Rot As Int = DisplayGetRotation
If LayVal.Height = LayVal.Width Then
Return 2
Else If Rot = 0 OR Rot = 2 Then
If LayVal.Height > LayVal.Width Then Return 0
Return 1
Else
If LayVal.Height < LayVal.Width Then Return 0
Return 1
End If
End Sub
'**************************************************************
'* Returns the current screen rotation
'* 0 = normal, 1=turned left, 2=upside down, 3= turned right
'* (Thanks to joseluis)
Sub DisplayGetRotation As Int
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindowManager")
r.Target = r.RunMethod("getDefaultDisplay")
Return r.RunMethod("getRotation")
End Sub
I want to mark the north direction on the screen.
The magnetic sensor returns 0°, if you hold the device in the 'normal' orientation looking to north.
So I have to combine the magnetic information, the device orientation and the device type.
So it's done in the attached project.
Oh, I don't know how to attach a zip file !