From 5a04995b7780ae69b42dcdcf6b231134a2364062 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 21 Mar 2017 22:39:25 +0100 Subject: [PATCH] use the apps color on the focus rect --- .../kotlin/com/simplemobiletools/camera/Preview.kt | 12 ++++++------ .../camera/activities/MainActivity.kt | 1 + .../simplemobiletools/camera/views/FocusRectView.kt | 10 ++++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index 89883fd7..c4b1d743 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -316,17 +316,17 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } private fun calculateFocusArea(x: Float, y: Float): Rect { - var left = java.lang.Float.valueOf(x / mSurfaceView.width * 2000 - 1000)!!.toInt() - var top = java.lang.Float.valueOf(y / mSurfaceView.height * 2000 - 1000)!!.toInt() + var left = x / mSurfaceView.width * 2000 - 1000 + var top = y / mSurfaceView.height * 2000 - 1000 val tmp = left left = top top = -tmp - val rectLeft = Math.max(left - FOCUS_AREA_SIZE / 2, -1000) - val rectTop = Math.max(top - FOCUS_AREA_SIZE / 2, -1000) - val rectRight = Math.min(left + FOCUS_AREA_SIZE / 2, 1000) - val rectBottom = Math.min(top + FOCUS_AREA_SIZE / 2, 1000) + val rectLeft = Math.max(left.toInt() - FOCUS_AREA_SIZE / 2, -1000) + val rectTop = Math.max(top.toInt() - FOCUS_AREA_SIZE / 2, -1000) + val rectRight = Math.min(left.toInt() + FOCUS_AREA_SIZE / 2, 1000) + val rectBottom = Math.min(top.toInt() + FOCUS_AREA_SIZE / 2, 1000) return Rect(rectLeft, rectTop, rectRight, rectBottom) } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index 4138e759..74694e02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -436,6 +436,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho resumeCameraItems() setupPreviewImage(mIsInPhotoMode) scheduleFadeOut() + mFocusRectView.setStrokeColor(config.primaryColor) if (mIsVideoCaptureIntent && mIsInPhotoMode) { togglePhotoVideo() diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/FocusRectView.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/FocusRectView.kt index a43b1b89..acf20819 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/FocusRectView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/FocusRectView.kt @@ -6,7 +6,7 @@ import android.graphics.Paint import android.graphics.Rect import android.os.Handler import android.view.ViewGroup -import com.simplemobiletools.camera.R +import com.simplemobiletools.camera.extensions.config class FocusRectView(context: Context) : ViewGroup(context) { companion object { @@ -14,7 +14,6 @@ class FocusRectView(context: Context) : ViewGroup(context) { private val RECT_DURATION = 500 private var mDrawRect = false - private var mPrimaryColor = 0 lateinit var mPaint: Paint lateinit var mHandler: Handler @@ -24,18 +23,21 @@ class FocusRectView(context: Context) : ViewGroup(context) { init { setWillNotDraw(false) mHandler = Handler() - mPrimaryColor = resources.getColor(R.color.color_primary) setupPaint() } private fun setupPaint() { mPaint = Paint().apply { style = Paint.Style.STROKE - color = mPrimaryColor + color = context.config.primaryColor strokeWidth = 2f } } + fun setStrokeColor(color: Int) { + 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)