Merge pull request #98 from esensar/fix/icon-menu

Fix position of popup menu anchor to be more consistent
This commit is contained in:
Tibor Kaputa 2023-07-31 11:13:08 +02:00 committed by GitHub
commit 65f4cf4b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -32,6 +32,7 @@ import androidx.core.graphics.drawable.toBitmap
import androidx.core.view.GestureDetectorCompat
import androidx.core.view.WindowCompat
import androidx.core.view.isVisible
import androidx.core.view.iterator
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.launcher.BuildConfig
@ -523,11 +524,11 @@ class MainActivity : SimpleActivity(), FlingListener {
home_screen_grid.hideResizeLines()
mLongPressedIcon = gridItem
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
y
} else if (gridItem.top == config.homeRowCount - 1) {
home_screen_grid.sideMargins.top + (gridItem.top * home_screen_grid.cellHeight.toFloat())
val iconSize = realScreenSize.x / config.drawerColumnCount
y - iconSize / 2f
} else {
(gridItem.top * home_screen_grid.cellHeight.toFloat())
val clickableRect = home_screen_grid.getClickableRect(gridItem)
clickableRect.top.toFloat() - home_screen_grid.getCurrentIconSize() / 2f
}
home_screen_popup_menu_anchor.x = x
@ -563,23 +564,6 @@ class MainActivity : SimpleActivity(), FlingListener {
}
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
var visibleMenuButtons = 6
visibleMenuButtons -= when (gridItem.type) {
ITEM_TYPE_ICON -> 1
ITEM_TYPE_WIDGET -> 3
else -> 4
}
if (isOnAllAppsFragment) {
visibleMenuButtons--
}
if (gridItem.type != ITEM_TYPE_WIDGET) {
visibleMenuButtons--
}
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1)
anchorView.y -= yOffset
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
@ -612,6 +596,15 @@ class MainActivity : SimpleActivity(), FlingListener {
resetFragmentTouches()
}
var visibleMenuItems = 0
for (item in menu.iterator()) {
if (item.isVisible) {
visibleMenuItems++
}
}
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuItems - 1)
anchorView.y -= yOffset
show()
}
}

View File

@ -120,7 +120,9 @@ class LaunchersAdapter(
setOnClickListener { itemClick(launcher) }
setOnLongClickListener { view ->
allAppsListener.onAppLauncherLongPressed(view.x + width / 2, view.y, launcher)
val location = IntArray(2)
getLocationOnScreen(location)
allAppsListener.onAppLauncherLongPressed((location[0] + width / 2).toFloat(), location[1].toFloat(), launcher)
true
}
}

View File

@ -1076,6 +1076,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
return false
}
fun getCurrentIconSize(): Int = iconSize
private fun handlePageChange(redraw: Boolean = false) {
pageChangeEnabled = false
pageChangeIndicatorsAlpha = 0f