mirror of
https://github.com/godotengine/godot.git
synced 2024-11-23 12:43:43 +00:00
Android: Refactor Icon logic and make monochrome icon optional
This commit is contained in:
parent
5e09d747e8
commit
c8aca3568f
@ -947,7 +947,7 @@ void EditorExportPlatformAndroid::_get_permissions(const Ref<EditorExportPreset>
|
||||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug) {
|
||||
void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug, bool p_monochrome_icon) {
|
||||
print_verbose("Building temporary manifest...");
|
||||
String manifest_text =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
@ -984,7 +984,7 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
|
||||
}
|
||||
}
|
||||
|
||||
manifest_text += _get_application_tag(Ref<EditorExportPlatform>(this), p_preset, _has_read_write_storage_permission(perms), p_debug);
|
||||
manifest_text += _get_application_tag(Ref<EditorExportPlatform>(this), p_preset, _has_read_write_storage_permission(perms), p_debug, p_monochrome_icon);
|
||||
manifest_text += "</manifest>\n";
|
||||
String manifest_path = ExportTemplateManager::get_android_build_directory(p_preset).path_join(vformat("src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release")));
|
||||
|
||||
@ -992,7 +992,7 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
|
||||
store_string_at_path(manifest_path, manifest_text);
|
||||
}
|
||||
|
||||
void EditorExportPlatformAndroid::_fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet) {
|
||||
void EditorExportPlatformAndroid::_fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet, bool p_monochrome_icon) {
|
||||
// Leaving the unused types commented because looking these constants up
|
||||
// again later would be annoying
|
||||
// const int CHUNK_AXML_FILE = 0x00080003;
|
||||
@ -1153,6 +1153,16 @@ void EditorExportPlatformAndroid::_fix_manifest(const Ref<EditorExportPreset> &p
|
||||
encode_uint32(is_resizeable, &p_manifest.write[iofs + 16]);
|
||||
}
|
||||
|
||||
if (tname == "activity-alias" && attrname == "enabled") {
|
||||
if (attr_resid != 0x00000000) {
|
||||
// Activity alias for Default Icons
|
||||
encode_uint32(!p_monochrome_icon, &p_manifest.write[iofs + 16]);
|
||||
} else {
|
||||
// Activity alias for Themed Icons, it is initially false.
|
||||
encode_uint32(p_monochrome_icon, &p_manifest.write[iofs + 16]);
|
||||
}
|
||||
}
|
||||
|
||||
if (tname == "provider" && attrname == "authorities") {
|
||||
string_table.write[attr_value] = get_package_name(package_name) + String(".fileprovider");
|
||||
}
|
||||
@ -1698,7 +1708,7 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
|
||||
path = static_cast<String>(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);
|
||||
ImageLoader::load_image(path, monochrome);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3080,6 +3090,8 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
|
||||
load_icon_refs(p_preset, main_image, foreground, background, monochrome);
|
||||
|
||||
bool p_monochrome_icon = (monochrome.is_valid() && !monochrome->is_empty());
|
||||
|
||||
Vector<uint8_t> command_line_flags;
|
||||
// Write command line flags into the command_line_flags variable.
|
||||
get_command_line_flags(p_preset, p_path, p_flags, command_line_flags);
|
||||
@ -3151,7 +3163,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
// Copies the project icon files into the appropriate Gradle project directory.
|
||||
_copy_icons_to_gradle_project(p_preset, main_image, foreground, background, monochrome);
|
||||
// Write an AndroidManifest.xml file into the Gradle project directory.
|
||||
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
|
||||
_write_tmp_manifest(p_preset, p_give_internet, p_debug, p_monochrome_icon);
|
||||
|
||||
//stores all the project files inside the Gradle project directory. Also includes all ABIs
|
||||
_clear_assets_directory(p_preset);
|
||||
@ -3468,7 +3480,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
|
||||
//write
|
||||
if (file == "AndroidManifest.xml") {
|
||||
_fix_manifest(p_preset, data, p_give_internet);
|
||||
_fix_manifest(p_preset, data, p_give_internet, p_monochrome_icon);
|
||||
}
|
||||
if (file == "resources.arsc") {
|
||||
_fix_resources(p_preset, data);
|
||||
|
@ -154,9 +154,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||
|
||||
void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions);
|
||||
|
||||
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);
|
||||
void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug, bool p_monochrome_icon);
|
||||
|
||||
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet);
|
||||
void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet, bool p_monochrome_icon);
|
||||
|
||||
static String _get_keystore_path(const Ref<EditorExportPreset> &p_preset, bool p_debug);
|
||||
|
||||
|
@ -305,14 +305,23 @@ String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, con
|
||||
return manifest_activity_text;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug) {
|
||||
String _remove_activity_alias_tags() {
|
||||
String activity_alias = "<activity-alias\n"
|
||||
" android:name=\".DefaultIcon\"\n"
|
||||
" tools:node=\"remove\" />\n"
|
||||
"<activity-alias\n"
|
||||
" android:name=\".ThemedIcon\"\n"
|
||||
" tools:node=\"remove\" />\n";
|
||||
return activity_alias;
|
||||
}
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug, bool p_monochrome_icon) {
|
||||
int app_category_index = (int)(p_preset->get("package/app_category"));
|
||||
bool is_game = app_category_index == APP_CATEGORY_GAME;
|
||||
|
||||
String manifest_application_text = vformat(
|
||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||
" android:allowBackup=\"%s\"\n"
|
||||
" android:icon=\"@mipmap/icon\"\n"
|
||||
" android:isGame=\"%s\"\n"
|
||||
" android:hasFragileUserData=\"%s\"\n"
|
||||
" android:requestLegacyExternalStorage=\"%s\"\n",
|
||||
@ -320,12 +329,19 @@ String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform,
|
||||
bool_to_string(is_game),
|
||||
bool_to_string(p_preset->get("package/retain_data_on_uninstall")),
|
||||
bool_to_string(p_has_read_write_storage_permission));
|
||||
|
||||
if (p_monochrome_icon) {
|
||||
manifest_application_text += " android:icon=\"@mipmap/themed_icon\"\n";
|
||||
} else {
|
||||
manifest_application_text += " android:icon=\"@mipmap/icon\"\n";
|
||||
}
|
||||
|
||||
if (app_category_index != APP_CATEGORY_UNDEFINED) {
|
||||
manifest_application_text += vformat(" android:appCategory=\"%s\"\n", _get_app_category_label(app_category_index));
|
||||
manifest_application_text += " tools:replace=\"android:allowBackup,android:appCategory,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n";
|
||||
manifest_application_text += " tools:replace=\"android:allowBackup,android:icon,android:appCategory,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n";
|
||||
} else {
|
||||
manifest_application_text += " tools:remove=\"android:appCategory\"\n";
|
||||
manifest_application_text += " tools:replace=\"android:allowBackup,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n";
|
||||
manifest_application_text += " tools:replace=\"android:allowBackup,android:icon,android:isGame,android:hasFragileUserData,android:requestLegacyExternalStorage\"\n";
|
||||
}
|
||||
manifest_application_text += " tools:ignore=\"GoogleAppIndexingWarning\">\n\n";
|
||||
|
||||
@ -341,6 +357,7 @@ String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform,
|
||||
}
|
||||
|
||||
manifest_application_text += _get_activity_tag(p_export_platform, p_preset, p_debug);
|
||||
manifest_application_text += _remove_activity_alias_tags();
|
||||
manifest_application_text += " </application>\n";
|
||||
return manifest_application_text;
|
||||
}
|
||||
|
@ -106,6 +106,6 @@ String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset);
|
||||
|
||||
String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug);
|
||||
|
||||
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug);
|
||||
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug, bool p_monochrome_icon);
|
||||
|
||||
#endif // ANDROID_GRADLE_EXPORT_UTIL_H
|
||||
|
@ -45,14 +45,37 @@
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|density|keyboard|navigation|screenLayout|uiMode"
|
||||
android:resizeableActivity="false"
|
||||
tools:ignore="UnusedAttribute" >
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Alias for Default icons -->
|
||||
<activity-alias
|
||||
android:name=".DefaultIcon"
|
||||
android:exported="true"
|
||||
android:targetActivity=".GodotApp"
|
||||
android:icon="@mipmap/icon"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<!-- Alias for Themed icons -->
|
||||
<activity-alias
|
||||
android:name=".ThemedIcon"
|
||||
android:exported="true"
|
||||
android:targetActivity=".GodotApp"
|
||||
android:icon="@mipmap/themed_icon"
|
||||
android:enabled="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -2,5 +2,4 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@mipmap/icon_background"/>
|
||||
<foreground android:drawable="@mipmap/icon_foreground"/>
|
||||
<monochrome android:drawable="@mipmap/icon_monochrome"/>
|
||||
</adaptive-icon>
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@mipmap/icon_background"/>
|
||||
<foreground android:drawable="@mipmap/icon_foreground"/>
|
||||
<monochrome android:drawable="@mipmap/icon_monochrome"/>
|
||||
</adaptive-icon>
|
Loading…
Reference in New Issue
Block a user