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;
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)
&& (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();
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();
} 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;
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) {
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;
});
}
+ 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
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);
</TableLayout>
</LinearLayout>
- <TableLayout
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_weight="1">
+ android:layout_weight="1"
+ android:orientation="vertical">
- <TableRow
+ <TextView
+ android:id="@+id/header_sides"
android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <Button
- android:id="@+id/btn_wait_short"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/wait_short" />
+ android:layout_height="wrap_content"
+ android:gravity="center" />
- <ProgressBar
- android:id="@+id/pb_wait_short"
- style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_weight="1"
- android:indeterminate="false"
- android:padding="5dp"
- android:rotation="180"
- android:visibility="invisible" />
-
- <Chronometer
- android:id="@+id/ch_wait_short"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:visibility="invisible" />
-
- </TableRow>
-
- <TableRow
+ <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
- <Button
- android:id="@+id/btn_wait_long"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/wait_long" />
+ <TableRow
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <Button
+ android:id="@+id/btn_wait_short"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wait_short" />
- <ProgressBar
- android:id="@+id/pb_wait_long"
- style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
+ <ProgressBar
+ android:id="@+id/pb_wait_short"
+ style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ android:indeterminate="false"
+ android:padding="5dp"
+ android:rotation="180"
+ android:visibility="invisible" />
+
+ <Chronometer
+ android:id="@+id/ch_wait_short"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:visibility="invisible" />
+
+ </TableRow>
+
+ <TableRow
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_weight="1"
- android:indeterminate="false"
- android:padding="5dp"
- android:rotation="180"
- android:visibility="invisible" />
-
- <Chronometer
- android:id="@+id/ch_wait_long"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:visibility="invisible" />
- </TableRow>
-
- </TableLayout>
+ android:layout_height="match_parent">
+
+ <Button
+ android:id="@+id/btn_wait_long"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wait_long" />
+
+ <ProgressBar
+ android:id="@+id/pb_wait_long"
+ style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ android:indeterminate="false"
+ android:padding="5dp"
+ android:rotation="180"
+ android:visibility="invisible" />
+
+ <Chronometer
+ android:id="@+id/ch_wait_long"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:visibility="invisible" />
+ </TableRow>
+
+ </TableLayout>
+ </LinearLayout>
</LinearLayout>