diff --git a/src/com/androidemu/EmulatorActivity.java b/src/com/androidemu/EmulatorActivity.java index 497fb50..05e4f80 100644 --- a/src/com/androidemu/EmulatorActivity.java +++ b/src/com/androidemu/EmulatorActivity.java @@ -8,6 +8,8 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.net.Uri; import android.os.Bundle; import android.view.KeyEvent; @@ -31,7 +33,7 @@ import com.androidemu.wrapper.Wrapper; -public class EmulatorActivity extends GameActivity implements GameKeyListener +public class EmulatorActivity extends GameActivity implements GameKeyListener, OnSharedPreferenceChangeListener { private static final int REQUEST_BROWSE_ROM = 1; private static final int REQUEST_BROWSE_BIOS = 2; @@ -68,6 +70,8 @@ protected void onCreate(Bundle savedInstanceState) cfg = new UserPrefs(getApplicationContext()); + cfg.setHandler(this); + File datadir = getDir("data", MODE_PRIVATE); emulator = Emulator.createInstance(this, datadir); @@ -300,10 +304,6 @@ protected void onActivityResult(int request, int result, Intent data) case REQUEST_BROWSE_BIOS: loadBIOS(result == RESULT_OK ? data.getData().getPath() : null); break; - - case REQUEST_SETTINGS: - loadGlobalSettings(); - break; } } @@ -356,6 +356,8 @@ private static int getScalingMode(String mode) private void loadGlobalSettings() { + debug("reloading settings"); + emulator.setOption("autoFrameSkip", cfg.autoFrameSkip); emulator.setOption("maxFrameSkips", cfg.maxFrameSkips); @@ -575,4 +577,12 @@ private static String getGameStateFile(String name, int slot) name += ".ss" + slot; return name; } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) + { + cfg = new UserPrefs(getApplicationContext()); + + loadGlobalSettings(); + } } diff --git a/src/com/androidemu/gba/UserPrefs.java b/src/com/androidemu/gba/UserPrefs.java index 337078e..59269e8 100644 --- a/src/com/androidemu/gba/UserPrefs.java +++ b/src/com/androidemu/gba/UserPrefs.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; public class UserPrefs extends com.androidemu.persistent.UserPrefs { @@ -76,4 +77,9 @@ public void setBIOS(String bios) editor.putString("bios", bios); editor.commit(); } + + public void setHandler(OnSharedPreferenceChangeListener listener) + { + prefsData.registerOnSharedPreferenceChangeListener(listener); + } }