mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-16 19:40:41 +01:00
Properly translate tap coordinates into grid coordinates for touch events
This commit is contained in:
parent
934651e88d
commit
3545701f21
@ -427,11 +427,12 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
}, ANIMATION_DURATION)
|
||||
}
|
||||
|
||||
fun homeScreenLongPressed(x: Float, y: Float) {
|
||||
fun homeScreenLongPressed(eventX: Float, eventY: Float) {
|
||||
if (isAllAppsFragmentExpanded()) {
|
||||
return
|
||||
}
|
||||
|
||||
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
|
||||
mIgnoreMoveEvents = true
|
||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||
if (clickedGridItem != null) {
|
||||
@ -448,8 +449,9 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
showMainLongPressMenu(x, y)
|
||||
}
|
||||
|
||||
fun homeScreenClicked(x: Float, y: Float) {
|
||||
fun homeScreenClicked(eventX: Float, eventY: Float) {
|
||||
home_screen_grid.hideResizeLines()
|
||||
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
|
||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||
if (clickedGridItem != null) {
|
||||
if (clickedGridItem.type == ITEM_TYPE_ICON) {
|
||||
|
@ -733,6 +733,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||
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 {
|
||||
return (left >= cellXCoords.size || right >= cellXCoords.size || top >= cellYCoords.size || bottom >= cellYCoords.size)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user