From a58c9b08f07dfa7532156cb4d4b035766e63d5eb Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 7 Apr 2021 18:29:26 +0200 Subject: [PATCH] android: add support for adaptive icon/launcher 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. --- .../bootstraps/common/build/build.py | 21 ++++++++++++++++++- .../src/main/res/mipmap-anydpi-v26/.gitkeep | 0 .../sdl2/build/src/main/res/mipmap/.gitkeep | 0 .../build/templates/AndroidManifest.tmpl.xml | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap-anydpi-v26/.gitkeep create mode 100644 pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap/.gitkeep diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 895e599f6c..84ef7959ae 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -340,8 +340,21 @@ def make_package(args): default_presplash = 'templates/kivy-presplash.jpg' shutil.copy( args.icon or default_icon, - join(res_dir, 'drawable/icon.png') + join(res_dir, 'mipmap/icon.png') ) + if args.icon_fg and args.icon_bg: + shutil.copy(args.icon_fg, join(res_dir, 'mipmap/icon_foreground.png')) + shutil.copy(args.icon_bg, join(res_dir, 'mipmap/icon_background.png')) + with open(join(res_dir, 'mipmap-anydpi-v26/icon.xml'), "w") as fd: + fd.write(""" + + + + +""") + elif args.icon_fg or args.icon_bg: + print("WARNING: Received an --icon_fg or an --icon_bg argument, but not both. " + "Ignoring.") if args.enable_androidx: shutil.copy('templates/gradle.properties', 'gradle.properties') @@ -671,6 +684,12 @@ def parse_args_and_make_package(args=None): ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) + ap.add_argument('--icon-fg', dest='icon_fg', + help=('A png file to use as the foreground of the adaptive icon ' + 'for the application.')) + ap.add_argument('--icon-bg', dest='icon_bg', + help=('A png file to use as the background of the adaptive icon ' + 'for the application.')) ap.add_argument('--service', dest='services', action='append', default=[], help='Declare a new service entrypoint: ' 'NAME:PATH_TO_PY[:foreground]') diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap-anydpi-v26/.gitkeep b/pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap-anydpi-v26/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap/.gitkeep b/pythonforandroid/bootstraps/sdl2/build/src/main/res/mipmap/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml index 340bf9f023..dae6e1197a 100644 --- a/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml +++ b/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml @@ -56,7 +56,7 @@ -->