Skip to content

Commit 76a1359

Browse files
authored
Merge pull request godotengine#97517 from syntaxerror247/android-themed-icon
Add support for Android Themed Icons (monochrome)
2 parents ac3eadf + dbcc7f3 commit 76a1359

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

platform/android/doc_classes/EditorExportPlatformAndroid.xml

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
<member name="launcher_icons/adaptive_foreground_432x432" type="String" setter="" getter="">
103103
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].
104104
</member>
105+
<member name="launcher_icons/adaptive_monochrome_432x432" type="String" setter="" getter="">
106+
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].
107+
</member>
105108
<member name="launcher_icons/main_192x192" type="String" setter="" getter="">
106109
Application icon file. If left empty, it will fallback to [member ProjectSettings.application/config/icon].
107110
</member>

platform/android/export/export_plugin.cpp

+38-4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static const int icon_densities_count = 6;
222222
static const char *launcher_icon_option = PNAME("launcher_icons/main_192x192");
223223
static const char *launcher_adaptive_icon_foreground_option = PNAME("launcher_icons/adaptive_foreground_432x432");
224224
static const char *launcher_adaptive_icon_background_option = PNAME("launcher_icons/adaptive_background_432x432");
225+
static const char *launcher_adaptive_icon_monochrome_option = PNAME("launcher_icons/adaptive_monochrome_432x432");
225226

226227
static const LauncherIcon launcher_icons[icon_densities_count] = {
227228
{ "res/mipmap-xxxhdpi-v4/icon.png", 192 },
@@ -250,6 +251,15 @@ static const LauncherIcon launcher_adaptive_icon_backgrounds[icon_densities_coun
250251
{ "res/mipmap/icon_background.png", 432 }
251252
};
252253

254+
static const LauncherIcon launcher_adaptive_icon_monochromes[icon_densities_count] = {
255+
{ "res/mipmap-xxxhdpi-v4/icon_monochrome.png", 432 },
256+
{ "res/mipmap-xxhdpi-v4/icon_monochrome.png", 324 },
257+
{ "res/mipmap-xhdpi-v4/icon_monochrome.png", 216 },
258+
{ "res/mipmap-hdpi-v4/icon_monochrome.png", 162 },
259+
{ "res/mipmap-mdpi-v4/icon_monochrome.png", 108 },
260+
{ "res/mipmap/icon_monochrome.png", 432 }
261+
};
262+
253263
static const int EXPORT_FORMAT_APK = 0;
254264
static const int EXPORT_FORMAT_AAB = 1;
255265

@@ -1644,12 +1654,13 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n
16441654
}
16451655
}
16461656

1647-
void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) {
1657+
void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome) {
16481658
String project_icon_path = GLOBAL_GET("application/config/icon");
16491659

16501660
icon.instantiate();
16511661
foreground.instantiate();
16521662
background.instantiate();
1663+
monochrome.instantiate();
16531664

16541665
// Regular icon: user selection -> project icon -> default.
16551666
String path = static_cast<String>(p_preset->get(launcher_icon_option)).strip_edges();
@@ -1677,12 +1688,20 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
16771688
print_verbose("Loading adaptive background icon from " + path);
16781689
ImageLoader::load_image(path, background);
16791690
}
1691+
1692+
// Adaptive monochrome: user selection -> default.
1693+
path = static_cast<String>(p_preset->get(launcher_adaptive_icon_monochrome_option)).strip_edges();
1694+
if (!path.is_empty()) {
1695+
print_verbose("Loading adaptive monochrome icon from " + path);
1696+
ImageLoader::load_image(path, background);
1697+
}
16801698
}
16811699

16821700
void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
16831701
const Ref<Image> &p_main_image,
16841702
const Ref<Image> &p_foreground,
1685-
const Ref<Image> &p_background) {
1703+
const Ref<Image> &p_background,
1704+
const Ref<Image> &p_monochrome) {
16861705
String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset);
16871706

16881707
// 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 Ref<Editor
17111730
launcher_adaptive_icon_backgrounds[i].dimensions, data);
17121731
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_backgrounds[i].export_path), data);
17131732
}
1733+
1734+
if (p_monochrome.is_valid() && !p_monochrome->is_empty()) {
1735+
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);
1736+
Vector<uint8_t> data;
1737+
_process_launcher_icons(launcher_adaptive_icon_monochromes[i].export_path, p_monochrome,
1738+
launcher_adaptive_icon_monochromes[i].dimensions, data);
1739+
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_monochromes[i].export_path), data);
1740+
}
17141741
}
17151742
}
17161743

@@ -1875,6 +1902,7 @@ void EditorExportPlatformAndroid::get_export_options(List<ExportOption> *r_optio
18751902
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_icon_option, PROPERTY_HINT_FILE, "*.png"), ""));
18761903
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_foreground_option, PROPERTY_HINT_FILE, "*.png"), ""));
18771904
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_background_option, PROPERTY_HINT_FILE, "*.png"), ""));
1905+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_monochrome_option, PROPERTY_HINT_FILE, "*.png"), ""));
18781906

18791907
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "graphics/opengl_debug"), false));
18801908

@@ -3035,8 +3063,9 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
30353063
Ref<Image> main_image;
30363064
Ref<Image> foreground;
30373065
Ref<Image> background;
3066+
Ref<Image> monochrome;
30383067

3039-
load_icon_refs(p_preset, main_image, foreground, background);
3068+
load_icon_refs(p_preset, main_image, foreground, background, monochrome);
30403069

30413070
Vector<uint8_t> command_line_flags;
30423071
// Write command line flags into the command_line_flags variable.
@@ -3107,7 +3136,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
31073136
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Unable to overwrite res/*.xml files with project name."));
31083137
}
31093138
// Copies the project icon files into the appropriate Gradle project directory.
3110-
_copy_icons_to_gradle_project(p_preset, main_image, foreground, background);
3139+
_copy_icons_to_gradle_project(p_preset, main_image, foreground, background, monochrome);
31113140
// Write an AndroidManifest.xml file into the Gradle project directory.
31123141
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
31133142

@@ -3446,6 +3475,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
34463475
_process_launcher_icons(file, background, launcher_adaptive_icon_backgrounds[i].dimensions, data);
34473476
}
34483477
}
3478+
if (monochrome.is_valid() && !monochrome->is_empty()) {
3479+
if (file == launcher_adaptive_icon_monochromes[i].export_path) {
3480+
_process_launcher_icons(file, monochrome, launcher_adaptive_icon_monochromes[i].dimensions, data);
3481+
}
3482+
}
34493483
}
34503484
}
34513485

platform/android/export/export_plugin.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,13 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
167167

168168
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
169169

170-
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background);
170+
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background, Ref<Image> &monochrome);
171171

172172
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
173173
const Ref<Image> &p_main_image,
174174
const Ref<Image> &p_foreground,
175-
const Ref<Image> &p_background);
175+
const Ref<Image> &p_background,
176+
const Ref<Image> &p_monochrome);
176177

177178
static void _create_editor_debug_keystore_if_needed();
178179

platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
33
<background android:drawable="@mipmap/icon_background"/>
44
<foreground android:drawable="@mipmap/icon_foreground"/>
5+
<monochrome android:drawable="@mipmap/icon_monochrome"/>
56
</adaptive-icon>
Loading

0 commit comments

Comments
 (0)