mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
Update the splash screen logic for the Godot app template
Due to limitations to the splash screen introduced in Android 12, the splash screen logic is updated to the same logic as used on other platforms, i.e: the splash screen is rendered by the Godot engine instead of the Android runtime.
This commit is contained in:
parent
dd966f5680
commit
f20e21a6d6
@ -2896,7 +2896,7 @@ Error Main::setup2() {
|
||||
|
||||
MAIN_PRINT("Main: Setup Logo");
|
||||
|
||||
#if !defined(TOOLS_ENABLED) && (defined(WEB_ENABLED) || defined(ANDROID_ENABLED))
|
||||
#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
|
||||
bool show_logo = false;
|
||||
#else
|
||||
bool show_logo = true;
|
||||
|
@ -212,11 +212,6 @@ static const char *android_perms[] = {
|
||||
|
||||
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.";
|
||||
|
||||
static const char *SPLASH_IMAGE_EXPORT_PATH = "res/drawable-nodpi/splash.png";
|
||||
static const char *LEGACY_BUILD_SPLASH_IMAGE_EXPORT_PATH = "res/drawable-nodpi-v4/splash.png";
|
||||
static const char *SPLASH_BG_COLOR_PATH = "res/drawable-nodpi/splash_bg_color.png";
|
||||
static const char *LEGACY_BUILD_SPLASH_BG_COLOR_PATH = "res/drawable-nodpi-v4/splash_bg_color.png";
|
||||
static const char *SPLASH_CONFIG_PATH = "res/drawable/splash_drawable.xml";
|
||||
static const char *GDEXTENSION_LIBS_PATH = "libs/gdextensionlibs.json";
|
||||
|
||||
static const int icon_densities_count = 6;
|
||||
@ -1642,67 +1637,6 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n
|
||||
}
|
||||
}
|
||||
|
||||
String EditorExportPlatformAndroid::load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image) {
|
||||
bool scale_splash = GLOBAL_GET("application/boot_splash/fullsize");
|
||||
bool apply_filter = GLOBAL_GET("application/boot_splash/use_filter");
|
||||
bool show_splash_image = GLOBAL_GET("application/boot_splash/show_image");
|
||||
String project_splash_path = GLOBAL_GET("application/boot_splash/image");
|
||||
|
||||
// Setup the splash bg color.
|
||||
bool bg_color_valid = false;
|
||||
Color bg_color = ProjectSettings::get_singleton()->get("application/boot_splash/bg_color", &bg_color_valid);
|
||||
if (!bg_color_valid) {
|
||||
bg_color = boot_splash_bg_color;
|
||||
}
|
||||
|
||||
if (show_splash_image) {
|
||||
if (!project_splash_path.is_empty()) {
|
||||
splash_image.instantiate();
|
||||
print_verbose("Loading splash image: " + project_splash_path);
|
||||
const Error err = ImageLoader::load_image(project_splash_path, splash_image);
|
||||
if (err) {
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_error("- unable to load splash image from " + project_splash_path + " (" + itos(err) + ")");
|
||||
}
|
||||
splash_image.unref();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
splash_image.instantiate();
|
||||
splash_image->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
|
||||
splash_image->set_pixel(0, 0, bg_color);
|
||||
}
|
||||
|
||||
if (splash_image.is_null()) {
|
||||
// Use the default
|
||||
print_verbose("Using default splash image.");
|
||||
splash_image = Ref<Image>(memnew(Image(boot_splash_png)));
|
||||
}
|
||||
|
||||
if (scale_splash) {
|
||||
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
|
||||
int width, height;
|
||||
if (screen_size.width > screen_size.height) {
|
||||
// scale horizontally
|
||||
height = screen_size.height;
|
||||
width = splash_image->get_width() * screen_size.height / splash_image->get_height();
|
||||
} else {
|
||||
// scale vertically
|
||||
width = screen_size.width;
|
||||
height = splash_image->get_height() * screen_size.width / splash_image->get_width();
|
||||
}
|
||||
splash_image->resize(width, height);
|
||||
}
|
||||
|
||||
print_verbose("Creating splash background color image.");
|
||||
splash_bg_color_image.instantiate();
|
||||
splash_bg_color_image->initialize_data(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format());
|
||||
splash_bg_color_image->fill(bg_color);
|
||||
|
||||
String processed_splash_config_xml = vformat(SPLASH_CONFIG_XML_CONTENT, bool_to_string(apply_filter));
|
||||
return processed_splash_config_xml;
|
||||
}
|
||||
|
||||
void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) {
|
||||
String project_icon_path = GLOBAL_GET("application/config/icon");
|
||||
|
||||
@ -1739,61 +1673,34 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref<EditorExportPreset> &
|
||||
}
|
||||
|
||||
void EditorExportPlatformAndroid::_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) {
|
||||
const Ref<Image> &p_main_image,
|
||||
const Ref<Image> &p_foreground,
|
||||
const Ref<Image> &p_background) {
|
||||
String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset);
|
||||
|
||||
// Store the splash configuration
|
||||
if (!processed_splash_config_xml.is_empty()) {
|
||||
print_verbose("Storing processed splash configuration: " + String("\n") + processed_splash_config_xml);
|
||||
store_string_at_path(gradle_build_dir.path_join(SPLASH_CONFIG_PATH), processed_splash_config_xml);
|
||||
}
|
||||
|
||||
// Store the splash image
|
||||
if (splash_image.is_valid() && !splash_image->is_empty()) {
|
||||
String splash_export_path = gradle_build_dir.path_join(SPLASH_IMAGE_EXPORT_PATH);
|
||||
print_verbose("Storing splash image in " + splash_export_path);
|
||||
Vector<uint8_t> data;
|
||||
_load_image_data(splash_image, data);
|
||||
store_file_at_path(splash_export_path, data);
|
||||
}
|
||||
|
||||
// Store the splash bg color image
|
||||
if (splash_bg_color_image.is_valid() && !splash_bg_color_image->is_empty()) {
|
||||
String splash_bg_color_path = gradle_build_dir.path_join(SPLASH_BG_COLOR_PATH);
|
||||
print_verbose("Storing splash background image in " + splash_bg_color_path);
|
||||
Vector<uint8_t> data;
|
||||
_load_image_data(splash_bg_color_image, data);
|
||||
store_file_at_path(splash_bg_color_path, data);
|
||||
}
|
||||
|
||||
// Prepare images to be resized for the icons. If some image ends up being uninitialized,
|
||||
// the default image from the export template will be used.
|
||||
|
||||
for (int i = 0; i < icon_densities_count; ++i) {
|
||||
if (main_image.is_valid() && !main_image->is_empty()) {
|
||||
if (p_main_image.is_valid() && !p_main_image->is_empty()) {
|
||||
print_verbose("Processing launcher icon for dimension " + itos(launcher_icons[i].dimensions) + " into " + launcher_icons[i].export_path);
|
||||
Vector<uint8_t> data;
|
||||
_process_launcher_icons(launcher_icons[i].export_path, main_image, launcher_icons[i].dimensions, data);
|
||||
_process_launcher_icons(launcher_icons[i].export_path, p_main_image, launcher_icons[i].dimensions, data);
|
||||
store_file_at_path(gradle_build_dir.path_join(launcher_icons[i].export_path), data);
|
||||
}
|
||||
|
||||
if (foreground.is_valid() && !foreground->is_empty()) {
|
||||
print_verbose("Processing launcher adaptive icon foreground for dimension " + itos(launcher_adaptive_icon_foregrounds[i].dimensions) + " into " + launcher_adaptive_icon_foregrounds[i].export_path);
|
||||
if (p_foreground.is_valid() && !p_foreground->is_empty()) {
|
||||
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);
|
||||
Vector<uint8_t> data;
|
||||
_process_launcher_icons(launcher_adaptive_icon_foregrounds[i].export_path, foreground,
|
||||
_process_launcher_icons(launcher_adaptive_icon_foregrounds[i].export_path, p_foreground,
|
||||
launcher_adaptive_icon_foregrounds[i].dimensions, data);
|
||||
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_foregrounds[i].export_path), data);
|
||||
}
|
||||
|
||||
if (background.is_valid() && !background->is_empty()) {
|
||||
print_verbose("Processing launcher adaptive icon background for dimension " + itos(launcher_adaptive_icon_backgrounds[i].dimensions) + " into " + launcher_adaptive_icon_backgrounds[i].export_path);
|
||||
if (p_background.is_valid() && !p_background->is_empty()) {
|
||||
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);
|
||||
Vector<uint8_t> data;
|
||||
_process_launcher_icons(launcher_adaptive_icon_backgrounds[i].export_path, background,
|
||||
_process_launcher_icons(launcher_adaptive_icon_backgrounds[i].export_path, p_background,
|
||||
launcher_adaptive_icon_backgrounds[i].dimensions, data);
|
||||
store_file_at_path(gradle_build_dir.path_join(launcher_adaptive_icon_backgrounds[i].export_path), data);
|
||||
}
|
||||
@ -3093,10 +3000,6 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
print_verbose("- include filter: " + p_preset->get_include_filter());
|
||||
print_verbose("- exclude filter: " + p_preset->get_exclude_filter());
|
||||
|
||||
Ref<Image> splash_image;
|
||||
Ref<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;
|
||||
Ref<Image> background;
|
||||
@ -3172,7 +3075,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Unable to overwrite res/*.xml files with project name."));
|
||||
}
|
||||
// Copies the project icon files into the appropriate Gradle project directory.
|
||||
_copy_icons_to_gradle_project(p_preset, processed_splash_config_xml, splash_image, splash_bg_color_image, main_image, foreground, background);
|
||||
_copy_icons_to_gradle_project(p_preset, main_image, foreground, background);
|
||||
// Write an AndroidManifest.xml file into the Gradle project directory.
|
||||
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
|
||||
|
||||
@ -3486,16 +3389,6 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
|
||||
_fix_resources(p_preset, data);
|
||||
}
|
||||
|
||||
// Process the splash image
|
||||
if ((file == SPLASH_IMAGE_EXPORT_PATH || file == LEGACY_BUILD_SPLASH_IMAGE_EXPORT_PATH) && splash_image.is_valid() && !splash_image->is_empty()) {
|
||||
_load_image_data(splash_image, data);
|
||||
}
|
||||
|
||||
// Process the splash bg color image
|
||||
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()) {
|
||||
_load_image_data(splash_bg_color_image, data);
|
||||
}
|
||||
|
||||
if (file.ends_with(".png") && file.contains("mipmap")) {
|
||||
for (int i = 0; i < icon_densities_count; ++i) {
|
||||
if (main_image.is_valid() && !main_image->is_empty()) {
|
||||
|
@ -39,18 +39,6 @@
|
||||
#include "core/os/os.h"
|
||||
#include "editor/export/editor_export_platform.h"
|
||||
|
||||
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="center"
|
||||
android:filter="%s"
|
||||
android:src="@drawable/splash" />
|
||||
</item>
|
||||
</layer-list>
|
||||
)SPLASH";
|
||||
|
||||
// Optional environment variables for defining confidential information. If any
|
||||
// of these is set, they will override the values set in the credentials file.
|
||||
const String ENV_ANDROID_KEYSTORE_DEBUG_PATH = "GODOT_ANDROID_KEYSTORE_DEBUG_PATH";
|
||||
@ -179,17 +167,12 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||
|
||||
void _process_launcher_icons(const String &p_file_name, const Ref<Image> &p_source_image, int dimension, Vector<uint8_t> &p_data);
|
||||
|
||||
String load_splash_refs(Ref<Image> &splash_image, Ref<Image> &splash_bg_color_image);
|
||||
|
||||
void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background);
|
||||
|
||||
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);
|
||||
const Ref<Image> &p_main_image,
|
||||
const Ref<Image> &p_foreground,
|
||||
const Ref<Image> &p_background);
|
||||
|
||||
static void _create_editor_debug_keystore_if_needed();
|
||||
|
||||
|
@ -32,6 +32,7 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
implementation "androidx.fragment:fragment:$versions.fragmentVersion"
|
||||
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
|
||||
|
||||
if (rootProject.findProject(":lib")) {
|
||||
implementation project(":lib")
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
@ -1,12 +0,0 @@
|
||||
<?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="center"
|
||||
android:filter="false"
|
||||
android:src="@drawable/splash" />
|
||||
</item>
|
||||
</layer-list>
|
@ -3,8 +3,17 @@
|
||||
|
||||
<style name="GodotAppMainTheme" parent="@android:style/Theme.Black.NoTitleBar"/>
|
||||
|
||||
<style name="GodotAppSplashTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
|
||||
<item name="android:windowBackground">@drawable/splash_drawable</item>
|
||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||
<style name="GodotAppSplashTheme" parent="Theme.SplashScreen">
|
||||
<!-- Set the splash screen background, animated icon, and animation
|
||||
duration. -->
|
||||
<item name="android:windowSplashScreenBackground">@mipmap/icon_background</item>
|
||||
|
||||
<!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
|
||||
drawable. One of these is required. -->
|
||||
<item name="windowSplashScreenAnimatedIcon">@mipmap/icon_foreground</item>
|
||||
|
||||
<!-- Set the theme of the Activity that directly follows your splash
|
||||
screen. This is required. -->
|
||||
<item name="postSplashScreenTheme">@style/GodotAppMainTheme</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@ -34,6 +34,8 @@ import org.godotengine.godot.GodotActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.core.splashscreen.SplashScreen;
|
||||
|
||||
/**
|
||||
* Template activity for Godot Android builds.
|
||||
* Feel free to extend and modify this class for your custom logic.
|
||||
@ -41,7 +43,7 @@ import android.os.Bundle;
|
||||
public class GodotApp extends GodotActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(R.style.GodotAppMainTheme);
|
||||
SplashScreen.installSplashScreen(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user