From c9dc585dcbc2e99d2032a5ef1c1212c72044ea1d Mon Sep 17 00:00:00 2001 From: mahdihijazi Date: Sun, 21 Jan 2018 01:31:53 +0100 Subject: [PATCH] Android: Support change disc --- .../dolphinemu/dolphinemu/NativeLibrary.java | 2 ++ .../activities/EmulationActivity.java | 32 ++++++++++++++++++- .../dolphinemu/fragments/MenuFragment.java | 1 + .../dolphinemu/utils/FileBrowserHelper.java | 22 ++++++++++--- .../main/res/layout/fragment_ingame_menu.xml | 5 +++ .../app/src/main/res/menu/menu_emulation.xml | 6 ++++ .../app/src/main/res/values/strings.xml | 2 ++ Source/Android/jni/MainAndroid.cpp | 14 ++++++++ 8 files changed, 79 insertions(+), 5 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index d7e0e50f00..f013523f5a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -350,6 +350,8 @@ public final class NativeLibrary */ public static native void Run(String path, String savestatePath, boolean deleteSavestate); + public static native void ChangeDisc(String path); + // Surface Handling public static native void SurfaceChanged(Surface surf); public static native void SurfaceDestroyed(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 80972f0c7f..217ba73336 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -14,6 +14,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; +import android.text.TextUtils; import android.util.SparseIntArray; import android.view.InputDevice; import android.view.KeyEvent; @@ -35,10 +36,12 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.fragments.EmulationFragment; import org.dolphinemu.dolphinemu.fragments.MenuFragment; import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment; +import org.dolphinemu.dolphinemu.ui.main.MainActivity; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.utils.Animations; import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper; +import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.Java_GCAdapter; import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter; @@ -51,6 +54,8 @@ public final class EmulationActivity extends AppCompatActivity { private static final String BACKSTACK_NAME_MENU = "menu"; private static final String BACKSTACK_NAME_SUBMENU = "submenu"; + public static final int REQUEST_CHANGE_DISC = 1; + private View mDecorView; private ImageView mImageView; private EmulationFragment mEmulationFragment; @@ -84,7 +89,7 @@ public final class EmulationActivity extends AppCompatActivity MENU_ACTION_SAVE_SLOT3, MENU_ACTION_SAVE_SLOT4, MENU_ACTION_SAVE_SLOT5, MENU_ACTION_SAVE_SLOT6, MENU_ACTION_LOAD_SLOT1, MENU_ACTION_LOAD_SLOT2, MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5, - MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT}) + MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC}) public @interface MenuAction { } @@ -111,6 +116,7 @@ public final class EmulationActivity extends AppCompatActivity public static final int MENU_ACTION_LOAD_SLOT5 = 20; public static final int MENU_ACTION_LOAD_SLOT6 = 21; public static final int MENU_ACTION_EXIT = 22; + public static final int MENU_ACTION_CHANGE_DISC = 23; private static SparseIntArray buttonsActionsMap = new SparseIntArray(); @@ -136,6 +142,7 @@ public final class EmulationActivity extends AppCompatActivity buttonsActionsMap.append(R.id.menu_emulation_load_3, EmulationActivity.MENU_ACTION_LOAD_SLOT3); buttonsActionsMap.append(R.id.menu_emulation_load_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4); buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5); + buttonsActionsMap.append(R.id.menu_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC); buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT); } @@ -310,6 +317,25 @@ public final class EmulationActivity extends AppCompatActivity } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent result) + { + switch (requestCode) + { + case REQUEST_CHANGE_DISC: + // If the user picked a file, as opposed to just backing out. + if (resultCode == MainActivity.RESULT_OK) + { + String newDiscPath = FileBrowserHelper.getSelectedDirectory(result); + if (!TextUtils.isEmpty(newDiscPath)) + { + NativeLibrary.ChangeDisc(newDiscPath); + } + } + break; + } + } + private void enableFullscreenImmersive() { // It would be nice to use IMMERSIVE_STICKY, but that doesn't show the toolbar. @@ -518,6 +544,10 @@ public final class EmulationActivity extends AppCompatActivity NativeLibrary.LoadState(5); return; + case MENU_ACTION_CHANGE_DISC: + FileBrowserHelper.openFilePicker(this, REQUEST_CHANGE_DISC); + return; + case MENU_ACTION_EXIT: toggleMenu(); // Hide the menu (it will be showing since we just clicked it) mEmulationFragment.stopEmulation(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java index 34898e8f8b..52b36af1bd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java @@ -25,6 +25,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener buttonsActionsMap.append(R.id.menu_emulation_save_root, EmulationActivity.MENU_ACTION_SAVE_ROOT); buttonsActionsMap.append(R.id.menu_emulation_load_root, EmulationActivity.MENU_ACTION_LOAD_ROOT); buttonsActionsMap.append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES); + buttonsActionsMap.append(R.id.menu_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC); buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java index e2fe1cf818..327988271b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java @@ -1,6 +1,5 @@ package org.dolphinemu.dolphinemu.utils; -import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Environment; @@ -18,7 +17,8 @@ import java.util.List; public final class FileBrowserHelper { - public static void openDirectoryPicker(FragmentActivity activity) { + public static void openDirectoryPicker(FragmentActivity activity) + { Intent i = new Intent(activity, CustomFilePickerActivity.class); i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); @@ -29,11 +29,25 @@ public final class FileBrowserHelper activity.startActivityForResult(i, MainPresenter.REQUEST_ADD_DIRECTORY); } + public static void openFilePicker(FragmentActivity activity, int requestCode) + { + Intent i = new Intent(activity, CustomFilePickerActivity.class); + + i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); + i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); + i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE); + i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath()); + + activity.startActivityForResult(i, requestCode); + } + @Nullable - public static String getSelectedDirectory(Intent result) { + public static String getSelectedDirectory(Intent result) + { // Use the provided utility method to parse the result List files = Utils.getSelectedFilesFromResult(result); - if(!files.isEmpty()) { + if (!files.isEmpty()) + { File file = Utils.getFileForUri(files.get(0)); return file.getAbsolutePath(); } diff --git a/Source/Android/app/src/main/res/layout/fragment_ingame_menu.xml b/Source/Android/app/src/main/res/layout/fragment_ingame_menu.xml index 6aa1e9dc8b..8415a2045b 100644 --- a/Source/Android/app/src/main/res/layout/fragment_ingame_menu.xml +++ b/Source/Android/app/src/main/res/layout/fragment_ingame_menu.xml @@ -57,6 +57,11 @@ android:text="@string/emulation_refresh_wiimotes" style="@style/InGameMenuOption"/> +