make mOrientation a local variable

This commit is contained in:
tibbi 2017-04-01 22:17:07 +02:00
parent 824ad221df
commit 3bfde4d4a3
3 changed files with 10 additions and 12 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}
}