</intent-filter>
</activity>
<activity
- android:name=".ShisenShoOptionsActivity"
+ android:name=".SettingsActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="de.cwde.shisensho.SETTINGS"/>
--- /dev/null
+*
+!.gitignore
+++ /dev/null
-<?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>
+++ /dev/null
-<?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>
<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>
</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>
--- /dev/null
+<?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
--- /dev/null
+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, ""));
+ }
+ }
+}
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 {
@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;
package de.cwde.shisensho;
-import de.cwde.shisensho.R;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
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;
@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,
+++ /dev/null
-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();
- }
-
-}
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;
surfaceHolder.addCallback(this);
}
+ public ShisenShoView(Context ctx) {
+ super((Context)ctx);
+ // silence lint?
+ }
+
private void paint(StatePaint pstate) {
this.pstate=pstate;
repaint();
}
}
+ @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));
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
}
*/
-}
\ No newline at end of file
+}