[Android] Decouple Dolphin.ini config file saving from GameListActivity. It doesn't make sense to save the config AFTER control is returned from PrefsFragment to GameListActivity, since the main purpose of PrefsFragment is to handle the user settings. So, instead, we call SaveConfigToDolphinIni() in the PrefsFragment.onDestroy() method. This way, when the PrefsFragment object is being 'destroyed', it will write the settings to the ini.

This commit is contained in:
Lioncash 2013-08-19 21:56:13 -04:00
parent a87b967cde
commit 8dc0b38f00
3 changed files with 71 additions and 14 deletions

View File

@ -106,19 +106,6 @@ public final class GameListActivity extends Activity
case 1:
recreateFragment();
break;
// Settings
case 2:
{
// Saves the settings that the user has set in the settings menu to the Dolphin ini files.
// This is done so that changes can be reflected when the emulator is run next.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUCore", prefs.getString("cpuCorePref", ""));
NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUThread", prefs.getBoolean("dualCorePref", true) ? "True" : "False");
NativeLibrary.SetConfig("Dolphin.ini", "Core", "GFXBackend", prefs.getString("gpuPref", ""));
}
break;
case 3: // Gamepad settings
{
@ -137,6 +124,7 @@ public final class GameListActivity extends Activity
break;
case 0: // Game List
case 2: // Settings
case 4: // About
/* Do Nothing */
break;

View File

@ -5,7 +5,6 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceFragment;
import javax.microedition.khronos.egl.*;
import javax.microedition.khronos.opengles.GL10;
@ -203,4 +202,15 @@ public final class PrefsFragment extends PreferenceFragment
+ " must implement OnGameListZeroListener");
}
}
@Override
public void onDestroy()
{
super.onDestroy();
// When the fragment is done being used, save the settings
// to the Dolphin ini file.
UserPreferences userPrefs = new UserPreferences(m_activity);
userPrefs.SaveConfigToDolphinIni();
}
}

View File

@ -0,0 +1,59 @@
package org.dolphinemu.dolphinemu;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
/**
* A class that retrieves all of the set user preferences in Android, in a safe way.
* <p>
* If any preferences are added to this emulator, an accessor for that preference
* should be added here. This way lengthy calls to getters from SharedPreferences
* aren't made necessary.
*/
public final class UserPreferences
{
// The cached shared preferences.
private final SharedPreferences mPrefs;
// Whether or not the user is using dual core.
private final boolean isUsingDualCore;
// The current CPU core being used.
private final String currentEmuCore;
// The current video back-end being used.
private final String currentVideoBackend;
/**
* Constructor
*
* @param ctx The context to use an instance of this class in.
* This allows the class to retrieve the SharedPreferences
* instance from the given context, which, in turn allows
* this class to function for its intended purpose.
*/
public UserPreferences(Context ctx)
{
// Get an instance of all of our stored preferences.
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
//-- Assign to the variables to cache the settings. --//
this.isUsingDualCore = mPrefs.getBoolean("dualCorePref", true);
// Fall back to interpreter if it somehow can't find a CPU core.
this.currentEmuCore = mPrefs.getString("cpuCorePref", "0");
// Fall back to using software rendering if another valid backend can't be found.
this.currentVideoBackend = mPrefs.getString("gpuPref", "Software Renderer");
}
/** Writes the config to the Dolphin ini file. */
public void SaveConfigToDolphinIni()
{
NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUCore", currentEmuCore);
NativeLibrary.SetConfig("Dolphin.ini", "Core", "CPUThread", isUsingDualCore ? "True" : "False");
NativeLibrary.SetConfig("Dolphin.ini", "Core", "GFXBackend", currentVideoBackend);
}
}