diff options
author | Fredia Huya-Kouadio <fhuyakou@gmail.com> | 2022-06-09 13:22:18 -0700 |
---|---|---|
committer | Fredia Huya-Kouadio <fhuyakou@gmail.com> | 2022-06-09 13:26:24 -0700 |
commit | 6b9a81900ed44319abe2f47fdf0237a65a7fa047 (patch) | |
tree | 261ec0202b1697959bf70c00b3c61bdd151e4575 /platform/android | |
parent | d120b099f528673fb6aebaa5d9cff0fa91a774d0 (diff) |
Migrate the Godot Editor java source file to Kotlin.
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt (renamed from platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.java) | 143 | ||||
-rw-r--r-- | platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt (renamed from platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.java) | 10 | ||||
-rw-r--r-- | platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.kt (renamed from platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.java) | 9 |
3 files changed, 77 insertions, 85 deletions
diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.java b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt index c05ed965ca..a1ade722e8 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.java +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt @@ -1,5 +1,5 @@ /*************************************************************************/ -/* GodotEditor.java */ +/* GodotEditor.kt */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,23 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -package org.godotengine.editor; +package org.godotengine.editor -import org.godotengine.godot.FullScreenGodotApp; -import org.godotengine.godot.utils.PermissionsUtil; - -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.os.Debug; - -import androidx.annotation.Nullable; -import androidx.window.layout.WindowMetrics; -import androidx.window.layout.WindowMetricsCalculator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.os.Debug +import androidx.window.layout.WindowMetricsCalculator +import org.godotengine.godot.FullScreenGodotApp +import org.godotengine.godot.utils.PermissionsUtil +import java.util.* +import kotlin.math.min /** * Base class for the Godot Android Editor activities. @@ -55,97 +49,98 @@ import java.util.List; * * It also plays the role of the primary editor window. */ -public class GodotEditor extends FullScreenGodotApp { - private static final boolean WAIT_FOR_DEBUGGER = false; - private static final String COMMAND_LINE_PARAMS = "command_line_params"; +open class GodotEditor : FullScreenGodotApp() { - private static final String EDITOR_ARG = "--editor"; - private static final String PROJECT_MANAGER_ARG = "--project-manager"; + companion object { + private const val WAIT_FOR_DEBUGGER = false - private final List<String> commandLineParams = new ArrayList<>(); + private const val COMMAND_LINE_PARAMS = "command_line_params" - @Override - public void onCreate(Bundle savedInstanceState) { - PermissionsUtil.requestManifestPermissions(this); + private const val EDITOR_ARG = "--editor" + private const val PROJECT_MANAGER_ARG = "--project-manager" + } - String[] params = getIntent().getStringArrayExtra(COMMAND_LINE_PARAMS); - updateCommandLineParams(params); + private val commandLineParams = ArrayList<String>() - if (BuildConfig.BUILD_TYPE.equals("debug") && WAIT_FOR_DEBUGGER) { - Debug.waitForDebugger(); + override fun onCreate(savedInstanceState: Bundle?) { + PermissionsUtil.requestManifestPermissions(this) + + val params = intent.getStringArrayExtra(COMMAND_LINE_PARAMS) + updateCommandLineParams(params) + + if (BuildConfig.BUILD_TYPE == "debug" && WAIT_FOR_DEBUGGER) { + Debug.waitForDebugger() } - super.onCreate(savedInstanceState); + + super.onCreate(savedInstanceState) } - private void updateCommandLineParams(@Nullable String[] args) { + private fun updateCommandLineParams(args: Array<String>?) { // Update the list of command line params with the new args - commandLineParams.clear(); - if (args != null && args.length > 0) { - commandLineParams.addAll(Arrays.asList(args)); + commandLineParams.clear() + if (args != null && args.isNotEmpty()) { + commandLineParams.addAll(listOf(*args)) } } - @Override - public List<String> getCommandLine() { - return commandLineParams; - } + override fun getCommandLine() = commandLineParams - @Override - public void onNewGodotInstanceRequested(String[] args) { + override fun onNewGodotInstanceRequested(args: Array<String>) { // Parse the arguments to figure out which activity to start. - Class<?> targetClass = GodotGame.class; + var targetClass: Class<*> = GodotGame::class.java + // Whether we should launch the new godot instance in an adjacent window // https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT - boolean launchAdjacent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode() || isLargeScreen()); - - for (String arg : args) { - if (EDITOR_ARG.equals(arg)) { - targetClass = GodotEditor.class; - launchAdjacent = false; - break; + var launchAdjacent = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode || isLargeScreen) + + for (arg in args) { + if (EDITOR_ARG == arg) { + targetClass = GodotEditor::class.java + launchAdjacent = false + break } - if (PROJECT_MANAGER_ARG.equals(arg)) { - targetClass = GodotProjectManager.class; - launchAdjacent = false; - break; + if (PROJECT_MANAGER_ARG == arg) { + targetClass = GodotProjectManager::class.java + launchAdjacent = false + break } } // Launch a new activity - Intent newInstance = new Intent(this, targetClass) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(COMMAND_LINE_PARAMS, args); + val newInstance = Intent(this, targetClass) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .putExtra(COMMAND_LINE_PARAMS, args) if (launchAdjacent) { - newInstance.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); + newInstance.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT) } - startActivity(newInstance); + startActivity(newInstance) } - protected boolean isLargeScreen() { - WindowMetrics metrics = - WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(this); + // Get the screen's density scale + protected val isLargeScreen: Boolean + // Get the minimum window size // Correspond to the EXPANDED window size class. + get() { + val metrics = WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(this) - // Get the screen's density scale - float scale = getResources().getDisplayMetrics().density; + // Get the screen's density scale + val scale = resources.displayMetrics.density - // Get the minimum window size - float minSize = Math.min(metrics.getBounds().width(), metrics.getBounds().height()); - float minSizeDp = minSize / scale; - return minSizeDp >= 840f; // Correspond to the EXPANDED window size class. - } + // Get the minimum window size + val minSize = min(metrics.bounds.width(), metrics.bounds.height()).toFloat() + val minSizeDp = minSize / scale + return minSizeDp >= 840f // Correspond to the EXPANDED window size class. + } - @Override - public void setRequestedOrientation(int requestedOrientation) { + override fun setRequestedOrientation(requestedOrientation: Int) { if (!overrideOrientationRequest()) { - super.setRequestedOrientation(requestedOrientation); + super.setRequestedOrientation(requestedOrientation) } } /** * The Godot Android Editor sets its own orientation via its AndroidManifest */ - protected boolean overrideOrientationRequest() { - return true; - } + protected open fun overrideOrientationRequest() = true } diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.java b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt index 12766775a8..783095f93a 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.java +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt @@ -1,5 +1,5 @@ /*************************************************************************/ -/* GodotGame.java */ +/* GodotGame.kt */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -package org.godotengine.editor; +package org.godotengine.editor /** * Drives the 'run project' window of the Godot Editor. */ -public class GodotGame extends GodotEditor { - protected boolean overrideOrientationRequest() { - return false; - } +class GodotGame : GodotEditor() { + override fun overrideOrientationRequest() = false } diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.java b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.kt index d30f66bb8c..bcf4659603 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.java +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotProjectManager.kt @@ -1,5 +1,5 @@ /*************************************************************************/ -/* GodotProjectManager.java */ +/* GodotProjectManager.kt */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -package org.godotengine.editor; +package org.godotengine.editor /** * Launcher activity for the Godot Android Editor. * * It presents the user with the project manager interface. * Upon selection of a project, this activity (via its parent logic) starts the - * {@link GodotEditor} activity. + * [GodotEditor] activity. */ -public class GodotProjectManager extends GodotEditor { -} +class GodotProjectManager : GodotEditor() |