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

@ -3,28 +3,23 @@ package com.simplemobiletools.camera.views
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.os.Handler
import android.view.ViewGroup
import com.simplemobiletools.camera.extensions.config
class FocusRectView(context: Context) : ViewGroup(context) {
private val RECT_SIZE = 50
private val RECT_DURATION = 500
class FocusCircleView(context: Context) : ViewGroup(context) {
private val CIRCLE_RADIUS = 50f
private val CIRCLE_DURATION = 500L
private var mDrawRect = false
private var mDrawCircle = false
private var mHandler: Handler
lateinit var mPaint: Paint
lateinit var mRect: Rect
private var mPaint: Paint
private var mLastCenterX = 0f
private var mLastCenterY = 0f
init {
setWillNotDraw(false)
mHandler = Handler()
setupPaint()
}
private fun setupPaint() {
mPaint = Paint().apply {
style = Paint.Style.STROKE
color = context.config.primaryColor
@ -36,18 +31,19 @@ class FocusRectView(context: Context) : ViewGroup(context) {
mPaint.color = color
}
fun drawFocusRect(x: Int, y: Int) {
mRect = Rect(x - RECT_SIZE, y - RECT_SIZE, x + RECT_SIZE, y + RECT_SIZE)
toggleRect(true)
fun drawFocusRect(x: Float, y: Float) {
mLastCenterX = x
mLastCenterY = y
toggleCircle(true)
mHandler.removeCallbacksAndMessages(null)
mHandler.postDelayed({
toggleRect(false)
}, RECT_DURATION.toLong())
toggleCircle(false)
}, CIRCLE_DURATION)
}
private fun toggleRect(show: Boolean) {
mDrawRect = show
private fun toggleCircle(show: Boolean) {
mDrawCircle = show
invalidate()
}
@ -55,8 +51,8 @@ class FocusRectView(context: Context) : ViewGroup(context) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (mDrawRect) {
canvas.drawRect(mRect, mPaint)
if (mDrawCircle) {
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 mIsPreviewShown = false
private var mWasCameraPreviewSet = false
private var mLastClickX = 0
private var mLastClickY = 0
private var mLastClickX = 0f
private var mLastClickY = 0f
private var mCurrCameraId = 0
private var mMaxZoom = 0
private var mRotationAtCapture = 0
@ -87,8 +87,8 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
initGestureDetector()
mSurfaceView.setOnTouchListener { view, event ->
mLastClickX = event.x.toInt()
mLastClickY = event.y.toInt()
mLastClickX = event.x
mLastClickY = event.y
if (mMaxZoom > 0 && mParameters?.isZoomSupported == true) {
mScaleGestureDetector!!.onTouchEvent(event)
@ -388,18 +388,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mCamera!!.cancelAutoFocus()
if (mParameters!!.maxNumFocusAreas > 0) {
if (mLastClickX == 0 && mLastClickY == 0) {
mLastClickX = width / 2
mLastClickY = height / 2
if (mLastClickX == 0f && mLastClickY == 0f) {
mLastClickX = width / 2.toFloat()
mLastClickY = height / 2.toFloat()
}
val focusRect = calculateFocusArea(mLastClickX.toFloat(), mLastClickY.toFloat())
val focusRect = calculateFocusArea(mLastClickX, mLastClickY)
val focusAreas = ArrayList<Camera.Area>(1)
focusAreas.add(Camera.Area(focusRect, 1000))
mParameters!!.focusAreas = focusAreas
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 drawFocusRect(x: Int, y: Int)
fun drawFocusCircle(x: Float, y: Float)
}
}