Asynchronus preferences, where appropriate

Most UI settings should be saved asynchronously with immediate results few from runtime memory, but storing the keys for cloud saves should probably remain direct to disk with error checking.
This commit is contained in:
TwistedUmbrella 2018-03-28 12:20:18 -04:00
parent 81d2389c42
commit 858d617673
8 changed files with 122 additions and 131 deletions

View File

@ -404,7 +404,7 @@ public class FileBrowser extends Fragment {
getActivity().getString(R.string.config_data, home_directory), getActivity().getString(R.string.config_data, home_directory),
R.drawable.ic_notification, Toast.LENGTH_LONG); R.drawable.ic_notification, Toast.LENGTH_LONG);
} }
mPrefs.edit().putString("home_directory", home_directory).commit(); mPrefs.edit().putString("home_directory", home_directory).apply();
mCallback.onFolderSelected(Uri.fromFile(new File(home_directory))); mCallback.onFolderSelected(Uri.fromFile(new File(home_directory)));
JNIdc.config(home_directory); JNIdc.config(home_directory);
} }
@ -490,11 +490,11 @@ public class FileBrowser extends Fragment {
if (games) { if (games) {
game_directory = heading; game_directory = heading;
mPrefs.edit().putString(Config.pref_games, heading).commit(); mPrefs.edit().putString(Config.pref_games, heading).apply();
mCallback.onFolderSelected(Uri.fromFile(new File(game_directory))); mCallback.onFolderSelected(Uri.fromFile(new File(game_directory)));
} else { } else {
home_directory = heading.replace("/data", ""); home_directory = heading.replace("/data", "");
mPrefs.edit().putString(Config.pref_home, home_directory).commit(); mPrefs.edit().putString(Config.pref_home, home_directory).apply();
if (!DataDirectoryBIOS()) { if (!DataDirectoryBIOS()) {
MainActivity.showToastMessage(getActivity(), MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.config_data, home_directory), getActivity().getString(R.string.config_data, home_directory),

View File

@ -220,7 +220,7 @@ public class GL2JNIActivity extends Activity {
if(prefs.getBoolean(Config.pref_vmu, false)){ if(prefs.getBoolean(Config.pref_vmu, false)){
//kind of a hack - if the user last had the vmu on screen //kind of a hack - if the user last had the vmu on screen
//inverse it and then "toggle" //inverse it and then "toggle"
prefs.edit().putBoolean(Config.pref_vmu, false).commit(); prefs.edit().putBoolean(Config.pref_vmu, false).apply();
//can only display a popup after onCreate //can only display a popup after onCreate
mView.post(new Runnable() { mView.post(new Runnable() {
public void run() { public void run() {
@ -462,7 +462,7 @@ public class GL2JNIActivity extends Activity {
//add back to popup menu //add back to popup menu
popUp.showVmu(); popUp.showVmu();
} }
prefs.edit().putBoolean(Config.pref_vmu, showFloating).commit(); prefs.edit().putBoolean(Config.pref_vmu, showFloating).apply();
} }
public void displayConfig(PopupWindow popUpConfig) { public void displayConfig(PopupWindow popUpConfig) {

View File

@ -237,7 +237,7 @@ public class GL2JNINative extends NativeActivity {
if(prefs.getBoolean(Config.pref_vmu, false)){ if(prefs.getBoolean(Config.pref_vmu, false)){
//kind of a hack - if the user last had the vmu on screen //kind of a hack - if the user last had the vmu on screen
//inverse it and then "toggle" //inverse it and then "toggle"
prefs.edit().putBoolean(Config.pref_vmu, false).commit(); prefs.edit().putBoolean(Config.pref_vmu, false).apply();
//can only display a popup after onCreate //can only display a popup after onCreate
mView.post(new Runnable() { mView.post(new Runnable() {
public void run() { public void run() {
@ -308,7 +308,7 @@ public class GL2JNINative extends NativeActivity {
//add back to popup menu //add back to popup menu
popUp.showVmu(); popUp.showVmu();
} }
prefs.edit().putBoolean(Config.pref_vmu, showFloating).commit(); prefs.edit().putBoolean(Config.pref_vmu, showFloating).apply();
} }
public void displayConfig(PopupWindow popUpConfig) { public void displayConfig(PopupWindow popUpConfig) {

View File

@ -91,7 +91,7 @@ public class MainActivity extends AppCompatActivity implements
String prior_error = mPrefs.getString("prior_error", null); String prior_error = mPrefs.getString("prior_error", null);
if (prior_error != null) { if (prior_error != null) {
displayLogOutput(prior_error); displayLogOutput(prior_error);
mPrefs.edit().remove("prior_error").commit(); mPrefs.edit().remove("prior_error").apply();
} else { } else {
mUEHandler = new Thread.UncaughtExceptionHandler() { mUEHandler = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable error) { public void uncaughtException(Thread t, Throwable error) {
@ -100,7 +100,7 @@ public class MainActivity extends AppCompatActivity implements
for (StackTraceElement trace : error.getStackTrace()) { for (StackTraceElement trace : error.getStackTrace()) {
output.append(trace.toString() + "\n"); output.append(trace.toString() + "\n");
} }
mPrefs.edit().putString("prior_error", output.toString()).commit(); mPrefs.edit().putString("prior_error", output.toString()).apply();
error.printStackTrace(); error.printStackTrace();
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0); System.exit(0);
@ -168,8 +168,8 @@ public class MainActivity extends AppCompatActivity implements
// firstFragment.setArguments(getIntent().getExtras()); // firstFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout // Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction().replace(
.replace(R.id.fragment_container, firstFragment, "MAIN_BROWSER").commit(); R.id.fragment_container, firstFragment, "MAIN_BROWSER").commit();
} }
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@ -319,9 +319,8 @@ public class MainActivity extends AppCompatActivity implements
} }
OptionsFragment optsFrag = new OptionsFragment(); OptionsFragment optsFrag = new OptionsFragment();
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction().replace(
.replace(R.id.fragment_container, optsFrag, "OPTIONS_FRAG") R.id.fragment_container, optsFrag, "OPTIONS_FRAG").commit();
.commit();
return; return;
} }

View File

@ -128,7 +128,7 @@ public class InputFragment extends Fragment {
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress() + 5; int progress = seekBar.getProgress() + 5;
sharedPreferences.edit().putInt(Config.pref_vibrationDuration, progress).commit(); sharedPreferences.edit().putInt(Config.pref_vibrationDuration, progress).apply();
Config.vibrationDuration = progress; Config.vibrationDuration = progress;
vib.vibrate(progress); vib.vibrate(progress);
} }
@ -138,7 +138,7 @@ public class InputFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
sharedPreferences.edit() sharedPreferences.edit()
.putBoolean(Config.pref_touchvibe, isChecked).commit(); .putBoolean(Config.pref_touchvibe, isChecked).apply();
vibLay.setVisibility( isChecked ? View.VISIBLE : View.GONE ); vibLay.setVisibility( isChecked ? View.VISIBLE : View.GONE );
} }
}; };
@ -164,9 +164,7 @@ public class InputFragment extends Fragment {
.setOnCheckedChangeListener(new OnCheckedChangeListener() { .setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
sharedPreferences.edit() sharedPreferences.edit().putBoolean(Config.pref_mic, isChecked).apply();
.putBoolean(Config.pref_mic, isChecked)
.commit();
} }
}); });
} else { } else {
@ -477,20 +475,16 @@ public class InputFragment extends Fragment {
case 0: case 0:
return false; return false;
case 1: case 1:
sharedPreferences.edit() sharedPreferences.edit().putString(Gamepad.pref_player1, descriptor).apply();
.putString(Gamepad.pref_player1, descriptor).commit();
break; break;
case 2: case 2:
sharedPreferences.edit() sharedPreferences.edit().putString(Gamepad.pref_player2, descriptor).apply();
.putString(Gamepad.pref_player2, descriptor).commit();
break; break;
case 3: case 3:
sharedPreferences.edit() sharedPreferences.edit().putString(Gamepad.pref_player3, descriptor).apply();
.putString(Gamepad.pref_player3, descriptor).commit();
break; break;
case 4: case 4:
sharedPreferences.edit() sharedPreferences.edit().putString(Gamepad.pref_player4, descriptor).apply();
.putString(Gamepad.pref_player4, descriptor).commit();
break; break;
} }
@ -506,20 +500,16 @@ public class InputFragment extends Fragment {
private void removeController(int playerNum) { private void removeController(int playerNum) {
switch (playerNum) { switch (playerNum) {
case 1: case 1:
sharedPreferences.edit().putString(Gamepad.pref_player1, null) sharedPreferences.edit().putString(Gamepad.pref_player1, null).apply();
.commit();
break; break;
case 2: case 2:
sharedPreferences.edit().putString(Gamepad.pref_player2, null) sharedPreferences.edit().putString(Gamepad.pref_player2, null).apply();
.commit();
break; break;
case 3: case 3:
sharedPreferences.edit().putString(Gamepad.pref_player3, null) sharedPreferences.edit().putString(Gamepad.pref_player3, null).apply();
.commit();
break; break;
case 4: case 4:
sharedPreferences.edit().putString(Gamepad.pref_player4, null) sharedPreferences.edit().putString(Gamepad.pref_player4, null).apply();
.commit();
break; break;
} }

View File

@ -107,9 +107,7 @@ public class InputModFragment extends Fragment {
OnCheckedChangeListener joystick_mode = new OnCheckedChangeListener() { OnCheckedChangeListener joystick_mode = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit() mPrefs.edit().putBoolean(Gamepad.pref_js_merged + player, isChecked).apply();
.putBoolean(Gamepad.pref_js_merged + player,
isChecked).commit();
} }
}; };
@ -118,9 +116,7 @@ public class InputModFragment extends Fragment {
OnCheckedChangeListener rstick_mode = new OnCheckedChangeListener() { OnCheckedChangeListener rstick_mode = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit() mPrefs.edit().putBoolean(Gamepad.pref_js_rbuttons + player, isChecked).apply();
.putBoolean(Gamepad.pref_js_rbuttons + player,
isChecked).commit();
} }
}; };
@ -129,9 +125,7 @@ public class InputModFragment extends Fragment {
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() { OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit() mPrefs.edit().putBoolean(Gamepad.pref_js_modified + player, isChecked).apply();
.putBoolean(Gamepad.pref_js_modified + player,
isChecked).commit();
} }
}; };
@ -140,9 +134,7 @@ public class InputModFragment extends Fragment {
OnCheckedChangeListener compat_mode = new OnCheckedChangeListener() { OnCheckedChangeListener compat_mode = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit() mPrefs.edit().putBoolean(Gamepad.pref_js_compat + player, isChecked).apply();
.putBoolean(Gamepad.pref_js_compat + player, isChecked)
.commit();
if (isChecked) { if (isChecked) {
selectController(); selectController();
} }
@ -469,9 +461,7 @@ public class InputModFragment extends Fragment {
}); });
builder.setOnKeyListener(new Dialog.OnKeyListener() { builder.setOnKeyListener(new Dialog.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
mPrefs.edit() mPrefs.edit().putInt("controller" + player, event.getDeviceId()).apply();
.putInt("controller" + player, event.getDeviceId())
.commit();
dialog.dismiss(); dialog.dismiss();
return true; return true;
} }
@ -540,7 +530,7 @@ public class InputModFragment extends Fragment {
return -1; return -1;
} }
mPrefs.edit().putInt(button + player, keyCode).commit(); mPrefs.edit().putInt(button + player, keyCode).apply();
return keyCode; return keyCode;
} }
@ -627,7 +617,7 @@ public class InputModFragment extends Fragment {
} }
private void remKeyCode(final String button, TextView output) { private void remKeyCode(final String button, TextView output) {
mPrefs.edit().remove(button + player).commit(); mPrefs.edit().remove(button + player).apply();
getKeyCode(button, output); getKeyCode(button, output);
} }
} }

View File

@ -119,7 +119,7 @@ public class OptionsFragment extends Fragment {
mainBrowse.setOnClickListener(new View.OnClickListener() { mainBrowse.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
mPrefs.edit().remove(Config.pref_home).commit(); mPrefs.edit().remove(Config.pref_home).apply();
hideSoftKeyBoard(); hideSoftKeyBoard();
mCallback.onMainBrowseSelected(home_directory, false); mCallback.onMainBrowseSelected(home_directory, false);
} }
@ -134,8 +134,7 @@ public class OptionsFragment extends Fragment {
Toast.makeText(getActivity(), R.string.data_folder, Toast.makeText(getActivity(), R.string.data_folder,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
mPrefs.edit().putString(Config.pref_home, home_directory) mPrefs.edit().putString(Config.pref_home, home_directory).apply();
.commit();
JNIdc.config(home_directory); JNIdc.config(home_directory);
new LocateThemes().execute(home_directory + "/themes"); new LocateThemes().execute(home_directory + "/themes");
} }
@ -152,7 +151,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_usereios, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_usereios, isChecked).apply();
} }
}; };
CompoundButton reios_opt = (CompoundButton) getView().findViewById( CompoundButton reios_opt = (CompoundButton) getView().findViewById(
@ -164,7 +163,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Config.pref_gamedetails, isChecked).commit(); mPrefs.edit().putBoolean(Config.pref_gamedetails, isChecked).apply();
if (!isChecked) { if (!isChecked) {
File dir = new File(getActivity().getExternalFilesDir(null), "images"); File dir = new File(getActivity().getExternalFilesDir(null), "images");
for (File file : dir.listFiles()) { for (File file : dir.listFiles()) {
@ -189,10 +188,9 @@ public class OptionsFragment extends Fragment {
gameBrowse.setOnClickListener(new View.OnClickListener() { gameBrowse.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
mPrefs.edit().remove(Config.pref_games).commit(); mPrefs.edit().remove(Config.pref_games).apply();
if (editBrowse.getText() != null) { if (editBrowse.getText() != null) {
game_directory = editGames.getText().toString(); game_directory = editGames.getText().toString();
//mPrefs.edit().putString("game_directory", game_directory).commit();
} }
hideSoftKeyBoard(); hideSoftKeyBoard();
mCallback.onMainBrowseSelected(game_directory, true); mCallback.onMainBrowseSelected(game_directory, true);
@ -203,8 +201,7 @@ public class OptionsFragment extends Fragment {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (editBrowse.getText() != null) { if (editBrowse.getText() != null) {
game_directory = editGames.getText().toString(); game_directory = editGames.getText().toString();
mPrefs.edit().putString(Config.pref_games, game_directory) mPrefs.edit().putString(Config.pref_games, game_directory).apply();
.commit();
} }
} }
@ -243,7 +240,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_nativeact, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_nativeact, isChecked).apply();
Emulator.nativeact = isChecked; Emulator.nativeact = isChecked;
} }
}; };
@ -256,7 +253,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_dynarecopt, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_dynarecopt, isChecked).apply();
Emulator.dynarecopt = isChecked; Emulator.dynarecopt = isChecked;
} }
}; };
@ -269,7 +266,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_unstable, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_unstable, isChecked).apply();
Emulator.unstableopt = isChecked; Emulator.unstableopt = isChecked;
} }
}; };
@ -298,7 +295,7 @@ public class OptionsFragment extends Fragment {
public void onItemSelected(AdapterView<?> parent, View view, public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) { int pos, long id) {
mPrefs.edit().putInt(Emulator.pref_cable, pos + 1).commit(); mPrefs.edit().putInt(Emulator.pref_cable, pos + 1).apply();
Emulator.cable = pos + 1; Emulator.cable = pos + 1;
} }
@ -321,7 +318,7 @@ public class OptionsFragment extends Fragment {
region_spnr.setSelection(Emulator.dcregion, true); region_spnr.setSelection(Emulator.dcregion, true);
region_spnr.setOnItemSelectedListener(new OnItemSelectedListener() { region_spnr.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
mPrefs.edit().putInt(Emulator.pref_dcregion, pos).commit(); mPrefs.edit().putInt(Emulator.pref_dcregion, pos).apply();
Emulator.dcregion = pos; Emulator.dcregion = pos;
} }
@ -351,9 +348,7 @@ public class OptionsFragment extends Fragment {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String item = parent.getItemAtPosition(pos).toString(); String item = parent.getItemAtPosition(pos).toString();
String selection = item.substring(0, item.indexOf(" - ")); String selection = item.substring(0, item.indexOf(" - "));
mPrefs.edit() mPrefs.edit().putInt(Emulator.pref_broadcast, Integer.parseInt(selection)).apply();
.putInt(Emulator.pref_broadcast, Integer.parseInt(selection))
.commit();
Emulator.broadcast = Integer.parseInt(selection); Emulator.broadcast = Integer.parseInt(selection);
} }
@ -366,7 +361,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener limitfps_option = new OnCheckedChangeListener() { OnCheckedChangeListener limitfps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_limitfps, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_limitfps, isChecked).apply();
Emulator.limitfps = isChecked; Emulator.limitfps = isChecked;
} }
}; };
@ -377,7 +372,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener mipmaps_option = new OnCheckedChangeListener() { OnCheckedChangeListener mipmaps_option = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_mipmaps, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_mipmaps, isChecked).apply();
Emulator.mipmaps = isChecked; Emulator.mipmaps = isChecked;
} }
}; };
@ -388,7 +383,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener full_screen = new OnCheckedChangeListener() { OnCheckedChangeListener full_screen = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_widescreen, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_widescreen, isChecked).apply();
Emulator.widescreen = isChecked; Emulator.widescreen = isChecked;
} }
}; };
@ -413,7 +408,7 @@ public class OptionsFragment extends Fragment {
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress(); int progress = seekBar.getProgress();
mPrefs.edit().putInt(Emulator.pref_frameskip, progress).commit(); mPrefs.edit().putInt(Emulator.pref_frameskip, progress).apply();
Emulator.frameskip = progress; Emulator.frameskip = progress;
} }
}); });
@ -423,7 +418,7 @@ public class OptionsFragment extends Fragment {
if (frameText != null) { if (frameText != null) {
int frames = Integer.parseInt(frameText); int frames = Integer.parseInt(frameText);
frameSeek.setProgress(frames); frameSeek.setProgress(frames);
mPrefs.edit().putInt(Emulator.pref_frameskip, frames).commit(); mPrefs.edit().putInt(Emulator.pref_frameskip, frames).apply();
Emulator.frameskip = frames; Emulator.frameskip = frames;
} }
} }
@ -438,7 +433,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener pvr_rendering = new OnCheckedChangeListener() { OnCheckedChangeListener pvr_rendering = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_pvrrender, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_pvrrender, isChecked).apply();
Emulator.pvrrender = isChecked; Emulator.pvrrender = isChecked;
} }
}; };
@ -448,7 +443,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener synchronous = new OnCheckedChangeListener() { OnCheckedChangeListener synchronous = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_syncedrender, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_syncedrender, isChecked).apply();
Emulator.syncedrender = isChecked; Emulator.syncedrender = isChecked;
} }
}; };
@ -475,7 +470,7 @@ public class OptionsFragment extends Fragment {
} else { } else {
cheatEdit.setText(disk); cheatEdit.setText(disk);
} }
mPrefs.edit().putString(Emulator.pref_cheatdisk, disk).commit(); mPrefs.edit().putString(Emulator.pref_cheatdisk, disk).apply();
Emulator.cheatdisk = disk; Emulator.cheatdisk = disk;
} }
} }
@ -492,7 +487,7 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
mPrefs.edit().putBoolean(Config.pref_showfps, isChecked).commit(); mPrefs.edit().putBoolean(Config.pref_showfps, isChecked).apply();
} }
}; };
boolean counter = mPrefs.getBoolean(Config.pref_showfps, false); boolean counter = mPrefs.getBoolean(Config.pref_showfps, false);
@ -504,7 +499,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener force_gpu_options = new OnCheckedChangeListener() { OnCheckedChangeListener force_gpu_options = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Config.pref_forcegpu, isChecked).commit(); mPrefs.edit().putBoolean(Config.pref_forcegpu, isChecked).apply();
} }
}; };
boolean enhanced = mPrefs.getBoolean(Config.pref_forcegpu, true); boolean enhanced = mPrefs.getBoolean(Config.pref_forcegpu, true);
@ -520,14 +515,13 @@ public class OptionsFragment extends Fragment {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit() mPrefs.edit()
.putInt(Config.pref_rendertype, .putInt(Config.pref_rendertype, isChecked
isChecked ? GL2JNIView.LAYER_TYPE_SOFTWARE ? GL2JNIView.LAYER_TYPE_SOFTWARE : GL2JNIView.LAYER_TYPE_HARDWARE
: GL2JNIView.LAYER_TYPE_HARDWARE) ).apply();
.commit();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (isChecked) { if (isChecked) {
force_gpu_opt.setEnabled(false); force_gpu_opt.setEnabled(false);
mPrefs.edit().putBoolean(Config.pref_forcegpu, false).commit(); mPrefs.edit().putBoolean(Config.pref_forcegpu, false).apply();
} else { } else {
force_gpu_opt.setEnabled(true); force_gpu_opt.setEnabled(true);
} }
@ -542,7 +536,7 @@ public class OptionsFragment extends Fragment {
OnCheckedChangeListener emu_sound = new OnCheckedChangeListener() { OnCheckedChangeListener emu_sound = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPrefs.edit().putBoolean(Emulator.pref_nosound, isChecked).commit(); mPrefs.edit().putBoolean(Emulator.pref_nosound, isChecked).apply();
Emulator.nosound = isChecked; Emulator.nosound = isChecked;
} }
}; };
@ -565,7 +559,7 @@ public class OptionsFragment extends Fragment {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int render = Integer.parseInt(parent.getItemAtPosition(pos).toString()); int render = Integer.parseInt(parent.getItemAtPosition(pos).toString());
mPrefs.edit().putInt(Config.pref_renderdepth, render).commit(); mPrefs.edit().putInt(Config.pref_renderdepth, render).apply();
} }
public void onNothingSelected(AdapterView<?> arg0) { public void onNothingSelected(AdapterView<?> arg0) {
@ -617,10 +611,10 @@ public class OptionsFragment extends Fragment {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
String theme = String.valueOf(parentView.getItemAtPosition(position)); String theme = String.valueOf(parentView.getItemAtPosition(position));
if (theme.equals("None")) { if (theme.equals("None")) {
mPrefs.edit().remove(Config.pref_theme).commit(); mPrefs.edit().remove(Config.pref_theme).apply();
} else { } else {
String theme_path = home_directory + "/themes/" + theme; String theme_path = home_directory + "/themes/" + theme;
mPrefs.edit().putString(Config.pref_theme, theme_path).commit(); mPrefs.edit().putString(Config.pref_theme, theme_path).apply();
} }
} }
@Override @Override
@ -654,6 +648,6 @@ public class OptionsFragment extends Fragment {
} }
local.renameTo(flash); local.renameTo(flash);
} }
mPrefs.edit().putString("localized", localized).commit(); mPrefs.edit().putString("localized", localized).apply();
} }
} }

View File

@ -52,12 +52,30 @@ public class VJoy {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return new float[][] { return new float[][] {
// x-shift, y-shift, sizing-factor // x-shift, y-shift, sizing-factor
new float[] { prefs.getFloat("touch_x_shift_dpad", 0), prefs.getFloat("touch_y_shift_dpad", 0), prefs.getFloat("touch_scale_dpad", 1) }, // DPAD new float[] { prefs.getFloat("touch_x_shift_dpad", 0),
new float[] { prefs.getFloat("touch_x_shift_buttons", 0), prefs.getFloat("touch_y_shift_buttons", 0), prefs.getFloat("touch_scale_buttons", 1) }, // X, Y, B, A Buttons prefs.getFloat("touch_y_shift_dpad", 0),
new float[] { prefs.getFloat("touch_x_shift_start", 0), prefs.getFloat("touch_y_shift_start", 0), prefs.getFloat("touch_scale_start", 1) }, // Start prefs.getFloat("touch_scale_dpad", 1)
new float[] { prefs.getFloat("touch_x_shift_left_trigger", 0), prefs.getFloat("touch_y_shift_left_trigger", 0), prefs.getFloat("touch_scale_left_trigger", 1) }, // Left Trigger }, // DPAD
new float[] { prefs.getFloat("touch_x_shift_right_trigger", 0), prefs.getFloat("touch_y_shift_right_trigger", 0), prefs.getFloat("touch_scale_right_trigger", 1) }, // Right Trigger new float[] { prefs.getFloat("touch_x_shift_buttons", 0),
new float[] { prefs.getFloat("touch_x_shift_analog", 0), prefs.getFloat("touch_y_shift_analog", 0), prefs.getFloat("touch_scale_analog", 1) } // Analog Stick prefs.getFloat("touch_y_shift_buttons", 0),
prefs.getFloat("touch_scale_buttons", 1)
}, // X, Y, B, A Buttons
new float[] { prefs.getFloat("touch_x_shift_start", 0),
prefs.getFloat("touch_y_shift_start", 0),
prefs.getFloat("touch_scale_start", 1)
}, // Start
new float[] { prefs.getFloat("touch_x_shift_left_trigger", 0),
prefs.getFloat("touch_y_shift_left_trigger", 0),
prefs.getFloat("touch_scale_left_trigger", 1)
}, // Left Trigger
new float[] { prefs.getFloat("touch_x_shift_right_trigger", 0),
prefs.getFloat("touch_y_shift_right_trigger", 0),
prefs.getFloat("touch_scale_right_trigger", 1)
}, // Right Trigger
new float[] { prefs.getFloat("touch_x_shift_analog", 0),
prefs.getFloat("touch_y_shift_analog", 0),
prefs.getFloat("touch_scale_analog", 1)
} // Analog Stick
}; };
} }
@ -91,56 +109,56 @@ public class VJoy {
public static void writeCustomVjoyValues(float[][] vjoy_d_custom, Context context) { public static void writeCustomVjoyValues(float[][] vjoy_d_custom, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putFloat("touch_x_shift_dpad", vjoy_d_custom[0][0]).commit(); prefs.edit().putFloat("touch_x_shift_dpad", vjoy_d_custom[0][0]).apply();
prefs.edit().putFloat("touch_y_shift_dpad", vjoy_d_custom[0][1]).commit(); prefs.edit().putFloat("touch_y_shift_dpad", vjoy_d_custom[0][1]).apply();
prefs.edit().putFloat("touch_scale_dpad", vjoy_d_custom[0][2]).commit(); prefs.edit().putFloat("touch_scale_dpad", vjoy_d_custom[0][2]).apply();
prefs.edit().putFloat("touch_x_shift_buttons", vjoy_d_custom[1][0]).commit(); prefs.edit().putFloat("touch_x_shift_buttons", vjoy_d_custom[1][0]).apply();
prefs.edit().putFloat("touch_y_shift_buttons", vjoy_d_custom[1][1]).commit(); prefs.edit().putFloat("touch_y_shift_buttons", vjoy_d_custom[1][1]).apply();
prefs.edit().putFloat("touch_scale_buttons", vjoy_d_custom[1][2]).commit(); prefs.edit().putFloat("touch_scale_buttons", vjoy_d_custom[1][2]).apply();
prefs.edit().putFloat("touch_x_shift_start", vjoy_d_custom[2][0]).commit(); prefs.edit().putFloat("touch_x_shift_start", vjoy_d_custom[2][0]).apply();
prefs.edit().putFloat("touch_y_shift_start", vjoy_d_custom[2][1]).commit(); prefs.edit().putFloat("touch_y_shift_start", vjoy_d_custom[2][1]).apply();
prefs.edit().putFloat("touch_scale_start", vjoy_d_custom[2][2]).commit(); prefs.edit().putFloat("touch_scale_start", vjoy_d_custom[2][2]).apply();
prefs.edit().putFloat("touch_x_shift_left_trigger", vjoy_d_custom[3][0]).commit(); prefs.edit().putFloat("touch_x_shift_left_trigger", vjoy_d_custom[3][0]).apply();
prefs.edit().putFloat("touch_y_shift_left_trigger", vjoy_d_custom[3][1]).commit(); prefs.edit().putFloat("touch_y_shift_left_trigger", vjoy_d_custom[3][1]).apply();
prefs.edit().putFloat("touch_scale_left_trigger", vjoy_d_custom[3][2]).commit(); prefs.edit().putFloat("touch_scale_left_trigger", vjoy_d_custom[3][2]).apply();
prefs.edit().putFloat("touch_x_shift_right_trigger", vjoy_d_custom[4][0]).commit(); prefs.edit().putFloat("touch_x_shift_right_trigger", vjoy_d_custom[4][0]).apply();
prefs.edit().putFloat("touch_y_shift_right_trigger", vjoy_d_custom[4][1]).commit(); prefs.edit().putFloat("touch_y_shift_right_trigger", vjoy_d_custom[4][1]).apply();
prefs.edit().putFloat("touch_scale_right_trigger", vjoy_d_custom[4][2]).commit(); prefs.edit().putFloat("touch_scale_right_trigger", vjoy_d_custom[4][2]).apply();
prefs.edit().putFloat("touch_x_shift_analog", vjoy_d_custom[5][0]).commit(); prefs.edit().putFloat("touch_x_shift_analog", vjoy_d_custom[5][0]).apply();
prefs.edit().putFloat("touch_y_shift_analog", vjoy_d_custom[5][1]).commit(); prefs.edit().putFloat("touch_y_shift_analog", vjoy_d_custom[5][1]).apply();
prefs.edit().putFloat("touch_scale_analog", vjoy_d_custom[5][2]).commit(); prefs.edit().putFloat("touch_scale_analog", vjoy_d_custom[5][2]).apply();
} }
public static void resetCustomVjoyValues(Context context) { public static void resetCustomVjoyValues(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().remove("touch_x_shift_dpad").commit(); prefs.edit().remove("touch_x_shift_dpad").apply();
prefs.edit().remove("touch_y_shift_dpad").commit(); prefs.edit().remove("touch_y_shift_dpad").apply();
prefs.edit().remove("touch_scale_dpad").commit(); prefs.edit().remove("touch_scale_dpad").apply();
prefs.edit().remove("touch_x_shift_buttons").commit(); prefs.edit().remove("touch_x_shift_buttons").apply();
prefs.edit().remove("touch_y_shift_buttons").commit(); prefs.edit().remove("touch_y_shift_buttons").apply();
prefs.edit().remove("touch_scale_buttons").commit(); prefs.edit().remove("touch_scale_buttons").apply();
prefs.edit().remove("touch_x_shift_start").commit(); prefs.edit().remove("touch_x_shift_start").apply();
prefs.edit().remove("touch_y_shift_start").commit(); prefs.edit().remove("touch_y_shift_start").apply();
prefs.edit().remove("touch_scale_start").commit(); prefs.edit().remove("touch_scale_start").apply();
prefs.edit().remove("touch_x_shift_left_trigger").commit(); prefs.edit().remove("touch_x_shift_left_trigger").apply();
prefs.edit().remove("touch_y_shift_left_trigger").commit(); prefs.edit().remove("touch_y_shift_left_trigger").apply();
prefs.edit().remove("touch_scale_left_trigger").commit(); prefs.edit().remove("touch_scale_left_trigger").apply();
prefs.edit().remove("touch_x_shift_right_trigger").commit(); prefs.edit().remove("touch_x_shift_right_trigger").apply();
prefs.edit().remove("touch_y_shift_right_trigger").commit(); prefs.edit().remove("touch_y_shift_right_trigger").apply();
prefs.edit().remove("touch_scale_right_trigger").commit(); prefs.edit().remove("touch_scale_right_trigger").apply();
prefs.edit().remove("touch_x_shift_analog").commit(); prefs.edit().remove("touch_x_shift_analog").apply();
prefs.edit().remove("touch_y_shift_analog").commit(); prefs.edit().remove("touch_y_shift_analog").apply();
prefs.edit().remove("touch_scale_analog").commit(); prefs.edit().remove("touch_scale_analog").apply();
} }
} }