Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions pythonforandroid/recipes/android/src/android/display_cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand All @@ -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'

Expand All @@ -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')
Loading