]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
On pre-N devices, Chronometers only count up
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Wed, 22 Feb 2017 15:29:26 +0000 (10:29 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Wed, 22 Feb 2017 15:45:43 +0000 (10:45 -0500)
So keep times in the past

mobile/build.gradle
mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/MainServiceNotification.java
mobile/src/main/res/layout/activity_main.xml

index 34d48884e5a48dfebb6eb9837ec9f88e4ad75a5d..40cd18a471bfbe0fe6ac850dc996054edfa0c374 100644 (file)
@@ -5,9 +5,9 @@ android {
     buildToolsVersion "25.0.2"
     defaultConfig {
         applicationId "com.acmetensortoys.ctfwstimer"
-        minSdkVersion 19
+        minSdkVersion 16
         targetSdkVersion 25
-        versionCode 4
+        versionCode 5
         versionName "1.0"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
index 2fc574ca966866fd769efaaa5a4426ba238afafb..5b5a552907fc0084b7663557cb02e6ac559c92d8 100644 (file)
@@ -1,6 +1,8 @@
 package com.acmetensortoys.ctfwstimer;
 
 import android.app.Activity;
+import android.graphics.Color;
+import android.os.Build;
 import android.os.SystemClock;
 import android.text.format.DateUtils;
 import android.util.Log;
@@ -82,9 +84,6 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
         }
 
         // Upper progress bar and chronometer
-        // TODO: Older devices cannot count down in Chronometer, so will see only zeros, I
-        // think.  This should be fixed by making those devices count up (and still rendering
-        // the progress bar rotated for decreasing, one assumes).
         {
             final ProgressBar pb_jb = (ProgressBar) (mAct.findViewById(R.id.pb_jailbreak));
             pb_jb.post(new Runnable() {
@@ -100,7 +99,14 @@ class CtFwSDisplayLocal implements CtFwSGameState.Observer {
             ch_jb.post(new Runnable() {
                 @Override
                 public void run() {
-                    ch_jb.setBase((now.roundEnd + 1) * 1000 - tbcf);
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                        ch_jb.setBase((now.roundEnd + 1) * 1000 - tbcf);
+                        ch_jb.setCountDown(true);
+                    } else {
+                        ch_jb.setBase(now.roundStart * 1000 - tbcf);
+                        ch_jb.setBackgroundColor(Color.BLACK);
+                        ch_jb.setTextColor(Color.WHITE);
+                    }
                     ch_jb.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                         @Override
                         public void onChronometerTick(Chronometer c) {
index 47e67e92c243a4e688293604b7dd836b88590f4b..d52006da805decf199356061dd066fedf148bf9f 100644 (file)
@@ -7,6 +7,7 @@ import android.content.Intent;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.content.res.Resources;
+import android.os.Build;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
 import android.support.v4.app.NotificationCompat;
@@ -38,7 +39,11 @@ class MainServiceNotification {
 
             @Override
             public void onCtFwSNow(CtFwSGameState game, CtFwSGameState.Now now) {
-                userNoteBuilder.setWhen((now.roundEnd + 1) * 1000);
+                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!
index 059d4fa6ec3534bdcac591e2ea70bfbec893ae07..18b3495e0a44254f682c9866c3a2bb1e48feb95d 100644 (file)
                 <Chronometer
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:id="@+id/ch_jailbreak"
-                    android:countDown="true" />
+                    android:id="@+id/ch_jailbreak" />
 
             </TableRow>