package com.coloros.ocrscanner.translator.screen.utils
import android.graphics.Rect
import android.view.View
import com.coloros.ocrscanner.utils.LogUtils
object PointInView {
private const val TAG = "PointInView"
@JvmStatic
fun isTouchPointInView(view: View?, x: Float, y: Float): Boolean {
if (view == null) {
return false
}
val location = IntArray(2)
view.getLocationOnScreen(location)
val left = location[0]
val top = location[1]
val right = left + view.measuredWidth
val bottom = top + view.measuredHeight
if (y.toInt() in top..bottom && x >= left
&& x <= right
) {
return true
}
return false
}
fun mGetLocation(view: View?): Rect {
val location = IntArray(2)
view!!.getLocationOnScreen(location)
val left = location[0]
val top = location[1]
val right = left + view.measuredWidth
val bottom = top + view.measuredHeight
var mViewRect: Rect = Rect()
mViewRect.left = left
mViewRect.right = right
mViewRect.top = top
mViewRect.bottom = bottom
LogUtils.d(TAG, "left:$left top:$top right:$right bottom:$bottom")
return mViewRect
}
}