]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
TinyChrono: add a "single chronometer" display
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 22 Sep 2019 12:57:19 +0000 (13:57 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 22 Sep 2019 14:35:53 +0000 (15:35 +0100)
We're going to use this to address https://github.com/cmukgb/ctfws-timer-android/issues/17

mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayTinyChrono.java [new file with mode: 0644]
mobile/src/main/res/values/strings.xml

diff --git a/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayTinyChrono.java b/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayTinyChrono.java
new file mode 100644 (file)
index 0000000..c962786
--- /dev/null
@@ -0,0 +1,82 @@
+package com.acmetensortoys.ctfwstimer;
+
+import android.content.res.Resources;
+import android.os.SystemClock;
+import android.widget.Chronometer;
+
+import com.acmetensortoys.ctfwstimer.lib.CtFwSGameStateManager;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.SortedSet;
+
+/*
+ * For our non-primary displays, we probably want a simple count-up timer
+ * in the headers.  This provides that for us.
+ */
+
+class CtFwSDisplayTinyChrono implements CtFwSGameStateManager.Observer {
+
+    private final Chronometer mCh;
+    private final Resources mRes;
+
+    public CtFwSDisplayTinyChrono(Resources res, Chronometer ch) {
+        mCh = ch;
+        mRes = res;
+    }
+
+    @Override
+    public void onCtFwSConfigure(final CtFwSGameStateManager gs) {
+        if (!gs.isConfigured()) {
+            mCh.post(new Runnable() {
+                @Override
+                public void run() {
+                    mCh.setText(R.string.ctfws_chrono_nogame);
+                }
+            });
+        }
+    }
+
+    @Override
+    public void onCtFwSNow(final CtFwSGameStateManager gs, final CtFwSGameStateManager.Now now) {
+        final long tbcf = System.currentTimeMillis() - SystemClock.elapsedRealtime();
+
+        mCh.post(new Runnable() {
+            @Override
+            public void run() {
+                mCh.stop();
+
+                if (now.rationale != CtFwSGameStateManager.NowRationale.NR_GAME_IN_PROGRESS) {
+                    int rid = R.string.ctfws_chrono_nogame;
+                    switch(now.rationale) {
+                        case NR_TIME_UP:      rid = R.string.ctfws_chrono_over  ; break;
+                        case NR_EXPLICIT_END: rid = R.string.ctfws_chrono_over  ; break;
+                        case NR_START_FUTURE: rid = R.string.ctfws_chrono_future; break;
+                        case NR_NOT_CONFIG:   rid = R.string.ctfws_chrono_nogame; break;
+                    }
+                    mCh.setText(rid);
+                    return;
+                }
+
+                if (now.round == 0) {
+                    mCh.setFormat(mRes.getString(R.string.ctfws_chrono_gamestart));
+                } else if (now.round == gs.getRounds()) {
+                    mCh.setFormat(mRes.getString(R.string.ctfws_chrono_gameend));
+                } else {
+                    mCh.setFormat(String.format(mRes.getString(R.string.ctfws_chrono_jailbreak),
+                                    now.round));
+                }
+
+                mCh.setBase(now.roundStart * 1000 - tbcf);
+                mCh.start();
+            }
+        });
+    }
+
+    @Override
+    public void onCtFwSFlags(CtFwSGameStateManager gs) { }
+
+    @Override
+    public void onCtFwSMessage(CtFwSGameStateManager gs, SortedSet<CtFwSGameStateManager.Msg> msgs) { }
+
+}
\ No newline at end of file
index 6052a47b70582b2dcee0816d0d71232526ce5bbe..7016d51a6bf51ebfe018fe9f6762b49e384e99ed 100644 (file)
@@ -8,6 +8,14 @@
     <string name="ctfws_gamestart">Game\nStart</string>
     <string name="ctfws_jailbreak">Jailbreak\n%1$d of %2$d</string>
 
+    <string name="ctfws_chrono_future">Pending</string>
+    <string name="ctfws_chrono_gameend">Ending\n%s</string>
+    <string name="ctfws_chrono_gamestart">Setup\n%s</string>
+    <string name="ctfws_chrono_jailbreak">JB %1$d:\n%%s</string>
+    <string name="ctfws_chrono_menutext">Game Timer</string>
+    <string name="ctfws_chrono_nogame">No Game</string>
+    <string name="ctfws_chrono_over">Over!</string>
+
     <string name="ctfws_sides_wd">
         <![CDATA[<b><font color=#a94442>Red</font></b> is defending Wean; <b><font color=#8a6d3b>Yellow</font></b> is defending Doherty.]]>
     </string>