change the focus rectangle to a focus circle

This commit is contained in:
tibbi 2018-05-27 21:47:54 +02:00
parent d6ff4c5c64
commit 7bf69e1d04
3 changed files with 33 additions and 37 deletions

View File

@ -21,7 +21,7 @@ import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.implementations.MyCameraOneImpl import com.simplemobiletools.camera.implementations.MyCameraOneImpl
import com.simplemobiletools.camera.implementations.MyCameraTwoImpl import com.simplemobiletools.camera.implementations.MyCameraTwoImpl
import com.simplemobiletools.camera.interfaces.MyCamera import com.simplemobiletools.camera.interfaces.MyCamera
import com.simplemobiletools.camera.views.FocusRectView import com.simplemobiletools.camera.views.FocusCircleView
import com.simplemobiletools.camera.views.Preview import com.simplemobiletools.camera.views.Preview
import com.simplemobiletools.camera.views.Preview.PreviewListener import com.simplemobiletools.camera.views.Preview.PreviewListener
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@ -32,7 +32,7 @@ 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 = 5000
lateinit var mFocusRectView: FocusRectView lateinit var mFocusCircleView: FocusCircleView
lateinit var mTimerHandler: Handler lateinit var mTimerHandler: Handler
lateinit var mFadeHandler: Handler lateinit var mFadeHandler: Handler
lateinit var mCameraImpl: MyCamera lateinit var mCameraImpl: MyCamera
@ -74,7 +74,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
resumeCameraItems() resumeCameraItems()
setupPreviewImage(mIsInPhotoMode) setupPreviewImage(mIsInPhotoMode)
scheduleFadeOut() scheduleFadeOut()
mFocusRectView.setStrokeColor(config.primaryColor) mFocusCircleView.setStrokeColor(config.primaryColor)
if (mIsVideoCaptureIntent && mIsInPhotoMode) { if (mIsVideoCaptureIntent && mIsInPhotoMode) {
handleTogglePhotoVideo() handleTogglePhotoVideo()
@ -201,8 +201,8 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
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)
mFocusRectView = FocusRectView(applicationContext) mFocusCircleView = FocusCircleView(applicationContext)
view_holder.addView(mFocusRectView) view_holder.addView(mFocusCircleView)
mIsInPhotoMode = true mIsInPhotoMode = true
mTimerHandler = Handler() mTimerHandler = Handler()
@ -566,7 +566,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
} }
} }
override fun drawFocusRect(x: Int, y: Int) = mFocusRectView.drawFocusRect(x, y) override fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusRect(x, y)
override fun mediaSaved(path: String) { override fun mediaSaved(path: String) {
rescanPaths(arrayListOf(path)) { rescanPaths(arrayListOf(path)) {

View File

@ -3,28 +3,23 @@ package com.simplemobiletools.camera.views
import android.content.Context import android.content.Context
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Paint import android.graphics.Paint
import android.graphics.Rect
import android.os.Handler import android.os.Handler
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.camera.extensions.config import com.simplemobiletools.camera.extensions.config
class FocusRectView(context: Context) : ViewGroup(context) { class FocusCircleView(context: Context) : ViewGroup(context) {
private val RECT_SIZE = 50 private val CIRCLE_RADIUS = 50f
private val RECT_DURATION = 500 private val CIRCLE_DURATION = 500L
private var mDrawRect = false private var mDrawCircle = false
private var mHandler: Handler private var mHandler: Handler
private var mPaint: Paint
lateinit var mPaint: Paint private var mLastCenterX = 0f
lateinit var mRect: Rect private var mLastCenterY = 0f
init { init {
setWillNotDraw(false) setWillNotDraw(false)
mHandler = Handler() mHandler = Handler()
setupPaint()
}
private fun setupPaint() {
mPaint = Paint().apply { mPaint = Paint().apply {
style = Paint.Style.STROKE style = Paint.Style.STROKE
color = context.config.primaryColor color = context.config.primaryColor
@ -36,18 +31,19 @@ class FocusRectView(context: Context) : ViewGroup(context) {
mPaint.color = color mPaint.color = color
} }
fun drawFocusRect(x: Int, y: Int) { fun drawFocusRect(x: Float, y: Float) {
mRect = Rect(x - RECT_SIZE, y - RECT_SIZE, x + RECT_SIZE, y + RECT_SIZE) mLastCenterX = x
toggleRect(true) mLastCenterY = y
toggleCircle(true)
mHandler.removeCallbacksAndMessages(null) mHandler.removeCallbacksAndMessages(null)
mHandler.postDelayed({ mHandler.postDelayed({
toggleRect(false) toggleCircle(false)
}, RECT_DURATION.toLong()) }, CIRCLE_DURATION)
} }
private fun toggleRect(show: Boolean) { private fun toggleCircle(show: Boolean) {
mDrawRect = show mDrawCircle = show
invalidate() invalidate()
} }
@ -55,8 +51,8 @@ class FocusRectView(context: Context) : ViewGroup(context) {
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
super.onDraw(canvas) super.onDraw(canvas)
if (mDrawRect) { if (mDrawCircle) {
canvas.drawRect(mRect, mPaint) canvas.drawCircle(mLastCenterX, mLastCenterY, CIRCLE_RADIUS, mPaint)
} }
} }
} }

View File

@ -54,8 +54,8 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private var mWasZooming = false private var mWasZooming = false
private var mIsPreviewShown = false private var mIsPreviewShown = false
private var mWasCameraPreviewSet = false private var mWasCameraPreviewSet = false
private var mLastClickX = 0 private var mLastClickX = 0f
private var mLastClickY = 0 private var mLastClickY = 0f
private var mCurrCameraId = 0 private var mCurrCameraId = 0
private var mMaxZoom = 0 private var mMaxZoom = 0
private var mRotationAtCapture = 0 private var mRotationAtCapture = 0
@ -87,8 +87,8 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
initGestureDetector() initGestureDetector()
mSurfaceView.setOnTouchListener { view, event -> mSurfaceView.setOnTouchListener { view, event ->
mLastClickX = event.x.toInt() mLastClickX = event.x
mLastClickY = event.y.toInt() mLastClickY = event.y
if (mMaxZoom > 0 && mParameters?.isZoomSupported == true) { if (mMaxZoom > 0 && mParameters?.isZoomSupported == true) {
mScaleGestureDetector!!.onTouchEvent(event) mScaleGestureDetector!!.onTouchEvent(event)
@ -388,18 +388,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mCamera!!.cancelAutoFocus() mCamera!!.cancelAutoFocus()
if (mParameters!!.maxNumFocusAreas > 0) { if (mParameters!!.maxNumFocusAreas > 0) {
if (mLastClickX == 0 && mLastClickY == 0) { if (mLastClickX == 0f && mLastClickY == 0f) {
mLastClickX = width / 2 mLastClickX = width / 2.toFloat()
mLastClickY = height / 2 mLastClickY = height / 2.toFloat()
} }
val focusRect = calculateFocusArea(mLastClickX.toFloat(), mLastClickY.toFloat()) val focusRect = calculateFocusArea(mLastClickX, mLastClickY)
val focusAreas = ArrayList<Camera.Area>(1) val focusAreas = ArrayList<Camera.Area>(1)
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.drawFocusCircle(mLastClickX, mLastClickY)
} }
} }
@ -829,6 +829,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
fun videoSaved(uri: Uri) fun videoSaved(uri: Uri)
fun drawFocusRect(x: Int, y: Int) fun drawFocusCircle(x: Float, y: Float)
} }
} }