RxCamera

Additional

Language
Java
Version
N/A
Created
Oct 25, 2015
Updated
Jan 18, 2017 (Retired)
Owner
RagnarokStack (ragnraok)
Contributors
Ravindra Kumar (ravidsrk)
RagnarokStack (ragnraok)
sibelius
EzequielAdrianM
keiththompson
gylee2011
elrutas
7
Activity
Badge
Generate
Download
Source code
APK file

Advertising

RxCamera

RxJava style camera API for android, it based on android.hardware.camera

Add to your project dependence:

repositories {
        jcenter()
}
dependencies {
 compile 'com.ragnarok.rxcamera:lib:0.0.5'
}


Basic Usage:

  1. set the camera parameter by choose a RxCameraConfig, which created by RxCameraConfig.Builder:

    RxCameraConfig config = new RxCameraConfig.Builder()
                .useBackCamera()
                .setAutoFocus(true)
                .setPreferPreviewFrameRate(15, 30)
                .setPreferPreviewSize(new Point(640, 480), false)
                .setHandleSurfaceEvent(true)
                .build();

    for all camera config currently support, please see RxCameraConfig

  2. open camera

    RxCamera.open(context, config)

    it return an RxJava Observable object, the type is Observable<RxCamera>

  3. bind a SurfaceView or TextureView and startPreview

    since RxCamera.open is return an Observable, so you can chain the call like this

    RxCamera.open(this, config).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
          @Override
          public Observable<RxCamera> call(RxCamera rxCamera) {
              return rxCamera.bindTexture(textureView);
              // or bind a SurfaceView:
              // rxCamera.bindSurface(SurfaceView)
          }
    }).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
          @Override
          public Observable<RxCamera> call(RxCamera rxCamera) {
              return rxCamera.startPreview();
          }
    });

    both RxCamera.bindTexture and RxCamera.startPreview will return an Observable<RxCamera> object

    PS: if set isHandleSurfaceEventto true(set by setHandleSurfaceEvent(true) in RxCameraConfigChooser), RxCamera will do the actual camera start preview action when the surface is available, otherwise it will start preview immediately, and may failed if surface is not available, in this case, the return Observable will call onError

  4. switch camera

    switch the camera in runtime

     camera.switchCamera(); 

    and it will also change the internal camera config, so after switch camera, the camera.getConfig will return with new setting