RxCamera


Source link: https://github.com/ragnraok/RxCamera

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


request camera data

RxCamera support many styles of camera data requests:

  • successiveDataRequest

    camera.request().successiveDataRequest()

    it will return the camera data infinitely

  • periodicDataRequest

     camera.request().periodicDataRequest(1000)

    as the name, it will return camera data periodic, pass the interval in millisecond

  • oneShotRequest

     camera.request().oneShotRequest()

    it will return the camera data only once

  • takePictureRequest

     camera.request().takePictureRequest(boolean isContinuePreview, Func shutterAction, boolean openFlash)

    the encapsulation of takePicture API, if isContinuePreview set to true, the RxCamera will try to restart preview after capture the picture, otherwise will behave as system takePicture call, stop preview after captured successfully

    and the shutterAction will called after picture just captured, like the [ShutterCallback] ( http://developer.android.com/intl/es/reference/android/hardware/Camera.ShutterCallback.html) (actually it is called in the system shutterCallback)

    and the openFlash if set to true, it will open the flash when taking picture, and automatically close it after this request

  • FaceDetectionRequest

     camera.request().faceDetectionRequest()

    the encapsulation of Camera.FaceDetectionListener, it will return the faces location in CameraData.faceList


All the data request will return an Observalbe<RxCameraData>

the RxCameraData contained these fields:

  • byte[] cameraData, the raw data of camera, for the takePicture request, it will return the jpeg encode byte, other request just return raw camera preview data, if you don't set preview format, the default is YUV420SP
    • Matrix rotateMatrix, this matrix help you rotate the camera data in portrait
    • Camera.Face[] faceList, the locatoin of faces, only returned in FaceDetectionRequest

camera action request

the camera action request will change the behavior of the camera

  • zoom and somoothZoom action:

     camera.action().zoom(int level)  camera.action().smoothZoom(int level)

    change the camera zoom level

  • open or close the flash

     camera.action().flashAction(boolean isOn)
  • area focus and area metering

    camera.action().areaFocusAction(List<Camera.Area> focusAreaList) camera.action().areaMeterAction(List<Camera.Area> focusAreaList)

    and there is a helper function to convert the coordinate to [-1000, 1000], which is suitable for Camera.Area, in CameraUtil:

    Rect transferCameraAreaFromOuterSize(Point center, Point outerSize, int size)

    check out the example to see how to use this

This project still in very early stage, and welcome the pull request

Resources

???? A basic sample android application to understand MVP in a very simple way. Just clone, build, run and understand MVP.
Pull or Swipe to Refresh Webview
Simple clock view for displaying uh...time?
Custom toasts with color and icon for Android.
A simple Android project using asynchronous programming with Kotlin Coroutines.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes