Merge pull request #270 from lwansbrough/v1

v1 Updates
This commit is contained in:
Zack Story
2016-04-27 20:34:46 -07:00
13 changed files with 532 additions and 249 deletions
@@ -53,10 +53,12 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
public static final int MEDIA_TYPE_VIDEO = 2;
private final ReactApplicationContext _reactContext;
private RCTSensorOrientationChecker _sensorOrientationChecker;
public RCTCameraModule(ReactApplicationContext reactContext) {
super(reactContext);
_reactContext = reactContext;
_sensorOrientationChecker = new RCTSensorOrientationChecker(_reactContext);
}
@Override
@@ -70,6 +72,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("Aspect", getAspectConstants());
put("BarCodeType", getBarCodeConstants());
put("Type", getTypeConstants());
put("CaptureQuality", getCaptureQualityConstants());
put("CaptureMode", getCaptureModeConstants());
@@ -89,6 +92,14 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
});
}
private Map<String, Object> getBarCodeConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
// @TODO add barcode types
}
});
}
private Map<String, Object> getTypeConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
@@ -165,27 +176,38 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
@ReactMethod
public void capture(final ReadableMap options, final Promise promise) {
_sensorOrientationChecker.onResume();
_sensorOrientationChecker.registerOrientationListener(new RCTSensorOrientationListener() {
@Override
public void orientationEvent() {
int deviceOrientation = _sensorOrientationChecker.getOrientation();
_sensorOrientationChecker.unregisterOrientationListener();
_sensorOrientationChecker.onPause();
captureWithOrientation(options, promise, deviceOrientation);
}
});
}
public void captureWithOrientation(final ReadableMap options, final Promise promise, int deviceOrientation) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
if (null == camera) {
promise.reject("No camera found.");
return;
}
if (options.getBoolean("playSoundOnCapture")) {
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
}
RCTCamera.getInstance().adjustCameraRotationToDeviceOrientation(options.getInt("type"), deviceOrientation);
RCTCamera.getInstance().setCaptureQuality(options.getInt("type"), options.getString("quality"));
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
camera.stopPreview();
camera.startPreview();
WritableMap response = new WritableNativeMap();
switch (options.getInt("target")) {
case RCT_CAMERA_CAPTURE_TARGET_MEMORY:
String encoded = Base64.encodeToString(data, Base64.DEFAULT);
promise.resolve(encoded);
response.putString("data", encoded);
promise.resolve(response);
break;
case RCT_CAMERA_CAPTURE_TARGET_CAMERA_ROLL:
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
@@ -194,7 +216,8 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
_reactContext.getContentResolver(),
bitmap, options.getString("title"),
options.getString("description"));
promise.resolve(url);
response.putString("path", url);
promise.resolve(response);
break;
case RCT_CAMERA_CAPTURE_TARGET_DISK:
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
@@ -212,7 +235,8 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
} catch (IOException e) {
promise.reject("Error accessing file: " + e.getMessage());
}
promise.resolve(Uri.fromFile(pictureFile).toString());
response.putString("path", Uri.fromFile(pictureFile).toString());
promise.resolve(response);
break;
case RCT_CAMERA_CAPTURE_TARGET_TEMP:
File tempFile = getTempMediaFile(MEDIA_TYPE_IMAGE);
@@ -231,7 +255,8 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
} catch (IOException e) {
promise.reject("Error accessing file: " + e.getMessage());
}
promise.resolve(Uri.fromFile(tempFile).toString());
response.putString("path", Uri.fromFile(tempFile).toString());
promise.resolve(response);
break;
}
}