SimpleMobileTools / Simple-Camera

Quick photo and video camera with a flash, customizable aspect ratio.
https://www.simplemobiletools.com
GNU General Public License v3.0
764 stars 284 forks source link

Black bottom FIX! - due to wrong setMeasuredDimension() parameters #222

Closed fritexvz closed 1 year ago

fritexvz commented 5 years ago

Testing on my Xiaomi Redmi Note 6 Pro, I have the black bottom - almost half screen black background.

If I change color of the RelativeLayout in activity_main.xml - I have other like orange, blue, etc. Setting to transparent window or transparent color, using fui_transparent or either over drawable did not helped me.

Figure it out, as taken from Camera2 Google, it has to be something with it.

File: AutoFitTextureView.kt

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        val width = View.MeasureSpec.getSize(widthMeasureSpec)
        val height = View.MeasureSpec.getSize(heightMeasureSpec)

        if (mRatioWidth == 0 || mRatioHeight == 0) {
            setMeasuredDimension(width, height)
        } else {
            if (width < height * mRatioWidth / mRatioHeight) {
                setMeasuredDimension(width, width * mRatioHeight / mRatioWidth)
            } else {
                setMeasuredDimension(height * mRatioWidth / mRatioHeight, height)
            }
        }
    }

Change this:

            if (width < height * mRatioWidth / mRatioHeight) {
                setMeasuredDimension(width, width * mRatioHeight / mRatioWidth)
            } else {
                setMeasuredDimension(height * mRatioWidth / mRatioHeight, height)
            }

to this:

          if (width < height * mRatioWidth / mRatioHeight) {
            setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
          } else {
            setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
          }

Also, if needed consider editing @+id/camera_texture_view of the AutoFitTextureView:

or vice versa.

tibbi commented 1 year ago

camera has been rewritten from scratch in 5.4.0, so Im closing this