From e77d454b8b31b8c50a4eaa5cca2b85947d7915e5 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 1 Jan 2016 08:05:55 -0600 Subject: [PATCH] [Android] Add support for launching a game through activity monitor. This also allows setting the user directory. This is mainly for FifoCI in the future. --- .../dolphinemu/activities/MainActivity.java | 16 +----- .../dolphinemu/activities/TvMainActivity.java | 16 +----- .../dolphinemu/utils/StartupHandler.java | 54 +++++++++++++++++++ 3 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/MainActivity.java index 9ffa651cc2..6fcd8d4a43 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/MainActivity.java @@ -28,6 +28,7 @@ import org.dolphinemu.dolphinemu.model.Game; import org.dolphinemu.dolphinemu.model.GameDatabase; import org.dolphinemu.dolphinemu.model.GameProvider; import org.dolphinemu.dolphinemu.services.AssetCopyService; +import org.dolphinemu.dolphinemu.utils.StartupHandler; /** * The main Activity of the Lollipop style UI. Manages several PlatformGamesFragments, which @@ -90,20 +91,7 @@ public final class MainActivity extends AppCompatActivity implements LoaderManag // Stuff in this block only happens when this activity is newly created (i.e. not a rotation) if (savedInstanceState == null) - { - NativeLibrary.SetUserDirectory(""); // Auto-Detect - - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - boolean assetsCopied = preferences.getBoolean("assetsCopied", false); - - // Only perform these extensive copy operations once. - if (!assetsCopied) - { - // Copy assets into appropriate locations. - Intent copyAssets = new Intent(this, AssetCopyService.class); - startService(copyAssets); - } - } + StartupHandler.HandleInit(this); } /** diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java index 3f3b8c168d..a01e080549 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/TvMainActivity.java @@ -30,6 +30,7 @@ import org.dolphinemu.dolphinemu.model.GameDatabase; import org.dolphinemu.dolphinemu.model.GameProvider; import org.dolphinemu.dolphinemu.model.TvSettingsItem; import org.dolphinemu.dolphinemu.services.AssetCopyService; +import org.dolphinemu.dolphinemu.utils.StartupHandler; import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder; public final class TvMainActivity extends Activity @@ -118,20 +119,7 @@ public final class TvMainActivity extends Activity // Stuff in this block only happens when this activity is newly created (i.e. not a rotation) if (savedInstanceState == null) - { - NativeLibrary.SetUserDirectory(""); // Auto-Detect - - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - boolean assetsCopied = preferences.getBoolean("assetsCopied", false); - - // Only perform these extensive copy operations once. - if (!assetsCopied) - { - // Copy assets into appropriate locations. - Intent copyAssets = new Intent(this, AssetCopyService.class); - startService(copyAssets); - } - } + StartupHandler.HandleInit(this); } /** diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java new file mode 100644 index 0000000000..d59865cb75 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java @@ -0,0 +1,54 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.TextUtils; +import android.util.Log; + +import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.activities.EmulationActivity; +import org.dolphinemu.dolphinemu.services.AssetCopyService; + +public final class StartupHandler +{ + public static boolean HandleInit(Activity parent) + { + NativeLibrary.SetUserDirectory(""); // Auto-Detect + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(parent); + boolean assetsCopied = preferences.getBoolean("assetsCopied", false); + + // Only perform these extensive copy operations once. + if (!assetsCopied) + { + // Copy assets into appropriate locations. + Intent copyAssets = new Intent(parent, AssetCopyService.class); + parent.startService(copyAssets); + } + + Intent intent = parent.getIntent(); + Bundle extras = intent.getExtras(); + + if (extras != null) + { + String user_dir = extras.getString("UserDir"); + String start_file = extras.getString("AutoStartFile"); + + if (!TextUtils.isEmpty(user_dir)) + NativeLibrary.SetUserDirectory(user_dir); + + if (!TextUtils.isEmpty(start_file)) + { + // Start the emulation activity and send the ISO passed in. + Intent emulation_intent = new Intent(parent, EmulationActivity.class); + emulation_intent.putExtra("SelectedGame", start_file); + parent.startActivity(emulation_intent); + return false; + } + } + return false; + } +}