From dbcc7f3051f24663c7215daba1c6a725c5b66096 Mon Sep 17 00:00:00 2001 From: Anish Mishra Date: Fri, 27 Sep 2024 04:42:41 +0530 Subject: [PATCH] Add support for Android Themed Icons (monochrome) --- .../EditorExportPlatformAndroid.xml | 3 ++ platform/android/export/export_plugin.cpp | 42 ++++++++++++++++-- platform/android/export/export_plugin.h | 5 ++- .../java/lib/res/mipmap-anydpi-v26/icon.xml | 1 + .../java/lib/res/mipmap/icon_monochrome.png | Bin 0 -> 5617 bytes 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 platform/android/java/lib/res/mipmap/icon_monochrome.png diff --git a/platform/android/doc_classes/EditorExportPlatformAndroid.xml b/platform/android/doc_classes/EditorExportPlatformAndroid.xml index 020e432155d..2fe5539e56d 100644 --- a/platform/android/doc_classes/EditorExportPlatformAndroid.xml +++ b/platform/android/doc_classes/EditorExportPlatformAndroid.xml @@ -102,6 +102,9 @@ Foreground layer of the application adaptive icon file. See [url=https://developer.android.com/develop/ui/views/launch/icon_design_adaptive#design-adaptive-icons]Design adaptive icons[/url]. + + Monochrome layer of the application adaptive icon file. See [url=https://developer.android.com/develop/ui/views/launch/icon_design_adaptive#design-adaptive-icons]Design adaptive icons[/url]. + Application icon file. If left empty, it will fallback to [member ProjectSettings.application/config/icon]. diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index e3d9807af79..cfd258cddc3 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -222,6 +222,7 @@ static const int icon_densities_count = 6; static const char *launcher_icon_option = PNAME("launcher_icons/main_192x192"); static const char *launcher_adaptive_icon_foreground_option = PNAME("launcher_icons/adaptive_foreground_432x432"); static const char *launcher_adaptive_icon_background_option = PNAME("launcher_icons/adaptive_background_432x432"); +static const char *launcher_adaptive_icon_monochrome_option = PNAME("launcher_icons/adaptive_monochrome_432x432"); static const LauncherIcon launcher_icons[icon_densities_count] = { { "res/mipmap-xxxhdpi-v4/icon.png", 192 }, @@ -250,6 +251,15 @@ static const LauncherIcon launcher_adaptive_icon_backgrounds[icon_densities_coun { "res/mipmap/icon_background.png", 432 } }; +static const LauncherIcon launcher_adaptive_icon_monochromes[icon_densities_count] = { + { "res/mipmap-xxxhdpi-v4/icon_monochrome.png", 432 }, + { "res/mipmap-xxhdpi-v4/icon_monochrome.png", 324 }, + { "res/mipmap-xhdpi-v4/icon_monochrome.png", 216 }, + { "res/mipmap-hdpi-v4/icon_monochrome.png", 162 }, + { "res/mipmap-mdpi-v4/icon_monochrome.png", 108 }, + { "res/mipmap/icon_monochrome.png", 432 } +}; + static const int EXPORT_FORMAT_APK = 0; static const int EXPORT_FORMAT_AAB = 1; @@ -1644,12 +1654,13 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n } } -void EditorExportPlatformAndroid::load_icon_refs(const Ref &p_preset, Ref &icon, Ref &foreground, Ref &background) { +void EditorExportPlatformAndroid::load_icon_refs(const Ref &p_preset, Ref &icon, Ref &foreground, Ref &background, Ref &monochrome) { String project_icon_path = GLOBAL_GET("application/config/icon"); icon.instantiate(); foreground.instantiate(); background.instantiate(); + monochrome.instantiate(); // Regular icon: user selection -> project icon -> default. String path = static_cast(p_preset->get(launcher_icon_option)).strip_edges(); @@ -1677,12 +1688,20 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref & print_verbose("Loading adaptive background icon from " + path); ImageLoader::load_image(path, background); } + + // Adaptive monochrome: user selection -> default. + path = static_cast(p_preset->get(launcher_adaptive_icon_monochrome_option)).strip_edges(); + if (!path.is_empty()) { + print_verbose("Loading adaptive monochrome icon from " + path); + ImageLoader::load_image(path, background); + } } void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref &p_preset, const Ref &p_main_image, const Ref &p_foreground, - const Ref &p_background) { + const Ref &p_background, + const Ref &p_monochrome) { String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset); // Prepare images to be resized for the icons. If some image ends up being uninitialized, @@ -1711,6 +1730,14 @@ void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Refis_empty()) { + print_verbose("Processing launcher adaptive icon p_monochrome for dimension " + itos(launcher_adaptive_icon_monochromes[i].dimensions) + " into " + launcher_adaptive_icon_monochromes[i].export_path); + Vector data; + _process_launcher_icons(launcher_adaptive_icon_monochromes[i].export_path, p_monochrome, + launcher_adaptive_icon_monochromes[i].dimensions, data); + store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_monochromes[i].export_path), data); + } } } @@ -1875,6 +1902,7 @@ void EditorExportPlatformAndroid::get_export_options(List *r_optio r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_icon_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_foreground_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_background_option, PROPERTY_HINT_FILE, "*.png"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_monochrome_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "graphics/opengl_debug"), false)); @@ -3035,8 +3063,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref main_image; Ref foreground; Ref background; + Ref monochrome; - load_icon_refs(p_preset, main_image, foreground, background); + load_icon_refs(p_preset, main_image, foreground, background, monochrome); Vector command_line_flags; // Write command line flags into the command_line_flags variable. @@ -3107,7 +3136,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Refis_empty()) { + if (file == launcher_adaptive_icon_monochromes[i].export_path) { + _process_launcher_icons(file, monochrome, launcher_adaptive_icon_monochromes[i].dimensions, data); + } + } } } diff --git a/platform/android/export/export_plugin.h b/platform/android/export/export_plugin.h index 708288fbf4c..7e1d626486b 100644 --- a/platform/android/export/export_plugin.h +++ b/platform/android/export/export_plugin.h @@ -167,12 +167,13 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { void _process_launcher_icons(const String &p_file_name, const Ref &p_source_image, int dimension, Vector &p_data); - void load_icon_refs(const Ref &p_preset, Ref &icon, Ref &foreground, Ref &background); + void load_icon_refs(const Ref &p_preset, Ref &icon, Ref &foreground, Ref &background, Ref &monochrome); void _copy_icons_to_gradle_project(const Ref &p_preset, const Ref &p_main_image, const Ref &p_foreground, - const Ref &p_background); + const Ref &p_background, + const Ref &p_monochrome); static void _create_editor_debug_keystore_if_needed(); diff --git a/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml b/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml index cfdcca2ab58..bb2ae6bee56 100644 --- a/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml +++ b/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml @@ -2,4 +2,5 @@ + diff --git a/platform/android/java/lib/res/mipmap/icon_monochrome.png b/platform/android/java/lib/res/mipmap/icon_monochrome.png new file mode 100644 index 0000000000000000000000000000000000000000..28f59ea119f224d0b7c37d4095e8d664d43dea5a GIT binary patch literal 5617 zcmeHKdod?{*PQdaJ(th-c|PCgdCq({2l)F; z*EQ8eAQ018OhzF5j8R=vCd2nMe&}`hQJWMT1_c5MD5*@s7sh}nC{YTcK!uQxKq%To z0qxT-;-|bFnQdO<%DG4>U>_3S8rrJ0`N2us*hr;dVQWX3;LLQC^!G!4jV(vkXBl4C zD%NP9V>eiN@c!}1^7FacFJ_-9qWE5WXK7I6L3ti^W(rHUhGv`@6mkAXyxI26-fx-n z*z+#T_t4Gm4h??uQm=opfEhNYmY6mse{#O+@`J${54=5^_b@pK(@Pubwc@<{Iw%?5 z1EL<|q%E(%fA_f8<27PcW%!0LpA%CN2#pOwIz50zr+>@`<HC-HmzC!>lf1>7g~j zW=GL=^XPHqTenbl*%{S*FSM`dimlZDK{WoFuUQrBB-4bd?cEH_`K?fF!zwzYjrHrou7BOaNm~8KgNhdo>u1@&zpA8!V*oYU?dT= z?hM5l7(@)BU9X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