make toggle_camera nullable at MainActivity
This commit is contained in:
parent
dccc85e0a1
commit
43ff590e64
|
@ -2,7 +2,6 @@ package com.simplemobiletools.camera.activities
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
|
||||||
import android.hardware.Camera
|
import android.hardware.Camera
|
||||||
import android.hardware.SensorManager
|
import android.hardware.SensorManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -37,7 +36,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
lateinit var mFocusRectView: FocusRectView
|
lateinit var mFocusRectView: FocusRectView
|
||||||
lateinit var mTimerHandler: Handler
|
lateinit var mTimerHandler: Handler
|
||||||
lateinit var mFadeHandler: Handler
|
lateinit var mFadeHandler: Handler
|
||||||
lateinit var mRes: Resources
|
|
||||||
|
|
||||||
private var mPreview: Preview? = null
|
private var mPreview: Preview? = null
|
||||||
private var mPreviewUri: Uri? = null
|
private var mPreviewUri: Uri? = null
|
||||||
|
@ -114,7 +112,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables() {
|
private fun initVariables() {
|
||||||
mRes = resources
|
|
||||||
mIsInPhotoMode = false
|
mIsInPhotoMode = false
|
||||||
mIsCameraAvailable = false
|
mIsCameraAvailable = false
|
||||||
mIsVideoCaptureIntent = false
|
mIsVideoCaptureIntent = false
|
||||||
|
@ -178,7 +175,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
} else if (intent?.action == MediaStore.ACTION_VIDEO_CAPTURE) {
|
} else if (intent?.action == MediaStore.ACTION_VIDEO_CAPTURE) {
|
||||||
mIsVideoCaptureIntent = true
|
mIsVideoCaptureIntent = true
|
||||||
hideToggleModeAbout()
|
hideToggleModeAbout()
|
||||||
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_rec))
|
shutter.setImageDrawable(resources.getDrawable(R.drawable.ic_video_rec))
|
||||||
}
|
}
|
||||||
mPreview?.isImageCaptureIntent = isImageCaptureIntent()
|
mPreview?.isImageCaptureIntent = isImageCaptureIntent()
|
||||||
}
|
}
|
||||||
|
@ -189,7 +186,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
initButtons()
|
initButtons()
|
||||||
|
|
||||||
(btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, (navBarHeight + mRes.getDimension(R.dimen.activity_margin)).toInt())
|
(btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, (navBarHeight + resources.getDimension(R.dimen.activity_margin)).toInt())
|
||||||
|
|
||||||
mCurrCameraId = config.lastUsedCamera
|
mCurrCameraId = config.lastUsedCamera
|
||||||
mPreview = Preview(this, camera_view, this)
|
mPreview = Preview(this, camera_view, this)
|
||||||
|
@ -300,11 +297,11 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
mPreview?.tryTakePicture()
|
mPreview?.tryTakePicture()
|
||||||
} else {
|
} else {
|
||||||
if (mPreview?.toggleRecording() == true) {
|
if (mPreview?.toggleRecording() == true) {
|
||||||
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_stop))
|
shutter.setImageDrawable(resources.getDrawable(R.drawable.ic_video_stop))
|
||||||
toggle_camera.beInvisible()
|
toggle_camera.beInvisible()
|
||||||
showTimer()
|
showTimer()
|
||||||
} else {
|
} else {
|
||||||
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_rec))
|
shutter.setImageDrawable(resources.getDrawable(R.drawable.ic_video_rec))
|
||||||
showToggleCameraIfNeeded()
|
showToggleCameraIfNeeded()
|
||||||
hideTimer()
|
hideTimer()
|
||||||
}
|
}
|
||||||
|
@ -369,8 +366,8 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initPhotoMode() {
|
private fun initPhotoMode() {
|
||||||
toggle_photo_video.setImageDrawable(mRes.getDrawable(R.drawable.ic_video))
|
toggle_photo_video.setImageDrawable(resources.getDrawable(R.drawable.ic_video))
|
||||||
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_shutter))
|
shutter.setImageDrawable(resources.getDrawable(R.drawable.ic_shutter))
|
||||||
mPreview?.initPhotoMode()
|
mPreview?.initPhotoMode()
|
||||||
setupPreviewImage(true)
|
setupPreviewImage(true)
|
||||||
}
|
}
|
||||||
|
@ -386,9 +383,9 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initVideoButtons() {
|
private fun initVideoButtons() {
|
||||||
toggle_photo_video.setImageDrawable(mRes.getDrawable(R.drawable.ic_camera))
|
toggle_photo_video.setImageDrawable(resources.getDrawable(R.drawable.ic_camera))
|
||||||
showToggleCameraIfNeeded()
|
showToggleCameraIfNeeded()
|
||||||
shutter.setImageDrawable(mRes.getDrawable(R.drawable.ic_video_rec))
|
shutter.setImageDrawable(resources.getDrawable(R.drawable.ic_video_rec))
|
||||||
checkFlash()
|
checkFlash()
|
||||||
setupPreviewImage(false)
|
setupPreviewImage(false)
|
||||||
}
|
}
|
||||||
|
@ -399,6 +396,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
if (lastMediaId == 0L) {
|
if (lastMediaId == 0L) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreviewUri = Uri.withAppendedPath(uri, lastMediaId.toString())
|
mPreviewUri = Uri.withAppendedPath(uri, lastMediaId.toString())
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -481,7 +479,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showToggleCameraIfNeeded() {
|
private fun showToggleCameraIfNeeded() {
|
||||||
toggle_camera.beInvisibleIf(Camera.getNumberOfCameras() <= 1)
|
toggle_camera?.beInvisibleIf(Camera.getNumberOfCameras() <= 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
|
private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
|
||||||
|
|
|
@ -28,8 +28,8 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val config: Config, v
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setOnDismissListener { callback() }
|
.setOnDismissListener { callback() }
|
||||||
.create().apply {
|
.create().apply {
|
||||||
activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera)
|
activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupPhotoResolutionPicker(view: View) {
|
private fun setupPhotoResolutionPicker(view: View) {
|
||||||
|
|
|
@ -380,8 +380,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (takePictureAfter)
|
if (takePictureAfter) {
|
||||||
mIsFocusingBeforeCapture = true
|
mIsFocusingBeforeCapture = true
|
||||||
|
}
|
||||||
|
|
||||||
mCamera!!.cancelAutoFocus()
|
mCamera!!.cancelAutoFocus()
|
||||||
if (mParameters!!.maxNumFocusAreas > 0) {
|
if (mParameters!!.maxNumFocusAreas > 0) {
|
||||||
|
@ -395,8 +396,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
|
||||||
focusAreas.add(Camera.Area(focusRect, 1000))
|
focusAreas.add(Camera.Area(focusRect, 1000))
|
||||||
mParameters!!.focusAreas = focusAreas
|
mParameters!!.focusAreas = focusAreas
|
||||||
|
|
||||||
if (showFocusRect)
|
if (showFocusRect) {
|
||||||
mCallback.drawFocusRect(mLastClickX, mLastClickY)
|
mCallback.drawFocusRect(mLastClickX, mLastClickY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue