X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/blobdiff_plain/e1331c9ca833e2bcb07e8b3ad26c8c2394d279de..a8ebc47081a14b3af3e22e3e6123a81e938e79ab:/src/de/cwde/freeshisen/ShisenSho.java diff --git a/src/de/cwde/freeshisen/ShisenSho.java b/src/de/cwde/freeshisen/ShisenSho.java index f32fa70..f24f0c0 100644 --- a/src/de/cwde/freeshisen/ShisenSho.java +++ b/src/de/cwde/freeshisen/ShisenSho.java @@ -18,32 +18,28 @@ public class ShisenSho extends Application { public boolean gravity=true; public boolean timeCounter=true; - public static void log(String msg) { - Log.w("ShisenSho", msg); - } - public void newPlay() { + loadOptions(); board = new Board(); board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity); } public void setSize(int s) { + size = s; + switch (s) { case 1: - size=1; - boardSize[0]=6+2; - boardSize[1]=8+2; + boardSize[0] = 6 + 2; + boardSize[1] = 8 + 2; break; case 2: - size=2; - boardSize[0]=6+2; - boardSize[1]=12+2; + boardSize[0] = 6 + 2; + boardSize[1] = 12 + 2; break; case 3: default: - size=3; - boardSize[0]=6+2; - boardSize[1]=16+2; + boardSize[0] = 6 + 2; + boardSize[1] = 16 + 2; break; } } @@ -73,48 +69,61 @@ public class ShisenSho extends Application { public void onCreate() { super.onCreate(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - setOptions(); + Log.d("ShisenSho", "starting up..."); + loadOptions(); + } + + private void loadOptions() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + + // FIXME: handle NumberFormatException here? + setSize(Integer.parseInt(sp.getString("pref_size", "1"))); + difficulty = Integer.parseInt(sp.getString("pref_diff", "1")); + gravity = sp.getBoolean("pref_grav", true); + timeCounter = sp.getBoolean("pref_time", true); + tilesetid = sp.getString("pref_tile", ""); } - public void setOptions() { - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + public void checkForChangedOptions() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); // FIXME: handle NumberFormatException here? - int size = Integer.parseInt(sharedPref.getString("pref_size", "1")); - int difficulty = Integer.parseInt(sharedPref.getString("pref_diff", "1")); - boolean gravity = sharedPref.getBoolean("pref_grav", true); - boolean timeCounter = sharedPref.getBoolean("pref_time", true); - String tilesetid = sharedPref.getString("pref_tile", ""); + int size = Integer.parseInt(sp.getString("pref_size", "1")); + int difficulty = Integer.parseInt(sp.getString("pref_diff", "1")); + boolean gravity = sp.getBoolean("pref_grav", true); + boolean timeCounter = sp.getBoolean("pref_time", true); + String tilesetid = sp.getString("pref_tile", ""); boolean needsReset = false; if (size != this.size) { - setSize(size); needsReset = true; } if (difficulty != this.difficulty) { - this.difficulty = difficulty; needsReset = true; } if (gravity != this.gravity) { - this.gravity = gravity; needsReset = true; } - if ((timeCounter != this.timeCounter) && (view != null)) { - this.timeCounter = timeCounter; - view.onTimeCounterActivate(); + if (timeCounter != this.timeCounter) { + needsReset = true; } if ((tilesetid != this.tilesetid) && (view != null)) { + // tileset can be changed without a reset this.tilesetid = tilesetid; view.loadTileset(); } - if (needsReset && (view != null)) { - view.reset(); + if (needsReset) { + if ((view != null) && (activity != null)) { + activity.onOptionsChanged(); + } else { + Log.d("ShisenSho", "Preferences changed, but no view or activity online - huh?"); + } } }