Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Follow up on bootsplash handling on Android #46168

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {

MAIN_PRINT("Main: Setup Logo");

#ifdef JAVASCRIPT_ENABLED
#if defined(JAVASCRIPT_ENABLED) || defined(ANDROID_ENABLED)
bool show_logo = false;
#else
bool show_logo = true;
Expand Down
33 changes: 29 additions & 4 deletions platform/android/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ static const char *android_perms[] = {

static const char *SPLASH_IMAGE_EXPORT_PATH = "res/drawable/splash.png";
static const char *SPLASH_BG_COLOR_PATH = "res/drawable/splash_bg_color.png";
static const char *SPLASH_CONFIG_PATH = "res://android/build/res/drawable/splash_drawable.xml";

const String SPLASH_CONFIG_XML_CONTENT = R"SPLASH(<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_bg_color" />
<item>
<bitmap
android:gravity="%s"
android:filter="%s"
android:src="@drawable/splash" />
</item>
</layer-list>
)SPLASH";

struct LauncherIcon {
const char *export_path;
Expand Down Expand Up @@ -1508,8 +1521,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
}

void load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image) {
// TODO: Figure out how to handle remaining boot splash parameters (e.g: fullsize, filter)
String load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image) {
bool scale_splash = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
bool apply_filter = ProjectSettings::get_singleton()->get("application/boot_splash/use_filter");
String project_splash_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");

if (!project_splash_path.empty()) {
Expand Down Expand Up @@ -1541,6 +1555,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
splash_bg_color_image.instance();
splash_bg_color_image->create(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format());
splash_bg_color_image->fill(bg_color);

String gravity = scale_splash ? "fill" : "center";
String processed_splash_config_xml = vformat(SPLASH_CONFIG_XML_CONTENT, gravity, bool_to_string(apply_filter));
return processed_splash_config_xml;
}

void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) {
Expand Down Expand Up @@ -1584,11 +1602,18 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}

void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
const String &processed_splash_config_xml,
const Ref<Image> &splash_image,
const Ref<Image> &splash_bg_color_image,
const Ref<Image> &main_image,
const Ref<Image> &foreground,
const Ref<Image> &background) {
// Store the splash configuration
if (!processed_splash_config_xml.empty()) {
print_verbose("Storing processed splash configuration: " + String("\n") + processed_splash_config_xml);
store_string_at_path(SPLASH_CONFIG_PATH, processed_splash_config_xml);
}

// Store the splash image
if (splash_image.is_valid() && !splash_image->empty()) {
print_verbose("Storing splash image in " + String(SPLASH_IMAGE_EXPORT_PATH));
Expand Down Expand Up @@ -2751,7 +2776,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

Ref<Image> splash_image;
Ref<Image> splash_bg_color_image;
load_splash_refs(splash_image, splash_bg_color_image);
String processed_splash_config_xml = load_splash_refs(splash_image, splash_bg_color_image);

Ref<Image> main_image;
Ref<Image> foreground;
Expand Down Expand Up @@ -2812,7 +2837,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
EditorNode::add_io_error("Unable to overwrite res://android/build/res/*.xml files with project name");
}
// Copies the project icon files into the appropriate Gradle project directory.
_copy_icons_to_gradle_project(p_preset, splash_image, splash_bg_color_image, main_image, foreground, background);
_copy_icons_to_gradle_project(p_preset, processed_splash_config_xml, splash_image, splash_bg_color_image, main_image, foreground, background);
// Write an AndroidManifest.xml file into the Gradle project directory.
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
_update_custom_build_project();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<item>
<bitmap
android:gravity="center"
android:filter="false"
android:src="@drawable/splash" />
</item>

</layer-list>