DEADSOFTWARE

AndroidLauncher in kotlin
authorfredboy <fredboy@protonmail.com>
Fri, 24 May 2024 09:53:05 +0000 (16:53 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 24 May 2024 09:53:05 +0000 (16:53 +0700)
android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java [deleted file]
android/src/ru/deadsoftware/cavedroid/AndroidLauncher.kt [new file with mode: 0644]

diff --git a/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java b/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.java
deleted file mode 100644 (file)
index 714c8df..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-package ru.deadsoftware.cavedroid;
-
-import android.content.pm.PackageManager;
-import android.os.Bundle;
-import com.badlogic.gdx.backends.android.AndroidApplication;
-import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
-
-public class AndroidLauncher extends AndroidApplication {
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
-        config.useImmersiveMode = true;
-        String gameFolder = "";
-        try {
-            gameFolder = getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.dataDir;
-        } catch (PackageManager.NameNotFoundException e) {
-            e.printStackTrace();
-            exit();
-        }
-        CaveGame caveGame = new CaveGame(gameFolder, true, BuildConfig.DEBUG,
-                new AndroidPreferencesStore(getApplicationContext()));
-        initialize(caveGame, config);
-    }
-
-    @Override
-    public void onBackPressed() {
-    }
-}
diff --git a/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.kt b/android/src/ru/deadsoftware/cavedroid/AndroidLauncher.kt
new file mode 100644 (file)
index 0000000..b6fff78
--- /dev/null
@@ -0,0 +1,34 @@
+package ru.deadsoftware.cavedroid
+
+import android.os.Bundle
+import com.badlogic.gdx.backends.android.AndroidApplication
+import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
+
+class AndroidLauncher : AndroidApplication() {
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        val gameDataDirectoryPath = packageManager.getPackageInfo(packageName, 0)
+            .applicationInfo.dataDir;
+
+        val config = AndroidApplicationConfiguration()
+        config.useImmersiveMode = true
+
+        initialize(
+            /* listener = */ CaveGame(
+                gameDataDirectoryPath = gameDataDirectoryPath,
+                isTouchScreen = true,
+                isDebug = BuildConfig.DEBUG,
+                preferencesStore = AndroidPreferencesStore(applicationContext)
+            ),
+            /* config = */ config
+        )
+    }
+
+    @Suppress("OVERRIDE_DEPRECATION")
+    override fun onBackPressed() {
+        // ignore
+    }
+
+}
\ No newline at end of file