Commits

shkoo committed c632f91

cleaned up warnings, changed reporting number to google voice number

Comments (0)

Files changed (3)

src/to/rcpt/icarus/DataSource.java

 
 public class DataSource implements LocationListener {
 
-	public int gsmState;
-	
-	private SensorManager sensors;
-	private List<SensorEventAdapter> adapterlist;
-
-	private LocationManager gps;
-	private String provider;
-	
-	private IcarusMission mission;
-
 	private class SensorEventAdapter implements SensorEventListener {
 		private DataSource ds;
 		private Sensor s;
-		
+
 		public SensorEventAdapter(Sensor s, DataSource ds) {
 			this.s = s;
 			this.ds = ds;
 		}
-		
-		public void onSensorChanged(SensorEvent event) {
-			String s = "";
-			for(float f: event.values) {
-				s += " " + f;
-			}
-			this.ds.logDataEvent(event.sensor.getName(), s, 0);
-		}
 
 		public void onAccuracyChanged(Sensor sensor, int accuracy) {
 		}
-		
-		public void startSensor() {			
-        	sensors.registerListener(this, s, SensorManager.SENSOR_DELAY_UI);
+
+		public void onSensorChanged(SensorEvent event) {
+			String sdata = "";
+			for (float f : event.values)
+				sdata += " " + f;
+			this.ds.logDataEvent(event.sensor.getName(), sdata, 0);
 		}
-		
+
+		public void startSensor() {
+			sensors.registerListener(this, s, SensorManager.SENSOR_DELAY_UI);
+		}
+
 		public void stopSensor() {
 			sensors.unregisterListener(this);
 		}
 
 	private class StateListener extends PhoneStateListener {
 		private DataSource ds;
+
 		public StateListener(DataSource ds) {
 			this.ds = ds;
 		}
+
+		@Override
 		public void onServiceStateChanged(ServiceState serviceState) {
-			int gsmState = serviceState.getState();
-			this.ds.gsmState = gsmState;
-			this.ds.logDataEvent(
-					"gsmState changed", 
-					""+gsmState,
-					0);
+			int newGsmState = serviceState.getState();
+			this.ds.gsmState = newGsmState;
+			this.ds.logDataEvent("gsmState changed", "" + gsmState, 0);
 		}
 	}
-	
+
+	public int gsmState;
+
+	private SensorManager sensors;
+	private List<SensorEventAdapter> adapterlist;
+
+	private LocationManager gps;
+
+	private String provider;
+
+	private IcarusMission mission;
+
 	public DataSource(IcarusMission m) {
 		mission = m;
-		
+
 		// set up service state listener
-        gsmState = -1;
-        TelephonyManager tm = (TelephonyManager) m.getSystemService(Context.TELEPHONY_SERVICE);
-        tm.listen(new StateListener(this), PhoneStateListener.LISTEN_SERVICE_STATE);
+		gsmState = -1;
+		TelephonyManager tm = (TelephonyManager) m
+				.getSystemService(Context.TELEPHONY_SERVICE);
+		tm.listen(new StateListener(this),
+				PhoneStateListener.LISTEN_SERVICE_STATE);
 
-        // set up sensor listener
-        sensors = (SensorManager) m.getSystemService(Context.SENSOR_SERVICE);
-        adapterlist = new LinkedList<SensorEventAdapter>();
-        for(Sensor s: sensors.getSensorList(Sensor.TYPE_ALL)) {
-        	adapterlist.add(new SensorEventAdapter(s, this));
-        }
+		// set up sensor listener
+		sensors = (SensorManager) m.getSystemService(Context.SENSOR_SERVICE);
+		adapterlist = new LinkedList<SensorEventAdapter>();
+		for (Sensor s : sensors.getSensorList(Sensor.TYPE_ALL))
+			adapterlist.add(new SensorEventAdapter(s, this));
 
-        // set up gps
-        gps = (LocationManager) m.getSystemService(Context.LOCATION_SERVICE);
+		// set up gps
+		gps = (LocationManager) m.getSystemService(Context.LOCATION_SERVICE);
 		Criteria c = new Criteria();
 		c.setAccuracy(Criteria.ACCURACY_FINE);
 		c.setAltitudeRequired(true);
 		c.setSpeedRequired(true);
 		provider = gps.getBestProvider(c, true);
 	}
-	
-	public void resume() {
-		gps.requestLocationUpdates(provider, 0, 0, this);
-    	for (SensorEventAdapter s: adapterlist) {
-    		s.startSensor();
-    	}	
+
+	public void logDataEvent(String name, String data, long ts) {
+		mission.logDataEvent(name, data, ts,
+				this.gsmState == ServiceState.STATE_IN_SERVICE);
+	}
+
+	public void onLocationChanged(Location l) {
+		this.logDataEvent("gps", l.getLatitude() + "," + l.getLongitude() + " "
+				+ l.getAltitude(), l.getTime());
+	}
+
+	public void onProviderDisabled(String providezr) {
+	}
+
+	public void onProviderEnabled(String providezr) {
+	}
+
+	public void onStatusChanged(String providezr, int status, Bundle extras) {
 	}
 
 	public void pause() {
 		gps.removeUpdates(this);
-    	for (SensorEventAdapter s: adapterlist) {
-    		s.stopSensor();
-    	}
-	}
-	
-	public void logDataEvent(String name, String data, long ts) {
-		mission.logDataEvent(name, data, ts, this.gsmState == ServiceState.STATE_IN_SERVICE);
+		for (SensorEventAdapter s : adapterlist)
+			s.stopSensor();
 	}
 
-	public void onLocationChanged(Location l) {
-		this.logDataEvent(
-				"gps", 
-				l.getLatitude() + "," + l.getLongitude() + " " + l.getAltitude(), 
-				l.getTime());
-	}
-
-	public void onProviderDisabled(String provider) {	
-	}
-
-	public void onProviderEnabled(String provider) {
-	}
-
-	public void onStatusChanged(String provider, int status, Bundle extras) {
+	public void resume() {
+		gps.requestLocationUpdates(provider, 0, 0, this);
+		for (SensorEventAdapter s : adapterlist)
+			s.startSensor();
 	}
 }

src/to/rcpt/icarus/IcarusLogger.java

 package to.rcpt.icarus;
 
-import java.lang.System;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import android.telephony.SmsManager;
 import android.widget.CompoundButton;
-import android.telephony.SmsManager;
 
 public class IcarusLogger implements CompoundButton.OnCheckedChangeListener {
 
-	public final String destPhoneNumber = "4155086087";
+	public final String destPhoneNumber = "2096270247";
 	final String logfileName = "IcarusLog";
 	final long sendInterval = 60000;
 
 	private PrintWriter file;
 	private SmsManager smsmanager;
 	private long lastSent;
-	
+
 	private boolean logging;
-	
+
 	public IcarusLogger() {
 		smsmanager = SmsManager.getDefault();
 		lastSent = 0;
 		logging = false;
 	}
 
-	public void startLogging() {
-		try {
-			File f = new File("/sdcard", logfileName);
-			try {
-				f.createNewFile();
-			} catch(IOException e) {
-				throw new RuntimeException(e);
-			}
-			file = new PrintWriter(new FileOutputStream(f, true));
-		} catch(FileNotFoundException e) {
-			throw new RuntimeException(e);
-		}
-		logging = true;
-		this.logDataEvent("log", "Logging Started", 0, false);
-	}
-	
-		
-	public void stopLogging() {
-		if (logging)
-			return;
-		file.close();
-		logging = false;
-	}
-	
-	public void logDataEvent(String name, String data, long ts, boolean hasService) {
+	public void logDataEvent(String name, String data, long ts,
+			boolean hasService) {
 		if (!logging)
 			return;
 
 		// update the file
-		file.println(System.currentTimeMillis() + " " + name + ": " + data + " " + ts);
+		file.println(System.currentTimeMillis() + " " + name + ": " + data
+				+ " " + ts);
 
 		if (name != "gps") // only send SMS for gps coords
 			return;
 
 		// send SMS if okay to do so
-		boolean sendIntervalExceeded = lastSent < (ts-sendInterval);
+		boolean sendIntervalExceeded = lastSent < (ts - sendInterval);
 		if (hasService && sendIntervalExceeded) {
 			smsmanager.sendTextMessage(destPhoneNumber, null, data, null, null);
 			lastSent = ts;
 		else
 			this.stopLogging();
 	}
-	
+
+	public void startLogging() {
+		try {
+			File f = new File("/sdcard", logfileName);
+			try {
+				f.createNewFile();
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+			file = new PrintWriter(new FileOutputStream(f, true));
+		} catch (FileNotFoundException e) {
+			throw new RuntimeException(e);
+		}
+		logging = true;
+		this.logDataEvent("log", "Logging Started", 0, false);
+	}
+
+	public void stopLogging() {
+		if (logging)
+			return;
+		file.close();
+		logging = false;
+	}
+
 }

src/to/rcpt/icarus/IcarusMission.java

 package to.rcpt.icarus;
 
-import java.util.HashMap;
-import java.lang.System;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.HashMap;
 
+import android.app.Activity;
 import android.content.Context;
-import android.app.Activity;
+import android.hardware.Camera;
+import android.os.Bundle;
 import android.os.PowerManager;
-import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.ToggleButton;
-import android.widget.Button;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.hardware.Camera;
 
-public class IcarusMission extends Activity implements Camera.PictureCallback, Camera.PreviewCallback {
+public class IcarusMission extends Activity implements Camera.PictureCallback,
+		Camera.PreviewCallback {
 
 	private class ExitActivityListener implements OnClickListener {
 		private IcarusMission act;
+
 		public ExitActivityListener(IcarusMission a) {
 			act = a;
 		}
 			act.finish();
 		}
 	}
-	
+
 	private TextView tv;
 	private LinearLayout ll;
 	private int index;
 	private HashMap<String, TextView> dataViews;
-	
+
 	private DataSource ds;
 	private IcarusLogger logger;
 	private PowerManager pm;
 	private PowerManager.WakeLock wl;
-	
-	private Camera camera;
+
+	// private Camera camera;
 	private int previewFrames;
 	final int maxPreviewFrames = 20;
 
+	public void logDataEvent(String name, String data, long ts,
+			boolean hasService) {
+		logger.logDataEvent(name, data, ts, hasService);
+		if (ts > 0)
+			tv.setText("GPS Timestamp: " + ts);
+		TextView t;
+		if (!dataViews.containsKey(name)) {
+			t = new TextView(this);
+			ll.addView(t, index++);
+			dataViews.put(name, t);
+		} else
+			t = dataViews.get(name);
+		t.setText(name + " " + data);
+	}
+
 	@Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
 
-        logger = new IcarusLogger();
+		logger = new IcarusLogger();
 		ds = new DataSource(this);
-		
+
 		pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 		wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IcarusMission");
-		
-		//camera = Camera.open();
-		//camera.setPreviewCallback(this);
 
-    	index = 0;
-        ll = new LinearLayout(this);
-        ll.setOrientation(LinearLayout.VERTICAL);
+		// camera = Camera.open();
+		// camera.setPreviewCallback(this);
 
-        ToggleButton b = new ToggleButton(this);
-        b.setTextOff("Start mission");
-        b.setTextOn("Stop mission");
-        b.setOnCheckedChangeListener(logger);
-        ll.addView(b, index++);
-        
-        TextView destNum = new TextView(this);
-        destNum.setText("Destination #: "+logger.destPhoneNumber);
-        ll.addView(destNum, index++);
+		index = 0;
+		ll = new LinearLayout(this);
+		ll.setOrientation(LinearLayout.VERTICAL);
 
-        tv = new TextView(this);
-        tv.setText("Hello, Icarus");
-        ll.addView(tv, index++);
+		ToggleButton b = new ToggleButton(this);
+		b.setTextOff("Start mission");
+		b.setTextOn("Stop mission");
+		b.setOnCheckedChangeListener(logger);
+		ll.addView(b, index++);
+
+		TextView destNum = new TextView(this);
+		destNum.setText("Destination #: " + logger.destPhoneNumber);
+		ll.addView(destNum, index++);
+
+		tv = new TextView(this);
+		tv.setText("Hello, Icarus");
+		ll.addView(tv, index++);
 
 		Button exitButton = new Button(this);
-        exitButton.setOnClickListener(new ExitActivityListener(this));
-        exitButton.setText("Exit");
-        ll.addView(exitButton, index++);        
+		exitButton.setOnClickListener(new ExitActivityListener(this));
+		exitButton.setText("Exit");
+		ll.addView(exitButton, index++);
 
-        setContentView(ll);
-        
-        dataViews = new HashMap<String, TextView>();
-    }
-    
-    @Override
-    public void onResume() {
-    	super.onResume();
-    	wl.acquire();
-    	ds.resume();
-    	//camera.startPreview();
-    	//previewFrames = 0;
-    }
-    
-    public void onDestroy() {
-    	super.onDestroy();
-    	ds.pause();
-    }
-    
-    public void logDataEvent(String name, String data, long ts, boolean hasService) {
-    	logger.logDataEvent(name, data, ts, hasService);
-    	if (ts > 0)
-    		tv.setText("GPS Timestamp: "+ts);
-    	TextView t;
-    	if (!dataViews.containsKey(name))
-    	{
-    		t = new TextView(this);
-    		ll.addView(t, index++);
-    		dataViews.put(name, t);
-    	}
-    	else
-    		t = dataViews.get(name);
-    	t.setText(name + " " + data);
-    }
+		setContentView(ll);
+
+		dataViews = new HashMap<String, TextView>();
+	}
+
+	@Override
+	public void onDestroy() {
+		super.onDestroy();
+		ds.pause();
+	}
 
 	public void onPictureTaken(byte[] pictureData, Camera c) {
 		tv.setText("Picture Callback");
 		if (previewFrames > maxPreviewFrames)
 			c.takePicture(null, null, this);
 		else
-			previewFrames+= 1;
+			previewFrames += 1;
 	}
-	
+
+	@Override
+	public void onResume() {
+		super.onResume();
+		wl.acquire();
+		ds.resume();
+		// camera.startPreview();
+		// previewFrames = 0;
+	}
+
 	private void writeImage(byte[] pictureData) {
 		String fn = "/sdcard/autopic-" + System.currentTimeMillis() + ".jpg";
 		try {