]> git.zerfleddert.de Git - FreeShisen/blobdiff - src/de/cwde/shisensho/ShisenSho.java
fix indentation
[FreeShisen] / src / de / cwde / shisensho / ShisenSho.java
index 8fe7d30c2db5326fbd6b4aa0c75c4f736561adf0..fc23d4795d1042602cac8336c13051aef3552c1c 100644 (file)
@@ -1,17 +1,18 @@
 package de.cwde.shisensho;
 
 import android.app.Application;
-import android.os.Bundle;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 import android.util.Log;
 
 public class ShisenSho extends Application {   
        private static ShisenSho instance = null; 
        private ShisenShoView view = null;
        public ShisenShoActivity activity = null;
-       
+
        public Board board;
        public int[] boardSize=new int[2];
-       public int difficulty=1; // 1=Hard, 2=Easy
+       public int difficulty=1; // 1=Easy, 2=Hard
        public int size=3; // 1=Small, 2=Medium, 3=Big
        public boolean gravity=true;
        public boolean timeCounter=true;
@@ -56,44 +57,39 @@ public class ShisenSho extends Application {
                instance = this;
                setSize(size);
        }
-       
+
        public static synchronized ShisenSho app() {
                return instance;
        }
-       
+
        public ShisenShoView getView() {
                if (view == null) view = new ShisenShoView(this);
                return view;
        }
-               
+
        /** Called when the activity is first created. */
-    @Override
-    public void onCreate() {
-        super.onCreate();
-    }
-    
-       public Bundle getOptions() {
-               Bundle options = new Bundle();
-               options.putInt("size", size);
-               options.putInt("difficulty", difficulty);
-               options.putBoolean("gravity", gravity);
-               options.putBoolean("timeCounter", timeCounter);
-               return options;
+       @Override
+       public void onCreate() {
+               super.onCreate();
+               PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
+               setOptions();
        }
 
-       public void setOptions(Bundle options) {
-               int size = options.getInt("size");
-               int difficulty = options.getInt("difficulty");
-               boolean gravity = options.getBoolean("gravity");
-               boolean timeCounter = options.getBoolean("timeCounter");
+       public void setOptions() {
+               SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+
+               int size = sharedPref.getInt("size", 1);
+               int difficulty = sharedPref.getInt("difficulty", 1);
+               boolean gravity = sharedPref.getBoolean("gravity", true);
+               boolean timeCounter = sharedPref.getBoolean("timeCounter", true);
 
                boolean needsReset = false;
-               
+
                if (size != this.size) {
                        setSize(size);
                        needsReset = true;
                }
-               
+
                if (difficulty != this.difficulty) {
                        this.difficulty = difficulty;
                        needsReset = true;
@@ -103,13 +99,13 @@ public class ShisenSho extends Application {
                        this.gravity = gravity;
                        needsReset = true;
                }
-               
+
                if (timeCounter != this.timeCounter) {
                        this.timeCounter = timeCounter;
                        view.onTimeCounterActivate();
                }
 
-               if (needsReset) {
+               if (needsReset && (view != null)) {
                        view.reset();
                }
        }
Impressum, Datenschutz