From 3bfde4d4a349239315fe6f73d50a690a003c81c7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 1 Apr 2017 22:17:07 +0200 Subject: [PATCH] make mOrientation a local variable --- .../simplemobiletools/camera/PhotoProcessor.kt | 2 +- .../com/simplemobiletools/camera/Preview.kt | 2 +- .../camera/activities/MainActivity.kt | 18 ++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt b/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt index b7e090b4..553224b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt @@ -66,7 +66,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId var image = BitmapFactory.decodeByteArray(data, 0, data.size) val exif = ExifInterface(photoFile.toString()) - val deviceRot = MainActivity.mOrientation.compensateDeviceRotation(currCameraId) + val deviceRot = MainActivity.mLastHandledOrientation.compensateDeviceRotation(currCameraId) val previewRot = activity.getPreviewRotation(currCameraId) val imageRot = when (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) { ExifInterface.ORIENTATION_ROTATE_90 -> 90 diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index 10cb53d9..62aa82a2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -587,7 +587,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } private fun getVideoRotation(): Int { - val deviceRot = MainActivity.mOrientation.compensateDeviceRotation(mCurrCameraId) + val deviceRot = MainActivity.mLastHandledOrientation.compensateDeviceRotation(mCurrCameraId) val previewRot = mActivity.getPreviewRotation(mCurrCameraId) return (deviceRot + previewRot) % 360 } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index 79e00485..975ce7d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -31,7 +31,6 @@ import java.util.* class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, PhotoProcessor.MediaSavedListener { companion object { - private val CAMERA_STORAGE_PERMISSION = 1 private val RECORD_AUDIO_PERMISSION = 2 private val FADE_DELAY = 5000 @@ -53,8 +52,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho private var mIsHardwareShutterHandled = false private var mCurrVideoRecTimer = 0 private var mCurrCameraId = 0 - private var mLastHandledOrientation = 0 - var mOrientation = 0 + var mLastHandledOrientation = 0 } override fun onCreate(savedInstanceState: Bundle?) { @@ -488,18 +486,18 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho } override fun onSensorChanged(event: SensorEvent) { - if (event.values[0] < 6.5 && event.values[0] > -6.5) { - mOrientation = ORIENT_PORTRAIT + val orientation = if (event.values[0] < 6.5 && event.values[0] > -6.5) { + ORIENT_PORTRAIT } else { if (event.values[0] > 0) { - mOrientation = ORIENT_LANDSCAPE_LEFT + ORIENT_LANDSCAPE_LEFT } else { - mOrientation = ORIENT_LANDSCAPE_RIGHT + ORIENT_LANDSCAPE_RIGHT } } - if (mOrientation != mLastHandledOrientation) { - val degrees = when (mOrientation) { + if (orientation != mLastHandledOrientation) { + val degrees = when (orientation) { ORIENT_LANDSCAPE_LEFT -> 90 ORIENT_LANDSCAPE_RIGHT -> -90 else -> 0 @@ -507,7 +505,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho mPreview!!.deviceOrientationChanged() animateViews(degrees) - mLastHandledOrientation = mOrientation + mLastHandledOrientation = orientation } }