mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Camera code, adding the Commons Codec to the repo, need to read the licence to see whether we can include it
This commit is contained in:
parent
8c5f2ce916
commit
87f91602f7
@ -3,5 +3,6 @@
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="lib" path="libs/commons-codec-1.3.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
BIN
libs/commons-codec-1.3.jar
Normal file
BIN
libs/commons-codec-1.3.jar
Normal file
Binary file not shown.
@ -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
|
||||
|
@ -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();");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user