mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-22 18:58:21 +00:00
Minor code cleanups.
This commit is contained in:
parent
ae5221947a
commit
fbc0b8f0eb
@ -9,7 +9,6 @@ import android.content.*;
|
|||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ public class DirectoryActivity extends Activity implements
|
|||||||
|
|
||||||
private void finishWithPath(String path) {
|
private void finishWithPath(String path) {
|
||||||
if (pathSettingKey != null && !pathSettingKey.isEmpty()) {
|
if (pathSettingKey != null && !pathSettingKey.isEmpty()) {
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences settings = MainMenuActivity.getPreferences();
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putString(pathSettingKey, path);
|
editor.putString(pathSettingKey, path);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
@ -8,7 +8,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -36,7 +35,7 @@ public class DisplayRefreshRateTest extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setFPSSetting(double fps) {
|
private void setFPSSetting(double fps) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences prefs = MainMenuActivity.getPreferences();
|
||||||
SharedPreferences.Editor edit = prefs.edit();
|
SharedPreferences.Editor edit = prefs.edit();
|
||||||
edit.putString("video_refresh_rate", Double.valueOf(fps).toString());
|
edit.putString("video_refresh_rate", Double.valueOf(fps).toString());
|
||||||
edit.commit();
|
edit.commit();
|
||||||
@ -117,7 +116,7 @@ public class DisplayRefreshRateTest extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences prefs = MainMenuActivity.getPreferences();
|
||||||
String fps = prefs.getString("video_refresh_rate", "ERROR");
|
String fps = prefs.getString("video_refresh_rate", "ERROR");
|
||||||
Toast.makeText(this, "Refresh rate measured to: " + fps + " Hz.", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Refresh rate measured to: " + fps + " Hz.", Toast.LENGTH_LONG).show();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -32,20 +32,40 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
static private final String TAG = "MainMenu";
|
static private final String TAG = "MainMenu";
|
||||||
static private String libretro_path;
|
static private String libretro_path;
|
||||||
static private String libretro_name;
|
static private String libretro_name;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
private void refreshPreferenceScreen() {
|
||||||
|
setPreferenceScreen(null);
|
||||||
|
addPreferencesFromResource(R.xml.prefs);
|
||||||
|
|
||||||
|
setCoreTitle(libretro_name);
|
||||||
|
PreferenceManager.setDefaultValues(this, R.xml.prefs, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean usePerCoreConfig() {
|
||||||
|
SharedPreferences prefs = getPreferences();
|
||||||
|
|
||||||
|
boolean global_config_enable = prefs.getBoolean("global_config_enable", true);
|
||||||
|
boolean config_same_as_native_lib_dir = libretro_path
|
||||||
|
.equals(getApplicationInfo().nativeLibraryDir);
|
||||||
|
|
||||||
|
return !global_config_enable && !config_same_as_native_lib_dir;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
|
SharedPreferences prefs = getPreferences();
|
||||||
|
|
||||||
|
libretro_path = prefs.getString("libretro_path", getApplicationInfo().nativeLibraryDir);
|
||||||
|
libretro_name = prefs.getString("libretro_name", "No core");
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.prefs);
|
refreshPreferenceScreen();
|
||||||
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
|
|
||||||
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager
|
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
|
|
||||||
extractAssets();
|
extractAssets();
|
||||||
|
|
||||||
if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) {
|
if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) {
|
||||||
@ -57,37 +77,11 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
.setTitle("Welcome to RetroArch")
|
.setTitle("Welcome to RetroArch")
|
||||||
.setMessage(
|
.setMessage(
|
||||||
"This is your first time starting up RetroArch. RetroArch will now be preconfigured for the best possible gameplay experience.")
|
"This is your first time starting up RetroArch. RetroArch will now be preconfigured for the best possible gameplay experience.")
|
||||||
.setPositiveButton("OK",
|
.setPositiveButton("OK", null);
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog,
|
|
||||||
int which) {
|
|
||||||
SharedPreferences prefs = PreferenceManager
|
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs
|
|
||||||
.edit();
|
|
||||||
edit.putBoolean("video_threaded", true);
|
|
||||||
edit.commit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.show();
|
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 {
|
|
||||||
libretro_path = getInstance().getApplicationInfo().nativeLibraryDir;
|
|
||||||
libretro_name = "No core";
|
|
||||||
setCoreTitle("No core");
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent startedByIntent = getIntent();
|
Intent startedByIntent = getIntent();
|
||||||
if (null != startedByIntent.getStringExtra("ROM")
|
if (null != startedByIntent.getStringExtra("ROM")
|
||||||
&& null != startedByIntent.getStringExtra("LIBRETRO")) {
|
&& null != startedByIntent.getStringExtra("LIBRETRO")) {
|
||||||
@ -120,9 +114,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
public static final double getRefreshRate() {
|
public static final double getRefreshRate() {
|
||||||
double rate = 0;
|
double rate = 0;
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getInstance()
|
|
||||||
.getBaseContext());
|
|
||||||
String refresh_rate = prefs.getString("video_refresh_rate", "");
|
String refresh_rate = prefs.getString("video_refresh_rate", "");
|
||||||
if (!refresh_rate.isEmpty()) {
|
if (!refresh_rate.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
@ -193,26 +185,23 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
Log.i(TAG, "Using sampling rate: " + ret + " Hz");
|
Log.i(TAG, "Using sampling rate: " + ret + " Hz");
|
||||||
return ret;
|
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() {
|
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
|
|
||||||
.getDefaultSharedPreferences(getInstance()
|
|
||||||
.getBaseContext());
|
|
||||||
|
|
||||||
boolean global_config_enable = prefs.getBoolean("global_config_enable",
|
|
||||||
true);
|
|
||||||
boolean config_same_as_native_lib_dir = libretro_path
|
|
||||||
.equals(getInstance().getApplicationInfo().nativeLibraryDir);
|
|
||||||
String append_path;
|
String append_path;
|
||||||
if (!global_config_enable && (config_same_as_native_lib_dir == false)) {
|
if (getInstance().usePerCoreConfig()) {
|
||||||
String sanitized_name = libretro_path.substring(
|
String sanitized_name = sanitizeLibretroPath(libretro_path);
|
||||||
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";
|
append_path = File.separator + sanitized_name + "retroarch.cfg";
|
||||||
} else {
|
} else {
|
||||||
append_path = File.separator + "retroarch.cfg";
|
append_path = File.separator + "retroarch.cfg";
|
||||||
@ -253,9 +242,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
config = new ConfigFile();
|
config = new ConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getInstance()
|
|
||||||
.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);
|
||||||
@ -536,16 +523,16 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SharedPreferences getPreferences() {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(getInstance().getBaseContext());
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
setCoreTitle((libretro_path_file.isDirectory() == true) ? "No core"
|
|
||||||
: core_name);
|
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs.edit();
|
SharedPreferences.Editor edit = prefs.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);
|
||||||
@ -575,8 +562,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int which) {
|
int which) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs
|
SharedPreferences.Editor edit = prefs
|
||||||
.edit();
|
.edit();
|
||||||
edit.putString("video_refresh_rate", Double
|
edit.putString("video_refresh_rate", Double
|
||||||
@ -599,8 +585,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int which) {
|
int which) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs
|
SharedPreferences.Editor edit = prefs
|
||||||
.edit();
|
.edit();
|
||||||
edit.putBoolean("input_overlay_enable",
|
edit.putBoolean("input_overlay_enable",
|
||||||
@ -622,8 +607,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int which) {
|
int which) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs
|
SharedPreferences.Editor edit = prefs
|
||||||
.edit();
|
.edit();
|
||||||
edit.putBoolean("input_overlay_enable",
|
edit.putBoolean("input_overlay_enable",
|
||||||
@ -644,8 +628,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int which) {
|
int which) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = getPreferences();
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
|
||||||
SharedPreferences.Editor edit = prefs
|
SharedPreferences.Editor edit = prefs
|
||||||
.edit();
|
.edit();
|
||||||
edit.putString("video_refresh_rate", Double
|
edit.putString("video_refresh_rate", Double
|
||||||
@ -663,6 +646,8 @@ public class MainMenuActivity extends PreferenceActivity {
|
|||||||
"Device either not detected in list or doesn't have any optimal settings in our database.",
|
"Device either not detected in list or doesn't have any optimal settings in our database.",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshPreferenceScreen();
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,12 @@ import java.io.File;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
public class ROMActivity extends DirectoryActivity {
|
public class ROMActivity extends DirectoryActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences prefs = MainMenuActivity.getPreferences();
|
||||||
String startPath = prefs.getString("rgui_browser_directory", "");
|
String startPath = prefs.getString("rgui_browser_directory", "");
|
||||||
if (!startPath.isEmpty() && new File(startPath).exists())
|
if (!startPath.isEmpty() && new File(startPath).exists())
|
||||||
super.setStartDirectory(startPath);
|
super.setStartDirectory(startPath);
|
||||||
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -18,7 +17,7 @@ public class RefreshRateSetOS extends Activity {
|
|||||||
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||||
final Display display = wm.getDefaultDisplay();
|
final Display display = wm.getDefaultDisplay();
|
||||||
double rate = display.getRefreshRate();
|
double rate = display.getRefreshRate();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences prefs = MainMenuActivity.getPreferences();
|
||||||
SharedPreferences.Editor edit = prefs.edit();
|
SharedPreferences.Editor edit = prefs.edit();
|
||||||
edit.putString("video_refresh_rate", Double.valueOf(rate).toString());
|
edit.putString("video_refresh_rate", Double.valueOf(rate).toString());
|
||||||
edit.commit();
|
edit.commit();
|
||||||
|
Loading…
Reference in New Issue
Block a user