Android Question SDK 36 and problem with root.left

Filippo

Expert
Licensed User
Longtime User
Hi,

Erel's code works well; however, there's a problem with “root.left.”
When using “sensorLandscape,” the value of root.left is 135dip in one direction and 100dip in the other.
This causes the display to shift and get too close to the control buttons.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    ime.Initialize("ime")
    root = xui.CreatePanel("")
    Dim Content As Rect = ime.GetContentRect
    Activity.Color = Colors.Black
    Activity.AddView(root, Content.Left, Content.Top, Content.Width, Content.Height)
    ime.UpdatePercentageReference(root.Width, root.Height)
    root.LoadLayout("frmMain")

    Log("root.left= " & root.Left)
End Sub
*** Receiver (httputils2service) Receive (first time) ***
*** Service (starter) Create completed ***
*** Service (starter) Started ***
** Service (starter) Start **
*** Service (starter) Started completed ***
** Activity (main) Create (first time) **
root.left= 100
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
*** Receiver (httputils2service) Receive (first time) ***
*** Service (starter) Create completed ***
*** Service (starter) Started ***
** Service (starter) Start **
*** Service (starter) Started completed ***
** Activity (main) Create (first time) **
root.left= 135
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
*** Receiver (httputils2service) Receive (first time) ***
*** Service (starter) Create completed ***
*** Service (starter) Started ***
** Service (starter) Start **
*** Service (starter) Started completed ***
** Activity (main) Create (first time) **
root.left= 100
** Activity (main) Resume **
 
Solution
A probably better solution - with IME v2.01 there is a new InsetsChanged event that is raised when the insets changed. You need to call AddHeightChangedEvent to enable it.
B4X:
Private Sub IME_InsetsChanged
    Dim r As Rect = ime.GetContentRect
    root.SetLayoutAnimated(0, r.Left, r.Top, r.Width, r.Height)
End Sub

Note that the event will only be raised in E2E mode.

Filippo

Expert
Licensed User
Longtime User
In my case, I've solved the problem using the PhoneSensors library—or is there a better solution?

B4X:
#SupportedOrientations: sensorLandscape

Private magnetic As PhoneSensors
    
Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("frmMain")

    ime.Initialize("ime")
    root = xui.CreatePanel("")
    Dim Content As Rect = ime.GetContentRect
    Activity.Color = Colors.Black
    Activity.AddView(root, Content.Left, Content.Top, Content.Width, Content.Height)
    ime.UpdatePercentageReference(root.Width, root.Height)
    root.LoadLayout("frmMain")
    magnetic.Initialize(magnetic.TYPE_MAGNETIC_FIELD)
    magnetic.StartListening("Magnetic")
End Sub

Private Sub magnetic_SensorChanged (Values() As Float)
    Dim Content As Rect = ime.GetContentRect
    root.SetLayoutAnimated(0, Content.Left, Content.Top, Content.Width, Content.Height)
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
A probably better solution - with IME v2.01 there is a new InsetsChanged event that is raised when the insets changed. You need to call AddHeightChangedEvent to enable it.
B4X:
Private Sub IME_InsetsChanged
    Dim r As Rect = ime.GetContentRect
    root.SetLayoutAnimated(0, r.Left, r.Top, r.Width, r.Height)
End Sub

Note that the event will only be raised in E2E mode.
 

Attachments

  • IME.zip
    9.6 KB · Views: 55
Upvote 0
Solution

Filippo

Expert
Licensed User
Longtime User
A probably better solution - with IME v2.01 there is a new InsetsChanged event that is raised when the insets changed. You need to call AddHeightChangedEvent to enable it.
Thank you very much, Erel. As expected, your solution is much better.
 
Upvote 0
Top