]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
Treewide: tidy many warnings
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sat, 27 Oct 2018 03:53:58 +0000 (04:53 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sat, 27 Oct 2018 14:12:24 +0000 (15:12 +0100)
lib/src/main/java/com/acmetensortoys/ctfwstimer/lib/CtFwSGameStateManager.java
mobile/src/main/AndroidManifest.xml
mobile/src/main/java/com/acmetensortoys/ctfwstimer/CtFwSDisplayLocal.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/MainActivity.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/MainService.java
mobile/src/main/java/com/acmetensortoys/ctfwstimer/SettingsActivity.java
mobile/src/main/res/layout-land/activity_main.xml
mobile/src/main/res/layout/activity_main.xml
mobile/src/main/res/values/strings.xml
mobile/src/main/res/xml/backup_rules.xml [new file with mode: 0644]

index de2730a8ed7e71a4c6266e452228585ccab14e9c..44c529b988895df8bfa3059e2f2dc7b7210b7bab 100644 (file)
@@ -38,7 +38,7 @@ public class CtFwSGameStateManager {
                     && (this.endT == g.endT)
                     && (this.flagsTotal == g.flagsTotal);
         }
-    };
+    }
     private Game curstate = new Game();
 
     public synchronized void fromMqttConfigMessage(String st) {
@@ -219,7 +219,7 @@ public class CtFwSGameStateManager {
             if (this.when == m.when) {
                 return this.msg.compareTo(m.msg);
             }
-            return (Long.valueOf(when).compareTo(Long.valueOf(m.when)));
+            return Long.compare(this.when, m.when);
         }
 
         @Override
index b0d53bdaefad249f4712a19c63aca2e263e32d1c..b1fde30b7f49651f227d117e0d44344a8dd508b3 100644 (file)
@@ -13,6 +13,7 @@
 
     <application
         android:allowBackup="true"
+        android:fullBackupContent="@xml/backup_rules"
         android:icon="@mipmap/ic_shield_1"
         android:label="@string/app_name"
         android:supportsRtl="true"
 
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
         </activity>
 
         <service android:name="org.eclipse.paho.android.service.MqttService" />
index 1e9a8376656a7deb72f8bcd71fbb53bc498b543a..5b8b4ce3bd33e84ad2773ab115ef1985b0b3e6c8 100644 (file)
@@ -53,10 +53,10 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
                 });
     }
 
-    public void timersToBundle(Bundle out, String key) {
+    void timersToBundle(Bundle out, String key) {
         out.putLongArray(key, new long[]{ stun_short.wallEndMS, stun_long.wallEndMS });
     }
-    public void timersFromBundle(Bundle in, String key) {
+    void timersFromBundle(Bundle in, String key) {
         long[] es = in.getLongArray(key);
         if(es == null) { return; }
         if(es.length > 0) { resumeTimer(stun_short, es[0]); }
@@ -81,7 +81,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             gameStateLabelText = pfx;
         }
 
-        final TextView gstv = (TextView) mAct.findViewById(R.id.header_gamestate);
+        final TextView gstv = mAct.findViewById(R.id.header_gamestate);
         gstv.post(new Runnable() {
             @Override
             public void run() {
@@ -113,7 +113,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
 
         // Upper line text
         {
-            final TextView tv_jb = (TextView) (mAct.findViewById(R.id.tv_jailbreak));
+            final TextView tv_jb = mAct.findViewById(R.id.tv_jailbreak);
             tv_jb.post(new Runnable() {
                 @Override
                 public void run() {
@@ -132,7 +132,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
 
         // Upper progress bar and chronometer
         {
-            final ProgressBar pb_jb = (ProgressBar) (mAct.findViewById(R.id.pb_jailbreak));
+            final ProgressBar pb_jb = mAct.findViewById(R.id.pb_jailbreak);
             pb_jb.post(new Runnable() {
                 @Override
                 public void run() {
@@ -142,7 +142,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
                 }
             });
 
-            final Chronometer ch_jb = (Chronometer) (mAct.findViewById(R.id.ch_jailbreak));
+            final Chronometer ch_jb = mAct.findViewById(R.id.ch_jailbreak);
             ch_jb.post(new Runnable() {
                 @Override
                 public void run() {
@@ -168,7 +168,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
 
         // Lower progress bar and chronometer
         if (now.round > 0) {
-            final ProgressBar pb_gp = (ProgressBar) (mAct.findViewById(R.id.pb_gameProgress));
+            final ProgressBar pb_gp = mAct.findViewById(R.id.pb_gameProgress);
             pb_gp.post(new Runnable() {
                 @Override
                 public void run() {
@@ -178,7 +178,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
                 }
             });
 
-            final Chronometer ch_gp = (Chronometer) (mAct.findViewById(R.id.ch_gameProgress));
+            final Chronometer ch_gp = mAct.findViewById(R.id.ch_gameProgress);
             ch_gp.post(new Runnable() {
                 @Override
                 public void run() {
@@ -195,7 +195,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
                 }
             });
         } else {
-            final ProgressBar pb_gp = (ProgressBar) (mAct.findViewById(R.id.pb_gameProgress));
+            final ProgressBar pb_gp = mAct.findViewById(R.id.pb_gameProgress);
             pb_gp.post(new Runnable() {
                 @Override
                 public void run() {
@@ -203,7 +203,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
                 }
             });
 
-            final Chronometer ch_gp = (Chronometer) (mAct.findViewById(R.id.ch_gameProgress));
+            final Chronometer ch_gp = mAct.findViewById(R.id.ch_gameProgress);
             ch_gp.post(new Runnable() {
                 @Override
                 public void run() {
@@ -214,7 +214,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             });
         }
         {
-            final TextView tv_flags = (TextView) (mAct.findViewById(R.id.tv_flags_label));
+            final TextView tv_flags = mAct.findViewById(R.id.tv_flags_label);
             tv_flags.post(new Runnable() {
                 @Override
                 public void run() {
@@ -231,7 +231,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
         Log.d("CtFwS", "Display Reset");
 
         {
-            final Chronometer ch = (Chronometer) (mAct.findViewById(R.id.ch_jailbreak));
+            final Chronometer ch = mAct.findViewById(R.id.ch_jailbreak);
             ch.post(new Runnable() {
                 @Override
                 public void run() {
@@ -243,7 +243,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             });
         }
         {
-            final Chronometer ch = (Chronometer) (mAct.findViewById(R.id.ch_gameProgress));
+            final Chronometer ch = mAct.findViewById(R.id.ch_gameProgress);
             ch.post(new Runnable() {
                 @Override
                 public void run() {
@@ -254,7 +254,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             });
         }
         {
-            final ProgressBar pb = (ProgressBar) (mAct.findViewById(R.id.pb_jailbreak));
+            final ProgressBar pb = mAct.findViewById(R.id.pb_jailbreak);
             pb.post(new Runnable() {
                 @Override
                 public void run() {
@@ -263,7 +263,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             });
         }
         {
-            final ProgressBar pb = (ProgressBar) (mAct.findViewById(R.id.pb_gameProgress));
+            final ProgressBar pb = mAct.findViewById(R.id.pb_gameProgress);
             pb.post(new Runnable() {
                 @Override
                 public void run() {
@@ -289,7 +289,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
             }
         }
 
-        final TextView msgs = (TextView) (mAct.findViewById(R.id.tv_flags));
+        final TextView msgs = mAct.findViewById(R.id.tv_flags);
         msgs.post(new Runnable() {
             @Override
             public void run() {
@@ -301,7 +301,7 @@ class CtFwSDisplayLocal implements CtFwSGameStateManager.Observer {
     private CtFwSGameStateManager.Msg lastMsg;
     @Override
     public void onCtFwSMessage(CtFwSGameStateManager gs, List<CtFwSGameStateManager.Msg> msgs) {
-        final TextView msgstv = (TextView) (mAct.findViewById(R.id.msgs));
+        final TextView msgstv = mAct.findViewById(R.id.msgs);
         int s = msgs.size();
 
         if (s == 0) {
index f03c70755a10568caef68365ebdd5d8d5a32e209..d60d0756d1d68cc7e3e0f35893219a8eb7f160fc 100644 (file)
@@ -1,6 +1,5 @@
 package com.acmetensortoys.ctfwstimer;
 
-import android.annotation.SuppressLint;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -63,6 +62,20 @@ public class MainActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
+        findViewById(R.id.connmeta).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                onclick_connmeta(v);
+            }
+        });
+
+        findViewById(R.id.header_gamestate).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                onclick_gamestate(v);
+            }
+        });
+
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
 
         SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
@@ -73,8 +86,8 @@ public class MainActivity extends AppCompatActivity {
             throw new AssertionError("Shared Preferences not sticking!");
         }
 
-        mTvSU = (TextView) findViewById(R.id.tv_mqtt_server_uri);
-        mTvSS = (TextView) findViewById(R.id.tv_mqtt_state);
+        mTvSU = findViewById(R.id.tv_mqtt_server_uri);
+        mTvSS = findViewById(R.id.tv_mqtt_state);
 
         mCdl = new CtFwSDisplayLocal(this);
     }
@@ -158,13 +171,12 @@ public class MainActivity extends AppCompatActivity {
 
     // Every good application needs an easter egg
     private boolean egg = false;
-    @SuppressLint({"SetTextI18n"})
     public void onclick_gamestate(View v) {
         final TextView tv = (TextView) v;
         // Cam: Because every good easter egg needs to be way over-engineered.
         if (!egg) {
             egg = true;
-            tv.setText("DO NOT TAP ON GLASS");
+            tv.setText(R.string.header_egg);
             tv.postDelayed(new Runnable() {
                 public void run() {
                     if (mCdl != null) {
@@ -179,15 +191,12 @@ public class MainActivity extends AppCompatActivity {
     }
 
     // Kick the mqtt layer on a click on the status stuff
-    public void onclick_connmeta(@SuppressWarnings("UnusedParameters") View v) {
+    public void onclick_connmeta(View v) {
         if (mSrvBinder != null) {
             mSrvBinder.connect(true);
         }
     }
 
-    // TODO should we be using onClick instead for routing?
-    // Cam: According to official documentation, this is the preferred way to into menus, so
-    //      we're (overall) fine.
     @Override
     public boolean onOptionsItemSelected(MenuItem mi) {
         switch(mi.getItemId()) {
index b7d6ad70e17062bd428d16bf6513179a72b896d3..097244b688aa147ddfd23918f21b8098ba763c14 100644 (file)
@@ -92,7 +92,7 @@ public class MainService extends Service {
     };
     // And this handles making our subscriptions for us
     private class MyMQTTCallbacks implements MqttCallbackExtended {
-        public CtFwSCallbacksMQTT mCtfwscbs;
+        CtFwSCallbacksMQTT mCtfwscbs;
 
         @Override
         public void connectComplete(boolean reconnect, String serverURI) {
@@ -121,7 +121,7 @@ public class MainService extends Service {
         }
 
         @Override
-        public void messageArrived(String topic, MqttMessage message) throws Exception {
+        public void messageArrived(String topic, MqttMessage message) {
             Log.d("CtFwS", "Message(Generic) " + topic + " : '" + message + "'" );
         }
 
@@ -130,7 +130,7 @@ public class MainService extends Service {
             // Unused, as we never publish
             Log.d("CtFwS", "Delivery OK");
         }
-    };
+    }
     private final MyMQTTCallbacks mqttcb = new MyMQTTCallbacks();
 
         // And this handles yet more about connecting
index d007765f02d8c61e869ec3f1d379c29207724a84..5d5e3ae2958f887a75a8abda4f0d036c8ddc0f24 100644 (file)
@@ -4,7 +4,6 @@ import android.preference.PreferenceActivity;
 import android.preference.PreferenceFragment;\r
 import android.os.Bundle;\r
 \r
-// TODO (Cam): changing the server doesn't actually work yet\r
 public class SettingsActivity extends PreferenceActivity {\r
     @Override\r
     protected void onCreate(Bundle savedInstanceState) {\r
index b27aa51155c8e3664c7fff00925668a8f5de5ba3..b2064c21d8e3c62eeb34af50335d7fefd5bfb5e3 100644 (file)
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
-        android:onClick="onclick_connmeta"
         android:orientation="vertical">
 
         <TextView
index 9387c1b26a9824559e0e277016bd8ce0e7bff92d..a6a86998cb0e267ad3e6fa9ef4c797265c7d8952 100644 (file)
@@ -20,7 +20,6 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center"
-            android:onClick="onclick_gamestate"
             android:text="@string/header_gamestate0" />
 
         <TableLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
-        android:onClick="onclick_connmeta"
         android:orientation="vertical">
 
         <TextView
index ca845eaf6d79bd0cd85d19431781c3a06307cbc0..91bb10d56cfd5b0336e0be44c1e5336c45154463 100644 (file)
@@ -11,6 +11,7 @@
 
     <string name="header_gamestate0">Game State:</string>
     <string name="header_gamestateN" tools:ignore="PluralsCandidate">Game %1$d State:</string>
+    <string name="header_egg">DO NOT TAP ON GLASS</string>
     <string name="header_gametimeela">Game\nTime\nElapsed</string>
     <string name="header_messages">Messages:</string>
 
diff --git a/mobile/src/main/res/xml/backup_rules.xml b/mobile/src/main/res/xml/backup_rules.xml
new file mode 100644 (file)
index 0000000..231c813
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<full-backup-content>
+    <include domain="sharedpref" path="."/>
+</full-backup-content>
\ No newline at end of file