Permalink
Browse files

enabling debug mode. hunting for battery issues.

  • Loading branch information...
1 parent 4704fed commit 34309ba6e37d610f846a1fd34fca2c7bfd1235b6 @JacobSheehy committed Feb 17, 2013
View
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.cumulonimbus.barometernetwork"
- android:versionCode="301"
- android:versionName="3.0.1">
+ android:versionCode="302"
+ android:versionName="3.0.2">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity android:name="ca.cumulonimbus.barometernetwork.SettingsActivity"
@@ -462,12 +462,12 @@ private void getStoredPreferences() {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
mUpdateServerAutomatically = settings.getBoolean("autoupdate", true);
mUpdateServerFrequency = settings.getString("autofrequency", "10 minutes");
- log("shared prefs: " + mUpdateServerFrequency + " " + mUpdateServerAutomatically);
+ //log("shared prefs: " + mUpdateServerFrequency + " " + mUpdateServerAutomatically);
// Units
String abbrev = settings.getString("units", "mbar");
mUnit = new Unit(abbrev);
- log("abbrev: " + abbrev);
+ //log("abbrev: " + abbrev);
} catch(Exception e) {
log(e.getMessage() + "");
@@ -494,17 +494,16 @@ public void setId() {
}
}
-
-
// Used to write a log to SD card. Not used unless logging enabled.
public void setUpFiles() {
try {
File homeDirectory = getExternalFilesDir(null);
if(homeDirectory!=null) {
mAppDir = homeDirectory.getAbsolutePath();
+
}
} catch (Exception e) {
- //log(e.getMessage());
+ log(e.getMessage());
}
}
@@ -517,7 +516,7 @@ public void setUpBarometer() {
if(bar!=null) {
boolean running = sm.registerListener(this, bar, SensorManager.SENSOR_DELAY_NORMAL);
- log(running + "");
+ //log(running + "");
barometerDetected = true;
} else {
barometerDetected = false;
@@ -539,14 +538,13 @@ public void setUpMap() {
// Set default coordinates (centered around the user's location)
- log("about to get controller");
try {
MapController mc = mapView.getController();
LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Location loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
mc.setZoom(8);
if(loc.getLatitude()!=0) {
- log("setting center " + loc.getLatitude() + " " + loc.getLongitude());
+ //log("setting center " + loc.getLatitude() + " " + loc.getLongitude());
mc.animateTo(new GeoPoint((int)(loc.getLatitude()*1E6), (int)(loc.getLongitude() * 1E6)));
} else {
log("no known last location");
@@ -586,10 +584,10 @@ public void onLocationChanged(Location location) {
mLatitude = latitude;
mLongitude = longitude;
if(first) {
- log("first location start");
+ //log("first location start");
setUpMap();
loadAndShowData();
- log("end");
+ //log("end");
}
} catch(Exception e) {
log("On Location change failed.");
@@ -738,7 +736,6 @@ public void addDataToMap(ArrayList<BarometerReading> list, boolean showTendencie
mapOverlays.clear();
// add a bunch of coords
- log("starting adding total " + list.size());
try {
for(BarometerReading br : list) {
// log(br.getReading() + "");
@@ -772,7 +769,7 @@ public void addDataToMap(ArrayList<BarometerReading> list, boolean showTendencie
} catch(Exception e) {
log("add data error: " + e.getMessage());
}
- log("end of adddatatomap");
+
}
// Runnable to refresh the map. Can be called when another
@@ -811,16 +808,16 @@ public void run() {
// Assemble a HashMap of userIDs and tendencies. //This is the opposite of function barometerReadingToWeb in the servlet.
public HashMap<String, String> csvToBarometerTendencies(String[] readings) {
- log("csv to barometer tendencies : " + readings[0] + ", " + readings.length);
+ //log("csv to barometer tendencies : " + readings[0] + ", " + readings.length);
HashMap<String, String> tendencies = new HashMap<String, String>();
for(int i = 0; i<readings.length; i++) {
try {
String[] values = readings[i].split(",");
for(String a : values) {
- log(a);
+ //log(a);
}
- log("tendency check " + values[5]);
+ //log("tendency check " + values[5]);
tendencies.put(values[5], values[6]); // userid, tendency
} catch(Exception e) {
// Likely, the server returned an error.
@@ -947,7 +944,7 @@ protected String doInBackground(String... arg0) {
String responseText = "";
try {
- log("DataDownload doInBackground start try block");
+ //log("DataDownload doInBackground start try block");
// Instantiate the custom HttpClient
DefaultHttpClient client = new SecureHttpClient(getApplicationContext());
@@ -1010,7 +1007,7 @@ protected String doInBackground(String... arg0) {
return responseText;
}
protected void onPostExecute(String result) {
- log("datadownload post execute " + result);
+ //log("datadownload post execute " + result);
processDownloadResult(result);
mapHandler.postDelayed(refreshMap, 100);
@@ -1193,7 +1190,7 @@ public void logToFile(String text) {
}
public void log(String text) {
- //logToFile(text);
- //System.out.println(text);
+ logToFile(text);
+ System.out.println(text);
}
}
@@ -2,6 +2,7 @@
import java.io.BufferedInputStream;
import java.io.DataInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -78,6 +79,21 @@
private boolean waitingForReading = false;
+
+ // Used to write a log to SD card. Not used unless logging enabled.
+ public void setUpFiles() {
+ try {
+ File homeDirectory = getExternalFilesDir(null);
+ if(homeDirectory!=null) {
+ mAppDir = homeDirectory.getAbsolutePath();
+ }
+ log("setting up logging");
+ } catch (Exception e) {
+ //log(e.getMessage());
+ }
+ }
+
+
private boolean networkOnline() {
try {
// Test connectivity before attempting to send readings
@@ -103,7 +119,7 @@ private boolean networkOnline() {
LocationListener locationListener;
// Get the user's location from the location service, preferably GPS.
public void getLocationInformation() {
-
+ log("get location information");
// get the location
// Acquire a reference to the system Location Manager
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
@@ -121,6 +137,7 @@ public void onLocationChanged(Location location) {
// no changes. stop for now.
if(mLatitude == latitude) {
if (mLongitude == longitude) {
+ log("pausing location lookup");
locationManager.removeUpdates(locationListener);
}
}
@@ -163,7 +180,6 @@ public void setUpBarometer() {
if(bar!=null) {
barometerReadingsActive = sm.registerListener(this, bar, SensorManager.SENSOR_DELAY_UI);
- log("bar is not null, listening " + barometerReadingsActive);
} else {
log("bar is null");
}
@@ -302,7 +318,6 @@ protected Long doInBackground(String... arg0) {
try {
log("offline. adding to queue " + mReading + " of size " + submitList.size());
submitList.add(br);
- log("added to queue");
} catch(Exception e) {
log(e.getMessage());
}
@@ -323,7 +338,7 @@ protected void onPostExecute(Long result) {
private Runnable mWaitForBarometer = new Runnable() {
public void run() {
- log("rs attempt: " + mLatitude + " " + mLongitude + ": " + mReading);
+ //log("rs attempt: " + mLatitude + " " + mLongitude + ": " + mReading);
new ReadingSender().execute("");
}
};
@@ -337,7 +352,7 @@ public void sendBarometerReading() {
setId();
if(mReading == 0.0) {
- log("active barometer: " + barometerReadingsActive);
+ //log("active barometer: " + barometerReadingsActive);
} else {
log("rs attempt: " + mLatitude + " " + mLongitude + ": " + mReading);
new ReadingSender().execute("");
@@ -396,8 +411,8 @@ public void logToFile(String text) {
}
public void log(String text) {
- //System.out.println(text);
- //logToFile(text);
+ System.out.println(text);
+ logToFile(text);
}
private long convertSettingsTextToSeconds(String text) {
@@ -452,19 +467,6 @@ public void onDestroy() {
}
@Override
- public void onStart(Intent intent, int startId) {
- // TODO Auto-generated method stub
- //System.out.println("on start submitreadingservice");
- System.out.println("on start");
- try {
- //sendDataPeriodically();
- } catch(Exception e) {
- System.out.println(e.getMessage());
- }
- super.onStart(intent, startId);
- }
-
- @Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
try {
@@ -481,11 +483,7 @@ public boolean onUnbind(Intent intent) {
public int onStartCommand(Intent intent, int flags, int startId) {
log("on start command");
try {
- //mAppDir = intent.getStringExtra("appdir");
- } catch(Exception e) {
-
- }
- try {
+ setUpFiles(); // start logs
setUpDatabase();
} catch(Exception e) {
@@ -2,12 +2,16 @@
import java.io.BufferedInputStream;
import java.io.DataInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import android.app.Service;
import android.appwidget.AppWidgetManager;
@@ -44,11 +48,13 @@
private String mAppDir = "";
+
+
public void startListening() {
try {
sm = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
Sensor bar = sm.getDefaultSensor(Sensor.TYPE_PRESSURE);
-
+ log("widget start listening pressure");
if(bar!=null) {
running = sm.registerListener(this, bar, SensorManager.SENSOR_DELAY_NORMAL);
//Toast.makeText(getApplicationContext(), "starting listener", Toast.LENGTH_SHORT).show();
@@ -113,6 +119,8 @@ public void update(Intent intent, double reading) {
recents = dbAdapter.fetchRecentReadings(5); // the last few hours
String tendency = ScienceHandler.findTendency(recents);
+ log("widget getting tendency, updating and sending");
+
if(tendency.contains("rising")) {
remoteView.setInt(R.id.widget_tendency_image_up, "setVisibility", View.VISIBLE);
remoteView.setInt(R.id.widget_tendency_image_down, "setVisibility", View.INVISIBLE);
@@ -262,6 +270,7 @@ public void onDestroy() {
public void onStart(Intent intent, int startId) {
try {
mAppDir = intent.getStringExtra("appdir");
+
} catch(Exception e) {
}
@@ -282,13 +291,15 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
+
+
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_PRESSURE:
mReading = event.values[0];
- //Toast.makeText(getApplicationContext(), mReading + "", Toast.LENGTH_SHORT).show();
+ log("widget sensor changed " + mReading + " and unregistering");
update(new Intent(), mReading);
sm.unregisterListener(this);
mReading = 0.0;
@@ -297,4 +308,25 @@ public void onSensorChanged(SensorEvent event) {
}
+ // Log data to SD card for debug purposes.
+ // To enable logging, ensure the Manifest allows writing to SD card.
+ public void logToFile(String text) {
+ try {
+ OutputStream output = new FileOutputStream(mAppDir + "/log.txt", true);
+ String logString = (new Date()).toString() + ": " + text + "\n";
+ output.write(logString.getBytes());
+ output.close();
+
+ } catch(FileNotFoundException e) {
+
+ } catch(IOException ioe) {
+
+ }
+ }
+
+ public void log(String text) {
+ System.out.println(text);
+ logToFile(text);
+ }
+
}

0 comments on commit 34309ba

Please sign in to comment.