Skip to content

Commit 64ce0f8

Browse files
authored
[Display-Cutout] More tools for the developer + minor changes (kivy#3170)
* More tools for the developer + minor changes
1 parent be3de2e commit 64ce0f8

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

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

Lines changed: 30 additions & 11 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():
@@ -15,20 +16,20 @@ def _core_cutout():
1516

1617

1718
def get_cutout_pos():
18-
""" Get position of the display-cutout.
19-
Returns integer for each positions (xy)
19+
"""Get position of the display-cutout.
20+
Returns integer for each positions (xy)
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
2728

2829

2930
def get_cutout_size():
30-
""" Get the size (xy) of the front camera.
31-
Returns size with float values
31+
"""Get the size (xy) of the front camera.
32+
Returns size with float values
3233
"""
3334
try:
3435
cutout = _core_cutout()
@@ -39,8 +40,8 @@ def get_cutout_size():
3940

4041

4142
def get_height_of_bar(bar_target=None):
42-
""" Get the height of either statusbar or navigationbar
43-
bar_target = status or navigation and defaults to status
43+
"""Get the height of either statusbar or navigationbar
44+
bar_target = status or navigation and defaults to status
4445
"""
4546
bar_target = bar_target or 'status'
4647

@@ -61,12 +62,30 @@ def get_height_of_bar(bar_target=None):
6162

6263

6364
def get_width_of_bar(bar_target=None):
64-
" Get the width of the bar "
65+
"""Get the width of the bar"""
6566
return Window.width
6667

6768

6869
def get_size_of_bar(bar_target=None):
69-
""" Get the size of either statusbar or navigationbar
70-
bar_target = status or navigation and defaults to status
70+
"""Get the size of either statusbar or navigationbar
71+
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+
LayoutParams = autoclass('android.view.WindowManager$LayoutParams')
84+
window = mActivity.getWindow()
85+
layout_params = window.getAttributes()
86+
cutout_mode = layout_params.layoutInDisplayCutoutMode
87+
cutout_modes = {LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS: 'always',
88+
LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT: 'default',
89+
LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES: 'shortEdges'}
90+
91+
return cutout_modes.get(cutout_mode, 'never')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy