public class Now {
public String rationale = null; // null if game is in play, otherwise other fields invalid
public boolean stop = false;
+ public boolean past = false;
public int round = 0; // 0 for setup
public long roundStart = 0, roundEnd = 0; // POSIX seconds
res.rationale = "Game not configured!";
res.stop = true;
} else if (endT >= startT) {
- res.rationale = "Game over!";
+ res.rationale = "Game declared over!";
res.stop = true;
+ res.past = true;
} else if (now < startT) {
res.rationale = "Start time in the future!";
res.roundStart = res.roundEnd = startT;
elapsed -= setupD;
res.round = (int) (elapsed / roundD);
if (res.round >= rounds) {
- res.rationale = "Game over!";
+ res.rationale = "Game time up!";
res.stop = true;
+ res.past = true;
return res;
}
res.roundStart = startT + setupD + (res.round * roundD);
case R.id.menu_about :
startActivity(new Intent(this, AboutActivity.class));
return true;
+ case R.id.menu_quit:
+ if (mSrvBinder != null) {
+ mSrvBinder.exit();
+ }
+ finish();
+ return true;
// Cam: Changing this doesn't appear to do anything? Leaving just in case.
default:
return super.onOptionsItemSelected(mi);
void unregisterObserver(Observer o) {
synchronized(MainService.this) { mObsvs.remove(o); }
}
+ void exit() {
+ mMsn.ensureNoNotification(true);
+ }
}
private final LocalBinder mBinder = new LocalBinder();
@Override
public void onCtFwSNow(CtFwSGameState game, CtFwSGameState.Now now) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- userNoteBuilder.setWhen((now.roundEnd + 1) * 1000);
- } else {
- userNoteBuilder.setWhen(now.roundStart * 1000);
- }
- userNoteBuilder.setUsesChronometer(true);
if (now.rationale == null || !now.stop) {
// game is afoot or in the future!
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ userNoteBuilder.setWhen((now.roundEnd + 1) * 1000);
+ } else {
+ userNoteBuilder.setWhen(now.roundStart * 1000);
+ }
+ userNoteBuilder.setUsesChronometer(true);
+
Resources rs = mService.getResources();
if (now.rationale == null) {
ensureNotification();
} else {
// game no longer afoot
- ensureNoNotification();
+ if (now.past) {
+ userNoteBuilder.setUsesChronometer(false);
+ userNoteBuilder.setShowWhen(false);
+ userNoteBuilder.setContentTitle(now.rationale);
+ userNoteBuilder.setSubText(now.rationale);
+ refreshNotification();
+ }
+ ensureNoNotification(!now.past);
}
}
refreshNotification();
}
}
- private void ensureNoNotification() {
+ void ensureNoNotification(boolean remove) {
synchronized (this) {
if (userNoteSC != null) {
- mService.stopForeground(true);
+ mService.stopForeground(remove);
mService.unbindService(userNoteSC);
userNoteSC = null;
}
android:icon="@android:drawable/ic_menu_help"
android:title="@string/menutext_about"
android:visible="true" />
+ <item
+ android:id="@+id/menu_quit"
+ android:enabled="true"
+ android:title="@string/menutext_quit"
+ android:visible="true" />
</menu>
\ No newline at end of file
<string name="menutext_about">About</string>
<string name="menutext_prf">Settings</string>
+ <string name="menutext_quit">Quit</string>
<string name="mqtt_header">Connection Metadata:</string>
<string name="mqtt_uri_label">Server URI:</string>