Skip to content

Commit 79f9030

Browse files
authored
android: add support for adaptive icon/launcher (kivy#2446)
see https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive This adds a `--icon-fg` and a `--icon-bg` build option to the sdl2 bootstrap, that can be used to specify two PNG files to be used as the foreground and background of an adaptive icon. These will get used if API 26+ is available at runtime. The existing `--icon` option to specify an icon as a single PNG file is kept, as - this provides backwards compatibility, - and even if the new options are used, it might be a good idea to set all three options: when running on API <26, the PNG specified via `--icon` gets used.
1 parent 28411b7 commit 79f9030

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,21 @@ def make_package(args):
342342
default_presplash = 'templates/kivy-presplash.jpg'
343343
shutil.copy(
344344
args.icon or default_icon,
345-
join(res_dir, 'drawable/icon.png')
345+
join(res_dir, 'mipmap/icon.png')
346346
)
347+
if args.icon_fg and args.icon_bg:
348+
shutil.copy(args.icon_fg, join(res_dir, 'mipmap/icon_foreground.png'))
349+
shutil.copy(args.icon_bg, join(res_dir, 'mipmap/icon_background.png'))
350+
with open(join(res_dir, 'mipmap-anydpi-v26/icon.xml'), "w") as fd:
351+
fd.write("""<?xml version="1.0" encoding="utf-8"?>
352+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
353+
<background android:drawable="@mipmap/icon_background"/>
354+
<foreground android:drawable="@mipmap/icon_foreground"/>
355+
</adaptive-icon>
356+
""")
357+
elif args.icon_fg or args.icon_bg:
358+
print("WARNING: Received an --icon_fg or an --icon_bg argument, but not both. "
359+
"Ignoring.")
347360

348361
if args.enable_androidx:
349362
shutil.copy('templates/gradle.properties', 'gradle.properties')
@@ -673,6 +686,12 @@ def parse_args_and_make_package(args=None):
673686
ap.add_argument('--icon', dest='icon',
674687
help=('A png file to use as the icon for '
675688
'the application.'))
689+
ap.add_argument('--icon-fg', dest='icon_fg',
690+
help=('A png file to use as the foreground of the adaptive icon '
691+
'for the application.'))
692+
ap.add_argument('--icon-bg', dest='icon_bg',
693+
help=('A png file to use as the background of the adaptive icon '
694+
'for the application.'))
676695
ap.add_argument('--service', dest='services', action='append', default=[],
677696
help='Declare a new service entrypoint: '
678697
'NAME:PATH_TO_PY[:foreground]')

pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap-anydpi-v26/.gitkeep

Whitespace-only changes.

pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap/.gitkeep

Whitespace-only changes.

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
-->
5757
<application android:label="@string/app_name"
5858
{% if debug %}android:debuggable="true"{% endif %}
59-
android:icon="@drawable/icon"
59+
android:icon="@mipmap/icon"
6060
android:allowBackup="{{ args.allow_backup }}"
6161
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
6262
{{ args.extra_manifest_application_arguments }}
@@ -100,7 +100,7 @@
100100

101101
{% if args.launcher %}
102102
<activity android:name="org.kivy.android.launcher.ProjectChooser"
103-
android:icon="@drawable/icon"
103+
android:icon="@mipmap/icon"
104104
android:label="@string/app_name">
105105

106106
<intent-filter>

0 commit comments

Comments
 (0)