Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Decouple Dolphin.ini config file saving from GameListActivi…
…ty. 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.
  • Loading branch information
lioncash committed Aug 20, 2013
1 parent a87b967 commit 8dc0b38
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
Expand Up @@ -106,19 +106,6 @@ public void SwitchPage(int toPage)
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
{
Expand All @@ -137,6 +124,7 @@ public void SwitchPage(int toPage)
break;

case 0: // Game List
case 2: // Settings
case 4: // About
/* Do Nothing */
break;
Expand Down
12 changes: 11 additions & 1 deletion Source/Android/src/org/dolphinemu/dolphinemu/PrefsFragment.java
Expand Up @@ -5,7 +5,6 @@
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceFragment;

import javax.microedition.khronos.egl.*;
import javax.microedition.khronos.opengles.GL10;

Expand Down Expand Up @@ -203,4 +202,15 @@ public void onAttach(Activity activity)
+ " 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();
}
}
59 changes: 59 additions & 0 deletions Source/Android/src/org/dolphinemu/dolphinemu/UserPreferences.java
@@ -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);
}
}

0 comments on commit 8dc0b38

Please sign in to comment.