create a list of cells occupied by other items at resizing
This commit is contained in:
parent
830cea13fd
commit
5682968a0e
|
@ -184,7 +184,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
val viewX = widgetView.x.toInt()
|
||||
val viewY = widgetView.y.toInt()
|
||||
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
|
||||
resize_frame.updateFrameCoords(frameRect, cellWidth, cellHeight, sideMargins, appWidgetProviderInfo)
|
||||
val otherGridItems = gridItems.filter { it.widgetId != item.widgetId }.toMutableList() as ArrayList<HomeScreenGridItem>
|
||||
resize_frame.updateFrameCoords(frameRect, cellWidth, cellHeight, sideMargins, appWidgetProviderInfo, otherGridItems)
|
||||
resize_frame.beVisible()
|
||||
resize_frame.z = 1f // make sure the frame isnt behind the widget itself
|
||||
resize_frame.onClickListener = {
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.simplemobiletools.launcher.extensions.getTileCount
|
|||
import com.simplemobiletools.launcher.helpers.COLUMN_COUNT
|
||||
import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION
|
||||
import com.simplemobiletools.launcher.helpers.ROW_COUNT
|
||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
|
||||
|
@ -27,6 +28,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||
private var cellHeight = 0
|
||||
private var minResizeWidthCells = 1
|
||||
private var minResizeHeightCells = 1
|
||||
private val occupiedCells = ArrayList<Pair<Int, Int>>()
|
||||
private var providerInfo: AppWidgetProviderInfo? = null
|
||||
private var sideMargins = Rect()
|
||||
private val lineDotRadius = context.resources.getDimension(R.dimen.resize_frame_dot_radius)
|
||||
|
@ -54,7 +56,14 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||
}
|
||||
}
|
||||
|
||||
fun updateFrameCoords(coords: Rect, cellWidth: Int, cellHeight: Int, sideMargins: Rect, providerInfo: AppWidgetProviderInfo) {
|
||||
fun updateFrameCoords(
|
||||
coords: Rect,
|
||||
cellWidth: Int,
|
||||
cellHeight: Int,
|
||||
sideMargins: Rect,
|
||||
providerInfo: AppWidgetProviderInfo,
|
||||
allGridItems: ArrayList<HomeScreenGridItem>
|
||||
) {
|
||||
frameRect = coords
|
||||
this.cellWidth = cellWidth
|
||||
this.cellHeight = cellHeight
|
||||
|
@ -63,6 +72,15 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||
minResizeWidthCells = Math.min(COLUMN_COUNT, context.getTileCount(providerInfo.minResizeWidth))
|
||||
minResizeHeightCells = Math.min(ROW_COUNT, context.getTileCount(providerInfo.minResizeHeight))
|
||||
redrawFrame()
|
||||
|
||||
occupiedCells.clear()
|
||||
allGridItems.forEach { item ->
|
||||
for (xCell in item.left until item.right) {
|
||||
for (yCell in item.top until item.bottom) {
|
||||
occupiedCells.add(Pair(xCell, yCell))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun redrawFrame() {
|
||||
|
|
Loading…
Reference in New Issue