Merge branch 'master' of git://github.com/nitobi/phonegap into joe

This commit is contained in:
Brock Whitten 2008-11-28 16:18:48 -08:00
commit c9e7a5d9e4
3 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package com.nitobi.phonegap;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class CameraHandler implements PictureCallback{
private OutputStream oStream;
BitmapFactory photoLab;
CameraHandler(OutputStream output)
{
oStream = output;
}
public void onPictureTaken(byte[] graphic, Camera arg1) {
try {
oStream.write(graphic);
oStream.flush();
oStream.close();
}
catch (Exception ex)
{
//TO-DO: Put some logging here saying that this epic failed
}
// Do some other things, like post it to a service!
}
}

View File

@ -0,0 +1,52 @@
package com.nitobi.phonegap;
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.ContentValues;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.ShutterCallback;
import android.net.Uri;
import android.provider.MediaStore.Images.Media;
public class CameraListener implements ShutterCallback{
private Camera mCam;
private CameraHandler camHand;
private SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
private Context mCtx;
private Uri target = Media.EXTERNAL_CONTENT_URI;
CameraListener(Context ctx){
mCam = Camera.open();
mCtx = ctx;
}
public void snap()
{
String filename = timeStampFormat.format(new Date());
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "PhoneGap");
Uri uri = mCtx.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
try
{
OutputStream output = (OutputStream) mCtx.getContentResolver().openOutputStream(uri);
camHand = new CameraHandler(output);
mCam.takePicture(this, null, camHand);
}
catch (Exception ex)
{
/*TODO: Do some logging here */
}
}
public void onShutter() {
/* This is logged */
}
}

View File

@ -0,0 +1,48 @@
package com.nitobi.phonegap;
import android.content.Context;
import android.hardware.SensorManager;
import android.hardware.SensorListener;
import android.webkit.WebView;
public class Orientation implements SensorListener{
private WebView mAppView;
private SensorManager sensorManager;
private Context mCtx;
Orientation(WebView kit, Context ctx) {
mAppView = kit;
mCtx = ctx;
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
this.resumeAccel();
}
public void onSensorChanged(int sensor, final float[] values) {
if (sensor != SensorManager.SENSOR_ACCELEROMETER || values.length < 3)
return;
float x = values[0];
float y = values[1];
float z = values[2];
mAppView.loadUrl("javascript:gotAcceleration(" + x + ", " + y + "," + z + ")");
}
public void onAccuracyChanged(int arg0, int arg1) {
// This is a stub method.
}
public void pauseAccel()
{
sensorManager.unregisterListener(this);
}
public void resumeAccel()
{
sensorManager.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_GAME);
}
}