RedApparat / Fotoapparat

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

Preview orientation sideways when rotating device #260

Closed MaTriXy closed 5 years ago

MaTriXy commented 6 years ago

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

Have the preview view to show the front/rear camera and also rotate the device while doing so. catching the onconfiguration change and setting the preview sizes to replace width and height. didn't find a way to let the view know of the orientation

How did you initialize FA?

        fotoapparat = Fotoapparat(
                context = this,
                view = camera_view,
                focusView = focusView,
                logger = logcat(),
                lensPosition = activeCamera.lensPosition,
                cameraConfiguration = activeCamera.configuration,
                cameraErrorCallback = { Log.e("TAG", "Camera error: ", it) }
        )

private sealed class Camera(val lensPosition: LensPositionSelector, val configuration: CameraConfiguration) {

    object Back : Camera(
            lensPosition = back(),
            configuration = CameraConfiguration(
                    previewResolution = firstAvailable(
                            wideRatio(highestResolution()),
                            standardRatio(highestResolution())
                    ),
                    previewFpsRange = highestFps(),
                    flashMode = off(),
                    focusMode = firstAvailable(
                            continuousFocusPicture(),
                            autoFocus()
                    ),
                    frameProcessor = {

                    }
            )
    )

    object Front : Camera(
            lensPosition = front(),
            configuration = CameraConfiguration(
                    previewResolution = firstAvailable(
                            wideRatio(highestResolution()),
                            standardRatio(highestResolution())
                    ),
                    previewFpsRange = highestFps(),
                    flashMode = off(),
                    focusMode = firstAvailable(
                            fixed(),
                            autoFocus()
                    ),
                    frameProcessor = {

                    }
            )
    )
}

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        camera_view.layoutParams = ConstraintLayout.LayoutParams(camera_view.height, camera_view.width)
}

What was the result you received?

preview was rotated 90/270 degress

What did you expect?

preview will show properly on both orientations even while changing orientation.

Context:

jordaorodolfo commented 6 years ago

Occurence also confirmed on device Moto G 2013 ("Falcon"), running custom rom lineage OS 14.1, android 7.1; but in my case, I mostly stayed with the default options and followed the three get started points religiously. As a side note, if it helps, this same bug also happens in the same device and ROM with the library CameraView.