]> git.zerfleddert.de Git - FreeShisen/commitdiff
try to use the andriod way of Preferences and ruin everything[tm]
authorgitknilch <gitknilch@cwde.de>
Sun, 24 Feb 2013 20:13:19 +0000 (21:13 +0100)
committergitknilch <gitknilch@cwde.de>
Sun, 24 Feb 2013 20:13:19 +0000 (21:13 +0100)
19 files changed:
AndroidManifest.xml
bin/.gitignore [new file with mode: 0644]
gen/.gitignore [new file with mode: 0644]
res/drawable-mdpi/icon.png [new file with mode: 0644]
res/drawable-mdpi/kshisen_bgnd.png [new file with mode: 0644]
res/drawable-mdpi/tileset.png [new file with mode: 0644]
res/drawable/icon.png [deleted file]
res/drawable/kshisen_bgnd.png [deleted file]
res/drawable/tileset.png [deleted file]
res/layout/main.xml [deleted file]
res/layout/options.xml [deleted file]
res/values/arrays.xml
res/values/strings.xml
res/xml/preferences.xml [new file with mode: 0644]
src/de/cwde/shisensho/SettingsActivity.java [new file with mode: 0644]
src/de/cwde/shisensho/ShisenSho.java
src/de/cwde/shisensho/ShisenShoActivity.java
src/de/cwde/shisensho/ShisenShoOptionsActivity.java [deleted file]
src/de/cwde/shisensho/ShisenShoView.java

index a517c8177a55fda23d8f830c273084c62a6a1cac..d197126c2a0952722993b111701df1ceac2a4f64 100644 (file)
@@ -16,7 +16,7 @@
                        </intent-filter>
                </activity>
                <activity 
-                   android:name=".ShisenShoOptionsActivity"
+                   android:name=".SettingsActivity"
                        android:screenOrientation="landscape">
                        <intent-filter>
                                <action android:name="de.cwde.shisensho.SETTINGS"/>
diff --git a/bin/.gitignore b/bin/.gitignore
new file mode 100644 (file)
index 0000000..d6b7ef3
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!.gitignore
diff --git a/gen/.gitignore b/gen/.gitignore
new file mode 100644 (file)
index 0000000..7673daa
--- /dev/null
@@ -0,0 +1 @@
+de
diff --git a/res/drawable-mdpi/icon.png b/res/drawable-mdpi/icon.png
new file mode 100644 (file)
index 0000000..ce0bab0
Binary files /dev/null and b/res/drawable-mdpi/icon.png differ
diff --git a/res/drawable-mdpi/kshisen_bgnd.png b/res/drawable-mdpi/kshisen_bgnd.png
new file mode 100644 (file)
index 0000000..d1a7df7
Binary files /dev/null and b/res/drawable-mdpi/kshisen_bgnd.png differ
diff --git a/res/drawable-mdpi/tileset.png b/res/drawable-mdpi/tileset.png
new file mode 100644 (file)
index 0000000..b4286a7
Binary files /dev/null and b/res/drawable-mdpi/tileset.png differ
diff --git a/res/drawable/icon.png b/res/drawable/icon.png
deleted file mode 100644 (file)
index ce0bab0..0000000
Binary files a/res/drawable/icon.png and /dev/null differ
diff --git a/res/drawable/kshisen_bgnd.png b/res/drawable/kshisen_bgnd.png
deleted file mode 100644 (file)
index d1a7df7..0000000
Binary files a/res/drawable/kshisen_bgnd.png and /dev/null differ
diff --git a/res/drawable/tileset.png b/res/drawable/tileset.png
deleted file mode 100644 (file)
index b4286a7..0000000
Binary files a/res/drawable/tileset.png and /dev/null differ
diff --git a/res/layout/main.xml b/res/layout/main.xml
deleted file mode 100644 (file)
index 3a5f117..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    >
-<TextView  
-    android:layout_width="fill_parent" 
-    android:layout_height="wrap_content" 
-    android:text="@string/hello"
-    />
-</LinearLayout>
diff --git a/res/layout/options.xml b/res/layout/options.xml
deleted file mode 100644 (file)
index 1c1352f..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
-       android:id="@+id/tableLayout1" android:layout_width="fill_parent"
-       android:layout_height="wrap_content"
-       android:stretchColumns="1">
-       <TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content"
-               android:layout_width="fill_parent">
-               <TextView android:paddingLeft="5dip" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/title" android:text="@string/options" android:textSize="14pt" android:layout_marginBottom="10pt"></TextView>
-       </TableRow>
-       <TableRow android:id="@+id/tableRow2" android:layout_width="fill_parent" android:layout_height="wrap_content">
-               <TextView android:paddingLeft="5dip" android:id="@+id/sizeLabel"
-                       android:text="@string/size_label" android:textSize="8pt" android:layout_height="wrap_content" android:layout_width="fill_parent"></TextView>
-               <Spinner android:prompt="@string/size" android:layout_height="wrap_content"
-                       android:id="@+id/size" android:layout_width="fill_parent" ></Spinner>
-       </TableRow>
-       <TableRow android:id="@+id/tableRow3" android:layout_height="wrap_content"
-               android:layout_width="fill_parent">
-               <TextView android:paddingLeft="5dip" android:id="@+id/difficultyLabel"
-                       android:text="@string/difficulty_label" android:layout_width="wrap_content"
-                       android:textSize="8pt" android:layout_height="wrap_content"></TextView>
-               <Spinner android:prompt="@string/difficulty"
-                       android:layout_height="wrap_content" android:id="@+id/difficulty"
-                       android:layout_width="fill_parent" ></Spinner>
-       </TableRow>
-       <TableRow android:id="@+id/tableRow4" android:layout_height="wrap_content"
-               android:layout_width="fill_parent">
-               <TextView android:paddingLeft="5dip" android:layout_width="wrap_content"
-                       android:textSize="8pt" android:layout_height="wrap_content" android:id="@+id/gravityLabel" android:text="@string/gravity_label" android:layout_marginTop="12dp"></TextView>
-               <ToggleButton android:id="@+id/gravity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="3dp" android:layout_marginBottom="3dp"></ToggleButton>
-       </TableRow>
-       <TableRow android:id="@+id/tableRow5" android:layout_height="wrap_content"
-               android:layout_width="fill_parent">
-               <TextView android:paddingLeft="5dip" android:layout_width="wrap_content"
-                       android:textSize="8pt" android:layout_height="wrap_content" android:id="@+id/timeCounterLabel" android:text="@string/time_counter_label" android:layout_marginTop="12dp"></TextView>
-               <ToggleButton android:id="@+id/timeCounter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="3dp" android:layout_marginBottom="3dp"></ToggleButton>
-       </TableRow>
-</TableLayout>
index d24dbe9fa1adda417a2f0699beb865b6e37bdd3a..14a60b444af5dfb42469708eb8e8819593a21487 100644 (file)
@@ -9,5 +9,14 @@
         <item>Easy</item>
         <item>Hard</item>
     </string-array>
+    <string-array name="difficulty_values">
+        
+        <item >2</item><item>1</item>
+    </string-array>
+    <string-array name="size_values">
+        <item >1</item>
+        <item >2</item>
+        <item >3</item>
+    </string-array>
     
 </resources>
index 4b0535b40c421045910570bec436f3ed8c5e9ffe..ba7f9f8847f99c09285394e859b6d101d5c8093b 100644 (file)
@@ -17,8 +17,8 @@ Get the source code: TODO
     </string>
     <string name="size">Size</string>
     <string name="difficulty">Difficulty</string>
-    <string name="size_label">Size:</string>
-    <string name="difficulty_label">Difficulty:</string>
-    <string name="gravity_label">Gravity:</string>
-    <string name="time_counter_label">Time counter:</string>
+    <string name="size_default">2</string>
+    <string name="difficulty_default">1</string>
+    <string name="time_counter">Time Counter</string>
+    <string name="gravity">Gravity</string>
 </resources>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
new file mode 100644 (file)
index 0000000..327f350
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+    <ListPreference 
+        android:title="@string/size" 
+        android:entryValues="@array/size_values" 
+        android:key="pref_size" 
+        android:dialogTitle="@string/size" 
+        android:entries="@array/sizes" android:defaultValue="@string/size_default"/>
+    <ListPreference 
+        android:title="@string/difficulty" 
+        android:entryValues="@array/difficulty_values" 
+        android:key="pref_diff" 
+        android:dialogTitle="@string/difficulty" 
+        android:entries="@array/difficulties" android:defaultValue="@string/difficulty_default"/>
+    <CheckBoxPreference 
+        android:defaultValue="true" 
+        android:title="@string/gravity"
+        android:key="pref_grav"/>
+    <CheckBoxPreference 
+        android:defaultValue="true" 
+        android:title="@string/time_counter"
+        android:key="prev_time"/>
+</PreferenceScreen>
\ No newline at end of file
diff --git a/src/de/cwde/shisensho/SettingsActivity.java b/src/de/cwde/shisensho/SettingsActivity.java
new file mode 100644 (file)
index 0000000..f2ceaa2
--- /dev/null
@@ -0,0 +1,63 @@
+package de.cwde.shisensho;
+
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.preference.*;
+
+public class SettingsActivity extends PreferenceActivity
+    implements OnSharedPreferenceChangeListener {
+       
+       private ShisenSho app;
+       
+       private static final String KEY_PREF_DIFF = "pref_diff";
+       private static final String KEY_PREF_SIZE = "pref_size";
+       //private static final String KEY_PREF_GRAV = "pref_grav";
+       //private static final String KEY_PREF_TIME = "pref_time";
+       
+       @SuppressWarnings("deprecation")
+       @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        app = ShisenSho.app();
+        addPreferencesFromResource(R.xml.preferences);
+    }
+
+       @Override
+       public void onBackPressed() {
+               app.setOptions();
+               super.onBackPressed();
+       }
+
+       @SuppressWarnings("deprecation")
+       @Override
+       protected void onResume() {
+           super.onResume();
+           getPreferenceScreen().getSharedPreferences()
+                   .registerOnSharedPreferenceChangeListener(this);
+       }
+
+       @SuppressWarnings("deprecation")
+       @Override
+       protected void onPause() {
+           super.onPause();
+           getPreferenceScreen().getSharedPreferences()
+                   .unregisterOnSharedPreferenceChangeListener(this);
+       }
+       
+       
+    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+        if (key.equals(KEY_PREF_DIFF)) {
+            @SuppressWarnings("deprecation")
+                       Preference myPref = findPreference(key);
+            // Set summary to be the user-description for the selected value
+            myPref.setSummary(sharedPreferences.getString(key, ""));
+        }
+        if (key.equals(KEY_PREF_SIZE)) {
+            @SuppressWarnings("deprecation")
+                       Preference myPref = findPreference(key);
+            // Set summary to be the user-description for the selected value
+            myPref.setSummary(sharedPreferences.getString(key, ""));
+        }
+    }  
+}
index 8fe7d30c2db5326fbd6b4aa0c75c4f736561adf0..654e4e0f0c9f988bfdcbd2cb6cf855447cc6932a 100644 (file)
@@ -1,7 +1,8 @@
 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 {   
@@ -70,22 +71,16 @@ public class ShisenSho extends Application {
     @Override
     public void onCreate() {
         super.onCreate();
+        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
     }
     
-       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;
-       }
-
-       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;
                
index b87979f755a3e74c4640b72b44cf8948f65db61a..8ba59afe142a858ebf80fd43d469f323f14e29ed 100644 (file)
@@ -1,7 +1,5 @@
 package de.cwde.shisensho;
 
-import de.cwde.shisensho.R;
-
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.Intent;
@@ -9,6 +7,7 @@ import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.text.SpannableString;
 import android.text.util.Linkify;
 import android.view.Menu;
@@ -25,6 +24,8 @@ public class ShisenShoActivity extends Activity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        
+        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
 
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
diff --git a/src/de/cwde/shisensho/ShisenShoOptionsActivity.java b/src/de/cwde/shisensho/ShisenShoOptionsActivity.java
deleted file mode 100644 (file)
index 9d3ecbb..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-package de.cwde.shisensho;
-
-import java.io.Serializable;
-
-import de.cwde.shisensho.R;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.View;
-import android.view.Window;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.CompoundButton;
-import android.widget.Spinner;
-import android.widget.ToggleButton;
-
-public class ShisenShoOptionsActivity extends Activity {
-
-       Bundle state;
-       ShisenSho app;
-
-       private void appToState (boolean merge) {
-               String[] fields = { "size", "difficulty", "gravity", "timeCounter" };
-               Bundle options = app.getOptions();
-               if (state == null) state = new Bundle();
-               for (int i=0; i<fields.length; i++) {
-                       if (!merge || !state.containsKey(fields[i])) {
-                               state.putSerializable(fields[i], (Serializable)(options.get(fields[i])));
-                       }
-               }
-       }
-
-       /** Called when the activity is first created. */
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        requestWindowFeature(Window.FEATURE_NO_TITLE);
-        setContentView(R.layout.options);
-
-        app = ShisenSho.app();
-        state = savedInstanceState;
-        appToState(true);
-
-        Spinner s;
-        ToggleButton tb;
-        ArrayAdapter adapter;
-
-        s = (Spinner) findViewById(R.id.size);
-        adapter = ArrayAdapter.createFromResource(
-                this, R.array.sizes, android.R.layout.simple_spinner_item);
-        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-        s.setAdapter(adapter);
-        s.setSelection(state.getInt("size")-1);
-        s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
-                       public void onItemSelected(AdapterView<?> arg0, View arg1,
-                                       int pos, long arg3) {
-                               state.putInt("size", pos+1);
-                       }
-
-                       public void onNothingSelected(AdapterView<?> arg0) { }
-        });
-
-        s = (Spinner) findViewById(R.id.difficulty);
-        adapter = ArrayAdapter.createFromResource(
-                this, R.array.difficulties, android.R.layout.simple_spinner_item);
-        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-        s.setAdapter(adapter);
-        s.setSelection(2-state.getInt("difficulty"));
-        s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
-                       public void onItemSelected(AdapterView<?> arg0, View arg1,
-                                       int pos, long arg3) {
-                               state.putInt("difficulty", 2-pos);
-                       }
-
-                       public void onNothingSelected(AdapterView<?> arg0) { }
-        });
-
-        tb = (ToggleButton) findViewById(R.id.gravity);
-        tb.setChecked(state.getBoolean("gravity"));
-        tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-                       public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
-                               state.putBoolean("gravity", arg1);
-                       }
-        });
-
-        tb = (ToggleButton) findViewById(R.id.timeCounter);
-        tb.setChecked(state.getBoolean("timeCounter"));
-        tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-                       public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
-                               state.putBoolean("timeCounter", arg1);
-                       }
-        });
-    }
-
-       @Override
-       public void onBackPressed() {
-               app.setOptions(state);
-               super.onBackPressed();
-       }
-
-}
index cb1a57c17ad0421e202c12f6bfd2822f9db2af2b..48d16cb64c5c7bbbaec26a468619e28054a9198f 100644 (file)
@@ -5,8 +5,6 @@ import java.util.Locale;
 import java.util.Timer;
 import java.util.TimerTask;
 
-import de.cwde.shisensho.R;
-
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.Bitmap;
@@ -64,6 +62,11 @@ class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback {
                surfaceHolder.addCallback(this);
        }
 
+       public ShisenShoView(Context ctx) {
+               super((Context)ctx);
+               // silence lint?
+       }
+
        private void paint(StatePaint pstate) {
                this.pstate=pstate;
                repaint();
@@ -229,6 +232,7 @@ class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback {
            }
        }
 
+       @SuppressWarnings("deprecation")
        public void drawMessage(Canvas canvas, int x, int y, boolean centered, String message, String color, float textSize)  {
                Paint paint = new Paint();
                paint.setColor(Color.parseColor(color));
@@ -659,4 +663,4 @@ class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback {
                paint.setFlags(Paint.ANTI_ALIAS_FLAG);
        }
 */
-}
\ No newline at end of file
+}
Impressum, Datenschutz