]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
Update GameState objects to have gameIx field
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 18 Feb 2017 21:27:19 +0000 (16:27 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 20 Feb 2017 06:41:02 +0000 (01:41 -0500)
This is a new parameter in the "/config" message to indicate which game
out of a bunch is being played.  See parallel commit to IoT repo
703983bd66891a4e03c5946aa1f238ae3e685b54.

Display said parameter in the game header.

lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameState.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/MainActivity.java
mobile/src/main/res/layout/activity_main.xml
mobile/src/main/res/values/strings.xml

index 5a086ad53d221d7ca68ad61fc31d51bbea95c69c..cdd78f4f9229cab6b38ca8460bc647b76c5499e7 100644 (file)
@@ -28,6 +28,7 @@ public class CtFwSGameState {
     private int  setupD;
     private int  rounds;
     private int  roundD;
+    private int  gameIx;
     private long endT = 0;   // NTP seconds for game end (if >= startT)
 
     public void fromMqttConfigMessage(String st) {
@@ -39,11 +40,12 @@ public class CtFwSGameState {
             default:
                 try {
                     Scanner s = new Scanner(tm);
-                    this.startT     s.nextLong();
+                    this.startT     = s.nextLong();
                     this.setupD     = s.nextInt();
                     this.rounds     = s.nextInt();
                     this.roundD     = s.nextInt();
                     this.flagsTotal = s.nextInt();
+                    this.gameIx     = s.nextInt();
                     this.configured = true;
                 } catch (NoSuchElementException e) {
                     this.configured = false;
@@ -116,6 +118,7 @@ public class CtFwSGameState {
     public boolean isConfigured(){
         return configured;
     }
+    public int getGameIx() { return gameIx; }
     public long getStartT() { return startT; }
     public long getFirstRoundStartT() { return startT + setupD; }
     public int getRounds() { return rounds; }
index b19e454688367b8e3868f6fe294cdcb404ecc4fb..975af5c91e200b5e1f65a67445029a89b49b20d4 100644 (file)
@@ -19,16 +19,35 @@ import static android.view.View.INVISIBLE;
 // TODO nwf is bad at UI design; someone who isn't him should improve this
 class CtFwSDisplayLocal implements CtFwSGameState.Observer {
     final private Activity mAct;
-    final private Handler mHandler;
+    public String gameStateLabelText;
 
-    CtFwSDisplayLocal(Activity a, Handler h) {
+    CtFwSDisplayLocal(Activity a) {
         mAct = a;
-        mHandler = h;
+        gameStateLabelText = mAct.getResources().getString(R.string.header_gamestate0);
     }
 
     private Runnable mProber;
+
     @Override
     public void onCtFwSConfigure(final CtFwSGameState gs) {
+        int gameix = gs.getGameIx();
+        gameStateLabelText =
+                (gs.isConfigured() && gameix != 0)
+                        ?
+                        String.format(
+                                mAct.getResources()
+                                        .getString(R.string.header_gamestateN),
+                                gameix)
+                        : mAct.getResources().getString(R.string.header_gamestate0);
+
+
+        final TextView gstv = (TextView) mAct.findViewById(R.id.header_gamestate);
+        gstv.post(new Runnable() {
+            @Override
+            public void run() {
+                gstv.setText(gameStateLabelText);
+            }
+        });
     }
 
     @Override
@@ -58,7 +77,7 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
                     } else {
                         tv_jb.setText(
                                 String.format(mAct.getResources().getString(R.string.ctfws_jailbreak),
-                                now.round, gs.getRounds() - 1));
+                                        now.round, gs.getRounds() - 1));
                     }
                 }
             });
@@ -68,7 +87,7 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
                 @Override
                 public void run() {
                     pb_jb.setIndeterminate(false);
-                    pb_jb.setMax((int)(now.roundEnd - now.roundStart));
+                    pb_jb.setMax((int) (now.roundEnd - now.roundStart));
                     pb_jb.setProgress(0);
                 }
             });
@@ -81,14 +100,14 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
                     ch_jb.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                         @Override
                         public void onChronometerTick(Chronometer c) {
-                            pb_jb.setProgress((int)(now.roundEnd - System.currentTimeMillis()/1000));
+                            pb_jb.setProgress((int) (now.roundEnd - System.currentTimeMillis() / 1000));
                         }
                     });
                     ch_jb.start();
                 }
             });
         }
-        if (now.round > 0){
+        if (now.round > 0) {
             final ProgressBar pb_gp = (ProgressBar) (mAct.findViewById(R.id.pb_gameProgress));
             pb_gp.post(new Runnable() {
                 @Override
@@ -107,7 +126,7 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
                     ch_gp.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                         @Override
                         public void onChronometerTick(Chronometer c) {
-                            pb_gp.setProgress((int)(System.currentTimeMillis()/1000
+                            pb_gp.setProgress((int) (System.currentTimeMillis() / 1000
                                     - gs.getFirstRoundStartT()));
                         }
                     });
@@ -166,7 +185,8 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
                 public void run() {
                     ch.stop();
                     ch.setVisibility(View.INVISIBLE);
-                }});
+                }
+            });
         }
         {
             final ProgressBar pb = (ProgressBar) (mAct.findViewById(R.id.pb_jailbreak));
@@ -204,7 +224,7 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
             }
         }
 
-        final TextView msgs = (TextView)(mAct.findViewById(R.id.tv_flags));
+        final TextView msgs = (TextView) (mAct.findViewById(R.id.tv_flags));
         msgs.post(new Runnable() {
             @Override
             public void run() {
@@ -215,7 +235,7 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
 
     @Override
     public void onCtFwSMessage(CtFwSGameState gs, List<CtFwSGameState.Msg> msgs) {
-        final TextView msgstv = (TextView)(mAct.findViewById(R.id.msgs));
+        final TextView msgstv = (TextView) (mAct.findViewById(R.id.msgs));
         int s = msgs.size();
 
         if (s == 0) {
@@ -245,4 +265,4 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
             });
         }
     }
-}
+}
\ No newline at end of file
index a7138215e371969e36907bc869b6a2ccbc14e27d..1b6f84bceab88d4f59dccfa1c30b035e8f436c80 100644 (file)
@@ -79,7 +79,7 @@ public class MainActivity extends AppCompatActivity {
         mTvSU = (TextView) findViewById(R.id.tv_mqtt_server_uri);
         mTvSS = (TextView) findViewById(R.id.tv_mqtt_state);
 
-        mCdl = new CtFwSDisplayLocal(this, new Handler());
+        mCdl = new CtFwSDisplayLocal(this);
     }
 
     private ServiceConnection ctfwssc = new ServiceConnection() {
@@ -137,7 +137,11 @@ public class MainActivity extends AppCompatActivity {
             tv.setText("DO NOT TAP ON GLASS");
             tv.postDelayed(new Runnable() {
                 public void run() {
-                    tv.setText(R.string.header_gamestate);
+                    if (mCdl != null) {
+                        tv.setText(mCdl.gameStateLabelText);
+                    } else {
+                        tv.setText(R.string.header_gamestate0);
+                    }
                     egg = false;
                 }
             }, 3000);
index f6c88f21cb64f86fee691089388be4c37359c1dc..cd57489d64824a1fd6de36b64b3c33904c152a7f 100644 (file)
         -->
 
         <TextView
-            android:text="@string/header_gamestate"
+            android:text="@string/header_gamestate0"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center"
             android:clickable="true"
-            android:onClick="onclick_gamestate" />
+            android:onClick="onclick_gamestate"
+            android:id="@+id/header_gamestate" />
 
         <TableLayout
             android:layout_width="match_parent"
index e53e1476e9e46f009031a35d4cfd40ba0535b890..d810b22969efb09f578cc205deba5535fe782140 100644 (file)
@@ -6,7 +6,8 @@
     <string name="ctfws_jailbreak">Jailbreak\n%1$d of %2$d</string>
     <string name="ctfws_flags">%1$d Flags:</string>
 
-    <string name="header_gamestate">Game State:</string>
+    <string name="header_gamestate0">Game State:</string>
+    <string name="header_gamestateN">Game %1$d State:</string>
     <string name="header_gametimeela">Game\nTime\nElapsed</string>
     <string name="header_messages">Messages:</string>