1 package de
.cwde
.shisensho
;
3 import java
.io
.Serializable
;
5 import de
.cwde
.shisensho
.R
;
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
;
17 public class ShisenShoOptionsActivity
extends Activity
{
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
])));
33 /** Called when the activity is first created. */
35 public void onCreate(Bundle savedInstanceState
) {
36 super.onCreate(savedInstanceState
);
37 requestWindowFeature(Window
.FEATURE_NO_TITLE
);
38 setContentView(R
.layout
.options
);
40 app
= ShisenSho
.app();
41 state
= savedInstanceState
;
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
,
57 state
.putInt("size", pos
+1);
60 public void onNothingSelected(AdapterView
<?
> arg0
) { }
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
,
72 state
.putInt("difficulty", 2-pos
);
75 public void onNothingSelected(AdapterView
<?
> arg0
) { }
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
);
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
);
96 public void onBackPressed() {
97 app
.setOptions(state
);
98 super.onBackPressed();