diff options
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java')
-rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java index 620f2b2..495c996 100644 --- a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java +++ b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java @@ -31,9 +31,6 @@ public class FullscreenActivity extends Activity { setContentView(R.layout.activity_fullscreen); - final RelativeLayout boardLayout = (RelativeLayout) findViewById(R.id.board); - Log.d("FA", boardLayout.toString()); - final Board board = new Board(); board.add(new Car(new Coordinate(0,0), new Coordinate(2,0), Color.YELLOW)); board.add(new Car(new Coordinate(3,0), new Coordinate(3,1), Color.rgb(128,223,182))); @@ -48,15 +45,6 @@ public class FullscreenActivity extends Activity { board.add(new Car(new Coordinate(5,4), new Coordinate(5,5), Color.rgb(219,202,161))); board.add(new Car(new Coordinate(0,5), new Coordinate(2,5), Color.rgb(25,195,167))); - ViewTreeObserver vto = boardLayout.getViewTreeObserver(); - vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - boardLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); - board.addToLayout(getBaseContext(), boardLayout); - } - }); - soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override @@ -66,10 +54,22 @@ public class FullscreenActivity extends Activity { }); soundBackgroundId = soundPool.load(this, R.raw.car_drive, 1); + final RelativeLayout boardLayout = (RelativeLayout) findViewById(R.id.board); + ViewTreeObserver vto = boardLayout.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + boardLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); + board.addToLayout(getBaseContext(), boardLayout); + } + }); + board.setDriveListener(new DriveListener() { @Override public void onDrive() { - soundPool.play(soundBackgroundId, 1, 1, 1, 0, 1f); + if (soundBackgroundLoaded) { + soundPool.play(soundBackgroundId, 1, 1, 1, 0, 1f); + } } }); } |