mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-16 19:40:41 +01:00
Merge pull request #98 from esensar/fix/icon-menu
Fix position of popup menu anchor to be more consistent
This commit is contained in:
commit
65f4cf4b0a
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user