-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for display cutouts in manifest and add methods to retrie…
…ve data (#2969) * Fresh changes of the display-cutout functionality * Fine tuning + added tools * Updated lib * Add missing None for default value while grabbing the sizes
- Loading branch information
Showing
9 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
pythonforandroid/bootstraps/qt/build/templates/strings.tmpl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
pythonforandroid/bootstraps/sdl2/build/templates/strings.tmpl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
pythonforandroid/bootstraps/webview/build/templates/strings.tmpl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pythonforandroid/recipes/android/src/android/display_cutout.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from jnius import autoclass | ||
from kivy.core.window import Window | ||
|
||
from android import mActivity | ||
|
||
__all__ = ('get_cutout_pos', 'get_cutout_size', 'get_width_of_bar', | ||
'get_height_of_bar', 'get_size_of_bar') | ||
|
||
|
||
def _core_cutout(): | ||
decorview = mActivity.getWindow().getDecorView() | ||
cutout = decorview.rootWindowInsets.displayCutout | ||
|
||
return cutout.boundingRects.get(0) | ||
|
||
|
||
def get_cutout_pos(): | ||
""" 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()) | ||
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 | ||
""" | ||
try: | ||
cutout = _core_cutout() | ||
return float(cutout.width()), float(cutout.height()) | ||
except Exception: | ||
# Doesn't have a camera builtin with the display | ||
return 0., 0. | ||
|
||
|
||
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 | ||
""" | ||
bar_target = bar_target or 'status' | ||
|
||
if bar_target not in ('status', 'navigation'): | ||
raise Exception("bar_target must be 'status' or 'navigation'") | ||
|
||
try: | ||
displayMetrics = autoclass('android.util.DisplayMetrics') | ||
mActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics()) | ||
resources = mActivity.getResources() | ||
resourceId = resources.getIdentifier(f'{bar_target}_bar_height', 'dimen', | ||
'android') | ||
|
||
return float(max(resources.getDimensionPixelSize(resourceId), 0)) | ||
except Exception: | ||
# Getting the size is not supported on older Androids | ||
return 0. | ||
|
||
|
||
def get_width_of_bar(bar_target=None): | ||
" 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 | ||
""" | ||
return get_width_of_bar(), get_height_of_bar(bar_target) |