Android Question Smartphones with a notch

yo3ggx

Active Member
Licensed User
Longtime User
Following the tutorial here I was able to display the application in full screen Iimmersive mode), including over the notch area.
It is possible to set the option (cover/not cover notch area0 from the code, not from the Manifest file?

Some smartphones can have a bigger notch and then to cover used areas on the screen, so I want the user to be able to decide.

Thank you.
 

yo3ggx

Active Member
Licensed User
Longtime User
I successfully achieved this. What I still have to do when I will have some more time is to automatically detect notch position. Currently the user choose manually the notch position (center, left or right). This help positioning some screen elements based on selection.


Manifest:
CreateResource(values, theme.xml,
<resources>
    <style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    </style>
</resources>)


Process_Globals:
    Dim iDisplayNotch As Int
    Dim NOTCH_NEVER As Int = 0
    Dim NOTCH_ALWAYS As Int = 1
    Dim NOTCH_LEFT As Int = 2
    Dim NOTCH_RIGHT As Int = 3
    Dim NOTCH_SIDE As Int = 4
    
    Dim LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS As Int = 3          ' The window is always allowed to extend into the DisplayCutout areas on the all edges of the screen.
    Dim LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT As Int = 0         ' The window is allowed to extend into the DisplayCutout area, only if the DisplayCutout is fully contained within a system bar. Otherwise, the window is laid out such that it does not overlap with the DisplayCutout area
    Dim LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER As Int = 2             ' The window is never allowed to overlap with the DisplayCutout area
    Dim LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES As Int = 1    ' The window is always allowed to extend into the DisplayCutout areas on the short edges of the screen even if fullscreen or in landscape. The window will never extend into a DisplayCutout area on the long edges of the screen.
    Dim Ph as Phone
Get the height of the notch (o if no notch):
Sub GetNotchHeight As Int
    ' find if the display has a notch and return his height
    ' if no notch, return 0
    If SDKver < 28 Then Return 0
    Dim ctxt As JavaObject
    ctxt.InitializeContext

    Dim JO As JavaObject = ctxt.RunMethodJO("getWindow", Null)
    JO = JO.RunMethodJO("getDecorView", Null)
    JO = JO.RunMethodJO("getRootWindowInsets",Null)
    JO = JO.RunMethodJO("getDisplayCutout",Null)

    If JO.IsInitialized Then
        Log("This device has a notch")
        Dim i As Int = JO.RunMethod("getSafeInsetTop",Null)
        Log("Notch Height: " & i)
        Return i
    Else
        Log("This device does not have a notch")
        Return 0
    End If
End Sub
First check if the smartphone has a notch.
Code:
        If Ph.SdkVersion>= 28 Then
            Dim jo As JavaObject
            jo.InitializeContext
            jo = jo.RunMethod("getWindow", Null)
            jo.RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode",LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)
            If GetNotchHeight > 0 Then
                bIsNotch = True
            Else
                bIsNotch = False
            End If
            If iDisplayNotch = NOTCH_NEVER Then
                jo.RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode", LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER)
            Else
                jo.RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode",LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)
            End If
        End If

Hope this helps others interested in this topic.
 
Upvote 0
Top