From e69dc7438c83a028b82f160812bdefa40b063483 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 4 Oct 2022 23:34:50 +0200 Subject: [PATCH] add a listener to cell count changes --- .../com/simplemobiletools/launcher/views/HomeScreenGrid.kt | 4 ++++ .../launcher/views/MyAppWidgetResizeFrame.kt | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index 7ba4082..b34a062 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -188,6 +188,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel hideResizeLines() } + resize_frame.onResizeListener = { cellsRect -> + + } + widgetView.ignoreTouches = true widgetView.setOnTouchListener { v, event -> resize_frame.onTouchEvent(event) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt index e346bbf..d026417 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt @@ -35,6 +35,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In private val lineDotRadius = context.resources.getDimension(R.dimen.resize_frame_dot_radius) private val MAX_TOUCH_LINE_DISTANCE = lineDotRadius * 5 // how close we have to be to the widgets side to drag it var onClickListener: (() -> Unit)? = null + var onResizeListener: ((cellsRect: Rect) -> Unit)? = null private val DRAGGING_NONE = 0 private val DRAGGING_LEFT = 1 @@ -66,7 +67,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In allGridItems: ArrayList ) { frameRect = coords - cellsRect = Rect(gridItem.left, gridItem.top, gridItem.right, gridItem.bottom) + cellsRect = Rect(gridItem.left, gridItem.top, gridItem.right - 1, gridItem.bottom - 1) this.cellWidth = cellWidth this.cellHeight = cellHeight this.sideMargins = sideMargins @@ -98,7 +99,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In } private fun cellChanged() { - + onResizeListener?.invoke(cellsRect) } override fun onTouchEvent(event: MotionEvent?): Boolean {