From df83491313cb971e4ec408096a3f87386501808d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 8 Dec 2023 15:48:43 -0600 Subject: [PATCH 1/2] Add ability to change default Android screen orientation. --- .../Platform/Android/AndroidPlatformTools.cpp | 25 +++++++++++++ .../Android/AndroidPlatformSettings.h | 37 +++++++++++++++++++ .../Project/app/src/main/AndroidManifest.xml | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp index 995f19fce..d1f4dc6fb 100644 --- a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp @@ -169,6 +169,30 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data) permissions += String::Format(TEXT("\n "), e.Item); } + // Setup default Android screen orientation + auto defaultOrienation = platformSettings->DefaultOrientation; + String orientation = String("fullSensor"); + switch (defaultOrienation) + { + case AndroidScreenOrientation::Portrait: + orientation = String("portrait"); + break; + case AndroidScreenOrientation::PortraitReverse: + orientation = String("reversePortrait"); + break; + case AndroidScreenOrientation::LandscapeRight: + orientation = String("landscape"); + break; + case AndroidScreenOrientation::LandscapeLeft: + orientation = String("reverseLandscape"); + break; + case AndroidScreenOrientation::AutoRotation: + orientation = String("fullSensor"); + break; + default: + break; + } + // Setup Android application attributes String attributes; if (data.Configuration != BuildConfiguration::Release) @@ -223,6 +247,7 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data) EditorUtilities::ReplaceInFile(manifestPath, TEXT("${PackageName}"), packageName); EditorUtilities::ReplaceInFile(manifestPath, TEXT("${ProjectVersion}"), projectVersion); EditorUtilities::ReplaceInFile(manifestPath, TEXT("${AndroidPermissions}"), permissions); + EditorUtilities::ReplaceInFile(manifestPath, TEXT("${DefaultOrientation}"), orientation); EditorUtilities::ReplaceInFile(manifestPath, TEXT("${AndroidAttributes}"), attributes); const String stringsPath = data.OriginalOutputPath / TEXT("app/src/main/res/values/strings.xml"); EditorUtilities::ReplaceInFile(stringsPath, TEXT("${ProjectName}"), gameSettings->ProductName); diff --git a/Source/Engine/Platform/Android/AndroidPlatformSettings.h b/Source/Engine/Platform/Android/AndroidPlatformSettings.h index 9cfe7f880..f9f12d811 100644 --- a/Source/Engine/Platform/Android/AndroidPlatformSettings.h +++ b/Source/Engine/Platform/Android/AndroidPlatformSettings.h @@ -9,6 +9,37 @@ class Texture; +/// +/// Android screen orientation options. +/// +API_ENUM() enum class FLAXENGINE_API AndroidScreenOrientation +{ + /// + /// "portrait" mode + /// + Portrait, + + /// + /// "reversePortrait" mode + /// + PortraitReverse, + + /// + /// "landscape" mode + /// + LandscapeRight, + + /// + /// "reverseLandscape" mode + /// + LandscapeLeft, + + /// + /// "fullSensor" mode + /// + AutoRotation, +}; + /// /// Android platform settings. /// @@ -29,6 +60,12 @@ API_CLASS(sealed, Namespace="FlaxEditor.Content.Settings") class FLAXENGINE_API API_FIELD(Attributes="EditorOrder(100), EditorDisplay(\"General\")") Array Permissions; + /// + /// The default screen orientation. + /// + API_FIELD(Attributes = "EditorOrder(110), EditorDisplay(\"General\")") + AndroidScreenOrientation DefaultOrientation = AndroidScreenOrientation::AutoRotation; + /// /// Custom icon texture to use for the application (overrides the default one). /// diff --git a/Source/Platforms/Android/Binaries/Project/app/src/main/AndroidManifest.xml b/Source/Platforms/Android/Binaries/Project/app/src/main/AndroidManifest.xml index e535cef40..5169e3846 100644 --- a/Source/Platforms/Android/Binaries/Project/app/src/main/AndroidManifest.xml +++ b/Source/Platforms/Android/Binaries/Project/app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ + android:screenOrientation="${DefaultOrientation}"> From 4725f51431e6cdeb9205de92e7ca607006835a87 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 11 Dec 2023 10:00:19 -0600 Subject: [PATCH 2/2] Move android screen orientation into platform settings --- .../Platform/Android/AndroidPlatformTools.cpp | 10 +-- .../Android/AndroidPlatformSettings.h | 64 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp index d1f4dc6fb..88f993f20 100644 --- a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp @@ -174,19 +174,19 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data) String orientation = String("fullSensor"); switch (defaultOrienation) { - case AndroidScreenOrientation::Portrait: + case AndroidPlatformSettings::ScreenOrientation::Portrait: orientation = String("portrait"); break; - case AndroidScreenOrientation::PortraitReverse: + case AndroidPlatformSettings::ScreenOrientation::PortraitReverse: orientation = String("reversePortrait"); break; - case AndroidScreenOrientation::LandscapeRight: + case AndroidPlatformSettings::ScreenOrientation::LandscapeRight: orientation = String("landscape"); break; - case AndroidScreenOrientation::LandscapeLeft: + case AndroidPlatformSettings::ScreenOrientation::LandscapeLeft: orientation = String("reverseLandscape"); break; - case AndroidScreenOrientation::AutoRotation: + case AndroidPlatformSettings::ScreenOrientation::AutoRotation: orientation = String("fullSensor"); break; default: diff --git a/Source/Engine/Platform/Android/AndroidPlatformSettings.h b/Source/Engine/Platform/Android/AndroidPlatformSettings.h index f9f12d811..974a4c488 100644 --- a/Source/Engine/Platform/Android/AndroidPlatformSettings.h +++ b/Source/Engine/Platform/Android/AndroidPlatformSettings.h @@ -9,37 +9,6 @@ class Texture; -/// -/// Android screen orientation options. -/// -API_ENUM() enum class FLAXENGINE_API AndroidScreenOrientation -{ - /// - /// "portrait" mode - /// - Portrait, - - /// - /// "reversePortrait" mode - /// - PortraitReverse, - - /// - /// "landscape" mode - /// - LandscapeRight, - - /// - /// "reverseLandscape" mode - /// - LandscapeLeft, - - /// - /// "fullSensor" mode - /// - AutoRotation, -}; - /// /// Android platform settings. /// @@ -48,6 +17,37 @@ API_CLASS(sealed, Namespace="FlaxEditor.Content.Settings") class FLAXENGINE_API DECLARE_SCRIPTING_TYPE_MINIMAL(AndroidPlatformSettings); API_AUTO_SERIALIZATION(); + /// + /// Android screen orientation options. + /// + API_ENUM() enum class FLAXENGINE_API ScreenOrientation + { + /// + /// "portrait" mode + /// + Portrait, + + /// + /// "reversePortrait" mode + /// + PortraitReverse, + + /// + /// "landscape" mode + /// + LandscapeRight, + + /// + /// "reverseLandscape" mode + /// + LandscapeLeft, + + /// + /// "fullSensor" mode + /// + AutoRotation, + }; + /// /// The application package name (eg. com.company.product). Custom tokens: ${PROJECT_NAME}, ${COMPANY_NAME}. /// @@ -64,7 +64,7 @@ API_CLASS(sealed, Namespace="FlaxEditor.Content.Settings") class FLAXENGINE_API /// The default screen orientation. /// API_FIELD(Attributes = "EditorOrder(110), EditorDisplay(\"General\")") - AndroidScreenOrientation DefaultOrientation = AndroidScreenOrientation::AutoRotation; + ScreenOrientation DefaultOrientation = ScreenOrientation::AutoRotation; /// /// Custom icon texture to use for the application (overrides the default one).