mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-23 06:17:20 +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 gridItems = ArrayList<HomeScreenGridItem>()
|
||||||
private var gridCenters = ArrayList<Pair<Int, Int>>()
|
private var gridCenters = ArrayList<Pair<Int, Int>>()
|
||||||
|
private var draggedItemCurrentCoords = Pair(-1, -1)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
@ -75,6 +76,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
if (draggedItem == null) {
|
if (draggedItem == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draggedItemCurrentCoords = Pair(x, y)
|
||||||
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// figure out at which cell was the item dropped, if it is empty
|
// 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
|
draggedItem = null
|
||||||
|
draggedItemCurrentCoords = Pair(-1, -1)
|
||||||
if (redrawIcons) {
|
if (redrawIcons) {
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
@ -166,6 +171,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
|
|
||||||
gridItems.filter { it.drawable != null }.forEach { item ->
|
gridItems.filter { it.drawable != null }.forEach { item ->
|
||||||
|
if (item.id != draggedItem?.id) {
|
||||||
val drawableX = rowXCoords[item.left] + iconMargin
|
val drawableX = rowXCoords[item.left] + iconMargin
|
||||||
|
|
||||||
// icons at the bottom are drawn at the bottom of the grid and they have no label
|
// 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)
|
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