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 boolean gravity
=true;
18 public boolean timeCounter
=true;
20 public static void log(String msg
) {
21 Log
.w("ShisenSho", msg
);
24 public void newPlay() {
26 board
.buildRandomBoard(boardSize
[0],boardSize
[1],difficulty
,gravity
);
29 public void setSize(int s
) {
50 public void sleep(int deciSeconds
) {
52 Thread
.sleep(deciSeconds
*100);
53 } catch (InterruptedException e
) { }
61 public static synchronized ShisenSho
app() {
65 public ShisenShoView
getView() {
66 if (view
== null) view
= new ShisenShoView(this);
70 /** Called when the activity is first created. */
72 public void onCreate() {
74 PreferenceManager
.setDefaultValues(this, R
.xml
.preferences
, false);
78 public void setOptions() {
79 SharedPreferences sharedPref
= PreferenceManager
.getDefaultSharedPreferences(this);
81 // FIXME: handle NumberFormatException here?
82 int size
= Integer
.parseInt(sharedPref
.getString("pref_size", "1"));
83 int difficulty
= Integer
.parseInt(sharedPref
.getString("pref_diff", "1"));
84 boolean gravity
= sharedPref
.getBoolean("pref_grav", true);
85 boolean timeCounter
= sharedPref
.getBoolean("pref_time", true);
87 boolean needsReset
= false;
89 if (size
!= this.size
) {
94 if (difficulty
!= this.difficulty
) {
95 this.difficulty
= difficulty
;
99 if (gravity
!= this.gravity
) {
100 this.gravity
= gravity
;
104 if (timeCounter
!= this.timeCounter
) {
105 this.timeCounter
= timeCounter
;
106 view
.onTimeCounterActivate();
109 if (needsReset
&& (view
!= null)) {