Skip to content

Configuration Java

Dionysis Lorentzos edited this page Jul 18, 2018 · 7 revisions

You don't need to include Kotlin support to your own project. The library is supposed to work with both Kotlin and Java (since Kotlin compiles to the save JVM bytecode in the end).

To configure Fotoapparat instance:

Fotoapparat
    .with(context)  
    .into(cameraView)           // view which will draw the camera preview
    .previewScaleType(ScaleType.CenterCrop)  // we want the preview to fill the view  
    .photoResolution(ResolutionSelectorsKt.highestResolution())   // we want to have the biggest photo possible
    .lensPosition(LensPositionSelectorsKt.back())       // we want back camera
    .focusMode(SelectorsKt.firstAvailable(  // (optional) use the first focus mode which is supported by device
            FocusModeSelectorsKt. continuousFocusPicture(),
            FocusModeSelectorsKt.autoFocus(),        // in case if continuous focus is not available on device, auto focus will be used
            FocusModeSelectorsKt.fixed()             // if even auto focus is not available - fixed focus mode will be used
    ))
    .flash(SelectorsKt.firstAvailable(      // (optional) similar to how it is done for focus mode, this time for flash
            FlashSelectorsKt.autoRedEye(),
            FlashSelectorsKt.autoFlash(),
            FlashSelectorsKt.torch()
    ))
    .frameProcessor(myFrameProcessor)   // (optional) receives each frame from preview stream
    .logger(LoggersKt.loggers(            // (optional) we want to log camera events in 2 places at once
            LoggersKt.logcat(),           // ... in logcat
            LoggersKt.fileLogger(this)    // ... and to file
    ))
    .build();
Clone this wiki locally