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 020e432155..2fe5539e56 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 e3d9807af7..cfd258cddc 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 708288fbf4..7e1d626486 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 cfdcca2ab5..bb2ae6bee5 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 zcmeAS@N?(olHy`uVBq!ia0y~yV8{Vs4mJh`hW@nhvkVLjN2)?1N`ey06$*;-(=u~X z6-p`#QWa7wGSe6sDsJTl+~z%O!13q1i0na|q{9|Ve3#~3_}I&*HnA*^2kgVf`YqbGe1r>3_=n%N;B}XYAzg zQTI4@FWXEDj`P3|-Cs;-|-|K7fI_{mVcC$crdeJdve17mBZvvYu_ zvop*;3=9=>YA4!y9Cna78Xvv1E<|RH(osd{(oNl67SpuE4mxFOZ+Vqa^itd;(<3NG zhV^<=vwU|byLfu6Yz(X82j(L;4|-m7_4*SZlp*-|V4?lJyVZC0GVkf-3hr5_v0%lr zd0od_a`Hky>|Z3V$g@~pS;=^dOO+w>^^c|e{PFLVY)=2ZGe6nkoHWk|jw6A~UaEa$ z`}k(r%EEi3Ns;o88|uX~uIax1ePh!s^@jJ7 zJA!Wi%VM7KTV?OPYlqwqJTNOLynAhl?SmqAiP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