Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Added shake to restart
Browse files Browse the repository at this point in the history
Added shake gesture to restart game
  • Loading branch information
marshall-davis committed Oct 27, 2013
1 parent ec59ff6 commit 4feb0b1
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 49 deletions.
9 changes: 6 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exposuresoftware.xsandos"
android:versionCode="2"
android:versionName="1.1" >
android:versionCode="6"
android:versionName="1.2" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
Expand Down
9 changes: 6 additions & 3 deletions bin/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exposuresoftware.xsandos"
android:versionCode="2"
android:versionName="1.1" >
android:versionCode="6"
android:versionName="1.2" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
Expand Down
Binary file modified bin/XsAndOs.apk
Binary file not shown.
Binary file modified bin/classes.dex
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/Game$1.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/Game$2.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/Game.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/Game2.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/MainMenu.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$drawable.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$id.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$layout.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$menu.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$string.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$style.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R$styleable.class
Binary file not shown.
Binary file modified bin/classes/com/exposuresoftware/xsandos/R.class
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
95 changes: 55 additions & 40 deletions gen/com/exposuresoftware/xsandos/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ theme attribute (in the form
*/
public static final int y=0x7f010001;
}
public static final class bool {
/** Enable automatic activity tracking
*/
public static final int ga_autoActivityTracking=0x7f060000;
/** Enable automatic exception tracking
*/
public static final int ga_reportUncaughtExceptions=0x7f060001;
}
public static final class drawable {
public static final int board_chalk=0x7f020000;
public static final int border_chalk=0x7f020001;
Expand All @@ -38,50 +46,57 @@ public static final class drawable {
public static final int vertical_line=0x7f020008;
}
public static final class id {
public static final int button_0_0=0x7f080000;
public static final int button_0_1=0x7f080001;
public static final int button_0_2=0x7f080002;
public static final int button_1_0=0x7f080003;
public static final int button_1_1=0x7f080004;
public static final int button_1_2=0x7f080005;
public static final int button_2_0=0x7f080006;
public static final int button_2_1=0x7f080007;
public static final int button_2_2=0x7f080008;
public static final int button_one_player=0x7f08000b;
public static final int button_settings=0x7f08000c;
public static final int button_two_player=0x7f08000a;
public static final int dialog_header=0x7f08000d;
public static final int dialog_message=0x7f08000e;
public static final int dialog_new_game=0x7f08000f;
public static final int dialog_title_screen=0x7f080010;
public static final int main_logo=0x7f080009;
public static final int menu_settings=0x7f080011;
public static final int button_0_0=0x7f090000;
public static final int button_0_1=0x7f090001;
public static final int button_0_2=0x7f090002;
public static final int button_1_0=0x7f090003;
public static final int button_1_1=0x7f090004;
public static final int button_1_2=0x7f090005;
public static final int button_2_0=0x7f090006;
public static final int button_2_1=0x7f090007;
public static final int button_2_2=0x7f090008;
public static final int button_one_player=0x7f09000b;
public static final int button_settings=0x7f09000c;
public static final int button_two_player=0x7f09000a;
public static final int dialog_header=0x7f09000d;
public static final int dialog_message=0x7f09000e;
public static final int dialog_new_game=0x7f09000f;
public static final int dialog_title_screen=0x7f090010;
public static final int main_logo=0x7f090009;
public static final int menu_settings=0x7f090011;
}
public static final class layout {
public static final int activity_game=0x7f030000;
public static final int activity_main_menu=0x7f030001;
public static final int dialog_base=0x7f030002;
}
public static final class menu {
public static final int activity_main_menu=0x7f070000;
public static final int activity_main_menu=0x7f080000;
}
public static final class string {
public static final int app_name=0x7f050000;
public static final int desc_board=0x7f050006;
public static final int desc_main_logo=0x7f050002;
public static final int label_activity_game=0x7f050005;
public static final int label_activity_settings=0x7f05000f;
public static final int label_button_one_player=0x7f050003;
public static final int label_button_two_player=0x7f050004;
public static final int menu_settings=0x7f050001;
public static final int msg_new_game=0x7f050009;
public static final int msg_player_one=0x7f050007;
public static final int msg_player_two=0x7f050008;
public static final int ok=0x7f05000a;
public static final int pref_key_gameplay_settings=0x7f05000e;
public static final int pref_random_start=0x7f05000c;
public static final int pref_random_start_summ=0x7f05000d;
public static final int return_to_title=0x7f05000b;
public static final int app_name=0x7f050001;
public static final int cancel=0x7f050012;
public static final int clear_board=0x7f050014;
public static final int desc_board=0x7f050007;
public static final int desc_main_logo=0x7f050003;
public static final int dialog_shake_header=0x7f050011;
/** Replace placeholder ID with your tracking ID
*/
public static final int ga_trackingId=0x7f050000;
public static final int label_activity_game=0x7f050006;
public static final int label_activity_settings=0x7f050010;
public static final int label_button_one_player=0x7f050004;
public static final int label_button_two_player=0x7f050005;
public static final int menu_settings=0x7f050002;
public static final int msg_new_game=0x7f05000a;
public static final int msg_player_one=0x7f050008;
public static final int msg_player_two=0x7f050009;
public static final int new_game=0x7f050013;
public static final int ok=0x7f05000b;
public static final int pref_key_gameplay_settings=0x7f05000f;
public static final int pref_random_start=0x7f05000d;
public static final int pref_random_start_summ=0x7f05000e;
public static final int return_to_title=0x7f05000c;
}
public static final class style {
/**
Expand All @@ -105,14 +120,14 @@ public static final class style {
API 14 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
public static final int AppBaseTheme=0x7f070000;
/** Application theme.
All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
public static final int ChalkButton=0x7f060002;
public static final int ChalkButtonNormal=0x7f060003;
public static final int CleanDialog=0x7f060004;
public static final int AppTheme=0x7f070001;
public static final int ChalkButton=0x7f070002;
public static final int ChalkButtonNormal=0x7f070003;
public static final int CleanDialog=0x7f070004;
}
public static final class xml {
public static final int preferences=0x7f040000;
Expand Down
Binary file added libs/libGoogleAnalyticsServices.jar
Binary file not shown.
12 changes: 12 additions & 0 deletions res/values/analytics.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>

<resources>
<!--Replace placeholder ID with your tracking ID-->
<string name="ga_trackingId">UA-44695784-1</string>

<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>

<!--Enable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
6 changes: 5 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<string name="pref_random_start">Random starting player</string>
<string name="pref_random_start_summ">If selected, the starting player will be selected at random for each game.</string>
<string name="pref_key_gameplay_settings">Gameplay</string>
<string name="label_activity_settings">Settings</string>
<string name="label_activity_settings">Settings</string>
<string name="dialog_shake_header">Clear the Board?</string>
<string name="cancel">Cancel</string>
<string name="new_game">Reset</string>
<string name="clear_board">Clear the board?</string>

</resources>
84 changes: 83 additions & 1 deletion src/com/exposuresoftware/xsandos/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
Expand All @@ -18,6 +21,8 @@
import android.widget.Toast;

import com.exposuresoftware.xsandos.GameBoard.Mark;
import com.google.analytics.tracking.android.EasyTracker;


public class Game extends Activity {

Expand All @@ -31,8 +36,13 @@ public class Game extends Activity {
GameBoard board = null;
int[][] buttons = new int[3][3];

private SensorManager sensorManager;
private ShakeEventListener sensorListener;

Toast toast_player_x = null, toast_player_o = null;

boolean dialog_up = false;

// TODO Add shake to clear
// TODO Move switchPlayer() out of handleButtonForSpace(View)

Expand All @@ -45,16 +55,74 @@ public void onCreate(Bundle icicle) {
solo_player = getIntent().getExtras().getBoolean("solo");
chalkduster = Typeface.createFromAsset(getAssets(),
"fonts/Chalkduster.ttf");
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensorListener = new ShakeEventListener();

sensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {

public void onShake() {
if ( !dialog_up ) {
Typeface chalkduster = Typeface.createFromAsset(getAssets(),
"fonts/Chalkduster.ttf");
final Dialog dialog = new Dialog(Game.this, R.style.CleanDialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView( R.layout.dialog_base );
dialog.setCancelable( false );
TextView title = (TextView) dialog.findViewById( R.id.dialog_header );
title.setTypeface(chalkduster);
TextView message = (TextView) dialog.findViewById(R.id.dialog_message);
message.setTypeface(chalkduster);
Button ok_button = (Button) dialog.findViewById(R.id.dialog_new_game);
Button title_button = (Button) dialog.findViewById(R.id.dialog_title_screen);
ok_button.setTypeface( chalkduster );
title_button.setTypeface(chalkduster);
// Now, change what they say!
title.setText(R.string.dialog_shake_header);
ok_button.setText(R.string.new_game);
title_button.setText(R.string.cancel);
message.setText(R.string.clear_board);
ok_button.setOnClickListener( new OnClickListener() {
public void onClick(View view) {
Log.d( TAG, "Restarting game" );
Intent intentToRestart = getIntent();
startActivity(intentToRestart);
dialog.dismiss();
finish();
}
});
title_button.setOnClickListener( new OnClickListener() {
public void onClick(View view) {
Log.d( TAG, "Shake cancelled" );
dialog_up = false;
dialog.dismiss();
}
});
dialog.show();
dialog_up = true;
}
}
});
board = new GameBoard(SIZE);
Log.d(TAG, "Game board created.");
this.toast_player_x = Toast.makeText(this, R.string.msg_player_one, Toast.LENGTH_SHORT);
this.toast_player_o = Toast.makeText(this, R.string.msg_player_two, Toast.LENGTH_SHORT);
}

@Override
public void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}

public void onResume() {
super.onResume();
Log.d( TAG, "Building button ID array" );
buildButtonIds();
// Register shake listener
sensorManager.registerListener(sensorListener,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_UI);
// TODO Make sure orientation change doesn't restart game with this!
boolean random_start = PreferenceManager.getDefaultSharedPreferences( this )
.getBoolean( "pref_key_random_start", true );
Log.d( TAG, "Random starting player: " + Boolean.toString( random_start ) );
Expand All @@ -72,6 +140,18 @@ public void onResume() {
}
}

@Override
public void onPause() {
sensorManager.unregisterListener(sensorListener);
super.onPause();
}

@Override
public void onStop() {
EasyTracker.getInstance(this).activityStop(this);
super.onStop();
}

private void buildButtonIds() {
buttons[0][0] = R.id.button_0_0;
buttons[0][1] = R.id.button_0_1;
Expand Down Expand Up @@ -138,7 +218,9 @@ public void onClick(View view) {
case IN_PROGRESS:
}
}
switchPlayer();
if ( board.gameState == GameBoard.State.IN_PROGRESS ) {
switchPlayer();
}
}

private void switchPlayer() {
Expand Down
14 changes: 14 additions & 0 deletions src/com/exposuresoftware/xsandos/MainMenu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.exposuresoftware.xsandos;

import com.google.analytics.tracking.android.EasyTracker;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
Expand Down Expand Up @@ -28,6 +30,18 @@ protected void onCreate(Bundle savedInstanceState) {
button_one_player.setTypeface(chalkduster);
button_two_player.setTypeface(chalkduster);
}

@Override
public void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}

@Override
public void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down
16 changes: 15 additions & 1 deletion src/com/exposuresoftware/xsandos/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
package com.exposuresoftware.xsandos;

import com.google.analytics.tracking.android.EasyTracker;

import android.app.Activity;
import android.os.Bundle;

public class SettingsActivity extends Activity {
private static String TAG = "Xs And Os - Settings";

//private static String TAG = "Xs And Os - Settings";

public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
getFragmentManager().beginTransaction().replace( android.R.id.content, new SettingsFragment() )
.commit();
}

public void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}

public void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}
}
Loading

0 comments on commit 4feb0b1

Please sign in to comment.