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