diff --git a/assignments/week-5-assignment-4/W5-A4-Android/src/edu/vuum/mocca/AndroidPlatformStrategy.java b/assignments/week-5-assignment-4/W5-A4-Android/src/edu/vuum/mocca/AndroidPlatformStrategy.java index bc684b5ce..a229790c5 100644 --- a/assignments/week-5-assignment-4/W5-A4-Android/src/edu/vuum/mocca/AndroidPlatformStrategy.java +++ b/assignments/week-5-assignment-4/W5-A4-Android/src/edu/vuum/mocca/AndroidPlatformStrategy.java @@ -47,6 +47,8 @@ public void begin() { /** (Re)initialize the CountDownLatch. */ // TODO - You fill in here. + /// simple. same as for console platform strategy. + mLatch = new CountDownLatch(NUMBER_OF_THREADS); } /** Print the outputString to the display. */ @@ -57,20 +59,40 @@ public void print(final String outputString) * and appends the outputString to a TextView. */ // TODO - You fill in here. + /// this one is different. can't have background android threads printing to console. + /// create runnable. use activity weak reference to post runnable to runonui thread. + Runnable myRunnable = new Runnable() { + @Override + public void run() { + mTextViewOutput.append(outputString); + } + }; + mActivity.get().runOnUiThread(myRunnable); } /** Indicate that a game thread has finished running. */ public void done() { // TODO - You fill in here. + /// simple. same as for console platform strategy. + /// can do 2 ways... 1) call runonui thread and pass a runnable that decrements the count. + /// or 2) call countdownlatch directly. + + mLatch.countDown(); } /** Barrier that waits for all the game threads to finish. */ public void awaitDone() { // TODO - You fill in here. + /// simple. same as for console platform strategy. + try { + mLatch.await(); + } + catch(java.lang.InterruptedException e) { + } } - + /** * Error log formats the message and displays it for the * debugging purposes. diff --git a/ex/DownloadApplication/.classpath b/ex/DownloadApplication/.classpath index c06dfcb8e..51769745b 100644 --- a/ex/DownloadApplication/.classpath +++ b/ex/DownloadApplication/.classpath @@ -1,7 +1,7 @@ - + diff --git a/ex/ThreadedDownload/.classpath b/ex/ThreadedDownload/.classpath index 0b0840834..d57ec0251 100644 --- a/ex/ThreadedDownload/.classpath +++ b/ex/ThreadedDownload/.classpath @@ -1,7 +1,7 @@ - +