B4A Class Programmatically set screen settings

I recently had the need to work out how to set screen settings (orientation and full/non-full screen) via my B4A app.

I found relevant information in the forums limited, scattered and decidedly opaque - if I missed the tutorial then please hit the reply button.

So I set to and put together a small class and example, smothered in documentation...

The example is a bit crude as the following screenshots show, however it enables you to fully explore the 16 screen orientation options - unspecified, landscape and portrait and 13 others as detailed in:

http://developer.android.com/reference/android/R.attr.html#screenOrientation

It also shows you how to jump between non-full screen and full screen at will.

Note screenshot #4 - the phone is upside down.

6.png


-------------------------------------------------------------

The class header documentation pretty well explains the intent:
B4X:
'************************************************************************************
'
'This class module provides full programmatic control of screen settings, regardless
'of how they have been initially defined
'
'Features:
'
'   o 16 screen orientations, as per:
'     http://developer.android.com/reference/android/R.attr.html#screenOrientation
'
'   o Full screen mode on/off
'
'Methods:
'
'   Initialize
'
'   Change
'
'   Reset
'
'Events:
'
'   None
'
'Properties:
'
'   None
'
'Requirements:
'
'   o B4A libraries:
'
'         Phone (version 2.28 or later) - for screen orientation control
'         Reflection (version 2.40 or later) - for full screen control
'
'Update history:
'
'   16 Mar 16 - 1.0
'
'************************************************************************************
And the documentation of the Change method of the class describes the parameters that need to be passed:
B4X:
'************************************************************************************
'
'This procedure gets control when Change method is called by parent module
'
'Input parameters are:
'
'       SS_Orientation = required orientation, which can be "unspecified",
'                        "landscape", "portrait", "user", "behind", "sensor",
'                        "nosensor", "sensorlandscape", "sensorportrait",
'                        "reverselandscape", "reverseportrait", "fullsensor",
'                        "userlandscape", "userportrait", "fulluser" or "locked"
'       SS_Full_Screen = required full screen state (True or False)
'
'Returns:
'
'       None
'
'Notes on this procedure:
'
'       o Changes screen settings of current activity
'
'************************************************************************************

Happy coding...
 

Attachments

  • ScreenSetting.zip
    10.4 KB · Views: 160
Last edited:
Top