RedApparat / Fotoapparat

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

First click not registered when Camera is started (Android emulator only) #361

Open jeffreyfjohnson opened 5 years ago

jeffreyfjohnson commented 5 years ago

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

Emulator only In the activity where the CameraView is shown, on a Pixel 2 emulator running API 28, whenever the CameraView is started and shown, the first click for any View on that screen is not registered. Not even the bottom buttons (back, home, recents) work on the first click.

How did you initialize FA?

class CaptureActivity : AppCompatActivity() {

    private var camera: MyCamera? = null

    override fun onCreate(savedInstanceState: Bundle?) {
         camera = MyCamera(this, cameraView, lifecycle)
    }
    ....
}

class MyCamera(
    context: Context,
    cameraView: CameraView,
    private val lifecycle: Lifecycle,
    private val photoDirectory: File? = context.getExternalFilesDir(PHOTOS_DIRECTORY)
) : LifecycleObserver {

    companion object {
        private const val PHOTOS_DIRECTORY = "photos"
    }

    private val camera = Fotoapparat(
        context = context,
        view = cameraView,
        lensPosition = back(),
        scaleType = ScaleType.CenterInside,
        cameraErrorCallback = { error ->
            logError("Camera error", error)
        }
    )
    private var startedCamera = false

    init {
        lifecycle.addObserver(this)
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun start() {
        if (!startedCamera) {
            camera.start()
            startedCamera = true
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun stop() {
        camera.stop()
        startedCamera = false
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    private fun removeObserver() = lifecycle.removeObserver(this)
}

Note that nothing changes if instead of using OnLifeCycleEvent annotations, we just call start and stop on the camera in the Activity

Context:

jeduden commented 4 years ago

I have the feeling that this is not a specific issue of fotoapparat. I just tried the official Camera2BasicKotlin sample and it has the same issue. The first click on the "picture" button is also not registered in the emulator when i tested it.