Browse Source

Add "Open .love File" menu option.

Miku AuahDark 3 năm trước cách đây
mục cha
commit
760f8c3860

+ 18 - 3
app/src/normal/java/org/love2d/android/MainActivity.java

@@ -1,5 +1,7 @@
 package org.love2d.android;
 
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
 import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.constraintlayout.widget.ConstraintLayout;
@@ -8,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 
 import android.content.Intent;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
@@ -26,7 +29,16 @@ import java.util.zip.ZipFile;
 public class MainActivity extends AppCompatActivity {
     private static final String TAG = "MainActivity";
 
-    private Executor executor = Executors.newSingleThreadExecutor();
+    private final Executor executor = Executors.newSingleThreadExecutor();
+
+    private final ActivityResultLauncher<String[]> openFileLauncher = registerForActivityResult(
+        new ActivityResultContracts.OpenDocument(),
+        (Uri result) -> {
+            Intent intent = new Intent(this, GameActivity.class);
+            intent.setData(result);
+            startActivity(intent);
+        }
+    );
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -64,13 +76,16 @@ public class MainActivity extends AppCompatActivity {
 
         // Handle item selection
         if (itemId == R.id.optionItem) {
+            openFileLauncher.launch(new String[] {"*/*"});
+            return true;
+        } else if (itemId == R.id.optionItem2) {
             Intent intent = new Intent(this, GameActivity.class);
             startActivity(intent);
             return true;
-        } else if (itemId == R.id.optionItem2) {
+        } else if (itemId == R.id.optionItem3) {
             getGameFolderDialog().show();
             return true;
-        } else if (itemId == R.id.optionItem3) {
+        } else if (itemId == R.id.optionItem4) {
             Intent intent = new Intent(this, AboutActivity.class);
             startActivity(intent);
             return true;

+ 5 - 2
app/src/normal/res/menu/options_menu.xml

@@ -3,11 +3,14 @@
 
     <item
         android:id="@+id/optionItem"
-        android:title="@string/launch_nogame" />
+        android:title="@string/open_love_file" />
     <item
         android:id="@+id/optionItem2"
-        android:title="@string/game_folder" />
+        android:title="@string/launch_nogame" />
     <item
         android:id="@+id/optionItem3"
+        android:title="@string/game_folder" />
+    <item
+        android:id="@+id/optionItem4"
         android:title="@string/about" />
 </menu>

+ 1 - 0
app/src/normal/res/values/strings.xml

@@ -5,6 +5,7 @@
     <string name="official_website">Official Website</string>
     <string name="no_games">No Games :(</string>
     <string name="no_games_info">Looks like there are no LÖVE games found in the games folder. See the \"Game Folder\" in the options menu for more information.</string>
+    <string name="open_love_file">Open .love File</string>
     <string name="launch_nogame">Launch No-Game</string>
     <string name="game_folder">Game Folder</string>
     <string name="about">About</string>