Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 5691e38c32baba9389a121d8f1a01f87c053a28a @edwardcunningham edwardcunningham committed Oct 19, 2011
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,2 @@
+bin
+gen
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>SquirrelCamera</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="uk.ac.cam.cusf.squirrelcamera" android:versionCode="1"
+ android:versionName="1.1">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".SquirrelCamera" android:label="@string/app_name"
+ android:screenOrientation="portrait">
+
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+
+ <intent-filter>
+ <action android:name="uk.ac.cam.cusf.squirrelcamera.CAMERA_ACTIVITY" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ </application>
+ <uses-sdk android:minSdkVersion="8" />
+
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-feature android:name="android.hardware.camera" />
+ <uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.REBOOT" />
+
+</manifest>
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="fill_parent"
+ android:layout_height="fill_parent" android:gravity="center">
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:text="Squirrel Camera"
+ android:gravity="center" android:textAppearance="?android:attr/textAppearanceLarge"
+ android:paddingBottom="10dp" />
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:text="An app for scheduled photo and video capture"
+ android:gravity="center" android:textAppearance="?android:attr/textAppearanceSmall"
+ android:paddingBottom="20dp" />
+
+ <CheckBox android:text=" Confirm action?" android:id="@+id/CheckBox01"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
+ <Button android:text="Start" android:id="@+id/Button01"
+ android:layout_width="150dp" android:layout_height="wrap_content"
+ android:layout_marginTop="10dp"></Button>
+
+ <SurfaceView android:id="@+id/SurfaceView01"
+ android:layout_width="1dip" android:layout_height="1dip"></SurfaceView>
+
+</LinearLayout>
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Squirrel Camera</string>
+</resources>
@@ -0,0 +1,13 @@
+package uk.ac.cam.cusf.squirrelcamera;
+
+import java.io.IOException;
+
+public interface CameraRunnable {
+
+ public void takePhoto() throws Storage.DiskException;
+
+ public void startVideo() throws RuntimeException, IOException;
+
+ public void stopVideo();
+
+}
@@ -0,0 +1,232 @@
+package uk.ac.cam.cusf.squirrelcamera;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import android.hardware.Camera;
+import android.media.CamcorderProfile;
+import android.os.Environment;
+import android.util.Log;
+import android.view.Surface;
+
+public class DebugMediaRecorder {
+
+ private static final String TAG = "SquirrelCamera";
+
+ private android.media.MediaRecorder recorder;
+ private static PrintStream out;
+
+ private ExecutorService executor;
+ private Callable<Void> task;
+
+ private boolean ERROR = false;
+
+ public void openFile() {
+ if (out != null) {
+ out.close();
+ }
+ File exportDir = new File(Environment.getExternalStorageDirectory(),
+ "DebugMediaRecorder");
+ if (!exportDir.exists()) {
+ exportDir.mkdirs();
+ }
+ File file = new File(exportDir, "debuglog" + System.currentTimeMillis()
+ + ".txt");
+ try {
+ if (!file.exists())
+ file.createNewFile();
+ out = new PrintStream(file);
+ } catch (IOException e) {
+ Log.e("DebugMediaRecorder", "IOException!", e);
+ }
+ }
+
+ private void log(String msg, Exception e) {
+ out.print(msg + "\n");
+ e.printStackTrace(out);
+ out.flush();
+ }
+
+ private void log(String msg) {
+ out.print(msg + "\n");
+ out.flush();
+ }
+
+ public DebugMediaRecorder() {
+ openFile();
+
+ executor = Executors.newCachedThreadPool();
+
+ task = new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Log.i(TAG, "BEFORE recorder.stop");
+ recorder.stop();
+ Log.i(TAG, "AFTER recorder.stop");
+ return null;
+ }
+ };
+
+ log("MediaRecorder()");
+ recorder = new android.media.MediaRecorder();
+ }
+
+ public void start() throws IllegalStateException {
+ try {
+ log("start()");
+ recorder.start();
+ } catch (IllegalStateException e) {
+ log("IllegalStateException in start()", e);
+ throw e;
+ }
+ }
+
+ public void stop() throws IllegalStateException, ExecutionException {
+
+ /*
+ * Why do we use a Future/Executor here? - In testing under 2.3.3,
+ * stop() sometimes blocked indefinitely - Future attempts to connect to
+ * the camera will fail, so not really a solution
+ */
+
+ // Perhaps we should throw a fatal exception here and restart app,
+ // or even reboot the device (if on rooted ROM)?
+
+ Future<Void> future = executor.submit(task);
+ try {
+ ERROR = true;
+ future.get(5, TimeUnit.SECONDS);
+ ERROR = false;
+ } catch (ExecutionException e) {
+ Log.i(TAG, "ExecutionException", e);
+ log("ExecutionException", e);
+ throw e;
+ } catch (InterruptedException e) {
+ Log.i(TAG, "InterruptedException", e);
+ log("InterruptedException", e);
+ } catch (TimeoutException e) {
+ Log.i(TAG, "TimeoutException", e);
+ log("TimeoutException", e);
+ } finally {
+ future.cancel(true);
+ }
+ }
+
+ public void reset() {
+ log("reset()");
+ Log.i(TAG, "reset()");
+ if (!ERROR)
+ recorder.reset();
+ }
+
+ public void release() {
+ log("release()");
+ Log.i(TAG, "release()");
+ if (!ERROR)
+ recorder.release();
+ }
+
+ public void setOnInfoListener(
+ android.media.MediaRecorder.OnInfoListener listener) {
+ log("setOnInfoListener()");
+ recorder.setOnInfoListener(listener);
+ }
+
+ public void setOnErrorListener(
+ android.media.MediaRecorder.OnErrorListener listener) {
+ log("setOnErrorListener()");
+ recorder.setOnErrorListener(listener);
+ }
+
+ public void setPreviewDisplay(Surface surface) {
+ log("setPreviewDisplay()");
+ recorder.setPreviewDisplay(surface);
+ }
+
+ public void setCamera(Camera camera) {
+ log("setCamera()");
+ recorder.setCamera(camera);
+ }
+
+ public void setAudioSource(int audio_source) throws IllegalStateException {
+ try {
+ log("setAudioSource()");
+ recorder.setAudioSource(audio_source);
+ } catch (IllegalStateException e) {
+ log("IllegalStateException in setAudioSource()", e);
+ throw e;
+ }
+ }
+
+ public void setVideoSource(int video_source) throws IllegalStateException {
+ try {
+ log("setVideoSource()");
+ recorder.setVideoSource(video_source);
+ } catch (IllegalStateException e) {
+ log("IllegalStateException in setVideoSource()", e);
+ throw e;
+ }
+ }
+
+ public void setProfile(CamcorderProfile profile) {
+ log("setProfile()");
+ recorder.setProfile(profile);
+ }
+
+ public void setOutputFile(String path) throws IllegalStateException {
+ try {
+ log("setOutputFile()");
+ recorder.setOutputFile(path);
+ } catch (IllegalStateException e) {
+ log("IllegalStateException in setOutputFile()", e);
+ throw e;
+ }
+ }
+
+ public void setMaxDuration(int duration) throws IllegalArgumentException {
+ try {
+ log("setMaxDuration()");
+ recorder.setMaxDuration(duration);
+ } catch (IllegalArgumentException e) {
+ log("IllegalArgumentException in setMaxDuration()", e);
+ throw e;
+ }
+ }
+
+ public void setMaxFileSize(long max_filesize_bytes)
+ throws IllegalArgumentException {
+ try {
+ log("setMaxFileSize()");
+ recorder.setMaxFileSize(max_filesize_bytes);
+ } catch (IllegalArgumentException e) {
+ log("IllegalArgumentException in setMaxFileSize()", e);
+ throw e;
+ }
+ }
+
+ public void prepare() throws IllegalStateException, IOException {
+ try {
+ log("prepare()");
+ recorder.prepare();
+ } catch (IllegalStateException e) {
+ log("IllegalStateException in prepare()", e);
+ throw e;
+ } catch (IOException e) {
+ log("IOException in prepare()", e);
+ throw e;
+ }
+ }
+
+ public void setVideoFrameRate(int rate) {
+ recorder.setVideoFrameRate(rate);
+ }
+
+}
Oops, something went wrong.

0 comments on commit 5691e38

Please sign in to comment.