diff --git a/pythonforandroid/recipes/android/src/android/display_cutout.py b/pythonforandroid/recipes/android/src/android/display_cutout.py index dbe5d8a137..09f89672da 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(): @@ -15,20 +16,20 @@ 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() - 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 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() @@ -39,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' @@ -61,12 +62,30 @@ 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 get_height_of_bar('status'), get_height_of_bar('navigation') + + +def get_cutout_mode(): + """Return mode for cutout supported applications""" + 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')