Skip to content

Commit de8a05f

Browse files
committed
Merge pull request #92965 from m4gr3d/fix_splash_screen
Update the Android splash screen logic
2 parents e988c1a + f20e21a commit de8a05f

File tree

20 files changed

+123
-187
lines changed

20 files changed

+123
-187
lines changed

main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ Error Main::setup2() {
28962896

28972897
MAIN_PRINT("Main: Setup Logo");
28982898

2899-
#if !defined(TOOLS_ENABLED) && (defined(WEB_ENABLED) || defined(ANDROID_ENABLED))
2899+
#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
29002900
bool show_logo = false;
29012901
#else
29022902
bool show_logo = true;

platform/android/export/export_plugin.cpp

Lines changed: 12 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ static const char *android_perms[] = {
212212

213213
static const char *MISMATCHED_VERSIONS_MESSAGE = "Android build version mismatch:\n| Template installed: %s\n| Requested version: %s\nPlease reinstall Android build template from 'Project' menu.";
214214

215-
static const char *SPLASH_IMAGE_EXPORT_PATH = "res/drawable-nodpi/splash.png";
216-
static const char *LEGACY_BUILD_SPLASH_IMAGE_EXPORT_PATH = "res/drawable-nodpi-v4/splash.png";
217-
static const char *SPLASH_BG_COLOR_PATH = "res/drawable-nodpi/splash_bg_color.png";
218-
static const char *LEGACY_BUILD_SPLASH_BG_COLOR_PATH = "res/drawable-nodpi-v4/splash_bg_color.png";
219-
static const char *SPLASH_CONFIG_PATH = "res/drawable/splash_drawable.xml";
220215
static const char *GDEXTENSION_LIBS_PATH = "libs/gdextensionlibs.json";
221216

222217
static const int icon_densities_count = 6;
@@ -1642,67 +1637,6 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n
16421637
}
16431638
}
16441639

1645-
String EditorExportPlatformAndroid::load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image) {
1646-
bool scale_splash = GLOBAL_GET("application/boot_splash/fullsize");
1647-
bool apply_filter = GLOBAL_GET("application/boot_splash/use_filter");
1648-
bool show_splash_image = GLOBAL_GET("application/boot_splash/show_image");
1649-
String project_splash_path = GLOBAL_GET("application/boot_splash/image");
1650-
1651-
// Setup the splash bg color.
1652-
bool bg_color_valid = false;
1653-
Color bg_color = ProjectSettings::get_singleton()->get("application/boot_splash/bg_color", &bg_color_valid);
1654-
if (!bg_color_valid) {
1655-
bg_color = boot_splash_bg_color;
1656-
}
1657-
1658-
if (show_splash_image) {
1659-
if (!project_splash_path.is_empty()) {
1660-
splash_image.instantiate();
1661-
print_verbose("Loading splash image: " + project_splash_path);
1662-
const Error err = ImageLoader::load_image(project_splash_path, splash_image);
1663-
if (err) {
1664-
if (OS::get_singleton()->is_stdout_verbose()) {
1665-
print_error("- unable to load splash image from " + project_splash_path + " (" + itos(err) + ")");
1666-
}
1667-
splash_image.unref();
1668-
}
1669-
}
1670-
} else {
1671-
splash_image.instantiate();
1672-
splash_image->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
1673-
splash_image->set_pixel(0, 0, bg_color);
1674-
}
1675-
1676-
if (splash_image.is_null()) {
1677-
// Use the default
1678-
print_verbose("Using default splash image.");
1679-
splash_image = Ref<Image>(memnew(Image(boot_splash_png)));
1680-
}
1681-
1682-
if (scale_splash) {
1683-
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
1684-
int width, height;
1685-
if (screen_size.width > screen_size.height) {
1686-
// scale horizontally
1687-
height = screen_size.height;
1688-
width = splash_image->get_width() * screen_size.height / splash_image->get_height();
1689-
} else {
1690-
// scale vertically
1691-
width = screen_size.width;
1692-
height = splash_image->get_height() * screen_size.width / splash_image->get_width();
1693-
}
1694-
splash_image->resize(width, height);
1695-
}
1696-
1697-
print_verbose("Creating splash background color image.");
1698-
splash_bg_color_image.instantiate();
1699-
splash_bg_color_image->initialize_data(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format());
1700-
splash_bg_color_image->fill(bg_color);
1701-
1702-
String processed_splash_config_xml = vformat(SPLASH_CONFIG_XML_CONTENT, bool_to_string(apply_filter));
1703-
return processed_splash_config_xml;
1704-
}
1705-
17061640
void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) {
17071641
String project_icon_path = GLOBAL_GET("application/config/icon");
17081642

@@ -1739,61 +1673,34 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
17391673
}
17401674

17411675
void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
1742-
const String &processed_splash_config_xml,
1743-
const Ref<Image> &splash_image,
1744-
const Ref<Image> &splash_bg_color_image,
1745-
const Ref<Image> &main_image,
1746-
const Ref<Image> &foreground,
1747-
const Ref<Image> &background) {
1676+
const Ref<Image> &p_main_image,
1677+
const Ref<Image> &p_foreground,
1678+
const Ref<Image> &p_background) {
17481679
String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset);
17491680

1750-
// Store the splash configuration
1751-
if (!processed_splash_config_xml.is_empty()) {
1752-
print_verbose("Storing processed splash configuration: " + String("\n") + processed_splash_config_xml);
1753-
store_string_at_path(gradle_build_dir.path_join(SPLASH_CONFIG_PATH), processed_splash_config_xml);
1754-
}
1755-
1756-
// Store the splash image
1757-
if (splash_image.is_valid() && !splash_image->is_empty()) {
1758-
String splash_export_path = gradle_build_dir.path_join(SPLASH_IMAGE_EXPORT_PATH);
1759-
print_verbose("Storing splash image in " + splash_export_path);
1760-
Vector<uint8_t> data;
1761-
_load_image_data(splash_image, data);
1762-
store_file_at_path(splash_export_path, data);
1763-
}
1764-
1765-
// Store the splash bg color image
1766-
if (splash_bg_color_image.is_valid() && !splash_bg_color_image->is_empty()) {
1767-
String splash_bg_color_path = gradle_build_dir.path_join(SPLASH_BG_COLOR_PATH);
1768-
print_verbose("Storing splash background image in " + splash_bg_color_path);
1769-
Vector<uint8_t> data;
1770-
_load_image_data(splash_bg_color_image, data);
1771-
store_file_at_path(splash_bg_color_path, data);
1772-
}
1773-
17741681
// Prepare images to be resized for the icons. If some image ends up being uninitialized,
17751682
// the default image from the export template will be used.
17761683

17771684
for (int i = 0; i < icon_densities_count; ++i) {
1778-
if (main_image.is_valid() && !main_image->is_empty()) {
1685+
if (p_main_image.is_valid() && !p_main_image->is_empty()) {
17791686
print_verbose("Processing launcher icon for dimension " + itos(launcher_icons[i].dimensions) + " into " + launcher_icons[i].export_path);
17801687
Vector<uint8_t> data;
1781-
_process_launcher_icons(launcher_icons[i].export_path, main_image, launcher_icons[i].dimensions, data);
1688+
_process_launcher_icons(launcher_icons[i].export_path, p_main_image, launcher_icons[i].dimensions, data);
17821689
store_file_at_path(gradle_build_dir.path_join(launcher_icons[i].export_path), data);
17831690
}
17841691

1785-
if (foreground.is_valid() && !foreground->is_empty()) {
1786-
print_verbose("Processing launcher adaptive icon foreground for dimension " + itos(launcher_adaptive_icon_foregrounds[i].dimensions) + " into " + launcher_adaptive_icon_foregrounds[i].export_path);
1692+
if (p_foreground.is_valid() && !p_foreground->is_empty()) {
1693+
print_verbose("Processing launcher adaptive icon p_foreground for dimension " + itos(launcher_adaptive_icon_foregrounds[i].dimensions) + " into " + launcher_adaptive_icon_foregrounds[i].export_path);
17871694
Vector<uint8_t> data;
1788-
_process_launcher_icons(launcher_adaptive_icon_foregrounds[i].export_path, foreground,
1695+
_process_launcher_icons(launcher_adaptive_icon_foregrounds[i].export_path, p_foreground,
17891696
launcher_adaptive_icon_foregrounds[i].dimensions, data);
17901697
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_foregrounds[i].export_path), data);
17911698
}
17921699

1793-
if (background.is_valid() && !background->is_empty()) {
1794-
print_verbose("Processing launcher adaptive icon background for dimension " + itos(launcher_adaptive_icon_backgrounds[i].dimensions) + " into " + launcher_adaptive_icon_backgrounds[i].export_path);
1700+
if (p_background.is_valid() && !p_background->is_empty()) {
1701+
print_verbose("Processing launcher adaptive icon p_background for dimension " + itos(launcher_adaptive_icon_backgrounds[i].dimensions) + " into " + launcher_adaptive_icon_backgrounds[i].export_path);
17951702
Vector<uint8_t> data;
1796-
_process_launcher_icons(launcher_adaptive_icon_backgrounds[i].export_path, background,
1703+
_process_launcher_icons(launcher_adaptive_icon_backgrounds[i].export_path, p_background,
17971704
launcher_adaptive_icon_backgrounds[i].dimensions, data);
17981705
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_backgrounds[i].export_path), data);
17991706
}
@@ -3093,10 +3000,6 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
30933000
print_verbose("- include filter: " + p_preset->get_include_filter());
30943001
print_verbose("- exclude filter: " + p_preset->get_exclude_filter());
30953002

3096-
Ref<Image> splash_image;
3097-
Ref<Image> splash_bg_color_image;
3098-
String processed_splash_config_xml = load_splash_refs(splash_image, splash_bg_color_image);
3099-
31003003
Ref<Image> main_image;
31013004
Ref<Image> foreground;
31023005
Ref<Image> background;
@@ -3172,7 +3075,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
31723075
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Unable to overwrite res/*.xml files with project name."));
31733076
}
31743077
// Copies the project icon files into the appropriate Gradle project directory.
3175-
_copy_icons_to_gradle_project(p_preset, processed_splash_config_xml, splash_image, splash_bg_color_image, main_image, foreground, background);
3078+
_copy_icons_to_gradle_project(p_preset, main_image, foreground, background);
31763079
// Write an AndroidManifest.xml file into the Gradle project directory.
31773080
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
31783081

@@ -3486,16 +3389,6 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
34863389
_fix_resources(p_preset, data);
34873390
}
34883391

3489-
// Process the splash image
3490-
if ((file == SPLASH_IMAGE_EXPORT_PATH || file == LEGACY_BUILD_SPLASH_IMAGE_EXPORT_PATH) && splash_image.is_valid() && !splash_image->is_empty()) {
3491-
_load_image_data(splash_image, data);
3492-
}
3493-
3494-
// Process the splash bg color image
3495-
if ((file == SPLASH_BG_COLOR_PATH || file == LEGACY_BUILD_SPLASH_BG_COLOR_PATH) && splash_bg_color_image.is_valid() && !splash_bg_color_image->is_empty()) {
3496-
_load_image_data(splash_bg_color_image, data);
3497-
}
3498-
34993392
if (file.ends_with(".png") && file.contains("mipmap")) {
35003393
for (int i = 0; i < icon_densities_count; ++i) {
35013394
if (main_image.is_valid() && !main_image->is_empty()) {

platform/android/export/export_plugin.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@
3939
#include "core/os/os.h"
4040
#include "editor/export/editor_export_platform.h"
4141

42-
const String SPLASH_CONFIG_XML_CONTENT = R"SPLASH(<?xml version="1.0" encoding="utf-8"?>
43-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
44-
<item android:drawable="@drawable/splash_bg_color" />
45-
<item>
46-
<bitmap
47-
android:gravity="center"
48-
android:filter="%s"
49-
android:src="@drawable/splash" />
50-
</item>
51-
</layer-list>
52-
)SPLASH";
53-
5442
// Optional environment variables for defining confidential information. If any
5543
// of these is set, they will override the values set in the credentials file.
5644
const String ENV_ANDROID_KEYSTORE_DEBUG_PATH = "GODOT_ANDROID_KEYSTORE_DEBUG_PATH";
@@ -179,17 +167,12 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
179167

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

182-
String load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image);
183-
184170
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background);
185171

186172
void _copy_icons_to_gradle_project(const Ref<EditorExportPreset> &p_preset,
187-
const String &processed_splash_config_xml,
188-
const Ref<Image> &splash_image,
189-
const Ref<Image> &splash_bg_color_image,
190-
const Ref<Image> &main_image,
191-
const Ref<Image> &foreground,
192-
const Ref<Image> &background);
173+
const Ref<Image> &p_main_image,
174+
const Ref<Image> &p_foreground,
175+
const Ref<Image> &p_background);
193176

194177
static void _create_editor_debug_keystore_if_needed();
195178

platform/android/java/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ configurations {
3232

3333
dependencies {
3434
implementation "androidx.fragment:fragment:$versions.fragmentVersion"
35+
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
3536

3637
if (rootProject.findProject(":lib")) {
3738
implementation project(":lib")

platform/android/java/app/config.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ ext.versions = [
1111
nexusPublishVersion: '1.3.0',
1212
javaVersion : JavaVersion.VERSION_17,
1313
// Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
14-
ndkVersion : '23.2.8568313'
14+
ndkVersion : '23.2.8568313',
15+
splashscreenVersion: '1.0.1'
1516

1617
]
1718

-14.4 KB
Binary file not shown.
-1.33 KB
Binary file not shown.

platform/android/java/app/res/drawable/splash_drawable.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

platform/android/java/app/res/values/themes.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33

44
<style name="GodotAppMainTheme" parent="@android:style/Theme.Black.NoTitleBar"/>
55

6-
<style name="GodotAppSplashTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
7-
<item name="android:windowBackground">@drawable/splash_drawable</item>
8-
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
6+
<style name="GodotAppSplashTheme" parent="Theme.SplashScreen">
7+
<!-- Set the splash screen background, animated icon, and animation
8+
duration. -->
9+
<item name="android:windowSplashScreenBackground">@mipmap/icon_background</item>
10+
11+
<!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
12+
drawable. One of these is required. -->
13+
<item name="windowSplashScreenAnimatedIcon">@mipmap/icon_foreground</item>
14+
15+
<!-- Set the theme of the Activity that directly follows your splash
16+
screen. This is required. -->
17+
<item name="postSplashScreenTheme">@style/GodotAppMainTheme</item>
918
</style>
1019
</resources>

platform/android/java/app/src/com/godot/game/GodotApp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434

3535
import android.os.Bundle;
3636

37+
import androidx.core.splashscreen.SplashScreen;
38+
3739
/**
3840
* Template activity for Godot Android builds.
3941
* Feel free to extend and modify this class for your custom logic.
4042
*/
4143
public class GodotApp extends GodotActivity {
4244
@Override
4345
public void onCreate(Bundle savedInstanceState) {
44-
setTheme(R.style.GodotAppMainTheme);
46+
SplashScreen.installSplashScreen(this);
4547
super.onCreate(savedInstanceState);
4648
}
4749
}

0 commit comments

Comments
 (0)