mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-06-05 21:59:15 +02:00
Properly translate tap coordinates into grid coordinates for touch events
This commit is contained in:
@ -427,11 +427,12 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}, ANIMATION_DURATION)
|
}, ANIMATION_DURATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun homeScreenLongPressed(x: Float, y: Float) {
|
fun homeScreenLongPressed(eventX: Float, eventY: Float) {
|
||||||
if (isAllAppsFragmentExpanded()) {
|
if (isAllAppsFragmentExpanded()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
|
||||||
mIgnoreMoveEvents = true
|
mIgnoreMoveEvents = true
|
||||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||||
if (clickedGridItem != null) {
|
if (clickedGridItem != null) {
|
||||||
@ -448,8 +449,9 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
showMainLongPressMenu(x, y)
|
showMainLongPressMenu(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun homeScreenClicked(x: Float, y: Float) {
|
fun homeScreenClicked(eventX: Float, eventY: Float) {
|
||||||
home_screen_grid.hideResizeLines()
|
home_screen_grid.hideResizeLines()
|
||||||
|
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
|
||||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||||
if (clickedGridItem != null) {
|
if (clickedGridItem != null) {
|
||||||
if (clickedGridItem.type == ITEM_TYPE_ICON) {
|
if (clickedGridItem.type == ITEM_TYPE_ICON) {
|
||||||
|
@ -733,6 +733,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun intoViewSpaceCoords(screenSpaceX: Float, screenSpaceY: Float): Pair<Float, Float> {
|
||||||
|
val viewLocation = IntArray(2)
|
||||||
|
getLocationOnScreen(viewLocation)
|
||||||
|
val x = screenSpaceX - viewLocation[0]
|
||||||
|
val y = screenSpaceY - viewLocation[1]
|
||||||
|
return Pair(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
private fun HomeScreenGridItem.outOfBounds(): Boolean {
|
private fun HomeScreenGridItem.outOfBounds(): Boolean {
|
||||||
return (left >= cellXCoords.size || right >= cellXCoords.size || top >= cellYCoords.size || bottom >= cellYCoords.size)
|
return (left >= cellXCoords.size || right >= cellXCoords.size || top >= cellYCoords.size || bottom >= cellYCoords.size)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user