1 package de
.cwde
.freeshisen
;
3 import android
.app
.Application
;
4 import android
.content
.SharedPreferences
;
5 import android
.preference
.PreferenceManager
;
6 import android
.util
.Log
;
8 public class ShisenSho
extends Application
{
9 private static ShisenSho instance
= null;
10 private ShisenShoView view
= null;
11 public ShisenShoActivity activity
= null;
14 public int[] boardSize
=new int[2];
15 public int difficulty
=1; // 1=Easy, 2=Hard
16 public int size
=3; // 1=Small, 2=Medium, 3=Big
17 public String tilesetid
= "classic";
18 public boolean gravity
=true;
19 public boolean timeCounter
=true;
21 public void newPlay() {
24 board
.buildRandomBoard(boardSize
[0],boardSize
[1],difficulty
,gravity
);
27 public void setSize(int s
) {
37 boardSize
[1] = 12 + 2;
42 boardSize
[1] = 16 + 2;
47 public void sleep(int deciSeconds
) {
49 Thread
.sleep(deciSeconds
*100);
50 } catch (InterruptedException e
) { }
58 public static synchronized ShisenSho
app() {
62 public ShisenShoView
getView() {
63 if (view
== null) view
= new ShisenShoView(this);
67 /** Called when the activity is first created. */
69 public void onCreate() {
71 PreferenceManager
.setDefaultValues(this, R
.xml
.preferences
, false);
72 Log
.d("ShisenSho", "starting up...");
76 private void loadOptions() {
77 SharedPreferences sp
= PreferenceManager
.getDefaultSharedPreferences(this);
79 // FIXME: handle NumberFormatException here?
80 setSize(Integer
.parseInt(sp
.getString("pref_size", "1")));
81 difficulty
= Integer
.parseInt(sp
.getString("pref_diff", "1"));
82 gravity
= sp
.getBoolean("pref_grav", true);
83 timeCounter
= sp
.getBoolean("pref_time", true);
84 tilesetid
= sp
.getString("pref_tile", "");
87 public void checkForChangedOptions() {
88 SharedPreferences sp
= PreferenceManager
.getDefaultSharedPreferences(this);
90 // FIXME: handle NumberFormatException here?
91 int size
= Integer
.parseInt(sp
.getString("pref_size", "1"));
92 int difficulty
= Integer
.parseInt(sp
.getString("pref_diff", "1"));
93 boolean gravity
= sp
.getBoolean("pref_grav", true);
94 boolean timeCounter
= sp
.getBoolean("pref_time", true);
95 String tilesetid
= sp
.getString("pref_tile", "");
97 boolean needsReset
= false;
99 if (size
!= this.size
) {
103 if (difficulty
!= this.difficulty
) {
107 if (gravity
!= this.gravity
) {
111 if (timeCounter
!= this.timeCounter
) {
115 if ((tilesetid
!= this.tilesetid
) && (view
!= null)) {
116 // tileset can be changed without a reset
117 this.tilesetid
= tilesetid
;
122 if ((view
!= null) && (activity
!= null)) {
123 activity
.onOptionsChanged();
125 Log
.d("ShisenSho", "Preferences changed, but no view or activity online - huh?");