From eaa1f79cba9a23b034a5e83707c3f75638ce145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Lindstr=C3=B6m?= Date: Thu, 10 Jul 2025 13:31:42 +0300 Subject: [PATCH 1/3] More tools for the developer + minor changes --- .../android/src/android/display_cutout.py | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/recipes/android/src/android/display_cutout.py b/pythonforandroid/recipes/android/src/android/display_cutout.py index dbe5d8a137..9afd94a0aa 100644 --- a/pythonforandroid/recipes/android/src/android/display_cutout.py +++ b/pythonforandroid/recipes/android/src/android/display_cutout.py @@ -4,7 +4,8 @@ from android import mActivity __all__ = ('get_cutout_pos', 'get_cutout_size', 'get_width_of_bar', - 'get_height_of_bar', 'get_size_of_bar') + 'get_height_of_bar', 'get_size_of_bar', 'get_width_of_bar', + 'get_cutout_mode') def _core_cutout(): @@ -20,7 +21,7 @@ def get_cutout_pos(): """ try: cutout = _core_cutout() - return int(cutout.left), Window.height - int(cutout.height()) + return int(cutout.left), int(Window.height - cutout.height()) except Exception: # Doesn't have a camera builtin with the display return 0, 0 @@ -70,3 +71,32 @@ def get_size_of_bar(bar_target=None): bar_target = status or navigation and defaults to status """ return get_width_of_bar(), get_height_of_bar(bar_target) + + +def get_heights_of_both_bars(): + " Return heights of both bars " + return get_height_of_bar('status'), get_height_of_bar('navigation') + + +def get_cutout_mode(): + " Return mode for cutout supported applications " + mode = 'never' + + try: + LayoutParams = autoclass('android.view.WindowManager$LayoutParams') + window = mActivity.getWindow() + layout_params = window.getAttributes() + cutout_mode = layout_params.layoutInDisplayCutoutMode + + if cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS: + mode = 'always' + elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT: + mode = 'default' + elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES: + mode = 'shortEdges' + + except Exception: + # Something went wrong + pass + + return mode From 5d27bc1f716d667aba152486918bbc3a6885d134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Lindstr=C3=B6m?= Date: Thu, 10 Jul 2025 19:45:19 +0300 Subject: [PATCH 2/3] More tools for the developer + minor changes --- .../android/src/android/display_cutout.py | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/pythonforandroid/recipes/android/src/android/display_cutout.py b/pythonforandroid/recipes/android/src/android/display_cutout.py index 9afd94a0aa..af57af92bf 100644 --- a/pythonforandroid/recipes/android/src/android/display_cutout.py +++ b/pythonforandroid/recipes/android/src/android/display_cutout.py @@ -80,23 +80,12 @@ def get_heights_of_both_bars(): def get_cutout_mode(): " Return mode for cutout supported applications " - mode = 'never' - - try: - LayoutParams = autoclass('android.view.WindowManager$LayoutParams') - window = mActivity.getWindow() - layout_params = window.getAttributes() - cutout_mode = layout_params.layoutInDisplayCutoutMode - - if cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS: - mode = 'always' - elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT: - mode = 'default' - elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES: - mode = 'shortEdges' - - except Exception: - # Something went wrong - pass - - return mode + LayoutParams = autoclass('android.view.WindowManager$LayoutParams') + window = mActivity.getWindow() + layout_params = window.getAttributes() + cutout_mode = layout_params.layoutInDisplayCutoutMode + cutout_modes = {LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS: 'always', + LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT: 'default', + LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES: 'shortEdges'} + + return cutout_modes.get(cutout_mode, 'never') From fc61632b8f59cd99140bb3a16032dc7eefe3e0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Lindstr=C3=B6m?= Date: Thu, 10 Jul 2025 22:42:29 +0300 Subject: [PATCH 3/3] More tools for the developer + minor changes --- .../android/src/android/display_cutout.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pythonforandroid/recipes/android/src/android/display_cutout.py b/pythonforandroid/recipes/android/src/android/display_cutout.py index af57af92bf..09f89672da 100644 --- a/pythonforandroid/recipes/android/src/android/display_cutout.py +++ b/pythonforandroid/recipes/android/src/android/display_cutout.py @@ -16,8 +16,8 @@ def _core_cutout(): def get_cutout_pos(): - """ Get position of the display-cutout. - Returns integer for each positions (xy) + """Get position of the display-cutout. + Returns integer for each positions (xy) """ try: cutout = _core_cutout() @@ -28,8 +28,8 @@ def get_cutout_pos(): def get_cutout_size(): - """ Get the size (xy) of the front camera. - Returns size with float values + """Get the size (xy) of the front camera. + Returns size with float values """ try: cutout = _core_cutout() @@ -40,8 +40,8 @@ def get_cutout_size(): 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 + """Get the height of either statusbar or navigationbar + bar_target = status or navigation and defaults to status """ bar_target = bar_target or 'status' @@ -62,24 +62,24 @@ def get_height_of_bar(bar_target=None): def get_width_of_bar(bar_target=None): - " Get the width of the bar " + """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 + """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) def get_heights_of_both_bars(): - " Return heights of both bars " + """Return heights of both bars""" return get_height_of_bar('status'), get_height_of_bar('navigation') def get_cutout_mode(): - " Return mode for cutout supported applications " + """Return mode for cutout supported applications""" LayoutParams = autoclass('android.view.WindowManager$LayoutParams') window = mActivity.getWindow() layout_params = window.getAttributes()