Skip to content

Commit

Permalink
Allow to load roms from external apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
mng1dev committed Aug 19, 2013
1 parent 9ce4684 commit 56674fb
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 90 deletions.
11 changes: 11 additions & 0 deletions .project
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RetroArch_</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
4 changes: 2 additions & 2 deletions android/phoenix/AndroidManifest.xml
Expand Up @@ -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" />
Expand All @@ -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>
Expand Down
205 changes: 117 additions & 88 deletions android/phoenix/src/org/retroarch/browser/MainMenuActivity.java
Expand Up @@ -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);
Expand All @@ -45,7 +52,7 @@ public void onCreate(Bundle savedInstanceState) {
.getDefaultSharedPreferences(getBaseContext());

extractAssets();

if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) {
prefs.edit().putBoolean("first_time_refreshrate_calculate", true)
.commit();
Expand All @@ -71,17 +78,16 @@ public void onClick(DialogInterface dialog,
alert.show();
}
}

if (prefs.getString("libretro_path", "").isEmpty() == false) {
libretro_path = prefs.getString("libretro_path", "");
setCoreTitle("No core");

if (prefs.getString("libretro_name", "").isEmpty() == false) {
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");
Expand Down Expand Up @@ -168,21 +174,24 @@ public static int getOptimalSamplingRate() {
public static String getDefaultConfigPath() {
String internal = System.getenv("INTERNAL_STORAGE");
String external = System.getenv("EXTERNAL_STORAGE");

SharedPreferences prefs = PreferenceManager
.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_","");
sanitized_name = sanitized_name.replace("libretro_", "");
append_path = File.separator + sanitized_name + "retroarch.cfg";
}
else {
} else {
append_path = File.separator + "retroarch.cfg";
}

Expand All @@ -200,13 +209,10 @@ public static String getDefaultConfigPath() {
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)
Expand All @@ -227,11 +233,11 @@ public void updateConfigFile() {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(MainMenuActivity.getInstance()
.getBaseContext());

config.setString("libretro_path", libretro_path);
config.setString("libretro_name", libretro_name);
setCoreTitle(libretro_name);

config.setString("rgui_browser_directory",
prefs.getString("rgui_browser_directory", ""));
config.setBoolean("global_config_enable",
Expand Down Expand Up @@ -333,8 +339,9 @@ public void updateConfigFile() {

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",
Expand Down Expand Up @@ -390,20 +397,20 @@ private void extractAssets(AssetManager manager, String dataDir,
writer.close();
}
}

private int getVersionCode() {
int version = 0;
try {
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
}

return version;
}

private boolean areAssetsExtracted() {
int version = getVersionCode();

try {
String dataDir = getApplicationInfo().dataDir;
File cacheVersion = new File(dataDir, ".cacheversion");
Expand All @@ -428,10 +435,10 @@ private boolean areAssetsExtracted() {
Log.e(TAG, "Failed to extract assets to cache.");
return false;
}

return false;
}

private void extractAssetsThread() {
try {
AssetManager assets = getAssets();
Expand Down Expand Up @@ -465,13 +472,13 @@ private void extractAssetsThread() {
private void extractAssets() {
if (areAssetsExtracted())
return;

final Dialog dialog = new Dialog(this);
final Handler handler = new Handler();
dialog.setContentView(R.layout.assets);
dialog.setCancelable(false);
dialog.setTitle("Asset extraction");

// Java is fun :)
Thread assetsThread = new Thread(new Runnable() {
public void run() {
Expand All @@ -484,36 +491,37 @@ public void run() {
}
});
assetsThread.start();

dialog.show();
}

public void setModule(String core_path, String core_name) {
libretro_path = core_path;
libretro_name = core_name;
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();
}

public void setCoreTitle(String core_name) {
setTitle("RetroArch : " + core_name);
}

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")) {
Expand Down Expand Up @@ -542,27 +550,27 @@ public void onClick(DialogInterface dialog,
retval = true;
} else if (android.os.Build.MODEL.equals("GAMEMID_BT")) {
AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setTitle("GameMID detected")
.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs
.edit();
edit.putBoolean("input_overlay_enable",
false);
edit.putBoolean("input_autodetect_enable",
true);
edit.putBoolean("audio_high_latency", true);
edit.commit();
}
});
alert.show();
retval = true;
.setTitle("GameMID detected")
.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs
.edit();
edit.putBoolean("input_overlay_enable",
false);
edit.putBoolean("input_autodetect_enable",
true);
edit.putBoolean("audio_high_latency", true);
edit.commit();
}
});
alert.show();
retval = true;
} else if (android.os.Build.MODEL.equals("OUYA Console")) {
AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setTitle("OUYA detected")
Expand Down Expand Up @@ -621,30 +629,33 @@ public void onClick(DialogInterface dialog,
protected void onStart() {
super.onStart();
}

@Override
public void startActivity(Intent intent) {
if (intent.getComponent().getClassName().equals("org.retroarch.browser.ROMActivity")) {
if (new File(libretro_path).isDirectory() == false) {
super.startActivityForResult(intent, ACTIVITY_LOAD_ROM);
} else {

@Override
public void startActivity(Intent intent) {
if (intent.getComponent().getClassName()
.equals("org.retroarch.browser.ROMActivity")) {
if (new File(libretro_path).isDirectory() == false) {
super.startActivityForResult(intent, ACTIVITY_LOAD_ROM);
} else {
Toast.makeText(this,
"Go to 'Load Core' and select a core first.",
Toast.LENGTH_SHORT).show();
}
} else {
super.startActivity(intent);
}
}

@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
if (reqCode == ACTIVITY_LOAD_ROM) {
if (data.getStringExtra("PATH") != null) {
updateConfigFile();
Intent myIntent;
String current_ime = Settings.Secure.getString(getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
}
} else {
super.startActivity(intent);
}
}

@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
switch (reqCode) {
case ACTIVITY_LOAD_ROM: {
if (data.getStringExtra("PATH") != null) {
updateConfigFile();
Intent myIntent;
String current_ime = Settings.Secure.getString(
getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Toast.makeText(this,
"Loading: [" + data.getStringExtra("PATH") + "]...",
Toast.LENGTH_SHORT).show();
Expand All @@ -656,6 +667,24 @@ protected void onActivityResult(int reqCode, int resCode, Intent data) {
myIntent.putExtra("IME", current_ime);
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);

}
}

0 comments on commit 56674fb

Please sign in to comment.