From: gitknilch Date: Sun, 24 Feb 2013 20:13:19 +0000 (+0100) Subject: try to use the andriod way of Preferences and ruin everything[tm] X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/commitdiff_plain/42aa846accf450791edf0b254db044867179eb41 try to use the andriod way of Preferences and ruin everything[tm] --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a517c81..d197126 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/gen/.gitignore b/gen/.gitignore new file mode 100644 index 0000000..7673daa --- /dev/null +++ b/gen/.gitignore @@ -0,0 +1 @@ +de diff --git a/res/drawable-mdpi/icon.png b/res/drawable-mdpi/icon.png new file mode 100644 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 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 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 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 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 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 index 3a5f117..0000000 --- a/res/layout/main.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - diff --git a/res/layout/options.xml b/res/layout/options.xml deleted file mode 100644 index 1c1352f..0000000 --- a/res/layout/options.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/values/arrays.xml b/res/values/arrays.xml index d24dbe9..14a60b4 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -9,5 +9,14 @@ Easy Hard + + + 21 + + + 1 + 2 + 3 + diff --git a/res/values/strings.xml b/res/values/strings.xml index 4b0535b..ba7f9f8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -17,8 +17,8 @@ Get the source code: TODO Size Difficulty - Size: - Difficulty: - Gravity: - Time counter: + 2 + 1 + Time Counter + Gravity diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml new file mode 100644 index 0000000..327f350 --- /dev/null +++ b/res/xml/preferences.xml @@ -0,0 +1,23 @@ + + + + + + + \ 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 index 0000000..f2ceaa2 --- /dev/null +++ b/src/de/cwde/shisensho/SettingsActivity.java @@ -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, "")); + } + } +} diff --git a/src/de/cwde/shisensho/ShisenSho.java b/src/de/cwde/shisensho/ShisenSho.java index 8fe7d30..654e4e0 100644 --- a/src/de/cwde/shisensho/ShisenSho.java +++ b/src/de/cwde/shisensho/ShisenSho.java @@ -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; diff --git a/src/de/cwde/shisensho/ShisenShoActivity.java b/src/de/cwde/shisensho/ShisenShoActivity.java index b87979f..8ba59af 100644 --- a/src/de/cwde/shisensho/ShisenShoActivity.java +++ b/src/de/cwde/shisensho/ShisenShoActivity.java @@ -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 index 9d3ecbb..0000000 --- a/src/de/cwde/shisensho/ShisenShoOptionsActivity.java +++ /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 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(); - } - -} diff --git a/src/de/cwde/shisensho/ShisenShoView.java b/src/de/cwde/shisensho/ShisenShoView.java index cb1a57c..48d16cb 100644 --- a/src/de/cwde/shisensho/ShisenShoView.java +++ b/src/de/cwde/shisensho/ShisenShoView.java @@ -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 +}