Anonymous avatar Anonymous committed 24c0816

more reliable + unfinished camera support

Comments (0)

Files changed (3)

AndroidManifest.xml

 
 <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
 
+
+<uses-permission android:name="android.permission.CAMERA"></uses-permission>
+
+
+
+
+
 </manifest> 

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;
 			throw new RuntimeException(e);
 		}
 		logging = true;
+		this.logDataEvent("log", "Logging Started", 0, false);
 	}
+	
 		
 	public void stopLogging() {
 		if (logging)
 			return;
 
 		// update the file
-		file.println(name + ": " + data + " " + ts);
+		file.println(System.currentTimeMillis() + " " + name + ": " + data + " " + ts);
 
 		if (name != "gps") // only send SMS for gps coords
 			return;

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 android.content.Context;
 import android.app.Activity;
 import android.widget.Button;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.hardware.Camera;
 
-public class IcarusMission extends Activity {
+public class IcarusMission extends Activity implements Camera.PictureCallback, Camera.PreviewCallback {
 
 	private class ExitActivityListener implements OnClickListener {
 		private IcarusMission act;
 	private PowerManager pm;
 	private PowerManager.WakeLock wl;
 	
-    @Override
+	private Camera camera;
+	private int previewFrames;
+	final int maxPreviewFrames = 20;
+
+	@Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
 		
 		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);
         dataViews = new HashMap<String, TextView>();
     }
     
+    @Override
     public void onResume() {
     	super.onResume();
+    	wl.acquire();
     	ds.resume();
-    	wl.acquire();
-    }
-    
-    public void onPause() {
-    	super.onPause();
-    	ds.pause();
-    }
-    
-    public void onDestroy() {
-    	super.onDestroy();
-    	logger.stopLogging();
-    	if (wl.isHeld())
-    		wl.release();
+    	//camera.startPreview();
+    	//previewFrames = 0;
     }
     
     public void logDataEvent(String name, String data, long ts, boolean hasService) {
     	logger.logDataEvent(name, data, ts, hasService);
     	if (ts > 0)
-    		tv.setText("Timestamp: "+ts);
+    		tv.setText("GPS Timestamp: "+ts);
     	TextView t;
     	if (!dataViews.containsKey(name))
     	{
     	t.setText(name + " " + data);
     }
 
+	public void onPictureTaken(byte[] pictureData, Camera c) {
+		tv.setText("Picture Callback");
+		c.stopPreview();
+		this.writeImage(pictureData);
+	}
+
+	public void onPreviewFrame(byte[] pictureData, Camera c) {
+		tv.setText("Preview Callback");
+		if (previewFrames > maxPreviewFrames)
+			c.takePicture(null, null, this);
+		else
+			previewFrames+= 1;
+	}
+	
+	private void writeImage(byte[] pictureData) {
+		String fn = "/sdcard/autopic-" + System.currentTimeMillis() + ".jpg";
+		try {
+			FileOutputStream file = new FileOutputStream(fn);
+			file.write(pictureData);
+			file.close();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.