mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
make mOrientation a local variable
This commit is contained in:
@ -66,7 +66,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
|||||||
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
||||||
val exif = ExifInterface(photoFile.toString())
|
val exif = ExifInterface(photoFile.toString())
|
||||||
|
|
||||||
val deviceRot = MainActivity.mOrientation.compensateDeviceRotation(currCameraId)
|
val deviceRot = MainActivity.mLastHandledOrientation.compensateDeviceRotation(currCameraId)
|
||||||
val previewRot = activity.getPreviewRotation(currCameraId)
|
val previewRot = activity.getPreviewRotation(currCameraId)
|
||||||
val imageRot = when (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
|
val imageRot = when (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
|
||||||
ExifInterface.ORIENTATION_ROTATE_90 -> 90
|
ExifInterface.ORIENTATION_ROTATE_90 -> 90
|
||||||
|
@ -587,7 +587,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getVideoRotation(): Int {
|
private fun getVideoRotation(): Int {
|
||||||
val deviceRot = MainActivity.mOrientation.compensateDeviceRotation(mCurrCameraId)
|
val deviceRot = MainActivity.mLastHandledOrientation.compensateDeviceRotation(mCurrCameraId)
|
||||||
val previewRot = mActivity.getPreviewRotation(mCurrCameraId)
|
val previewRot = mActivity.getPreviewRotation(mCurrCameraId)
|
||||||
return (deviceRot + previewRot) % 360
|
return (deviceRot + previewRot) % 360
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import java.util.*
|
|||||||
|
|
||||||
class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, PhotoProcessor.MediaSavedListener {
|
class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, PhotoProcessor.MediaSavedListener {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val CAMERA_STORAGE_PERMISSION = 1
|
private val CAMERA_STORAGE_PERMISSION = 1
|
||||||
private val RECORD_AUDIO_PERMISSION = 2
|
private val RECORD_AUDIO_PERMISSION = 2
|
||||||
private val FADE_DELAY = 5000
|
private val FADE_DELAY = 5000
|
||||||
@ -53,8 +52,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho
|
|||||||
private var mIsHardwareShutterHandled = false
|
private var mIsHardwareShutterHandled = false
|
||||||
private var mCurrVideoRecTimer = 0
|
private var mCurrVideoRecTimer = 0
|
||||||
private var mCurrCameraId = 0
|
private var mCurrCameraId = 0
|
||||||
private var mLastHandledOrientation = 0
|
var mLastHandledOrientation = 0
|
||||||
var mOrientation = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -488,18 +486,18 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSensorChanged(event: SensorEvent) {
|
override fun onSensorChanged(event: SensorEvent) {
|
||||||
if (event.values[0] < 6.5 && event.values[0] > -6.5) {
|
val orientation = if (event.values[0] < 6.5 && event.values[0] > -6.5) {
|
||||||
mOrientation = ORIENT_PORTRAIT
|
ORIENT_PORTRAIT
|
||||||
} else {
|
} else {
|
||||||
if (event.values[0] > 0) {
|
if (event.values[0] > 0) {
|
||||||
mOrientation = ORIENT_LANDSCAPE_LEFT
|
ORIENT_LANDSCAPE_LEFT
|
||||||
} else {
|
} else {
|
||||||
mOrientation = ORIENT_LANDSCAPE_RIGHT
|
ORIENT_LANDSCAPE_RIGHT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOrientation != mLastHandledOrientation) {
|
if (orientation != mLastHandledOrientation) {
|
||||||
val degrees = when (mOrientation) {
|
val degrees = when (orientation) {
|
||||||
ORIENT_LANDSCAPE_LEFT -> 90
|
ORIENT_LANDSCAPE_LEFT -> 90
|
||||||
ORIENT_LANDSCAPE_RIGHT -> -90
|
ORIENT_LANDSCAPE_RIGHT -> -90
|
||||||
else -> 0
|
else -> 0
|
||||||
@ -507,7 +505,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho
|
|||||||
|
|
||||||
mPreview!!.deviceOrientationChanged()
|
mPreview!!.deviceOrientationChanged()
|
||||||
animateViews(degrees)
|
animateViews(degrees)
|
||||||
mLastHandledOrientation = mOrientation
|
mLastHandledOrientation = orientation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user