mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #6313 from mahdihijazi/support_change_disc
Android: Support change disc
This commit is contained in:
commit
9a166dca57
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -306,7 +306,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
||||
Log.debug("[EmulationFragment] Pausing emulation.");
|
||||
|
||||
// Release the surface before pausing, since emulation has to be running for that.
|
||||
mSurface = null;
|
||||
NativeLibrary.SurfaceDestroyed();
|
||||
NativeLibrary.PauseEmulation();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Uri> files = Utils.getSelectedFilesFromResult(result);
|
||||
if(!files.isEmpty()) {
|
||||
if (!files.isEmpty())
|
||||
{
|
||||
File file = Utils.getFileForUri(files.get(0));
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
@ -57,6 +57,11 @@
|
||||
android:text="@string/emulation_refresh_wiimotes"
|
||||
style="@style/InGameMenuOption"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/menu_change_disc"
|
||||
android:text="@string/emulation_change_disc"
|
||||
style="@style/InGameMenuOption"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/menu_exit"
|
||||
android:text="@string/emulation_exit"
|
||||
|
@ -1,5 +1,6 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
|
||||
|
||||
<item
|
||||
@ -95,4 +96,9 @@
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_change_disc"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/emulation_change_disc"/>
|
||||
|
||||
</menu>
|
@ -249,4 +249,6 @@
|
||||
<string name="write_permission_needed">You need to allow write access to external storage for the emulator to work</string>
|
||||
|
||||
<string name="load_settings">Loading Settings...</string>
|
||||
|
||||
<string name="emulation_change_disc">Change Disc</string>
|
||||
</resources>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "Core/BootManager.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/HW/DVD/DVDInterface.h"
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
||||
#include "Core/Host.h"
|
||||
@ -520,6 +521,10 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunnin
|
||||
return Core::IsRunning();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring jFile);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
||||
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action)
|
||||
{
|
||||
@ -869,6 +874,15 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_
|
||||
Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring jFile)
|
||||
{
|
||||
const std::string path = GetJString(env, jFile);
|
||||
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
|
||||
Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user