diff --git a/.classpath b/.classpath
index f0b94296..ff33dbc2 100644
--- a/.classpath
+++ b/.classpath
@@ -3,5 +3,6 @@
+
diff --git a/libs/commons-codec-1.3.jar b/libs/commons-codec-1.3.jar
new file mode 100644
index 00000000..957b6752
Binary files /dev/null and b/libs/commons-codec-1.3.jar differ
diff --git a/local.properties b/local.properties
index e3fc4c14..68fc6af4 100644
--- a/local.properties
+++ b/local.properties
@@ -7,4 +7,4 @@
# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
-sdk-location=/home/bowserj/android-sdk-linux_x86-1.5_r1
+sdk-location=/home/bowserj/android-sdk-linux_x86-1.5_r3
diff --git a/src/com/phonegap/demo/CameraLauncher.java b/src/com/phonegap/demo/CameraLauncher.java
index 4e40345d..eff8214d 100644
--- a/src/com/phonegap/demo/CameraLauncher.java
+++ b/src/com/phonegap/demo/CameraLauncher.java
@@ -1,19 +1,47 @@
package com.phonegap.demo;
-import android.content.Context;
+
+import java.io.ByteArrayOutputStream;
+
+import android.graphics.BitmapFactory;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
import android.webkit.WebView;
-
-
+import org.apache.commons.codec.binary.Base64;
public class CameraLauncher {
-
+
private WebView mAppView;
- private Context mCtx;
+ private DroidGap mGap;
+ int quality;
- CameraLauncher(WebView view, Context ctx)
+ CameraLauncher(WebView view, DroidGap gap)
{
mAppView = view;
- mCtx = ctx;
+ mGap = gap;
+ }
+
+ public void takePicture(int quality)
+ {
+ mGap.startCamera();
+ }
+
+ /* Return Base64 Encoded String to Javascript */
+ public void processPicture( byte[] data )
+ {
+ ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
+ Bitmap myMap = BitmapFactory.decodeByteArray(data, 0, data.length);
+ if (myMap.compress(CompressFormat.JPEG, quality, jpeg_data))
+ {
+ byte[] code = jpeg_data.toByteArray();
+ byte[] output = Base64.encodeBase64(code);
+ String js_out = output.toString();
+ mAppView.loadUrl("javascript:Camera.win('" + js_out + "');");
+ }
+ else
+ {
+ mAppView.loadUrl("javascript:Camera.fail();");
+ }
}
}
diff --git a/src/com/phonegap/demo/CameraPreview.java b/src/com/phonegap/demo/CameraPreview.java
index a4477480..8a0b974d 100644
--- a/src/com/phonegap/demo/CameraPreview.java
+++ b/src/com/phonegap/demo/CameraPreview.java
@@ -18,9 +18,15 @@ import android.view.SurfaceHolder.Callback;
public class CameraPreview extends Activity implements SurfaceHolder.Callback{
private static final String TAG = "CameraApiTest";
+ private SurfaceView mSurfaceView;
+ private SurfaceHolder mSurfaceHolder;
+
Camera mCamera;
boolean mPreviewRunning = false;
-
+
+ int quality;
+ Intent mIntent;
+
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
@@ -34,7 +40,8 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
- mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+ mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+ mIntent = this.getIntent();
}
public boolean onCreateOptionsMenu(android.view.Menu menu) {
@@ -57,17 +64,24 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
}
/*
- * Take JPEG Data and do what now?
+ * We got the data, send it back to PhoneGap to be handled and processed.
*
*/
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera c) {
Log.e(TAG, "PICTURE CALLBACK: data.length = " + data.length);
- mCamera.startPreview();
+ storeAndExit(data);
}
};
+ // Store what we have and get out!
+ public void storeAndExit(byte[] data)
+ {
+ mIntent.putExtra("picture", data);
+ setResult(RESULT_OK, mIntent);
+ finish();
+ }
public boolean onKeyDown(int keyCode, KeyEvent event)
{
@@ -137,7 +151,4 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
mCamera.release();
}
- private SurfaceView mSurfaceView;
- private SurfaceHolder mSurfaceHolder;
-
}
diff --git a/src/com/phonegap/demo/DroidGap.java b/src/com/phonegap/demo/DroidGap.java
index ff0655a9..162e1047 100644
--- a/src/com/phonegap/demo/DroidGap.java
+++ b/src/com/phonegap/demo/DroidGap.java
@@ -45,7 +45,7 @@ public class DroidGap extends Activity {
private PhoneGap gap;
private GeoBroker geo;
private AccelListener accel;
-
+ private CameraLauncher launcher;
/** Called when the activity is first created. */
@Override
@@ -64,6 +64,9 @@ public class DroidGap extends Activity {
appView.getSettings().setJavaScriptEnabled(true);
appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
+
+ launcher = new CameraLauncher(appView, this);
+
/* Bind the appView object to the gap class methods */
bindBrowser(appView);
@@ -128,6 +131,7 @@ public class DroidGap extends Activity {
}
}
+
// This is required to start the camera activity! It has to come from the previous activity
public void startCamera()
{
@@ -137,9 +141,11 @@ public class DroidGap extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
- super.onActivityResult(requestCode, resultCode, intent);
- Bundle extras = intent.getExtras();
- // Send the graphic back to the class that needs it
+ byte [] data;
+ super.onActivityResult(requestCode, resultCode, intent);
+ data = intent.getByteArrayExtra("picture");
+ // Send the graphic back to the class that needs it
+ launcher.processPicture(data);
}
}
\ No newline at end of file