Merge pull request #280 from zevektor/master

Allow to load roms from external apps.
This commit is contained in:
Squarepusher 2013-08-19 15:09:05 -07:00
commit e9218eaf51
3 changed files with 129 additions and 89 deletions

11
.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RetroArch_</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -19,7 +19,7 @@
<activity android:name=".browser.HistorySelection"></activity>
<activity android:name=".browser.DisplayRefreshRateTest"></activity>
<activity android:name=".browser.RefreshRateSetOS"></activity>
<activity android:name=".browser.MainMenuActivity">
<activity android:name=".browser.MainMenuActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -42,7 +42,7 @@
<activity android:name=".browser.StateDirActivity"></activity>
<activity android:name=".browser.SystemDirActivity"></activity>
<activity android:name=".browser.RetroActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:exported="true" >
<activity android:name=".browser.RetroActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity>

View File

@ -36,6 +36,13 @@ public class MainMenuActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent startedByIntent = getIntent();
if (null != startedByIntent.getStringExtra("ROM")
&& null != startedByIntent.getStringExtra("LIBRETRO")) {
loadRomExternal(startedByIntent.getStringExtra("ROM"),
startedByIntent.getStringExtra("LIBRETRO"));
return;
}
instance = this;
addPreferencesFromResource(R.xml.prefs);
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
@ -80,8 +87,7 @@ public class MainMenuActivity extends PreferenceActivity {
libretro_name = prefs.getString("libretro_name", "No core");
setCoreTitle(libretro_name);
}
}
else {
} else {
libretro_path = MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir;
libretro_name = "No core";
setCoreTitle("No core");
@ -173,16 +179,19 @@ public class MainMenuActivity extends PreferenceActivity {
.getDefaultSharedPreferences(MainMenuActivity.getInstance()
.getBaseContext());
boolean global_config_enable = prefs.getBoolean("global_config_enable", true);
boolean config_same_as_native_lib_dir = libretro_path.equals(MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir);
boolean global_config_enable = prefs.getBoolean("global_config_enable",
true);
boolean config_same_as_native_lib_dir = libretro_path
.equals(MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir);
String append_path;
if (!global_config_enable && (config_same_as_native_lib_dir == false)) {
String sanitized_name = libretro_path.substring(libretro_path.lastIndexOf("/")+1,libretro_path.lastIndexOf("."));
String sanitized_name = libretro_path.substring(
libretro_path.lastIndexOf("/") + 1,
libretro_path.lastIndexOf("."));
sanitized_name = sanitized_name.replace("neon", "");
sanitized_name = sanitized_name.replace("libretro_", "");
append_path = File.separator + sanitized_name + "retroarch.cfg";
}
else {
} else {
append_path = File.separator + "retroarch.cfg";
}
@ -200,13 +209,10 @@ public class MainMenuActivity extends PreferenceActivity {
return confPath;
}
if (internal != null
&& new File(internal + append_path)
.canWrite())
if (internal != null && new File(internal + append_path).canWrite())
return internal + append_path;
else if (external != null
&& new File(internal + append_path)
.canWrite())
&& new File(internal + append_path).canWrite())
return external + append_path;
else if ((MainMenuActivity.getInstance().getApplicationInfo().dataDir) != null)
return (MainMenuActivity.getInstance().getApplicationInfo().dataDir)
@ -334,7 +340,8 @@ public class MainMenuActivity extends PreferenceActivity {
config.setBoolean("video_font_enable",
prefs.getBoolean("video_font_enable", true));
config.setString("game_history_path", MainMenuActivity.getInstance().getApplicationInfo().dataDir + "/retroarch-history.txt");
config.setString("game_history_path", MainMenuActivity.getInstance()
.getApplicationInfo().dataDir + "/retroarch-history.txt");
for (int i = 1; i <= 4; i++) {
final String btns[] = { "up", "down", "left", "right", "a", "b",
@ -492,12 +499,12 @@ public class MainMenuActivity extends PreferenceActivity {
libretro_path = core_path;
libretro_name = core_name;
File libretro_path_file = new File(core_path);
setCoreTitle((libretro_path_file.isDirectory() == true) ? "No core" : core_name);
setCoreTitle((libretro_path_file.isDirectory() == true) ? "No core"
: core_name);
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs
.edit();
SharedPreferences.Editor edit = prefs.edit();
edit.putString("libretro_path", libretro_path);
edit.putString("libretro_name", libretro_name);
edit.commit();
@ -510,10 +517,11 @@ public class MainMenuActivity extends PreferenceActivity {
boolean detectDevice(boolean show_dialog) {
boolean retval = false;
boolean mentionPlayStore = !android.os.Build.MODEL.equals("OUYA Console");
final String message = "The ideal configuration options for your device will now be preconfigured.\n\nNOTE: For optimal performance, turn off Google Account sync, " +
(mentionPlayStore ? "Google Play Store auto-updates, " : "") +
"GPS and Wi-Fi in your Android settings menu.";
boolean mentionPlayStore = !android.os.Build.MODEL
.equals("OUYA Console");
final String message = "The ideal configuration options for your device will now be preconfigured.\n\nNOTE: For optimal performance, turn off Google Account sync, "
+ (mentionPlayStore ? "Google Play Store auto-updates, " : "")
+ "GPS and Wi-Fi in your Android settings menu.";
Log.i("Device MODEL", android.os.Build.MODEL);
if (android.os.Build.MODEL.equals("SHIELD")) {
@ -624,7 +632,8 @@ public class MainMenuActivity extends PreferenceActivity {
@Override
public void startActivity(Intent intent) {
if (intent.getComponent().getClassName().equals("org.retroarch.browser.ROMActivity")) {
if (intent.getComponent().getClassName()
.equals("org.retroarch.browser.ROMActivity")) {
if (new File(libretro_path).isDirectory() == false) {
super.startActivityForResult(intent, ACTIVITY_LOAD_ROM);
} else {
@ -639,11 +648,13 @@ public class MainMenuActivity extends PreferenceActivity {
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
if (reqCode == ACTIVITY_LOAD_ROM) {
switch (reqCode) {
case ACTIVITY_LOAD_ROM: {
if (data.getStringExtra("PATH") != null) {
updateConfigFile();
Intent myIntent;
String current_ime = Settings.Secure.getString(getContentResolver(),
String current_ime = Settings.Secure.getString(
getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Toast.makeText(this,
"Loading: [" + data.getStringExtra("PATH") + "]...",
@ -657,5 +668,23 @@ public class MainMenuActivity extends PreferenceActivity {
startActivity(myIntent);
}
}
break;
}
}
private void loadRomExternal(String rom, String core) {
updateConfigFile();
Intent myIntent = new Intent(this, RetroActivity.class);
String current_ime = Settings.Secure.getString(getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Toast.makeText(this, "Loading: [" + rom + "]...", Toast.LENGTH_SHORT)
.show();
myIntent.putExtra("ROM", rom);
myIntent.putExtra("LIBRETRO", core);
myIntent.putExtra("CONFIGFILE", MainMenuActivity.getDefaultConfigPath());
myIntent.putExtra("IME", current_ime);
startActivity(myIntent);
}
}