Skip to content

Commit eaa1f79

Browse files
committed
More tools for the developer + minor changes
1 parent be3de2e commit eaa1f79

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

pythonforandroid/recipes/android/src/android/display_cutout.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from android import mActivity
55

66
__all__ = ('get_cutout_pos', 'get_cutout_size', 'get_width_of_bar',
7-
'get_height_of_bar', 'get_size_of_bar')
7+
'get_height_of_bar', 'get_size_of_bar', 'get_width_of_bar',
8+
'get_cutout_mode')
89

910

1011
def _core_cutout():
@@ -20,7 +21,7 @@ def get_cutout_pos():
2021
"""
2122
try:
2223
cutout = _core_cutout()
23-
return int(cutout.left), Window.height - int(cutout.height())
24+
return int(cutout.left), int(Window.height - cutout.height())
2425
except Exception:
2526
# Doesn't have a camera builtin with the display
2627
return 0, 0
@@ -70,3 +71,32 @@ def get_size_of_bar(bar_target=None):
7071
bar_target = status or navigation and defaults to status
7172
"""
7273
return get_width_of_bar(), get_height_of_bar(bar_target)
74+
75+
76+
def get_heights_of_both_bars():
77+
" Return heights of both bars "
78+
return get_height_of_bar('status'), get_height_of_bar('navigation')
79+
80+
81+
def get_cutout_mode():
82+
" Return mode for cutout supported applications "
83+
mode = 'never'
84+
85+
try:
86+
LayoutParams = autoclass('android.view.WindowManager$LayoutParams')
87+
window = mActivity.getWindow()
88+
layout_params = window.getAttributes()
89+
cutout_mode = layout_params.layoutInDisplayCutoutMode
90+
91+
if cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS:
92+
mode = 'always'
93+
elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT:
94+
mode = 'default'
95+
elif cutout_mode == LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES:
96+
mode = 'shortEdges'
97+
98+
except Exception:
99+
# Something went wrong
100+
pass
101+
102+
return mode

0 commit comments

Comments
 (0)