send the device rotation to photo saver + cleanup

This commit is contained in:
tibbi 2018-05-30 14:28:52 +02:00
parent 4b17fbf3d3
commit f8dea07ebe
1 changed files with 9 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.camera.views
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.Context import android.content.Context
import android.content.res.Configuration
import android.graphics.ImageFormat import android.graphics.ImageFormat
import android.graphics.Point import android.graphics.Point
import android.graphics.SurfaceTexture import android.graphics.SurfaceTexture
@ -41,6 +40,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
private var mCameraId = "" private var mCameraId = ""
private var mCameraState = STATE_INIT private var mCameraState = STATE_INIT
private var mFlashlightState = FLASH_OFF private var mFlashlightState = FLASH_OFF
private var mRotationAtCapture = 0
private var mBackgroundThread: HandlerThread? = null private var mBackgroundThread: HandlerThread? = null
private var mBackgroundHandler: Handler? = null private var mBackgroundHandler: Handler? = null
@ -134,7 +134,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
val buffer = reader.acquireNextImage().planes[0].buffer val buffer = reader.acquireNextImage().planes[0].buffer
val bytes = ByteArray(buffer.remaining()) val bytes = ByteArray(buffer.remaining())
buffer.get(bytes) buffer.get(bytes)
PhotoProcessor(mActivity, mTargetUri, 0, 0, mActivity.config.flipPhotos && getIsFrontCamera()).execute(bytes) PhotoProcessor(mActivity, mTargetUri, 0, mRotationAtCapture, mActivity.config.flipPhotos && getIsFrontCamera()).execute(bytes)
} }
private fun getIsFrontCamera(): Boolean { private fun getIsFrontCamera(): Boolean {
@ -155,8 +155,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
continue continue
} }
val map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) ?: continue val configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) ?: continue
val largest = map.getOutputSizes(ImageFormat.JPEG).maxBy { it.width * it.height } val largest = configMap.getOutputSizes(ImageFormat.JPEG).maxBy { it.width * it.height }
mImageReader = ImageReader.newInstance(largest!!.width, largest.height, ImageFormat.JPEG, 2) mImageReader = ImageReader.newInstance(largest!!.width, largest.height, ImageFormat.JPEG, 2)
mImageReader!!.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler) mImageReader!!.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler)
@ -184,19 +184,11 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
maxPreviewHeight = MAX_PREVIEW_HEIGHT maxPreviewHeight = MAX_PREVIEW_HEIGHT
} }
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture::class.java), mPreviewSize = chooseOptimalSize(configMap.getOutputSizes(SurfaceTexture::class.java),
rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest)
maxPreviewHeight, largest)
val orientation = resources.configuration.orientation
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mTextureView.setAspectRatio(mPreviewSize!!.width, mPreviewSize!!.height)
} else {
mTextureView.setAspectRatio(mPreviewSize!!.height, mPreviewSize!!.width) mTextureView.setAspectRatio(mPreviewSize!!.height, mPreviewSize!!.width)
} mIsFlashSupported = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE) ?: false
val available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)
mIsFlashSupported = available ?: false
mCameraId = cameraId mCameraId = cameraId
return return
} }
@ -341,6 +333,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
return return
} }
mRotationAtCapture = mActivity.mLastHandledOrientation
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply { val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
addTarget(mImageReader!!.surface) addTarget(mImageReader!!.surface)
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE) set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)