mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-23 22:37:25 +02:00
show currenly dragged icon at its place
This commit is contained in:
parent
8247f8770d
commit
ee76ac602a
@ -36,6 +36,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
|
||||
private var gridItems = ArrayList<HomeScreenGridItem>()
|
||||
private var gridCenters = ArrayList<Pair<Int, Int>>()
|
||||
private var draggedItemCurrentCoords = Pair(-1, -1)
|
||||
|
||||
init {
|
||||
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
@ -75,6 +76,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
if (draggedItem == null) {
|
||||
return
|
||||
}
|
||||
|
||||
draggedItemCurrentCoords = Pair(x, y)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
// figure out at which cell was the item dropped, if it is empty
|
||||
@ -125,6 +129,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
}
|
||||
|
||||
draggedItem = null
|
||||
draggedItemCurrentCoords = Pair(-1, -1)
|
||||
if (redrawIcons) {
|
||||
invalidate()
|
||||
}
|
||||
@ -166,6 +171,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
}
|
||||
|
||||
gridItems.filter { it.drawable != null }.forEach { item ->
|
||||
if (item.id != draggedItem?.id) {
|
||||
val drawableX = rowXCoords[item.left] + iconMargin
|
||||
|
||||
// icons at the bottom are drawn at the bottom of the grid and they have no label
|
||||
@ -193,6 +199,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
}
|
||||
|
||||
item.drawable!!.draw(canvas)
|
||||
} else if (draggedItemCurrentCoords.first != -1 && draggedItemCurrentCoords.second != -1) {
|
||||
val drawableX = draggedItemCurrentCoords.first - iconSize
|
||||
val drawableY = draggedItemCurrentCoords.second - (iconSize * 1.5f).toInt()
|
||||
item.drawable!!.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
|
||||
item.drawable!!.draw(canvas)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user