From 28eb6a408045971d79b379ac5ef408cf6b84ecbd Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Wed, 29 Apr 2015 12:56:33 +0200
Subject: Cleanup; victory sound
---
.../java/com/camilstaps/rushhour/BoardLoader.java | 1 +
.../com/camilstaps/rushhour/FinishedActivity.java | 19 +-----------
.../com/camilstaps/rushhour/GamePlayActivity.java | 26 ++---------------
.../java/com/camilstaps/rushhour/MainActivity.java | 2 ++
.../java/com/camilstaps/rushhour/TheSoundPool.java | 34 ++++++++++++++++++++++
app/src/main/res/values-v11/styles.xml | 15 ----------
app/src/main/res/values/attrs.xml | 12 --------
app/src/main/res/values/colors.xml | 5 ----
app/src/main/res/values/styles.xml | 19 ------------
9 files changed, 40 insertions(+), 93 deletions(-)
create mode 100644 app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
delete mode 100644 app/src/main/res/values-v11/styles.xml
delete mode 100644 app/src/main/res/values/attrs.xml
delete mode 100644 app/src/main/res/values/colors.xml
diff --git a/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java b/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
index cb5ded7..0f9cd6f 100755
--- a/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
+++ b/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
@@ -30,6 +30,7 @@ import java.util.Scanner;
* Created by Jos on 23-4-2015.
*/
public class BoardLoader {
+
public BoardLoader()
{}
diff --git a/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java b/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
index 053006d..e0f3c37 100644
--- a/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
@@ -1,21 +1,3 @@
-/*
- * Rush Hour Android app
- * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Camil Staps
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
package com.camilstaps.rushhour;
import android.app.Activity;
@@ -56,6 +38,7 @@ public class FinishedActivity extends ActionBarActivity {
final int score = getIntent().getIntExtra("score", -1);
if (score != -1) {
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundVictoryId, 1, 1, 1, 0, 1);
final EditText input = new EditText(this);
new AlertDialog.Builder(this)
.setTitle("Congratulations!")
diff --git a/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java b/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
index c5740b3..8399446 100755
--- a/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
@@ -31,9 +31,6 @@ import java.io.InputStream;
public class GamePlayActivity extends Activity implements Board.SolveListener {
- private SoundPool soundPool;
- private int soundBackgroundId, soundCarDriveId, soundCantMoveId;
-
Board board;
boolean isFirstTime = true;
@@ -44,7 +41,6 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
setContentView(R.layout.activity_fullscreen);
- setupSoundPool();
setupBoard();
}
@@ -76,12 +72,12 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
board.setDriveListener(new DriveListener() {
@Override
public void onDrive() {
- soundPool.play(soundCarDriveId, 1, 1, 1, 0, 1);
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundCarDriveId, 1, 1, 1, 0, 1);
}
@Override
public void onBlocked() {
- soundPool.play(soundCantMoveId, 1, 1, 1, 0, 1);
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundCantMoveId, 1, 1, 1, 0, 1);
}
});
@@ -98,24 +94,6 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
}
}
- /**
- * Load sounds; start background music
- */
- protected void setupSoundPool() {
- soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
- soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
- @Override
- public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
- if (sampleId == soundBackgroundId) {
- soundPool.play(soundBackgroundId, 1, 1, 2, -1, 1);
- }
- }
- });
- soundBackgroundId = soundPool.load(this, R.raw.tune, 2);
- soundCarDriveId = soundPool.load(this, R.raw.car_drive, 1);
- soundCantMoveId = soundPool.load(this, R.raw.cantmove, 1);
- }
-
@Override
public void onSolve(int score) {
Intent intent = new Intent(this, FinishedActivity.class);
diff --git a/app/src/main/java/com/camilstaps/rushhour/MainActivity.java b/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
index 01b28df..e0a511f 100644
--- a/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
@@ -30,6 +30,8 @@ public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ TheSoundPool.getSoundPool(this);
}
public void onClickHandler(View v) {
diff --git a/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
new file mode 100644
index 0000000..c727979
--- /dev/null
+++ b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
@@ -0,0 +1,34 @@
+package com.camilstaps.rushhour;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.SoundPool;
+
+/**
+ * Created by camilstaps on 29-4-15.
+ */
+public class TheSoundPool {
+
+ private static SoundPool soundPool;
+ public static int soundBackgroundId, soundCarDriveId, soundCantMoveId, soundVictoryId;
+
+ public static SoundPool getSoundPool(Context context) {
+ if (soundPool == null) {
+ soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
+ soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
+ @Override
+ public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
+ if (sampleId == soundBackgroundId) {
+ soundPool.play(soundBackgroundId, 1, 1, 2, -1, 1);
+ }
+ }
+ });
+ soundBackgroundId = soundPool.load(context, R.raw.tune, 2);
+ soundCarDriveId = soundPool.load(context, R.raw.car_drive, 1);
+ soundCantMoveId = soundPool.load(context, R.raw.cantmove, 1);
+ soundVictoryId = soundPool.load(context, R.raw.victory, 1);
+ }
+ return soundPool;
+ }
+
+}
diff --git a/app/src/main/res/values-v11/styles.xml b/app/src/main/res/values-v11/styles.xml
deleted file mode 100644
index f72515d..0000000
--- a/app/src/main/res/values-v11/styles.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
deleted file mode 100644
index 7ce840e..0000000
--- a/app/src/main/res/values/attrs.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
deleted file mode 100644
index 327c060..0000000
--- a/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- #66000000
-
-
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 8d8c40e..766ab99 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -5,23 +5,4 @@
-
-
-
-
-
-
-
-
--
cgit v1.2.3