Android Question B4XPages App Orientation

Harris

Expert
Licensed User
Longtime User
Erel suggests:
#SupportedOrientations attribute must be set to landscape or portrait. (in the compile log)
B4XPages will support ONE or the OTHER - I set it to unspecified

He states there is a workaround..
Below I created a workaround which seems to work well enough,,,

The sub Set_App_Port_or_Land gets the height and width - then sets portrait or landscape based the test.

Anyone see any problem with this ?

Code below from the Main Activity.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A FusedExample
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified ' set to support either...
    #CanInstallToExternalStorage: False
'#AdditionalJar: androidx.legacy:legacy-support-core-utils
    
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#BridgeLogger: True

Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Private ph As Phone
    
End Sub

Sub Globals
  
End Sub


Sub Activity_Create(FirstTime As Boolean)

    Set_App_Port_or_Land  'set port or land before initing the page manager...

    Dim pm As B4XPagesManager
    pm.Initialize(Activity)

End Sub


Sub Set_App_Port_or_Land
 
    Dim lv As LayoutValues
    lv = GetDeviceLayoutValues
 
    If lv.Height > lv.Width Then  ' Set app Orientation to Portrait
        Log(" set portrait")
        ph.SetScreenOrientation( 1 )
    Else                           ' Set app Orientation to Landscape
        Log(" set landscape")
        ph.SetScreenOrientation( 0 )
    End If
 
End Sub


'Template version: B4A-1.01
#Region Delegates

Sub Activity_ActionBarHomeClick
    ActionBarHomeClicked = True
    B4XPages.Delegate.Activity_ActionBarHomeClick
    ActionBarHomeClicked = False
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Return B4XPages.Delegate.Activity_KeyPress( KeyCode)
End Sub

' .......................
 

Harris

Expert
Licensed User
Longtime User
Ok, I read your other code links which is essentially the same as mine (except I use 0 or 1 for the SetScreenOrientation() ).
My code was from previous projects that FORCED to port or land - and never changed when rotating the device...

Phones in portrait mode are terrible devices to use for a vehicle app. Tablets in landscape mode are better suited (larger readable text). But, I can't control this...
So, if user starts app - on any device - the B4XPages app will respect the orientation.
Switching orientation on the fly was always a freakin nightmare to control (in Android)... Much code was created (needlessly) to handle this.
I agree with Erel in B4XPages - pick one or the other - and stick with it!

Thanks for the assurance.
Harris
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
In most cases, it's a bad idea to fix an orientation. This should be in the user's control - they know best which orientation will work for their needs. The developer should not be tempted to second-guess them because of technical convenience.

I'd love to enjoy the simplicity of coding B4Xpages apps, but except for those few cases where I find a fixed orientation is needed, I'll continue coding conventional B4A apps so that the user can use them in the orientation that fits their needs.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Hey, that seems more like an underlying Android structural problem. Take Netflix (but also other applications) and watch it on a tablet in landscape mode. Netflix's home page can also no longer be displayed in portrait and landscape mode anymore. After an update last year, the Netflix home page is only displayed in portrait mode. Netflix has been looking for a solution to this problem I reported for more than six months.
If more and more people start complaining to Netflix, Netflix may push this problem caused by Android update to Google to solve this structural portrait / landscape Android problem.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The solution I cited is 3 years old and is precisely designed to put the orientation in the user's control.
I have used this method for all that time without any problem. It feels natural to me as a user that once the app starts in the orientation I start it with,
it continues in that orientation. Any rotational movements of my hand makes that obvious. If I start the app it in a different orientation next time it stays in the new orientation.

In situations where I want to show a landscape video inside a portrait oriented B4XPages app, I simply start a new activity for that subtask.

https://www.b4x.com/android/forum/t...ow-device-is-held-when-app-is-started.134764/
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
The solution I cited is 3 years old and is precisely designed to put the orientation in the user's control.
I have used this method for all that time without any problem. It feels natural to me as a user that once the app starts in the orientation I start it with,
it continues in that orientation. Any rotational movements of my hand makes that obvious. If I start the app it in a different orientation next time it stays in the new orientation.

In situations where I want to show a landscape video inside a portrait oriented B4XPages app, I simply start start a new activity for that subtask.

https://www.b4x.com/android/forum/t...ow-device-is-held-when-app-is-started.134764/
Exactly / 100%.

Now, if Android had created a system where the pause / resume BS was not a mandatory part of the architecture, then rotation would not be an issue...

I just started using B4XPages now, because of a new app being developed. Erel strongly suggests that B4XPages be used going forward. I tend believe and respect his guidance because the man knows a little more than I about dev (ok, 10,000 times more than I will ever hope know!). He creates "super things" that we mere mortals could not possibly conceive - for our benefit. In this case of B4XPages, if he chose NOT to deal with pause / resume - the more power to him! Furthermore - NOW I don't have to deal with it either!!! Since there is a valid solution to support both Port / Land, I couldn't be happier. In my case, the devices are fixed mounted in vehicles - so rotation is not an issue (thank Christ).

However, we are all free to dev as we want, using whatever, for our own personal requirements.
 
Upvote 0
Top