mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-30 03:30:45 +00:00
[Android] Initial implementation of new UserPreferences. Unifies preference loading and saving into one central class and moves it out of the MainMenuActivity.java.
This commit is contained in:
parent
010e691993
commit
ed649b44ab
@ -2,6 +2,7 @@ package org.retroarch.browser;
|
||||
|
||||
import org.retroarch.R;
|
||||
import org.retroarch.browser.preferences.ConfigFile;
|
||||
import org.retroarch.browser.preferences.UserPreferences;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -14,10 +15,9 @@ import android.view.*;
|
||||
|
||||
// JELLY_BEAN_MR1 = 17
|
||||
|
||||
public final class CoreSelection extends Activity implements
|
||||
AdapterView.OnItemClickListener {
|
||||
public final class CoreSelection extends Activity implements AdapterView.OnItemClickListener {
|
||||
private IconAdapter<ModuleWrapper> adapter;
|
||||
static private final String TAG = "CoreSelection";
|
||||
private static final String TAG = "CoreSelection";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -88,11 +88,10 @@ public final class CoreSelection extends Activity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> aListView, View aView,
|
||||
int aPosition, long aID) {
|
||||
final ModuleWrapper item = adapter.getItem(aPosition);
|
||||
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
|
||||
final ModuleWrapper item = adapter.getItem(position);
|
||||
MainMenuActivity.getInstance().setModule(item.file.getAbsolutePath(), item.getText());
|
||||
MainMenuActivity.getInstance().updateConfigFile();
|
||||
UserPreferences.updateConfigFile(this);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,14 @@ public final class FileWrapper implements IconAdapterItem {
|
||||
|
||||
protected final int typeIndex;
|
||||
|
||||
public FileWrapper(File aFile, int type, boolean aIsEnabled) {
|
||||
file = aFile;
|
||||
|
||||
parentItem = type == PARENT;
|
||||
dirSelectItem = type == DIRSELECT;
|
||||
typeIndex = type == FILE ? (FILE + (file.isDirectory() ? 0 : 1)) : type;
|
||||
|
||||
enabled = parentItem || dirSelectItem || aIsEnabled;
|
||||
public FileWrapper(File file, int type, boolean isEnabled) {
|
||||
this.file = file;
|
||||
|
||||
this.parentItem = type == PARENT;
|
||||
this.dirSelectItem = type == DIRSELECT;
|
||||
this.typeIndex = type == FILE ? (FILE + (file.isDirectory() ? 0 : 1)) : type;
|
||||
|
||||
this.enabled = parentItem || dirSelectItem || isEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,13 +63,13 @@ public final class FileWrapper implements IconAdapterItem {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int compareTo(FileWrapper aOther) {
|
||||
if (aOther != null) {
|
||||
public int compareTo(FileWrapper other) {
|
||||
if (other != null) {
|
||||
// Who says ternary is hard to follow
|
||||
if (isEnabled() == aOther.isEnabled()) {
|
||||
return (typeIndex == aOther.typeIndex) ? file
|
||||
.compareTo(aOther.file)
|
||||
: ((typeIndex < aOther.typeIndex) ? -1 : 1);
|
||||
if (isEnabled() == other.isEnabled()) {
|
||||
return (typeIndex == other.typeIndex) ? file
|
||||
.compareTo(other.file)
|
||||
: ((typeIndex < other.typeIndex) ? -1 : 1);
|
||||
} else {
|
||||
return isEnabled() ? -1 : 1;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.retroarch.R;
|
||||
import org.retroarch.browser.preferences.UserPreferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@ -17,8 +18,7 @@ import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public final class HistorySelection extends Activity implements
|
||||
AdapterView.OnItemClickListener {
|
||||
public final class HistorySelection extends Activity implements AdapterView.OnItemClickListener {
|
||||
|
||||
private IconAdapter<HistoryWrapper> adapter;
|
||||
|
||||
@ -57,9 +57,8 @@ public final class HistorySelection extends Activity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> aListView, View aView,
|
||||
int aPosition, long aID) {
|
||||
final HistoryWrapper item = adapter.getItem(aPosition);
|
||||
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
|
||||
final HistoryWrapper item = adapter.getItem(position);
|
||||
final String gamePath = item.getGamePath();
|
||||
final String corePath = item.getCorePath();
|
||||
|
||||
@ -69,13 +68,13 @@ public final class HistorySelection extends Activity implements
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(),
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
|
||||
MainMenuActivity.getInstance().updateConfigFile();
|
||||
UserPreferences.updateConfigFile(this);
|
||||
|
||||
Toast.makeText(this, String.format(getString(R.string.loading_gamepath), gamePath), Toast.LENGTH_SHORT).show();
|
||||
myIntent = new Intent(this, RetroActivity.class);
|
||||
myIntent.putExtra("ROM", gamePath);
|
||||
myIntent.putExtra("LIBRETRO", corePath);
|
||||
myIntent.putExtra("CONFIGFILE", MainMenuActivity.getDefaultConfigPath());
|
||||
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivity(myIntent);
|
||||
finish();
|
||||
|
@ -3,20 +3,18 @@ package org.retroarch.browser;
|
||||
import java.io.*;
|
||||
|
||||
import org.retroarch.R;
|
||||
import org.retroarch.browser.preferences.ConfigFile;
|
||||
import org.retroarch.browser.preferences.UserPreferences;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.CheckBoxPreference;
|
||||
@ -31,16 +29,14 @@ import android.widget.Toast;
|
||||
|
||||
public final class MainMenuActivity extends PreferenceActivity {
|
||||
private static MainMenuActivity instance = null;
|
||||
static private final int ACTIVITY_LOAD_ROM = 0;
|
||||
static private final String TAG = "MainMenu";
|
||||
static private String libretro_path;
|
||||
static private String libretro_name;
|
||||
|
||||
private boolean globalConfigEnable = true;
|
||||
private static final int ACTIVITY_LOAD_ROM = 0;
|
||||
private static final String TAG = "MainMenu";
|
||||
private static String libretro_path;
|
||||
private static String libretro_name;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void refreshPreferenceScreen() {
|
||||
readbackConfigFile();
|
||||
UserPreferences.readbackConfigFile(this);
|
||||
|
||||
setPreferenceScreen(null);
|
||||
addPreferencesFromResource(R.xml.prefs);
|
||||
@ -49,12 +45,10 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
|
||||
|
||||
final CheckBoxPreference param = (CheckBoxPreference) findPreference("global_config_enable");
|
||||
globalConfigEnable = param.isChecked();
|
||||
param.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
updateConfigFile();
|
||||
globalConfigEnable = param.isChecked();
|
||||
UserPreferences.updateConfigFile(MainMenuActivity.this);
|
||||
SharedPreferences prefs = MainMenuActivity.getPreferences();
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
edit.putBoolean("global_config_enable", param.isChecked());
|
||||
@ -65,13 +59,6 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean usePerCoreConfig() {
|
||||
boolean config_same_as_native_lib_dir = libretro_path
|
||||
.equals(getApplicationInfo().nativeLibraryDir);
|
||||
|
||||
return !globalConfigEnable && !config_same_as_native_lib_dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -168,330 +155,6 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
return result;
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static int getLowLatencyOptimalSamplingRate() {
|
||||
AudioManager manager = (AudioManager) getInstance()
|
||||
.getApplicationContext()
|
||||
.getSystemService(Context.AUDIO_SERVICE);
|
||||
return Integer.parseInt(manager
|
||||
.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static int getLowLatencyBufferSize() {
|
||||
AudioManager manager = (AudioManager) getInstance()
|
||||
.getApplicationContext()
|
||||
.getSystemService(Context.AUDIO_SERVICE);
|
||||
int buffersize = Integer.parseInt(manager
|
||||
.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
|
||||
Log.i(TAG, "Queried ideal buffer size (frames): " + buffersize);
|
||||
return buffersize;
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static boolean hasLowLatencyAudio() {
|
||||
PackageManager pm = getInstance().getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);
|
||||
}
|
||||
|
||||
public static int getOptimalSamplingRate() {
|
||||
int ret;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 17)
|
||||
ret = getLowLatencyOptimalSamplingRate();
|
||||
else
|
||||
ret = AudioTrack
|
||||
.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
||||
|
||||
Log.i(TAG, "Using sampling rate: " + ret + " Hz");
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String sanitizeLibretroPath(String path) {
|
||||
String sanitized_name = path.substring(
|
||||
path.lastIndexOf("/") + 1,
|
||||
path.lastIndexOf("."));
|
||||
sanitized_name = sanitized_name.replace("neon", "");
|
||||
sanitized_name = sanitized_name.replace("libretro_", "");
|
||||
return sanitized_name;
|
||||
}
|
||||
|
||||
public static String getDefaultConfigPath() {
|
||||
String internal = System.getenv("INTERNAL_STORAGE");
|
||||
String external = System.getenv("EXTERNAL_STORAGE");
|
||||
|
||||
String append_path;
|
||||
if (getInstance().usePerCoreConfig()) {
|
||||
String sanitized_name = sanitizeLibretroPath(libretro_path);
|
||||
append_path = File.separator + sanitized_name + ".cfg";
|
||||
} else {
|
||||
append_path = File.separator + "retroarch.cfg";
|
||||
}
|
||||
|
||||
if (external != null) {
|
||||
String confPath = external + append_path;
|
||||
if (new File(confPath).exists())
|
||||
return confPath;
|
||||
} else if (internal != null) {
|
||||
String confPath = internal + append_path;
|
||||
if (new File(confPath).exists())
|
||||
return confPath;
|
||||
} else {
|
||||
String confPath = "/mnt/extsd" + append_path;
|
||||
if (new File(confPath).exists())
|
||||
return confPath;
|
||||
}
|
||||
|
||||
if (internal != null && new File(internal + append_path).canWrite())
|
||||
return internal + append_path;
|
||||
else if (external != null
|
||||
&& new File(internal + append_path).canWrite())
|
||||
return external + append_path;
|
||||
else if ((getInstance().getApplicationInfo().dataDir) != null)
|
||||
return (getInstance().getApplicationInfo().dataDir)
|
||||
+ append_path;
|
||||
else
|
||||
// emergency fallback, all else failed
|
||||
return "/mnt/sd" + append_path;
|
||||
}
|
||||
|
||||
private void readbackString(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
||||
if (cfg.keyExists(key))
|
||||
edit.putString(key, cfg.getString(key));
|
||||
else
|
||||
edit.remove(key);
|
||||
}
|
||||
|
||||
private void readbackBool(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
||||
if (cfg.keyExists(key))
|
||||
edit.putBoolean(key, cfg.getBoolean(key));
|
||||
else
|
||||
edit.remove(key);
|
||||
}
|
||||
|
||||
private void readbackDouble(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
||||
if (cfg.keyExists(key))
|
||||
edit.putFloat(key, (float)cfg.getDouble(key));
|
||||
else
|
||||
edit.remove(key);
|
||||
}
|
||||
|
||||
private void readbackFloat(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
||||
if (cfg.keyExists(key))
|
||||
edit.putFloat(key, cfg.getFloat(key));
|
||||
else
|
||||
edit.remove(key);
|
||||
}
|
||||
|
||||
private void readbackInt(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
||||
if (cfg.keyExists(key))
|
||||
edit.putInt(key, cfg.getInt(key));
|
||||
else
|
||||
edit.remove(key);
|
||||
}
|
||||
|
||||
public void readbackConfigFile() {
|
||||
String path = getDefaultConfigPath();
|
||||
ConfigFile config;
|
||||
try {
|
||||
config = new ConfigFile(new File(path));
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Config readback from: " + path);
|
||||
|
||||
SharedPreferences prefs = getPreferences();
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
readbackString(config, edit, "rgui_browser_directory");
|
||||
readbackString(config, edit, "savefile_directory");
|
||||
readbackString(config, edit, "savestate_directory");
|
||||
readbackBool(config, edit, "savefile_directory_enable"); // Ignored by RetroArch
|
||||
readbackBool(config, edit, "savestate_directory_enable"); // Ignored by RetroArch
|
||||
|
||||
readbackString(config, edit, "input_overlay");
|
||||
readbackBool(config, edit, "input_overlay_enable");
|
||||
readbackBool(config, edit, "video_scale_integer");
|
||||
readbackBool(config, edit, "video_smooth");
|
||||
readbackBool(config, edit, "video_threaded");
|
||||
readbackBool(config, edit, "rewind_enable");
|
||||
readbackBool(config, edit, "savestate_auto_load");
|
||||
readbackBool(config, edit, "savestate_auto_save");
|
||||
//readbackDouble(config, edit, "video_refresh_rate");
|
||||
|
||||
readbackBool(config, edit, "audio_rate_control");
|
||||
readbackBool(config, edit, "audio_enable");
|
||||
// TODO: other audio settings
|
||||
|
||||
readbackDouble(config, edit, "input_overlay_opacity");
|
||||
readbackBool(config, edit, "input_autodetect_enable");
|
||||
//readbackInt(config, edit, "input_back_behavior");
|
||||
|
||||
readbackBool(config, edit, "video_allow_rotate");
|
||||
readbackBool(config, edit, "video_font_enable");
|
||||
|
||||
readbackBool(config, edit, "video_vsync");
|
||||
|
||||
edit.commit();
|
||||
}
|
||||
|
||||
public void updateConfigFile() {
|
||||
String path = getDefaultConfigPath();
|
||||
ConfigFile config;
|
||||
try {
|
||||
config = new ConfigFile(new File(path));
|
||||
} catch (IOException e) {
|
||||
config = new ConfigFile();
|
||||
}
|
||||
|
||||
Log.i(TAG, "Writing config to: " + path);
|
||||
|
||||
SharedPreferences prefs = getPreferences();
|
||||
|
||||
config.setString("libretro_path", libretro_path);
|
||||
|
||||
config.setString("rgui_browser_directory",
|
||||
prefs.getString("rgui_browser_directory", ""));
|
||||
config.setBoolean("audio_rate_control",
|
||||
prefs.getBoolean("audio_rate_control", true));
|
||||
|
||||
int optimalRate = getOptimalSamplingRate();
|
||||
config.setInt("audio_out_rate", optimalRate);
|
||||
|
||||
// Refactor this entire mess and make this usable for per-core config
|
||||
if (android.os.Build.VERSION.SDK_INT >= 17 &&
|
||||
prefs.getBoolean("audio_latency_auto", true)) {
|
||||
int buffersize = getLowLatencyBufferSize();
|
||||
|
||||
boolean lowLatency = hasLowLatencyAudio();
|
||||
Log.i(TAG, "Audio is low latency: " + (lowLatency ? "yes" : "no"));
|
||||
|
||||
config.setInt("audio_latency", 64);
|
||||
if (lowLatency) {
|
||||
config.setInt("audio_block_frames", buffersize);
|
||||
} else {
|
||||
config.setInt("audio_block_frames", 0);
|
||||
}
|
||||
} else {
|
||||
String latency_audio = prefs.getString("audio_latency", "64");
|
||||
config.setInt("audio_latency", Integer.parseInt(latency_audio));
|
||||
}
|
||||
|
||||
config.setBoolean("audio_enable",
|
||||
prefs.getBoolean("audio_enable", true));
|
||||
config.setBoolean("video_smooth",
|
||||
prefs.getBoolean("video_smooth", true));
|
||||
config.setBoolean("video_allow_rotate",
|
||||
prefs.getBoolean("video_allow_rotate", true));
|
||||
config.setBoolean("savestate_auto_load",
|
||||
prefs.getBoolean("savestate_auto_load", true));
|
||||
config.setBoolean("savestate_auto_save",
|
||||
prefs.getBoolean("savestate_auto_save", false));
|
||||
config.setBoolean("rewind_enable",
|
||||
prefs.getBoolean("rewind_enable", false));
|
||||
config.setBoolean("video_vsync", prefs.getBoolean("video_vsync", true));
|
||||
config.setBoolean("input_autodetect_enable",
|
||||
prefs.getBoolean("input_autodetect_enable", true));
|
||||
config.setBoolean("input_debug_enable",
|
||||
prefs.getBoolean("input_debug_enable", false));
|
||||
config.setInt("input_back_behavior",
|
||||
Integer.valueOf(prefs.getString("input_back_behavior", "0")));
|
||||
config.setInt("input_autodetect_icade_profile_pad1", Integer
|
||||
.valueOf(prefs.getString("input_autodetect_icade_profile_pad1",
|
||||
"0")));
|
||||
config.setInt("input_autodetect_icade_profile_pad2", Integer
|
||||
.valueOf(prefs.getString("input_autodetect_icade_profile_pad2",
|
||||
"0")));
|
||||
config.setInt("input_autodetect_icade_profile_pad3", Integer
|
||||
.valueOf(prefs.getString("input_autodetect_icade_profile_pad3",
|
||||
"0")));
|
||||
config.setInt("input_autodetect_icade_profile_pad4", Integer
|
||||
.valueOf(prefs.getString("input_autodetect_icade_profile_pad4",
|
||||
"0")));
|
||||
|
||||
config.setDouble("video_refresh_rate",
|
||||
getRefreshRate());
|
||||
config.setBoolean("video_threaded",
|
||||
prefs.getBoolean("video_threaded", true));
|
||||
|
||||
// Refactor these weird values - 'full', 'auto', 'square', whatever -
|
||||
// go by what we have in RGUI - makes maintaining state easier too
|
||||
String aspect = prefs.getString("video_aspect_ratio", "auto");
|
||||
if (aspect.equals("full")) {
|
||||
config.setBoolean("video_force_aspect", false);
|
||||
} else if (aspect.equals("auto")) {
|
||||
config.setBoolean("video_force_aspect", true);
|
||||
config.setBoolean("video_force_aspect_auto", true);
|
||||
config.setDouble("video_aspect_ratio", -1.0);
|
||||
} else if (aspect.equals("square")) {
|
||||
config.setBoolean("video_force_aspect", true);
|
||||
config.setBoolean("video_force_aspect_auto", false);
|
||||
config.setDouble("video_aspect_ratio", -1.0);
|
||||
} else {
|
||||
double aspect_ratio = Double.parseDouble(aspect);
|
||||
config.setBoolean("video_force_aspect", true);
|
||||
config.setDouble("video_aspect_ratio", aspect_ratio);
|
||||
}
|
||||
|
||||
config.setBoolean("video_scale_integer",
|
||||
prefs.getBoolean("video_scale_integer", false));
|
||||
|
||||
String shaderPath = prefs.getString("video_shader", "");
|
||||
config.setString("video_shader", shaderPath);
|
||||
config.setBoolean("video_shader_enable",
|
||||
prefs.getBoolean("video_shader_enable", false)
|
||||
&& new File(shaderPath).exists());
|
||||
|
||||
boolean useOverlay = prefs.getBoolean("input_overlay_enable", true);
|
||||
config.setBoolean("input_overlay_enable", useOverlay); // Not used by RetroArch directly.
|
||||
if (useOverlay) {
|
||||
String overlayPath = prefs
|
||||
.getString("input_overlay", (getInstance()
|
||||
.getApplicationInfo().dataDir)
|
||||
+ "/overlays/snes-landscape.cfg");
|
||||
config.setString("input_overlay", overlayPath);
|
||||
config.setDouble("input_overlay_opacity",
|
||||
prefs.getFloat("input_overlay_opacity", 1.0f));
|
||||
} else {
|
||||
config.setString("input_overlay", "");
|
||||
}
|
||||
config.setString(
|
||||
"savefile_directory",
|
||||
prefs.getBoolean("savefile_directory_enable", false) ? prefs
|
||||
.getString("savefile_directory", "") : "");
|
||||
config.setString(
|
||||
"savestate_directory",
|
||||
prefs.getBoolean("savestate_directory_enable", false) ? prefs
|
||||
.getString("savestate_directory", "") : "");
|
||||
config.setString(
|
||||
"system_directory",
|
||||
prefs.getBoolean("system_directory_enable", false) ? prefs
|
||||
.getString("system_directory", "") : "");
|
||||
|
||||
config.setBoolean("video_font_enable",
|
||||
prefs.getBoolean("video_font_enable", true));
|
||||
|
||||
config.setString("game_history_path", getInstance()
|
||||
.getApplicationInfo().dataDir + "/retroarch-history.txt");
|
||||
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
final String[] btns = { "up", "down", "left", "right", "a", "b",
|
||||
"x", "y", "start", "select", "l", "r", "l2", "r2", "l3",
|
||||
"r3" };
|
||||
for (String b : btns) {
|
||||
String p = "input_player" + i + "_" + b
|
||||
+ "_btn";
|
||||
config.setInt(p, prefs.getInt(p, 0));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config.write(new File(path));
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to save config file to: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] loadAsset(String asset) throws IOException {
|
||||
InputStream stream = getAssets().open(asset);
|
||||
int len = stream.available();
|
||||
@ -500,8 +163,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
return buf;
|
||||
}
|
||||
|
||||
private void extractAssets(AssetManager manager, String dataDir,
|
||||
String relativePath, int level) throws IOException {
|
||||
private void extractAssets(AssetManager manager, String dataDir, String relativePath, int level) throws IOException {
|
||||
final String[] paths = manager.list(relativePath);
|
||||
if (paths != null && paths.length > 0) { // Directory
|
||||
// Log.d(TAG, "Extracting assets directory: " + relativePath);
|
||||
@ -628,7 +290,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
public void setModule(String core_path, String core_name) {
|
||||
updateConfigFile();
|
||||
UserPreferences.updateConfigFile(this);
|
||||
|
||||
libretro_path = core_path;
|
||||
libretro_name = core_name;
|
||||
@ -639,7 +301,11 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
edit.putString("libretro_name", libretro_name);
|
||||
edit.commit();
|
||||
|
||||
if (usePerCoreConfig())
|
||||
final boolean globalConfigEnabled = prefs.getBoolean("global_config_enable", true);
|
||||
final String nativeLibraryDir = getApplicationInfo().nativeLibraryDir;
|
||||
|
||||
// Check if per-core settings are being used.
|
||||
if (!globalConfigEnabled && !libretro_path.equals(nativeLibraryDir))
|
||||
refreshPreferenceScreen();
|
||||
else {
|
||||
setCoreTitle(libretro_name); // this still needs to be applied
|
||||
@ -650,14 +316,14 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
setTitle("RetroArch : " + core_name);
|
||||
}
|
||||
|
||||
boolean detectDevice(boolean show_dialog) {
|
||||
private boolean detectDevice(boolean show_dialog) {
|
||||
boolean retval = false;
|
||||
|
||||
final boolean mentionPlayStore = !android.os.Build.MODEL.equals("OUYA Console");
|
||||
final String message = (mentionPlayStore ? getString(R.string.detect_device_msg_general) : getString(R.string.detect_device_msg_ouya));
|
||||
|
||||
Log.i("Device MODEL", android.os.Build.MODEL);
|
||||
if (android.os.Build.MODEL.equals("SHIELD")) {
|
||||
if (Build.MODEL.equals("SHIELD")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.nvidia_shield_detected)
|
||||
.setMessage(message)
|
||||
@ -677,7 +343,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
});
|
||||
alert.show();
|
||||
retval = true;
|
||||
} else if (android.os.Build.MODEL.equals("GAMEMID_BT")) {
|
||||
} else if (Build.MODEL.equals("GAMEMID_BT")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.game_mid_detected)
|
||||
.setMessage(message)
|
||||
@ -696,7 +362,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
});
|
||||
alert.show();
|
||||
retval = true;
|
||||
} else if (android.os.Build.MODEL.equals("OUYA Console")) {
|
||||
} else if (Build.MODEL.equals("OUYA Console")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.ouya_detected)
|
||||
.setMessage(message)
|
||||
@ -715,7 +381,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
});
|
||||
alert.show();
|
||||
retval = true;
|
||||
} else if (android.os.Build.MODEL.equals("R800x")) {
|
||||
} else if (Build.MODEL.equals("R800x")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.xperia_play_detected)
|
||||
.setMessage(message)
|
||||
@ -736,7 +402,7 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
});
|
||||
alert.show();
|
||||
retval = true;
|
||||
} else if (android.os.Build.ID.equals("JSS15J")) {
|
||||
} else if (Build.ID.equals("JSS15J")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.nexus_7_2013_detected)
|
||||
.setMessage(message)
|
||||
@ -789,13 +455,13 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
switch (reqCode) {
|
||||
case ACTIVITY_LOAD_ROM: {
|
||||
if (data.getStringExtra("PATH") != null) {
|
||||
updateConfigFile();
|
||||
UserPreferences.updateConfigFile(this);
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
Toast.makeText(this,String.format(getString(R.string.loading_data), data.getStringExtra("PATH")), Toast.LENGTH_SHORT).show();
|
||||
Intent myIntent = new Intent(this, RetroActivity.class);
|
||||
myIntent.putExtra("ROM", data.getStringExtra("PATH"));
|
||||
myIntent.putExtra("LIBRETRO", libretro_path);
|
||||
myIntent.putExtra("CONFIGFILE", getDefaultConfigPath());
|
||||
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivity(myIntent);
|
||||
}
|
||||
@ -811,13 +477,13 @@ public final class MainMenuActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
private void loadRomExternal(String rom, String core) {
|
||||
updateConfigFile();
|
||||
UserPreferences.updateConfigFile(this);
|
||||
Intent myIntent = new Intent(this, RetroActivity.class);
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
Toast.makeText(this, String.format(getString(R.string.loading_data), rom), Toast.LENGTH_SHORT).show();
|
||||
myIntent.putExtra("ROM", rom);
|
||||
myIntent.putExtra("LIBRETRO", core);
|
||||
myIntent.putExtra("CONFIGFILE", getDefaultConfigPath());
|
||||
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivity(myIntent);
|
||||
}
|
||||
|
@ -18,20 +18,20 @@ public final class RetroActivity extends NativeActivity {
|
||||
@Override
|
||||
public void onTrimMemory(int level) {
|
||||
}
|
||||
|
||||
// We call this function from native to display a toast string
|
||||
public void showToastAlert(String text)
|
||||
{
|
||||
|
||||
// We call this function from native to display a toast string
|
||||
public void showToastAlert(String text)
|
||||
{
|
||||
// We need to use a runnable here to ensure that when the spawned
|
||||
// native_app_glue thread calls, we actually post the work to the UI
|
||||
// thread. Otherwise, we'll likely get exceptions because there's no
|
||||
// prepared Looper on the native_app_glue main thread.
|
||||
final String finalText = text;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
final String finalText = text;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
Toast.makeText(getApplicationContext(), finalText, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(), finalText, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,23 @@
|
||||
package org.retroarch.browser;
|
||||
|
||||
import org.retroarch.browser.preferences.UserPreferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
public final class RetroTVMode extends Activity {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MainMenuActivity.getInstance().updateConfigFile();
|
||||
|
||||
|
||||
UserPreferences.updateConfigFile(this);
|
||||
|
||||
Intent myIntent = new Intent(this, RetroActivity.class);
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
myIntent.putExtra("CONFIGFILE", MainMenuActivity.getDefaultConfigPath());
|
||||
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivity(myIntent);
|
||||
finish();
|
||||
|
Loading…
Reference in New Issue
Block a user