From 599315327d3607bb7d6d6468931f429169a11d66 Mon Sep 17 00:00:00 2001 From: Tom Janson Date: Sun, 15 Mar 2015 15:29:26 +0100 Subject: [PATCH] clean up unneccessary strings, visibility, etc rm unneeded imports --- .../wifilocationlogger/MainActivity.java | 19 ++++++++++--------- .../wifilocationlogger/Uploader.java | 6 +++--- .../WifiBroadcastReceiver.java | 4 ++-- app/src/main/res/values-de/strings.xml | 5 +++-- app/src/main/res/values/strings.xml | 7 ++----- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/tomjanson/wifilocationlogger/MainActivity.java b/app/src/main/java/com/tomjanson/wifilocationlogger/MainActivity.java index 163e47e..59b61d4 100644 --- a/app/src/main/java/com/tomjanson/wifilocationlogger/MainActivity.java +++ b/app/src/main/java/com/tomjanson/wifilocationlogger/MainActivity.java @@ -11,7 +11,6 @@ import android.support.annotation.NonNull; import android.view.View; import android.widget.Button; -import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; @@ -24,9 +23,6 @@ import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; -import com.loopj.android.http.AsyncHttpClient; -import com.loopj.android.http.AsyncHttpResponseHandler; -import com.loopj.android.http.JsonHttpResponseHandler; import java.text.DateFormat; import java.util.Date; @@ -53,7 +49,8 @@ public class MainActivity extends Activity implements Logger dataLog; // sensor data (geo, wifi) for debugging (verbose) Logger diskLog; // pretty CSV output, i.e., the "product" of this app - static final String UPLOAD_SECRET = "sLlx6PaL"; // anti-spam filter on server + // anti-spam filter on server + static final String UPLOAD_SECRET = "sLlx6PaL"; // unique ID sent to server to distinguish clients // changes everytime logging is enabled @@ -83,16 +80,16 @@ public class MainActivity extends Activity implements Location currentLocation; // Wifi scan stuff - static WifiManager wifiManager; - static IntentFilter wifiIntentFilter; - static WifiBroadcastReceiver wifiBroadcastReceiver; + static WifiManager wifiManager; + private static IntentFilter wifiIntentFilter; + private static WifiBroadcastReceiver wifiBroadcastReceiver; // toggles logging location+wifi to file // debug logs may be created regardless of this boolean loggingEnabled = false; // wake-lock to (hopefully) continue logging while screen is off - PowerManager.WakeLock wakeLock; + private PowerManager.WakeLock wakeLock; // UI Elements Button loggingButton; @@ -107,9 +104,13 @@ public class MainActivity extends Activity implements String wifiListString; Date lastWifiScanTime; + // keys for saving user preferences private final static String SSID_FILTER_PREFERENCE_KEY = "ssid-filter-preference-key"; private final static String UPLOAD_URL_PREFERENCE_KEY = "upload-url-preference-key"; + // will be incremented when log format changes + final static int LOG_FORMAT_VERSION = 1; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/com/tomjanson/wifilocationlogger/Uploader.java b/app/src/main/java/com/tomjanson/wifilocationlogger/Uploader.java index 10f2c83..8a01b06 100644 --- a/app/src/main/java/com/tomjanson/wifilocationlogger/Uploader.java +++ b/app/src/main/java/com/tomjanson/wifilocationlogger/Uploader.java @@ -12,8 +12,8 @@ import java.io.FileNotFoundException; import java.util.UUID; -public class Uploader { - private static AsyncHttpClient client = new AsyncHttpClient(); +class Uploader { + private static final AsyncHttpClient client = new AsyncHttpClient(); private static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(url, params, responseHandler); @@ -26,7 +26,7 @@ private static void post(String url, RequestParams params, AsyncHttpResponseHand public static void upload(final MainActivity m, String pathToFile) { File file = new File(pathToFile); UUID uploadUuid = UUID.randomUUID(); - String targetFilename = m.UPLOAD_SECRET + "." + uploadUuid.toString(); + String targetFilename = MainActivity.UPLOAD_SECRET + "." + uploadUuid.toString(); m.log.info("Upload UUID: {}", uploadUuid); RequestParams params = new RequestParams(); diff --git a/app/src/main/java/com/tomjanson/wifilocationlogger/WifiBroadcastReceiver.java b/app/src/main/java/com/tomjanson/wifilocationlogger/WifiBroadcastReceiver.java index d4d1461..abf6a9f 100644 --- a/app/src/main/java/com/tomjanson/wifilocationlogger/WifiBroadcastReceiver.java +++ b/app/src/main/java/com/tomjanson/wifilocationlogger/WifiBroadcastReceiver.java @@ -100,13 +100,13 @@ private Pattern makeFilter() { } } - public static int convertFrequencyToChannel(int freq) { + private static int convertFrequencyToChannel(int freq) { if (freq >= 2412 && freq <= 2484) { return (freq - 2412) / 5 + 1; } else if (freq >= 5170 && freq <= 5825) { return (freq - 5170) / 5 + 34; } else { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(Integer.toString(freq)); } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2eba862..9751c55 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -11,10 +11,11 @@ regulärer Ausdruck WLAN WLAN-Liste - An Server senden - Bitte beachte: Die Datenübertragung zum Server erfolgt momentan unverschlüsselt und ist damit potentiell für Dritte lesbar.\nRemote Logging ist in einer frühen Versuchsphase. An Server hochladen Der Upload beinhaltet die vollständige aktuelle Logdatei, d.h. alle heute gesammelten Daten.\nWenn Du nur Auszüge des Logs hochladen möchtest, musst du es vor dem Upload manuell bearbeiten.\nÄltere Logs hochzuladen ist (noch) nicht möglich. Server Server URL + Fehler: Upload fehlgeschlagen! + Fehler: Logdatei wurde nicht gefunden + Upload erfolgreich \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e71dc1..bcd7a98 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,9 +4,6 @@ Start logging Pause logging - Send to server - Note: The remote logging connection is currently unencrypted. Data may be intercepted by third parties.\nRemote logging is experimental. - Location Lat-/Longitude Accuracy @@ -19,9 +16,9 @@ http://niobe.tomjanson.com:34570/ Upload to server Pressing upload will upload the entire current log file, i.e., all data logged today.\nIf you wish to exclude data, you must remove it from the log file before uploading.\nUploading older log files is not yet supported. - FileNotFoundException + Error: Log file was not found! Upload successful - Upload failed! + Error: Upload failed! Server Server URL