Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Fixed auto-reloading of settings (this time without onActivityResult)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-- committed Jan 17, 2013
1 parent 3e33684 commit 16493f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/com/androidemu/EmulatorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
}
6 changes: 6 additions & 0 deletions src/com/androidemu/gba/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -76,4 +77,9 @@ public void setBIOS(String bios)
editor.putString("bios", bios);
editor.commit();
}

public void setHandler(OnSharedPreferenceChangeListener listener)
{
prefsData.registerOnSharedPreferenceChangeListener(listener);
}
}

0 comments on commit 16493f8

Please sign in to comment.