minor cleanup here and there
This commit is contained in:
parent
2cdae95de8
commit
bad8653d36
|
@ -29,12 +29,13 @@ import com.simplemobiletools.commons.models.Release
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSavedListener {
|
class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSavedListener {
|
||||||
private val FADE_DELAY = 5000
|
private val FADE_DELAY = 5000L
|
||||||
|
|
||||||
lateinit var mFocusCircleView: FocusCircleView
|
|
||||||
lateinit var mTimerHandler: Handler
|
lateinit var mTimerHandler: Handler
|
||||||
lateinit var mFadeHandler: Handler
|
private lateinit var mOrientationEventListener: OrientationEventListener
|
||||||
lateinit var mCameraImpl: MyCamera
|
private lateinit var mFocusCircleView: FocusCircleView
|
||||||
|
private lateinit var mFadeHandler: Handler
|
||||||
|
private lateinit var mCameraImpl: MyCamera
|
||||||
|
|
||||||
private var mPreview: PreviewCameraOne? = null
|
private var mPreview: PreviewCameraOne? = null
|
||||||
private var mPreviewUri: Uri? = null
|
private var mPreviewUri: Uri? = null
|
||||||
|
@ -47,8 +48,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
private var mCurrCameraId = 0
|
private var mCurrCameraId = 0
|
||||||
var mLastHandledOrientation = 0
|
var mLastHandledOrientation = 0
|
||||||
|
|
||||||
lateinit var mOrientationEventListener: OrientationEventListener
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
|
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
|
||||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||||
|
@ -108,7 +107,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
mPreview?.releaseCamera()
|
mPreview?.releaseCamera()
|
||||||
mPreview?.mActivity = null
|
|
||||||
mPreview = null
|
mPreview = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,14 +190,10 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
initButtons()
|
initButtons()
|
||||||
|
|
||||||
camera_surface_view.beVisibleIf(!isLollipopPlus())
|
|
||||||
camera_texture_view.beVisibleIf(isLollipopPlus())
|
|
||||||
|
|
||||||
(btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, (navBarHeight + resources.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 = PreviewCameraOne(this, camera_surface_view, this)
|
mPreview = PreviewCameraOne(this, camera_surface_view, this)
|
||||||
mPreview!!.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
|
||||||
view_holder.addView(mPreview)
|
view_holder.addView(mPreview)
|
||||||
toggle_camera.setImageResource(if (mCurrCameraId == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear)
|
toggle_camera.setImageResource(if (mCurrCameraId == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear)
|
||||||
|
|
||||||
|
@ -288,7 +282,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun autoFlash() {
|
private fun autoFlash() {
|
||||||
mPreview?.autoFlash()
|
mPreview?.setAutoFlash()
|
||||||
toggle_flash.setImageResource(R.drawable.ic_flash_auto)
|
toggle_flash.setImageResource(R.drawable.ic_flash_auto)
|
||||||
mFlashlightState = FLASH_AUTO
|
mFlashlightState = FLASH_AUTO
|
||||||
config.flashlightState = FLASH_AUTO
|
config.flashlightState = FLASH_AUTO
|
||||||
|
@ -424,8 +418,11 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scheduleFadeOut() {
|
private fun scheduleFadeOut() {
|
||||||
if (!config.keepSettingsVisible)
|
if (!config.keepSettingsVisible) {
|
||||||
mFadeHandler.postDelayed({ fadeOutButtons() }, FADE_DELAY.toLong())
|
mFadeHandler.postDelayed({
|
||||||
|
fadeOutButtons()
|
||||||
|
}, FADE_DELAY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fadeOutButtons() {
|
private fun fadeOutButtons() {
|
||||||
|
@ -468,7 +465,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
runOnUiThread(object : Runnable {
|
runOnUiThread(object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
video_rec_curr_timer.text = mCurrVideoRecTimer++.getFormattedDuration()
|
video_rec_curr_timer.text = mCurrVideoRecTimer++.getFormattedDuration()
|
||||||
mTimerHandler.postDelayed(this, 1000)
|
mTimerHandler.postDelayed(this, 1000L)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -538,11 +535,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
return mIsCameraAvailable
|
return mIsCameraAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
fun finishActivity() {
|
|
||||||
setResult(Activity.RESULT_OK)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setFlashAvailable(available: Boolean) {
|
override fun setFlashAvailable(available: Boolean) {
|
||||||
if (available) {
|
if (available) {
|
||||||
toggle_flash.beVisible()
|
toggle_flash.beVisible()
|
||||||
|
@ -568,7 +560,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusRect(x, y)
|
override fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y)
|
||||||
|
|
||||||
override fun mediaSaved(path: String) {
|
override fun mediaSaved(path: String) {
|
||||||
rescanPaths(arrayListOf(path)) {
|
rescanPaths(arrayListOf(path)) {
|
||||||
|
@ -581,7 +573,8 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isImageCaptureIntent()) {
|
if (isImageCaptureIntent()) {
|
||||||
finishActivity()
|
setResult(Activity.RESULT_OK)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class FocusCircleView(context: Context) : ViewGroup(context) {
|
||||||
mPaint.color = color
|
mPaint.color = color
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawFocusRect(x: Float, y: Float) {
|
fun drawFocusCircle(x: Float, y: Float) {
|
||||||
mLastCenterX = x
|
mLastCenterX = x
|
||||||
mLastCenterY = y
|
mLastCenterY = y
|
||||||
toggleCircle(true)
|
toggleCircle(true)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.simplemobiletools.camera.views
|
package com.simplemobiletools.camera.views
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
|
@ -26,16 +27,16 @@ import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScanCompletedListener {
|
class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScanCompletedListener {
|
||||||
var mCamera: Camera? = null
|
private var mCamera: Camera? = null
|
||||||
private val FOCUS_AREA_SIZE = 100
|
private val FOCUS_AREA_SIZE = 100
|
||||||
private val PHOTO_PREVIEW_LENGTH = 500L
|
private val PHOTO_PREVIEW_LENGTH = 500L
|
||||||
private val REFOCUS_PERIOD = 3000L
|
private val REFOCUS_PERIOD = 3000L
|
||||||
|
|
||||||
lateinit var mSurfaceHolder: SurfaceHolder
|
private lateinit var mSurfaceHolder: SurfaceHolder
|
||||||
lateinit var mSurfaceView: SurfaceView
|
private lateinit var mSurfaceView: SurfaceView
|
||||||
lateinit var mCallback: PreviewListener
|
private lateinit var mCallback: PreviewListener
|
||||||
lateinit var mScreenSize: Point
|
private lateinit var mScreenSize: Point
|
||||||
lateinit var config: Config
|
private lateinit var mConfig: Config
|
||||||
private var mSupportedPreviewSizes: List<Camera.Size>? = null
|
private var mSupportedPreviewSizes: List<Camera.Size>? = null
|
||||||
private var mPreviewSize: Camera.Size? = null
|
private var mPreviewSize: Camera.Size? = null
|
||||||
private var mParameters: Camera.Parameters? = null
|
private var mParameters: Camera.Parameters? = null
|
||||||
|
@ -82,7 +83,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
mIsSurfaceCreated = false
|
mIsSurfaceCreated = false
|
||||||
mSetupPreviewAfterMeasure = false
|
mSetupPreviewAfterMeasure = false
|
||||||
mCurrVideoPath = ""
|
mCurrVideoPath = ""
|
||||||
config = activity.config
|
mConfig = activity.config
|
||||||
mScreenSize = getScreenSize()
|
mScreenSize = getScreenSize()
|
||||||
initGestureDetector()
|
initGestureDetector()
|
||||||
|
|
||||||
|
@ -214,11 +215,11 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getResolutionIndex(): Int {
|
private fun getResolutionIndex(): Int {
|
||||||
val isBackCamera = config.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK
|
val isBackCamera = mConfig.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK
|
||||||
return if (mIsVideoMode) {
|
return if (mIsVideoMode) {
|
||||||
if (isBackCamera) config.backVideoResIndex else config.frontVideoResIndex
|
if (isBackCamera) mConfig.backVideoResIndex else mConfig.frontVideoResIndex
|
||||||
} else {
|
} else {
|
||||||
if (isBackCamera) config.backPhotoResIndex else config.frontPhotoResIndex
|
if (isBackCamera) mConfig.backPhotoResIndex else mConfig.frontPhotoResIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +228,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
resolutions.forEachIndexed { index, size ->
|
resolutions.forEachIndexed { index, size ->
|
||||||
val diff = screenAspectRatio - (size.width / size.height.toFloat())
|
val diff = screenAspectRatio - (size.width / size.height.toFloat())
|
||||||
if (Math.abs(diff) < RATIO_TOLERANCE) {
|
if (Math.abs(diff) < RATIO_TOLERANCE) {
|
||||||
config.backPhotoResIndex = index
|
mConfig.backPhotoResIndex = index
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +283,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tryTakePicture() {
|
fun tryTakePicture() {
|
||||||
if (config.focusBeforeCapture) {
|
if (mConfig.focusBeforeCapture) {
|
||||||
focusArea(true)
|
focusArea(true)
|
||||||
} else {
|
} else {
|
||||||
takePicture()
|
takePicture()
|
||||||
|
@ -310,7 +311,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
Thread {
|
Thread {
|
||||||
mCamera!!.takePicture(null, null, takePictureCallback)
|
mCamera!!.takePicture(null, null, takePictureCallback)
|
||||||
|
|
||||||
if (config.isSoundEnabled) {
|
if (mConfig.isSoundEnabled) {
|
||||||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM)
|
val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM)
|
||||||
if (volume != 0) {
|
if (volume != 0) {
|
||||||
|
@ -341,7 +342,10 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
if (mTargetUri != null) {
|
if (mTargetUri != null) {
|
||||||
storePhoto(data)
|
storePhoto(data)
|
||||||
} else {
|
} else {
|
||||||
mActivity!!.finishActivity()
|
mActivity!!.apply {
|
||||||
|
setResult(Activity.RESULT_OK)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storePhoto(data)
|
storePhoto(data)
|
||||||
|
@ -353,10 +357,10 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handlePreview() {
|
private fun handlePreview() {
|
||||||
if (config.isShowPreviewEnabled) {
|
if (mConfig.isShowPreviewEnabled) {
|
||||||
if (!config.wasPhotoPreviewHintShown) {
|
if (!mConfig.wasPhotoPreviewHintShown) {
|
||||||
mActivity!!.toast(R.string.click_to_resume_preview)
|
mActivity!!.toast(R.string.click_to_resume_preview)
|
||||||
config.wasPhotoPreviewHintShown = true
|
mConfig.wasPhotoPreviewHintShown = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
|
@ -459,7 +463,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
fun showChangeResolutionDialog() {
|
fun showChangeResolutionDialog() {
|
||||||
if (mCamera != null) {
|
if (mCamera != null) {
|
||||||
val oldResolution = getSelectedResolution()
|
val oldResolution = getSelectedResolution()
|
||||||
ChangeResolutionDialog(mActivity!!, config, mCamera!!) {
|
ChangeResolutionDialog(mActivity!!, mConfig, mCamera!!) {
|
||||||
if (oldResolution != getSelectedResolution()) {
|
if (oldResolution != getSelectedResolution()) {
|
||||||
refreshPreview()
|
refreshPreview()
|
||||||
}
|
}
|
||||||
|
@ -472,6 +476,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
mCamera?.stopPreview()
|
mCamera?.stopPreview()
|
||||||
mCamera?.release()
|
mCamera?.release()
|
||||||
mCamera = null
|
mCamera = null
|
||||||
|
mActivity = null
|
||||||
cleanupRecorder()
|
cleanupRecorder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,7 +605,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
updateCameraParameters()
|
updateCameraParameters()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun autoFlash() {
|
fun setAutoFlash() {
|
||||||
mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF
|
mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF
|
||||||
updateCameraParameters()
|
updateCameraParameters()
|
||||||
|
|
||||||
|
@ -686,9 +691,9 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
|
|
||||||
private fun checkPermissions(): Boolean {
|
private fun checkPermissions(): Boolean {
|
||||||
if (mActivity!!.needsStupidWritePermissions(mCurrVideoPath)) {
|
if (mActivity!!.needsStupidWritePermissions(mCurrVideoPath)) {
|
||||||
if (config.treeUri.isEmpty()) {
|
if (mConfig.treeUri.isEmpty()) {
|
||||||
mActivity!!.toast(R.string.save_error_internal_storage)
|
mActivity!!.toast(R.string.save_error_internal_storage)
|
||||||
config.savePhotosFolder = Environment.getExternalStorageDirectory().toString()
|
mConfig.savePhotosFolder = Environment.getExternalStorageDirectory().toString()
|
||||||
releaseCamera()
|
releaseCamera()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -786,7 +791,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleShutterSound(mute: Boolean?) {
|
private fun toggleShutterSound(mute: Boolean?) {
|
||||||
if (!config.isSoundEnabled) {
|
if (!mConfig.isSoundEnabled) {
|
||||||
(mActivity!!.getSystemService(Context.AUDIO_SERVICE) as AudioManager).setStreamMute(AudioManager.STREAM_SYSTEM, mute!!)
|
(mActivity!!.getSystemService(Context.AUDIO_SERVICE) as AudioManager).setStreamMute(AudioManager.STREAM_SYSTEM, mute!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,6 @@
|
||||||
<SurfaceView
|
<SurfaceView
|
||||||
android:id="@+id/camera_surface_view"
|
android:id="@+id/camera_surface_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<com.simplemobiletools.camera.views.AutoFitTextureView
|
|
||||||
android:id="@+id/camera_texture_view"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|
Loading…
Reference in New Issue