Skip to content

Commit

Permalink
Merge pull request #2 from FrangSierra/development
Browse files Browse the repository at this point in the history
Tests and new callbacks
  • Loading branch information
FrangSierra authored Nov 22, 2016
2 parents 5c19224 + bd3c050 commit 90861fb
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 22 deletions.
23 changes: 20 additions & 3 deletions app/src/main/java/durdinapps/rxcamera2/RxCameraDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.InputConfiguration;
import android.hardware.camera2.params.OutputConfiguration;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.view.Surface;
Expand All @@ -24,7 +25,7 @@ public class RxCameraDevice {

private final CameraDevice cameraDevice;

public RxCameraDevice(CameraDevice cameraDevice){
public RxCameraDevice(CameraDevice cameraDevice) {
this.cameraDevice = cameraDevice;
}

Expand Down Expand Up @@ -74,8 +75,8 @@ public void subscribe(final SingleEmitter e) throws Exception {
}

@NonNull
public Single<RxConfigureSessionEvent> createCaptureSessionByOutputConfigurations(@NonNull final List<Surface> outputs,
final Handler handler) {
public Single<RxConfigureSessionEvent> createConstrainedHighSpeedCaptureSession(@NonNull final List<Surface> outputs,
final Handler handler) {
return Single.create(new SingleOnSubscribe<RxConfigureSessionEvent>() {
@Override
public void subscribe(final SingleEmitter e) throws Exception {
Expand All @@ -88,6 +89,22 @@ public void subscribe(final SingleEmitter e) throws Exception {
});
}


@NonNull
public Single<RxConfigureSessionEvent> createCaptureSessionByOutputConfigurations(final List<OutputConfiguration> outputConfiguration,
final Handler handler) {
return Single.create(new SingleOnSubscribe<RxConfigureSessionEvent>() {
@Override
public void subscribe(final SingleEmitter e) throws Exception {
try {
cameraDevice.createCaptureSessionByOutputConfigurations(outputConfiguration, new RxCameraStateCallback(e), handler);
} catch (CameraAccessException | IllegalStateException | IllegalArgumentException ex) {
e.onError(ex);
}
}
});
}

@NonNull
public Single<CaptureRequest.Builder> createReprocessCaptureRequest(@NonNull final TotalCaptureResult totalCaptureResult) {
return Single.create(new SingleOnSubscribe<CaptureRequest.Builder>() {
Expand Down
35 changes: 19 additions & 16 deletions app/src/main/java/durdinapps/rxcamera2/RxCameraManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.os.Handler;
import android.support.annotation.NonNull;

import durdinapps.rxcamera2.wrappers.OpenCameraEvent;
import durdinapps.rxcamera2.wrappers.RxOpenCameraEvent;
import io.reactivex.Completable;
import io.reactivex.CompletableEmitter;
import io.reactivex.CompletableOnSubscribe;
Expand All @@ -15,9 +15,10 @@
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Cancellable;

import static durdinapps.rxcamera2.wrappers.OpenCameraEvent.EventType.DISCONNECTED;
import static durdinapps.rxcamera2.wrappers.OpenCameraEvent.EventType.ERROR;
import static durdinapps.rxcamera2.wrappers.OpenCameraEvent.EventType.OPENED;
import static durdinapps.rxcamera2.wrappers.RxOpenCameraEvent.EventType.CLOSED;
import static durdinapps.rxcamera2.wrappers.RxOpenCameraEvent.EventType.DISCONNECTED;
import static durdinapps.rxcamera2.wrappers.RxOpenCameraEvent.EventType.ERROR;
import static durdinapps.rxcamera2.wrappers.RxOpenCameraEvent.EventType.OPENED;

public class RxCameraManager {

Expand All @@ -33,26 +34,31 @@ public CameraManager getCameraManager(){
}

@NonNull
public Observable<OpenCameraEvent> openCamera(@NonNull final String cameraId,
@NonNull final Handler handler) {
return Observable.create(new ObservableOnSubscribe<OpenCameraEvent>() {
public Observable<RxOpenCameraEvent> openCamera(@NonNull final String cameraId,
@NonNull final Handler handler) {
return Observable.create(new ObservableOnSubscribe<RxOpenCameraEvent>() {
@Override
public void subscribe(final ObservableEmitter e) throws Exception {
try {
cameraManager.openCamera(cameraId, new CameraDevice.StateCallback() {
@Override
public void onOpened(CameraDevice camera) {
e.onNext(new OpenCameraEvent(new RxCameraDevice(camera), OPENED));
e.onNext(new RxOpenCameraEvent(new RxCameraDevice(camera), OPENED));
}

@Override
public void onDisconnected(CameraDevice camera) {
e.onNext(new OpenCameraEvent(new RxCameraDevice(camera), DISCONNECTED));
e.onNext(new RxOpenCameraEvent(new RxCameraDevice(camera), DISCONNECTED));
}

@Override
public void onError(CameraDevice camera, int error) {
e.onNext(new OpenCameraEvent(new RxCameraDevice(camera), ERROR));
e.onNext(new RxOpenCameraEvent(new RxCameraDevice(camera), ERROR));
}

@Override
public void onClosed(CameraDevice camera) {
e.onNext(new RxOpenCameraEvent(new RxCameraDevice(camera), CLOSED));
}
}, handler);
} catch (CameraAccessException | IllegalArgumentException | SecurityException ex) {
Expand All @@ -63,8 +69,7 @@ public void onError(CameraDevice camera, int error) {
}

@NonNull
public static Observable<Boolean> registerAvailabilityCallback(@NonNull final CameraManager cameraManager,
@NonNull final Handler handler) {
public Observable<Boolean> registerAvailabilityCallback(@NonNull final Handler handler) {
return Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override
public void subscribe(final ObservableEmitter e) throws Exception {
Expand Down Expand Up @@ -97,8 +102,7 @@ public void cancel() throws Exception {
}

@NonNull
public static Observable<Boolean> registerTorchCallback(@NonNull final CameraManager cameraManager,
@NonNull final Handler handler) {
public Observable<Boolean> registerTorchCallback(@NonNull final Handler handler) {
return Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override
public void subscribe(final ObservableEmitter e) throws Exception {
Expand Down Expand Up @@ -130,8 +134,7 @@ public void cancel() throws Exception {
}

@NonNull
public static Completable setTorchMode(@NonNull final CameraManager cameraManager,
@NonNull final String cameraId, final boolean enabled) {
public Completable setTorchMode(@NonNull final String cameraId, final boolean enabled) {
return Completable.create(new CompletableOnSubscribe() {
@Override
public void subscribe(CompletableEmitter e) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

import durdinapps.rxcamera2.RxCameraDevice;

public class OpenCameraEvent {
public class RxOpenCameraEvent {
public final RxCameraDevice cameraDevice;
public final EventType eventType;

public OpenCameraEvent(RxCameraDevice cameraDevice, EventType eventType) {
public RxOpenCameraEvent(RxCameraDevice cameraDevice, EventType eventType) {
this.cameraDevice = cameraDevice;
this.eventType = eventType;
}

public enum EventType {
OPENED,
DISCONNECTED,
ERROR;
ERROR,
CLOSED;
}
}
Loading

0 comments on commit 90861fb

Please sign in to comment.