From: Nathaniel Wesley Filardo Date: Sat, 27 Oct 2018 15:51:26 +0000 (+0100) Subject: Add display of sides information X-Git-Tag: release-1.2~13 X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=a8ddcccf8c71c99cb400604d4ded32ba1c72653a;p=acmetensortoys-ctfws-android Add display of sides information --- diff --git a/lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameStateManager.java b/lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameStateManager.java index b765b53..a0b05ad 100644 --- a/lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameStateManager.java +++ b/lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameStateManager.java @@ -17,6 +17,19 @@ public class CtFwSGameStateManager { mT = t; } + private static boolean carefulStrEq(String a, String b) + { + if (a == null) { + return b == null; + } else { + if (b == null) { + return false; + } else { + return a.equals(b); + } + } + } + private class Game { // Game time private boolean configured = false; @@ -28,6 +41,7 @@ public class CtFwSGameStateManager { private long endT = 0; // POSIX seconds for game end (if >= startT) public int flagsTotal; + public String sides_str; public boolean equals(Game g) { return (this.configured == g.configured) @@ -37,7 +51,8 @@ public class CtFwSGameStateManager { && (this.roundD == g.roundD) && (this.gameIx == g.gameIx) && (this.endT == g.endT) - && (this.flagsTotal == g.flagsTotal); + && (this.flagsTotal == g.flagsTotal) + && (carefulStrEq(this.sides_str, g.sides_str)); } } private Game curstate = new Game(); @@ -50,9 +65,9 @@ public class CtFwSGameStateManager { case "none": g.configured = false; break; - default: + default: { + Scanner s = new Scanner(tm); try { - Scanner s = new Scanner(tm); g.startT = s.nextLong(); g.setupD = s.nextInt(); g.rounds = s.nextInt(); @@ -63,7 +78,14 @@ public class CtFwSGameStateManager { } catch (NoSuchElementException e) { g.configured = false; } + + try { + g.sides_str = s.next(); + } catch (NoSuchElementException e) { + g.sides_str = null; + } break; + } } if (!curstate.equals(g)) { curstate = g; @@ -161,6 +183,7 @@ public class CtFwSGameStateManager { public int getRounds() { return curstate.rounds; } public int getComputedGameDuration() { return curstate.rounds * curstate.roundD ; } public int getFlagsTotal() { return curstate.flagsTotal; } + public String getSides() { return curstate.sides_str; } // Leaves off the natural endT comparison so that messages can be posted after the // game ends and still count as part of this one (i.e. still be displayed). private boolean isMessageTimeWithin(long time) { diff --git a/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java b/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java index e30eb1d..87bdcf9 100644 --- a/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java +++ b/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java @@ -6,6 +6,8 @@ import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.SystemClock; +import android.text.Html; +import android.text.Spanned; import android.text.format.DateUtils; import android.util.Log; import android.view.View; @@ -120,9 +122,50 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer { }); } + private Spanned htmlFromStrResId(int id) { + if (Build.VERSION.SDK_INT >= 24) { + return Html.fromHtml(mAct.getResources().getString(id), 0); + } else { + return Html.fromHtml(mAct.getResources().getString(id)); + } + } + + private void doSetSidesText(final CtFwSGameStateManager gs) { + final TextView stv = mAct.findViewById(R.id.header_sides); + Runnable r = new Runnable() { + @Override + public void run() { + stv.setText(""); + } + }; + + if (gs.isConfigured()) { + String ss = gs.getSides(); + if (ss != null) { + final Spanned h; + + switch(ss) { + case "wd" : h = htmlFromStrResId(R.string.ctfws_sides_wd); break; + case "dw" : h = htmlFromStrResId(R.string.ctfws_sides_dw); break; + default : h = htmlFromStrResId(R.string.ctfws_unknown_sides); break; + } + + r = new Runnable() { + @Override + public void run() { + stv.setText(h); + } + }; + } + } + + stv.post(r); + } + @Override public void onCtFwSConfigure(final CtFwSGameStateManager gs) { doSetGameStateLabelText(gs, null); + doSetSidesText(gs); } @Override @@ -133,6 +176,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer { Log.d("CtFwS", "Display game state; nowMS=" + now.wallMS + " r=" + now.round + " rs=" + now.roundStart + " re=" + now.roundEnd); doSetGameStateLabelText(gs, now); + doSetSidesText(gs); if (now.rationale != CtFwSGameStateManager.NowRationale.NR_GAME_IN_PROGRESS) { Log.d("CtFwS", "Rationale: " + now.rationale + " stop=" + now.stop); diff --git a/mobile/src/main/res/layout-land/activity_main.xml b/mobile/src/main/res/layout-land/activity_main.xml index b2064c2..5875ba6 100644 --- a/mobile/src/main/res/layout-land/activity_main.xml +++ b/mobile/src/main/res/layout-land/activity_main.xml @@ -131,73 +131,85 @@ - + android:layout_weight="1" + android:orientation="vertical"> - - -