diff --git a/doc/source/buildoptions.rst b/doc/source/buildoptions.rst index 782bd67295..634f506faf 100644 --- a/doc/source/buildoptions.rst +++ b/doc/source/buildoptions.rst @@ -72,6 +72,10 @@ options (this list may not be exhaustive): - ``--permission``: A permission that needs to be declared into the App ``AndroidManifest.xml``. For multiple permissions, add multiple ``--permission`` arguments. ``--home-app`` Gives you the option to set your application as a home app (launcher) on your Android device. + ``--display-cutout``: A display cutout is an area on some devices that extends into the display surface. + It allows for an edge-to-edge experience while providing space for important sensors on the front of the device. + (Available options are ``default``, ``shortEdges``, ``never`` and defaults to ``never``) + `Android documentation `__. .. Note :: ``--permission`` accepts the following syntaxes: diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 29d16ea9f2..51e0a5fa94 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -793,6 +793,9 @@ def create_argument_parser(): 'launcher, rather than a single app.')) ap.add_argument('--home-app', dest='home_app', action='store_true', default=False, help=('Turn your application into a home app (launcher)')) + ap.add_argument('--display-cutout', dest='display_cutout', default='never', + help=('Enables display-cutout that renders around the area (notch) on ' + 'some devices that extends into the display surface')) ap.add_argument('--permission', dest='permissions', action='append', default=[], help='The permissions to give this app.', nargs='+') ap.add_argument('--meta-data', dest='meta_data', action='append', default=[], diff --git a/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml index 057794e4ed..8ccff2027a 100644 --- a/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/qt/build/templates/AndroidManifest.tmpl.xml @@ -61,6 +61,7 @@ android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode{% if args.min_sdk_version >= 8 %}|uiMode{% endif %}{% if args.min_sdk_version >= 13 %}|screenSize|smallestScreenSize{% endif %}{% if args.min_sdk_version >= 17 %}|layoutDirection{% endif %}{% if args.min_sdk_version >= 24 %}|density{% endif %}" android:screenOrientation="{{ args.manifest_orientation }}" android:exported="true" + android:theme="@style/KivySupportCutout" {% if args.activity_launch_mode %} android:launchMode="{{ args.activity_launch_mode }}" {% endif %} diff --git a/pythonforandroid/bootstraps/qt/build/templates/strings.tmpl.xml b/pythonforandroid/bootstraps/qt/build/templates/strings.tmpl.xml index 41c20ac663..fd15c25f47 100644 --- a/pythonforandroid/bootstraps/qt/build/templates/strings.tmpl.xml +++ b/pythonforandroid/bootstraps/qt/build/templates/strings.tmpl.xml @@ -1,5 +1,15 @@ + {{ args.name }} {{ private_version }} {{ args.presplash_color }} diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml index a887a53d54..c31bb3f747 100644 --- a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml @@ -70,6 +70,7 @@ android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode{% if args.min_sdk_version >= 8 %}|uiMode{% endif %}{% if args.min_sdk_version >= 13 %}|screenSize|smallestScreenSize{% endif %}{% if args.min_sdk_version >= 17 %}|layoutDirection{% endif %}{% if args.min_sdk_version >= 24 %}|density{% endif %}" android:screenOrientation="{{ args.manifest_orientation }}" android:exported="true" + android:theme="@style/KivySupportCutout" {% if args.activity_launch_mode %} android:launchMode="{{ args.activity_launch_mode }}" {% endif %} diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/strings.tmpl.xml b/pythonforandroid/bootstraps/sdl2/build/templates/strings.tmpl.xml index c8025518be..17e376adbd 100644 --- a/pythonforandroid/bootstraps/sdl2/build/templates/strings.tmpl.xml +++ b/pythonforandroid/bootstraps/sdl2/build/templates/strings.tmpl.xml @@ -1,5 +1,15 @@ + {{ args.name }} {{ private_version }} {{ args.presplash_color }} diff --git a/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml index f9e4fa3c61..9b436b1fa4 100644 --- a/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml @@ -62,6 +62,7 @@ android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode{% if args.min_sdk_version >= 8 %}|uiMode{% endif %}{% if args.min_sdk_version >= 13 %}|screenSize|smallestScreenSize{% endif %}{% if args.min_sdk_version >= 17 %}|layoutDirection{% endif %}{% if args.min_sdk_version >= 24 %}|density{% endif %}" android:screenOrientation="{{ args.manifest_orientation }}" android:exported="true" + android:theme="@style/KivySupportCutout" {% if args.activity_launch_mode %} android:launchMode="{{ args.activity_launch_mode }}" {% endif %} diff --git a/pythonforandroid/bootstraps/webview/build/templates/strings.tmpl.xml b/pythonforandroid/bootstraps/webview/build/templates/strings.tmpl.xml index 41c20ac663..fd15c25f47 100644 --- a/pythonforandroid/bootstraps/webview/build/templates/strings.tmpl.xml +++ b/pythonforandroid/bootstraps/webview/build/templates/strings.tmpl.xml @@ -1,5 +1,15 @@ + {{ args.name }} {{ private_version }} {{ args.presplash_color }} diff --git a/pythonforandroid/recipes/android/src/android/display_cutout.py b/pythonforandroid/recipes/android/src/android/display_cutout.py new file mode 100644 index 0000000000..dbe5d8a137 --- /dev/null +++ b/pythonforandroid/recipes/android/src/android/display_cutout.py @@ -0,0 +1,72 @@ +from jnius import autoclass +from kivy.core.window import Window + +from android import mActivity + +__all__ = ('get_cutout_pos', 'get_cutout_size', 'get_width_of_bar', + 'get_height_of_bar', 'get_size_of_bar') + + +def _core_cutout(): + decorview = mActivity.getWindow().getDecorView() + cutout = decorview.rootWindowInsets.displayCutout + + return cutout.boundingRects.get(0) + + +def get_cutout_pos(): + """ Get position of the display-cutout. + Returns integer for each positions (xy) + """ + try: + cutout = _core_cutout() + return int(cutout.left), Window.height - int(cutout.height()) + except Exception: + # Doesn't have a camera builtin with the display + return 0, 0 + + +def get_cutout_size(): + """ Get the size (xy) of the front camera. + Returns size with float values + """ + try: + cutout = _core_cutout() + return float(cutout.width()), float(cutout.height()) + except Exception: + # Doesn't have a camera builtin with the display + return 0., 0. + + +def get_height_of_bar(bar_target=None): + """ Get the height of either statusbar or navigationbar + bar_target = status or navigation and defaults to status + """ + bar_target = bar_target or 'status' + + if bar_target not in ('status', 'navigation'): + raise Exception("bar_target must be 'status' or 'navigation'") + + try: + displayMetrics = autoclass('android.util.DisplayMetrics') + mActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics()) + resources = mActivity.getResources() + resourceId = resources.getIdentifier(f'{bar_target}_bar_height', 'dimen', + 'android') + + return float(max(resources.getDimensionPixelSize(resourceId), 0)) + except Exception: + # Getting the size is not supported on older Androids + return 0. + + +def get_width_of_bar(bar_target=None): + " Get the width of the bar " + return Window.width + + +def get_size_of_bar(bar_target=None): + """ Get the size of either statusbar or navigationbar + bar_target = status or navigation and defaults to status + """ + return get_width_of_bar(), get_height_of_bar(bar_target)