| 
					
				 | 
			
			
				@@ -0,0 +1,125 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.ethan.psbc.ui.widget 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.content.Context 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.graphics.Canvas 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.graphics.Color 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.graphics.Paint 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.graphics.RectF 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.os.Handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.util.AttributeSet 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.util.TypedValue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.view.View 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import androidx.constraintlayout.widget.ConstraintLayout 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.qmuiteam.qmui.util.QMUIDisplayHelper.getDisplayMetrics 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+class CameraFocusView(context: Context?,attrs: AttributeSet?) : View(context,attrs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var focusSize = 0 //焦点框的大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var focusColor = 0 //焦点框的颜色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var focusTime = 0 //焦点框显示的时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var focusStrokeSize = 0 //焦点框线条的尺寸 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var cornerSize = 0 //焦点框圆角尺寸 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var handler: Handler? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var runnable: Runnable? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var mPaint: Paint? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private var rect: RectF? = null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    init { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (context != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            init(context) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private fun init(context: Context) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        handler = Handler() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mPaint = Paint(Paint.ANTI_ALIAS_FLAG) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rect = RectF() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        runnable = Runnable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            hideFocusView() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun setParam( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        focusViewSize: Int, focusViewColor: Int, focusViewTime: Int, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        focusViewStrokeSize: Int, cornerViewSize: Int 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (focusViewSize == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusSize = dp2px(context, 60F) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusSize = focusViewSize 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (focusViewColor == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusColor = Color.GREEN 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusColor = focusViewColor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.focusTime = focusViewTime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (focusViewStrokeSize == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusStrokeSize = dp2px(context, 2F) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.focusStrokeSize = focusViewStrokeSize 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cornerViewSize == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.cornerSize = focusSize / 5 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.cornerSize = cornerViewSize 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mPaint!!.style = Paint.Style.STROKE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mPaint!!.strokeWidth = focusStrokeSize.toFloat() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mPaint!!.color = focusColor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rect!!.top = 0f 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rect!!.left = rect!!.top 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rect!!.bottom = focusSize.toFloat() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rect!!.right = rect!!.bottom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun showFocusView(x: Int, y: Int) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        visibility = VISIBLE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        val layoutParams = layoutParams as ConstraintLayout.LayoutParams 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        layoutParams.leftMargin = x - focusSize / 2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        layoutParams.topMargin = y - focusSize / 2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        setLayoutParams(layoutParams) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        invalidate() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        runnable?.let { handler?.postDelayed(it, (focusTime * 1000).toLong()) } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun hideFocusView() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        visibility = GONE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        runnable?.let { handler?.removeCallbacks(it) } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        setMeasuredDimension(focusSize, focusSize) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    override fun onDraw(canvas: Canvas) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        super.onDraw(canvas) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        canvas.drawRoundRect(rect!!, cornerSize.toFloat(), cornerSize.toFloat(), mPaint!!) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    override fun onDetachedFromWindow() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        runnable?.let { handler?.removeCallbacks(it) } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        super.onDetachedFromWindow() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun dp2px(mContext:Context,   dipValue:Float) : Int { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return  TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, getDisplayMetrics(mContext)).toInt() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |