RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 405 forks source link

Add Flash selector only for focus routine #148

Open Raenar4k opened 6 years ago

Raenar4k commented 6 years ago

What are you trying to achieve or the steps to reproduce?

I've implemented focus on tap using focus method and flash toggle. If flash is on, then camera will activate flash while focusing and then deactivate it, just like when it is taking a photo. I expect it only to focus, without turning on flash.

fotoapparat.focus().whenAvailable {
            Timber.tag(TAG).d("focus state is $it")
        }

How did you initialize FA?

        return Fotoapparat
                .with(context)
                .into(renderer)
                .previewScaleType(ScaleType.CENTER_CROP)
                .photoSize(AspectRatioSelectors.wideRatio(SizeSelectors.biggestSize()))
                .lensPosition(LensPositionSelectors.lensPosition(LensPosition.BACK))
                .focusMode(Selectors.firstAvailable(
                        FocusModeSelectors.autoFocus(),
                        FocusModeSelectors.fixed()
                ))
                .flash(FlashSelectors.off())
                .logger(Loggers.loggers(Logger { Timber.tag(CameraImpl.TAG).d(it) }))
                .cameraErrorCallback({ errorSubject.onNext(it) })
                .build()

What was the result you received?

When camera is focusing, flash is activated.

What did you expect?

When camera is focusing, flash is not activated, like on default google camera.

Context:

Thanks for working on this lib! :)

Diolor commented 6 years ago

Thanks! I have seen few things with camera1 & flash so far... Related : #99

Diolor commented 6 years ago

I now understood what you want. No, this is not possible with android camera1 which this lib depends on.

Reason is focus & capture photos are actions while flash state is the "how" which the former actions use.

You may try to "silently" (w/o flash) focus by having flash off, then focus, then turn flash to auto, & then (probably) take a picture with auto flash. Be wary that this lib is not made for this kind of usage and the above might result in weird behaviour because of threading issues.

Honestly speaking, this is very specific usage, and for that reason if you are not planning to implement it, I doubt that we will... I can leave this issue open for a while if someone has same need and is interested picking it up.

Raenar4k commented 6 years ago

I've implemented workaround similar to what you say - triggering focus sets flash selectors to OFF (if it is not disabled already), then focus is called and when focus result is delivered through callback - then flash selector is being set back to whatever setting it was before focusing.

Im not sure if that is very specific use case, since triggering focus is something fairly common for users to do. But i do understand that it could be complicated problem.

In fact, i've seen different focus behavior in default cameras - Nexus 5x will not trigger flash while focusing, but Samsung A5 will.