public class Line {
public Line(Point a, Point b) {
- this.a=a;
- this.b=b;
- }
+ this.a=a;
+ this.b=b;
+ }
- public boolean equals(Line l) {
+ public boolean equals(Line l) {
return (a.equals(l.a) && b.equals(l.b));
- }
+ }
- public boolean isHorizontal() {
- return (a.i==b.i);
- }
+ public boolean isHorizontal() {
+ return (a.i==b.i);
+ }
- public boolean isVertical() {
- return (a.j==b.j);
- }
+ public boolean isVertical() {
+ return (a.j==b.j);
+ }
public boolean contains(Point p) {
return (p.i==a.i && p.i==b.i && p.j>=getMin().j && p.j<=getMax().j)
- || (p.j==a.j && p.j==b.j && p.i>=getMin().i && p.i<=getMax().i);
+ || (p.j==a.j && p.j==b.j && p.i>=getMin().i && p.i<=getMax().i);
}
public Point cuts(Line l) {
import android.preference.*;
public class SettingsActivity extends PreferenceActivity
- implements OnSharedPreferenceChangeListener {
-
+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) {
app = ShisenSho.app();
addPreferencesFromResource(R.xml.preferences);
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
-
+
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
updateSummary(sharedPreferences, KEY_PREF_DIFF, KEY_PREF_DIFF, R.array.difficulties);
updateSummary(sharedPreferences, KEY_PREF_SIZE, KEY_PREF_SIZE, R.array.sizes);
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
- .registerOnSharedPreferenceChangeListener(this);
+ .registerOnSharedPreferenceChangeListener(this);
}
@SuppressWarnings("deprecation")
protected void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
- .unregisterOnSharedPreferenceChangeListener(this);
+ .unregisterOnSharedPreferenceChangeListener(this);
}
-
-
+
+
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
private static ShisenSho instance = null;
private ShisenShoView view = null;
public ShisenShoActivity activity = null;
-
+
public Board board;
public int[] boardSize=new int[2];
public int difficulty=1; // 1=Easy, 2=Hard
instance = this;
setSize(size);
}
-
+
public static synchronized ShisenSho app() {
return instance;
}
-
+
public ShisenShoView getView() {
if (view == null) view = new ShisenShoView(this);
return view;
}
-
+
/** Called when the activity is first created. */
@Override
public void onCreate() {
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;
-
+
if (size != this.size) {
setSize(size);
needsReset = true;
}
-
+
if (difficulty != this.difficulty) {
this.difficulty = difficulty;
needsReset = true;
this.gravity = gravity;
needsReset = true;
}
-
+
if (timeCounter != this.timeCounter) {
this.timeCounter = timeCounter;
view.onTimeCounterActivate();
private ShisenShoView view;
/** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
+ @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,
- // WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ // WindowManager.LayoutParams.FLAG_FULLSCREEN);
- view = ShisenSho.app().getView();
- ShisenSho.app().activity = this;
- setContentView(view);
- }
+ view = ShisenSho.app().getView();
+ ShisenSho.app().activity = this;
+ setContentView(view);
+ }
@Override
protected void onDestroy() {
ViewGroup vg = (ViewGroup)(view.getParent());
vg.removeView(view);
- ShisenSho.app().activity = null;
+ ShisenSho.app().activity = null;
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.menu, menu);
- return true;
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.menu, menu);
+ return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.hint:
- case R.id.undo:
- case R.id.clean:
- return view.onOptionsItemSelected(item);
- case R.id.options:
- startActivityForResult(new Intent("de.cwde.shisensho.SETTINGS", null), 0);
- return true;
- case R.id.about:
- onAboutActivate();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.hint:
+ case R.id.undo:
+ case R.id.clean:
+ return view.onOptionsItemSelected(item);
+ case R.id.options:
+ startActivityForResult(new Intent("de.cwde.shisensho.SETTINGS", null), 0);
+ return true;
+ case R.id.about:
+ onAboutActivate();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
}
private void onAboutActivate() {
- // Try to load the a package matching the name of our own package
- PackageInfo pInfo;
+ // Try to load the a package matching the name of our own package
+ PackageInfo pInfo;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
- String aboutTitle = String.format("About %s", getString(R.string.app_name));
- String versionString = String.format("Version: %s", pInfo.versionName);
- String aboutText = getString(R.string.aboutText);
+ String aboutTitle = String.format("About %s", getString(R.string.app_name));
+ String versionString = String.format("Version: %s", pInfo.versionName);
+ String aboutText = getString(R.string.aboutText);
- // Set up the TextView
- final TextView message = new TextView(this);
- // We'll use a spannablestring to be able to make links clickable
- final SpannableString s = new SpannableString(aboutText);
+ // Set up the TextView
+ final TextView message = new TextView(this);
+ // We'll use a spannablestring to be able to make links clickable
+ final SpannableString s = new SpannableString(aboutText);
- // Set some padding
- message.setPadding(5, 5, 5, 5);
- // Set up the final string
- message.setText(versionString + "\n" + s);
- // Now linkify the text
- Linkify.addLinks(message, Linkify.ALL);
+ // Set some padding
+ message.setPadding(5, 5, 5, 5);
+ // Set up the final string
+ message.setText(versionString + "\n" + s);
+ // Now linkify the text
+ Linkify.addLinks(message, Linkify.ALL);
- new AlertDialog.Builder(this)
- .setTitle(aboutTitle)
- .setCancelable(true)
- .setIcon(R.drawable.icon)
- .setPositiveButton(getString(android.R.string.ok), null)
- .setView(message).create()
- .show();
+ new AlertDialog.Builder(this)
+ .setTitle(aboutTitle)
+ .setCancelable(true)
+ .setIcon(R.drawable.icon)
+ .setPositiveButton(getString(android.R.string.ok), null)
+ .setView(message).create()
+ .show();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
tileWidth = tileset.getWidth()/tilesetCols;
tileHeight = tileset.getHeight()/tilesetRows;
tile = new Bitmap[tilesetRows*tilesetCols];
-
+
// align to screen
Matrix matrix = new Matrix();
matrix.setScale(1.0f, 1.0f); // FIXME!
-
+
// TODO: go on.
-
+
int k=0;
for (int i=0; i<tilesetRows; i++) {
for (int j=0; j<tilesetCols; j++) {
}
};
timer=new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
- public void run() {
- timerHandler.sendEmptyMessage(Activity.RESULT_OK);
- }
- }, 0, 1000);
+ timer.scheduleAtFixedRate(new TimerTask() {
+ public void run() {
+ timerHandler.sendEmptyMessage(Activity.RESULT_OK);
+ }
+ }, 0, 1000);
timerRegistered=true;
}
private void unregisterTimer() {
if (timer==null) return; // Already unregistered
timer.cancel();
- timer = null;
+ timer = null;
timerHandler = null;
timerRegistered=false;
}
}
public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.hint:
- this.postDelayed(new Runnable() { public void run() { onHintActivate(); } }, 100);
- return true;
- case R.id.undo:
- this.postDelayed(new Runnable() { public void run() { onUndoActivate(); } }, 100);
- return true;
- case R.id.clean:
- this.postDelayed(new Runnable() { public void run() { reset(); } }, 100);
- return true;
- case R.id.options:
- return true;
- case R.id.about:
- return true;
- default:
- return false;
- }
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.hint:
+ this.postDelayed(new Runnable() { public void run() { onHintActivate(); } }, 100);
+ return true;
+ case R.id.undo:
+ this.postDelayed(new Runnable() { public void run() { onUndoActivate(); } }, 100);
+ return true;
+ case R.id.clean:
+ this.postDelayed(new Runnable() { public void run() { reset(); } }, 100);
+ return true;
+ case R.id.options:
+ return true;
+ case R.id.about:
+ return true;
+ default:
+ return false;
+ }
}
public void reset() {
private void onUpdateTime() {
paint(pstate);
- if (!(app.timeCounter && cstate!=StatePlay.GAMEOVER)) {
- unregisterTimer();
- }
+ if (!(app.timeCounter && cstate!=StatePlay.GAMEOVER)) {
+ unregisterTimer();
+ }
}
@SuppressWarnings("deprecation")
l+=30;
}
}
- */
+ */
// Double buffer dumping
// canvas.drawBitmap(buffer, 0, 0, null);
switch (cstate) {
case IDLE:
if (i>=0 &&
- i<app.board.boardSize[0] &&
- j>=0 && j<app.board.boardSize[1] &&
- app.board.board[i][j]!=0) {
+ i<app.board.boardSize[0] &&
+ j>=0 && j<app.board.boardSize[1] &&
+ app.board.board[i][j]!=0) {
selection1[0]=i;
selection1[1]=j;
paint(StatePaint.SELECTED1);
break;
case SELECTED1:
if (i>=0 && i<app.board.boardSize[0] &&
- j>=0 && j<app.board.boardSize[1] &&
- app.board.board[i][j]!=0) {
+ j>=0 && j<app.board.boardSize[1] &&
+ app.board.board[i][j]!=0) {
if (i==selection1[0] && j==selection1[1]) {
paint(StatePaint.BOARD);
control(StatePlay.IDLE);
paint.setColor(Color.parseColor("#006666"));
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
}
-*/
+ */
}