forked from github/cordova-android
Merge branch 'master' of git://github.com/nitobi/phonegap into joe
This commit is contained in:
commit
c9e7a5d9e4
37
src/com/nitobi/phonegap/CameraHandler.java
Normal file
37
src/com/nitobi/phonegap/CameraHandler.java
Normal 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!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
52
src/com/nitobi/phonegap/CameraListener.java
Normal file
52
src/com/nitobi/phonegap/CameraListener.java
Normal 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 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
src/com/nitobi/phonegap/Orientation.java
Normal file
48
src/com/nitobi/phonegap/Orientation.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user