adding some minimal sizes at the widget resizing

This commit is contained in:
tibbi 2022-10-04 10:41:26 +02:00
parent 2fd48bdf53
commit 830cea13fd
1 changed files with 34 additions and 4 deletions

View File

@ -95,11 +95,41 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
} }
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
val minWidth = minResizeWidthCells * cellWidth
val minHeight = minResizeHeightCells * cellHeight
when (dragDirection) { when (dragDirection) {
DRAGGING_LEFT -> frameRect.left = event.rawX.toInt() DRAGGING_LEFT -> {
DRAGGING_TOP -> frameRect.top = event.rawY.toInt() val newWidth = frameRect.right - event.rawX.toInt()
DRAGGING_RIGHT -> frameRect.right = event.rawX.toInt() if (newWidth >= minWidth) {
DRAGGING_BOTTOM -> frameRect.bottom = event.rawY.toInt() frameRect.left = event.rawX.toInt()
} else {
frameRect.left = frameRect.right - minWidth
}
}
DRAGGING_TOP -> {
val newHeight = frameRect.bottom - event.rawY.toInt()
if (newHeight >= minHeight) {
frameRect.top = event.rawY.toInt()
} else {
frameRect.top = frameRect.bottom - minHeight
}
}
DRAGGING_RIGHT -> {
val newWidth = event.rawX.toInt() - frameRect.left
if (newWidth >= minWidth) {
frameRect.right = event.rawX.toInt()
} else {
frameRect.right = frameRect.left + minWidth
}
}
DRAGGING_BOTTOM -> {
val newHeight = event.rawY.toInt() - frameRect.top
if (newHeight >= minHeight) {
frameRect.bottom = event.rawY.toInt()
} else {
frameRect.bottom = frameRect.top + minHeight
}
}
} }
if (dragDirection != DRAGGING_NONE) { if (dragDirection != DRAGGING_NONE) {