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.MyCameraTwoImpl
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.PreviewListener
import com.simplemobiletools.commons.extensions.*
@ -32,7 +32,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSavedListener {
private val FADE_DELAY = 5000
lateinit var mFocusRectView: FocusRectView
lateinit var mFocusCircleView: FocusCircleView
lateinit var mTimerHandler: Handler
lateinit var mFadeHandler: Handler
lateinit var mCameraImpl: MyCamera
@ -74,7 +74,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
resumeCameraItems()
setupPreviewImage(mIsInPhotoMode)
scheduleFadeOut()
mFocusRectView.setStrokeColor(config.primaryColor)
mFocusCircleView.setStrokeColor(config.primaryColor)
if (mIsVideoCaptureIntent && mIsInPhotoMode) {
handleTogglePhotoVideo()
@ -201,8 +201,8 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
view_holder.addView(mPreview)
toggle_camera.setImageResource(if (mCurrCameraId == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear)
mFocusRectView = FocusRectView(applicationContext)
view_holder.addView(mFocusRectView)
mFocusCircleView = FocusCircleView(applicationContext)
view_holder.addView(mFocusCircleView)
mIsInPhotoMode = true
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) {
rescanPaths(arrayListOf(path)) {

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)
}
}