]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/shisensho/ShisenShoOptionsActivity.java
9d3ecbbd7144d9a33cbe8081f288b049f5b182ee
[FreeShisen] / src / de / cwde / shisensho / ShisenShoOptionsActivity.java
1 package de.cwde.shisensho;
2
3 import java.io.Serializable;
4
5 import de.cwde.shisensho.R;
6
7 import android.app.Activity;
8 import android.os.Bundle;
9 import android.view.View;
10 import android.view.Window;
11 import android.widget.AdapterView;
12 import android.widget.ArrayAdapter;
13 import android.widget.CompoundButton;
14 import android.widget.Spinner;
15 import android.widget.ToggleButton;
16
17 public class ShisenShoOptionsActivity extends Activity {
18
19 Bundle state;
20 ShisenSho app;
21
22 private void appToState (boolean merge) {
23 String[] fields = { "size", "difficulty", "gravity", "timeCounter" };
24 Bundle options = app.getOptions();
25 if (state == null) state = new Bundle();
26 for (int i=0; i<fields.length; i++) {
27 if (!merge || !state.containsKey(fields[i])) {
28 state.putSerializable(fields[i], (Serializable)(options.get(fields[i])));
29 }
30 }
31 }
32
33 /** Called when the activity is first created. */
34 @Override
35 public void onCreate(Bundle savedInstanceState) {
36 super.onCreate(savedInstanceState);
37 requestWindowFeature(Window.FEATURE_NO_TITLE);
38 setContentView(R.layout.options);
39
40 app = ShisenSho.app();
41 state = savedInstanceState;
42 appToState(true);
43
44 Spinner s;
45 ToggleButton tb;
46 ArrayAdapter adapter;
47
48 s = (Spinner) findViewById(R.id.size);
49 adapter = ArrayAdapter.createFromResource(
50 this, R.array.sizes, android.R.layout.simple_spinner_item);
51 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
52 s.setAdapter(adapter);
53 s.setSelection(state.getInt("size")-1);
54 s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
55 public void onItemSelected(AdapterView<?> arg0, View arg1,
56 int pos, long arg3) {
57 state.putInt("size", pos+1);
58 }
59
60 public void onNothingSelected(AdapterView<?> arg0) { }
61 });
62
63 s = (Spinner) findViewById(R.id.difficulty);
64 adapter = ArrayAdapter.createFromResource(
65 this, R.array.difficulties, android.R.layout.simple_spinner_item);
66 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
67 s.setAdapter(adapter);
68 s.setSelection(2-state.getInt("difficulty"));
69 s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
70 public void onItemSelected(AdapterView<?> arg0, View arg1,
71 int pos, long arg3) {
72 state.putInt("difficulty", 2-pos);
73 }
74
75 public void onNothingSelected(AdapterView<?> arg0) { }
76 });
77
78 tb = (ToggleButton) findViewById(R.id.gravity);
79 tb.setChecked(state.getBoolean("gravity"));
80 tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
81 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
82 state.putBoolean("gravity", arg1);
83 }
84 });
85
86 tb = (ToggleButton) findViewById(R.id.timeCounter);
87 tb.setChecked(state.getBoolean("timeCounter"));
88 tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
89 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
90 state.putBoolean("timeCounter", arg1);
91 }
92 });
93 }
94
95 @Override
96 public void onBackPressed() {
97 app.setOptions(state);
98 super.onBackPressed();
99 }
100
101 }
Impressum, Datenschutz