use the apps color on the focus rect

This commit is contained in:
tibbi 2017-03-21 22:39:25 +01:00
parent e309221b76
commit 5a04995b77
3 changed files with 13 additions and 10 deletions

View File

@ -316,17 +316,17 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
private fun calculateFocusArea(x: Float, y: Float): Rect { private fun calculateFocusArea(x: Float, y: Float): Rect {
var left = java.lang.Float.valueOf(x / mSurfaceView.width * 2000 - 1000)!!.toInt() var left = x / mSurfaceView.width * 2000 - 1000
var top = java.lang.Float.valueOf(y / mSurfaceView.height * 2000 - 1000)!!.toInt() var top = y / mSurfaceView.height * 2000 - 1000
val tmp = left val tmp = left
left = top left = top
top = -tmp top = -tmp
val rectLeft = Math.max(left - FOCUS_AREA_SIZE / 2, -1000) val rectLeft = Math.max(left.toInt() - FOCUS_AREA_SIZE / 2, -1000)
val rectTop = Math.max(top - FOCUS_AREA_SIZE / 2, -1000) val rectTop = Math.max(top.toInt() - FOCUS_AREA_SIZE / 2, -1000)
val rectRight = Math.min(left + FOCUS_AREA_SIZE / 2, 1000) val rectRight = Math.min(left.toInt() + FOCUS_AREA_SIZE / 2, 1000)
val rectBottom = Math.min(top + FOCUS_AREA_SIZE / 2, 1000) val rectBottom = Math.min(top.toInt() + FOCUS_AREA_SIZE / 2, 1000)
return Rect(rectLeft, rectTop, rectRight, rectBottom) return Rect(rectLeft, rectTop, rectRight, rectBottom)
} }

View File

@ -436,6 +436,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho
resumeCameraItems() resumeCameraItems()
setupPreviewImage(mIsInPhotoMode) setupPreviewImage(mIsInPhotoMode)
scheduleFadeOut() scheduleFadeOut()
mFocusRectView.setStrokeColor(config.primaryColor)
if (mIsVideoCaptureIntent && mIsInPhotoMode) { if (mIsVideoCaptureIntent && mIsInPhotoMode) {
togglePhotoVideo() togglePhotoVideo()

View File

@ -6,7 +6,7 @@ import android.graphics.Paint
import android.graphics.Rect import android.graphics.Rect
import android.os.Handler import android.os.Handler
import android.view.ViewGroup import android.view.ViewGroup
import com.simplemobiletools.camera.R import com.simplemobiletools.camera.extensions.config
class FocusRectView(context: Context) : ViewGroup(context) { class FocusRectView(context: Context) : ViewGroup(context) {
companion object { companion object {
@ -14,7 +14,6 @@ class FocusRectView(context: Context) : ViewGroup(context) {
private val RECT_DURATION = 500 private val RECT_DURATION = 500
private var mDrawRect = false private var mDrawRect = false
private var mPrimaryColor = 0
lateinit var mPaint: Paint lateinit var mPaint: Paint
lateinit var mHandler: Handler lateinit var mHandler: Handler
@ -24,18 +23,21 @@ class FocusRectView(context: Context) : ViewGroup(context) {
init { init {
setWillNotDraw(false) setWillNotDraw(false)
mHandler = Handler() mHandler = Handler()
mPrimaryColor = resources.getColor(R.color.color_primary)
setupPaint() setupPaint()
} }
private fun setupPaint() { private fun setupPaint() {
mPaint = Paint().apply { mPaint = Paint().apply {
style = Paint.Style.STROKE style = Paint.Style.STROKE
color = mPrimaryColor color = context.config.primaryColor
strokeWidth = 2f strokeWidth = 2f
} }
} }
fun setStrokeColor(color: Int) {
mPaint.color = color
}
fun drawFocusRect(x: Int, y: Int) { fun drawFocusRect(x: Int, y: Int) {
mRect = Rect(x - RECT_SIZE, y - RECT_SIZE, x + RECT_SIZE, y + RECT_SIZE) mRect = Rect(x - RECT_SIZE, y - RECT_SIZE, x + RECT_SIZE, y + RECT_SIZE)
toggleRect(true) toggleRect(true)