Android Tutorial Edge Case use for B4XPages: Changing Orientation for Many Pages

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I think I will try your way. I know that a lot of my users like to be able to flip their phone or tablet around.
I move fields around the screen (based on device size) to make everything look nice (I know totally against designer standards) but I was doing this long before

Will let you know how I do.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
One thing I noticed is that after a rotation 100%x and 100%y are still reporting the Initial values.

Anyway to fix this?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I made some changes
B4X:
Public Sub Initialize as Object                                                          '  Changed by BobVal compiler complained
    Return Me
End Sub


Private Sub B4XPage_Resize(Width As Int, Height As Int)
#if not(b4j)
    LogColor($"B4XPage_Resize(Width=${Width}, Height=${Height})"$, Colors.Green)
#end if
    Dim AlreadyRestored As Boolean
    If LastOrientationPortrait=(Width>Height) Or Root.Width<>Width Or Root.Height<>Height Or FirstTime Then
        If Not(FirstTime) Then UI_Save_State

        '  Changed by BobVal  - If you do something in UI_Create that waits this code rolls on and and FirstTime is cleared 
        '                 and UI_Create may not have finished using it
        wait for (UI_Create(Width, Height)) Complete(RC as Boolean)    
                                                                                                                     
        If Not(FirstTime) Then
            UI_Restore_State
            AlreadyRestored=True
        End If
    End If
    If Not(FirstTime) And Not(AlreadyRestored) Then
        'save state
        UI_Save_State
        'restore state
        UI_Restore_State
    End If
    LastOrientationPortrait=(Height>Width)
    FirstTime = False
End Sub

Sub UI_Create(Width As Int, Height As Int) As ResumableSub ' changed by BobVal
#if not(b4j)
    LogColor($"UI_Create Width=${Width}, Height=${Height}"$, Colors.Magenta)
#end if
    Root.Width=Width
    Root.Height=Height
    Root.RemoveAllViews
'You will generally want to keep the 3 lines above and edit below.
    Root.LoadLayout("Page2")

    return true   ' changed by BobVal
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
I downloaded the sample project.

In Activity Main:
B4X:
'...
    ime1.Initialize("ime1")
    ime1.AddHeightChangedEvent
    Dim jo As JavaObject = Activity
    jo.RunMethodJO("getContext", Null).RunMethodJO("getWindow", Null).RunMethod("setSoftInputMode", _
     Array As Object(0x20))
    ActivityParent = jo.RunMethodJO("getParent", Null)
'...

Will IME and JavaObject work in B4i?
 

bparent

Member
Licensed User
Longtime User
Erel,

Is there a sample project with source code that illustrates this: Bottom line: most users should use the default B4XPages. If there is any specific "page" that needs to be displayed in other orientation or support multiple orientations, then you can use an additional activity outside of B4XPages."

Thanks.
"
 

AnandGupta

Expert
Licensed User
Longtime User
Let me give a hand here.
Take the 3-pages sample and instead of .showPage("Page 3") do StartActivity("Page3")
Add the new activity Page3 in your project first.

Hope that helps.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
The main module is different in the b4i app. IME is not used in b4i.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…