From: Nathaniel Wesley Filardo Date: Sun, 22 Sep 2019 12:57:19 +0000 (+0100) Subject: TinyChrono: add a "single chronometer" display X-Git-Tag: release-1.4~9 X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=6add8b1f7ac0718f6f1ef710e393194afb8504c5;p=acmetensortoys-ctfws-android TinyChrono: add a "single chronometer" display We're going to use this to address https://github.com/cmukgb/ctfws-timer-android/issues/17 --- 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 index 0000000..c962786 --- /dev/null +++ b/mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayTinyChrono.java @@ -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 msgs) { } + +} \ No newline at end of file diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 6052a47..7016d51 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -8,6 +8,14 @@ Game\nStart Jailbreak\n%1$d of %2$d + Pending + Ending\n%s + Setup\n%s + JB %1$d:\n%%s + Game Timer + No Game + Over! + Red is defending Wean; Yellow is defending Doherty.]]>