hide the resizing frame at clicking on the widget

This commit is contained in:
tibbi 2022-10-02 21:42:46 +02:00
parent 2a5909573d
commit ecc0243e60
2 changed files with 9 additions and 1 deletions

View File

@ -178,6 +178,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height) val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
resize_frame.updateFrameCoords(frameRect) resize_frame.updateFrameCoords(frameRect)
resize_frame.beVisible() resize_frame.beVisible()
widgetView.ignoreTouches = true
} }
} }
@ -186,8 +187,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
return return
} }
resizedWidget = null
resize_frame.beGone() resize_frame.beGone()
widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }?.ignoreTouches = false
resizedWidget = null
} }
private fun addAppIcon() { private fun addAppIcon() {
@ -387,6 +389,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
(context as? MainActivity)?.showHomeIconMenu(x, widgetView.y, item, false) (context as? MainActivity)?.showHomeIconMenu(x, widgetView.y, item, false)
} }
widgetView.onIgnoreInterceptedListener = {
hideResizeLines()
}
widgetView.x = calculateWidgetX(item.left) widgetView.x = calculateWidgetX(item.left)
widgetView.y = calculateWidgetY(item.top) widgetView.y = calculateWidgetY(item.top)
val widgetWidth = item.widthCells * rowWidth val widgetWidth = item.widthCells * rowWidth

View File

@ -16,9 +16,11 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
var hasLongPressed = false var hasLongPressed = false
var ignoreTouches = false var ignoreTouches = false
var longPressListener: ((x: Float, y: Float) -> Unit)? = null var longPressListener: ((x: Float, y: Float) -> Unit)? = null
var onIgnoreInterceptedListener: (() -> Unit)? = null // let the home grid react on swallowed clicks, for example by hiding the widget resize frame
override fun onTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
return if (ignoreTouches) { return if (ignoreTouches) {
onIgnoreInterceptedListener?.invoke()
true true
} else { } else {
super.onTouchEvent(event) super.onTouchEvent(event)