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.HistorySelection"></activity>
<activity android:name=".browser.DisplayRefreshRateTest"></activity> <activity android:name=".browser.DisplayRefreshRateTest"></activity>
<activity android:name=".browser.RefreshRateSetOS"></activity> <activity android:name=".browser.RefreshRateSetOS"></activity>
<activity android:name=".browser.MainMenuActivity"> <activity android:name=".browser.MainMenuActivity" android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
@ -42,7 +42,7 @@
<activity android:name=".browser.StateDirActivity"></activity> <activity android:name=".browser.StateDirActivity"></activity>
<activity android:name=".browser.SystemDirActivity"></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.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" /> <meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity> </activity>

View File

@ -36,6 +36,13 @@ public class MainMenuActivity extends PreferenceActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(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; instance = this;
addPreferencesFromResource(R.xml.prefs); addPreferencesFromResource(R.xml.prefs);
PreferenceManager.setDefaultValues(this, R.xml.prefs, false); PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
@ -45,7 +52,7 @@ public class MainMenuActivity extends PreferenceActivity {
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
extractAssets(); extractAssets();
if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) { if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) {
prefs.edit().putBoolean("first_time_refreshrate_calculate", true) prefs.edit().putBoolean("first_time_refreshrate_calculate", true)
.commit(); .commit();
@ -71,17 +78,16 @@ public class MainMenuActivity extends PreferenceActivity {
alert.show(); alert.show();
} }
} }
if (prefs.getString("libretro_path", "").isEmpty() == false) { if (prefs.getString("libretro_path", "").isEmpty() == false) {
libretro_path = prefs.getString("libretro_path", ""); libretro_path = prefs.getString("libretro_path", "");
setCoreTitle("No core"); setCoreTitle("No core");
if (prefs.getString("libretro_name", "").isEmpty() == false) { if (prefs.getString("libretro_name", "").isEmpty() == false) {
libretro_name = prefs.getString("libretro_name", "No core"); libretro_name = prefs.getString("libretro_name", "No core");
setCoreTitle(libretro_name); setCoreTitle(libretro_name);
} }
} } else {
else {
libretro_path = MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir; libretro_path = MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir;
libretro_name = "No core"; libretro_name = "No core";
setCoreTitle("No core"); setCoreTitle("No core");
@ -168,21 +174,24 @@ public class MainMenuActivity extends PreferenceActivity {
public static String getDefaultConfigPath() { public static String getDefaultConfigPath() {
String internal = System.getenv("INTERNAL_STORAGE"); String internal = System.getenv("INTERNAL_STORAGE");
String external = System.getenv("EXTERNAL_STORAGE"); String external = System.getenv("EXTERNAL_STORAGE");
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(MainMenuActivity.getInstance() .getDefaultSharedPreferences(MainMenuActivity.getInstance()
.getBaseContext()); .getBaseContext());
boolean global_config_enable = prefs.getBoolean("global_config_enable", true); boolean global_config_enable = prefs.getBoolean("global_config_enable",
boolean config_same_as_native_lib_dir = libretro_path.equals(MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir); true);
boolean config_same_as_native_lib_dir = libretro_path
.equals(MainMenuActivity.getInstance().getApplicationInfo().nativeLibraryDir);
String append_path; String append_path;
if (!global_config_enable && (config_same_as_native_lib_dir == false)) { 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("neon", "");
sanitized_name = sanitized_name.replace("libretro_",""); sanitized_name = sanitized_name.replace("libretro_", "");
append_path = File.separator + sanitized_name + "retroarch.cfg"; append_path = File.separator + sanitized_name + "retroarch.cfg";
} } else {
else {
append_path = File.separator + "retroarch.cfg"; append_path = File.separator + "retroarch.cfg";
} }
@ -200,13 +209,10 @@ public class MainMenuActivity extends PreferenceActivity {
return confPath; return confPath;
} }
if (internal != null if (internal != null && new File(internal + append_path).canWrite())
&& new File(internal + append_path)
.canWrite())
return internal + append_path; return internal + append_path;
else if (external != null else if (external != null
&& new File(internal + append_path) && new File(internal + append_path).canWrite())
.canWrite())
return external + append_path; return external + append_path;
else if ((MainMenuActivity.getInstance().getApplicationInfo().dataDir) != null) else if ((MainMenuActivity.getInstance().getApplicationInfo().dataDir) != null)
return (MainMenuActivity.getInstance().getApplicationInfo().dataDir) return (MainMenuActivity.getInstance().getApplicationInfo().dataDir)
@ -227,11 +233,11 @@ public class MainMenuActivity extends PreferenceActivity {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(MainMenuActivity.getInstance() .getDefaultSharedPreferences(MainMenuActivity.getInstance()
.getBaseContext()); .getBaseContext());
config.setString("libretro_path", libretro_path); config.setString("libretro_path", libretro_path);
config.setString("libretro_name", libretro_name); config.setString("libretro_name", libretro_name);
setCoreTitle(libretro_name); setCoreTitle(libretro_name);
config.setString("rgui_browser_directory", config.setString("rgui_browser_directory",
prefs.getString("rgui_browser_directory", "")); prefs.getString("rgui_browser_directory", ""));
config.setBoolean("global_config_enable", config.setBoolean("global_config_enable",
@ -333,8 +339,9 @@ public class MainMenuActivity extends PreferenceActivity {
config.setBoolean("video_font_enable", config.setBoolean("video_font_enable",
prefs.getBoolean("video_font_enable", true)); 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++) { for (int i = 1; i <= 4; i++) {
final String btns[] = { "up", "down", "left", "right", "a", "b", final String btns[] = { "up", "down", "left", "right", "a", "b",
@ -390,20 +397,20 @@ public class MainMenuActivity extends PreferenceActivity {
writer.close(); writer.close();
} }
} }
private int getVersionCode() { private int getVersionCode() {
int version = 0; int version = 0;
try { try {
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
} }
return version; return version;
} }
private boolean areAssetsExtracted() { private boolean areAssetsExtracted() {
int version = getVersionCode(); int version = getVersionCode();
try { try {
String dataDir = getApplicationInfo().dataDir; String dataDir = getApplicationInfo().dataDir;
File cacheVersion = new File(dataDir, ".cacheversion"); File cacheVersion = new File(dataDir, ".cacheversion");
@ -428,10 +435,10 @@ public class MainMenuActivity extends PreferenceActivity {
Log.e(TAG, "Failed to extract assets to cache."); Log.e(TAG, "Failed to extract assets to cache.");
return false; return false;
} }
return false; return false;
} }
private void extractAssetsThread() { private void extractAssetsThread() {
try { try {
AssetManager assets = getAssets(); AssetManager assets = getAssets();
@ -465,13 +472,13 @@ public class MainMenuActivity extends PreferenceActivity {
private void extractAssets() { private void extractAssets() {
if (areAssetsExtracted()) if (areAssetsExtracted())
return; return;
final Dialog dialog = new Dialog(this); final Dialog dialog = new Dialog(this);
final Handler handler = new Handler(); final Handler handler = new Handler();
dialog.setContentView(R.layout.assets); dialog.setContentView(R.layout.assets);
dialog.setCancelable(false); dialog.setCancelable(false);
dialog.setTitle("Asset extraction"); dialog.setTitle("Asset extraction");
// Java is fun :) // Java is fun :)
Thread assetsThread = new Thread(new Runnable() { Thread assetsThread = new Thread(new Runnable() {
public void run() { public void run() {
@ -484,36 +491,37 @@ public class MainMenuActivity extends PreferenceActivity {
} }
}); });
assetsThread.start(); assetsThread.start();
dialog.show(); dialog.show();
} }
public void setModule(String core_path, String core_name) { public void setModule(String core_path, String core_name) {
libretro_path = core_path; libretro_path = core_path;
libretro_name = core_name; libretro_name = core_name;
File libretro_path_file = new File(core_path); 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 SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs SharedPreferences.Editor edit = prefs.edit();
.edit();
edit.putString("libretro_path", libretro_path); edit.putString("libretro_path", libretro_path);
edit.putString("libretro_name", libretro_name); edit.putString("libretro_name", libretro_name);
edit.commit(); edit.commit();
} }
public void setCoreTitle(String core_name) { public void setCoreTitle(String core_name) {
setTitle("RetroArch : " + core_name); setTitle("RetroArch : " + core_name);
} }
boolean detectDevice(boolean show_dialog) { boolean detectDevice(boolean show_dialog) {
boolean retval = false; boolean retval = false;
boolean mentionPlayStore = !android.os.Build.MODEL.equals("OUYA Console"); boolean mentionPlayStore = !android.os.Build.MODEL
final String message = "The ideal configuration options for your device will now be preconfigured.\n\nNOTE: For optimal performance, turn off Google Account sync, " + .equals("OUYA Console");
(mentionPlayStore ? "Google Play Store auto-updates, " : "") + final String message = "The ideal configuration options for your device will now be preconfigured.\n\nNOTE: For optimal performance, turn off Google Account sync, "
"GPS and Wi-Fi in your Android settings menu."; + (mentionPlayStore ? "Google Play Store auto-updates, " : "")
+ "GPS and Wi-Fi in your Android settings menu.";
Log.i("Device MODEL", android.os.Build.MODEL); Log.i("Device MODEL", android.os.Build.MODEL);
if (android.os.Build.MODEL.equals("SHIELD")) { if (android.os.Build.MODEL.equals("SHIELD")) {
@ -542,27 +550,27 @@ public class MainMenuActivity extends PreferenceActivity {
retval = true; retval = true;
} else if (android.os.Build.MODEL.equals("GAMEMID_BT")) { } else if (android.os.Build.MODEL.equals("GAMEMID_BT")) {
AlertDialog.Builder alert = new AlertDialog.Builder(this) AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setTitle("GameMID detected") .setTitle("GameMID detected")
.setMessage(message) .setMessage(message)
.setPositiveButton("OK", .setPositiveButton("OK",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int which) { int which) {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs SharedPreferences.Editor edit = prefs
.edit(); .edit();
edit.putBoolean("input_overlay_enable", edit.putBoolean("input_overlay_enable",
false); false);
edit.putBoolean("input_autodetect_enable", edit.putBoolean("input_autodetect_enable",
true); true);
edit.putBoolean("audio_high_latency", true); edit.putBoolean("audio_high_latency", true);
edit.commit(); edit.commit();
} }
}); });
alert.show(); alert.show();
retval = true; retval = true;
} else if (android.os.Build.MODEL.equals("OUYA Console")) { } else if (android.os.Build.MODEL.equals("OUYA Console")) {
AlertDialog.Builder alert = new AlertDialog.Builder(this) AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setTitle("OUYA detected") .setTitle("OUYA detected")
@ -621,30 +629,33 @@ public class MainMenuActivity extends PreferenceActivity {
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
} }
@Override @Override
public void startActivity(Intent intent) { public void startActivity(Intent intent) {
if (intent.getComponent().getClassName().equals("org.retroarch.browser.ROMActivity")) { if (intent.getComponent().getClassName()
if (new File(libretro_path).isDirectory() == false) { .equals("org.retroarch.browser.ROMActivity")) {
super.startActivityForResult(intent, ACTIVITY_LOAD_ROM); if (new File(libretro_path).isDirectory() == false) {
} else { super.startActivityForResult(intent, ACTIVITY_LOAD_ROM);
} else {
Toast.makeText(this, Toast.makeText(this,
"Go to 'Load Core' and select a core first.", "Go to 'Load Core' and select a core first.",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
} else { } else {
super.startActivity(intent); super.startActivity(intent);
} }
} }
@Override @Override
protected void onActivityResult(int reqCode, int resCode, Intent data) { protected void onActivityResult(int reqCode, int resCode, Intent data) {
if (reqCode == ACTIVITY_LOAD_ROM) { switch (reqCode) {
if (data.getStringExtra("PATH") != null) { case ACTIVITY_LOAD_ROM: {
updateConfigFile(); if (data.getStringExtra("PATH") != null) {
Intent myIntent; updateConfigFile();
String current_ime = Settings.Secure.getString(getContentResolver(), Intent myIntent;
Settings.Secure.DEFAULT_INPUT_METHOD); String current_ime = Settings.Secure.getString(
getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Toast.makeText(this, Toast.makeText(this,
"Loading: [" + data.getStringExtra("PATH") + "]...", "Loading: [" + data.getStringExtra("PATH") + "]...",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
@ -656,6 +667,24 @@ public class MainMenuActivity extends PreferenceActivity {
myIntent.putExtra("IME", current_ime); myIntent.putExtra("IME", current_ime);
startActivity(myIntent); 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);
}
} }