mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-06-05 21:59:15 +02: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:
@ -32,6 +32,7 @@ import androidx.core.graphics.drawable.toBitmap
|
|||||||
import androidx.core.view.GestureDetectorCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.view.iterator
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.launcher.BuildConfig
|
import com.simplemobiletools.launcher.BuildConfig
|
||||||
@ -523,11 +524,11 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
home_screen_grid.hideResizeLines()
|
home_screen_grid.hideResizeLines()
|
||||||
mLongPressedIcon = gridItem
|
mLongPressedIcon = gridItem
|
||||||
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
|
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
|
||||||
y
|
val iconSize = realScreenSize.x / config.drawerColumnCount
|
||||||
} else if (gridItem.top == config.homeRowCount - 1) {
|
y - iconSize / 2f
|
||||||
home_screen_grid.sideMargins.top + (gridItem.top * home_screen_grid.cellHeight.toFloat())
|
|
||||||
} else {
|
} 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
|
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 {
|
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())
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
||||||
@ -612,6 +596,15 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
resetFragmentTouches()
|
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()
|
show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,9 @@ class LaunchersAdapter(
|
|||||||
|
|
||||||
setOnClickListener { itemClick(launcher) }
|
setOnClickListener { itemClick(launcher) }
|
||||||
setOnLongClickListener { view ->
|
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
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1076,6 +1076,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCurrentIconSize(): Int = iconSize
|
||||||
|
|
||||||
private fun handlePageChange(redraw: Boolean = false) {
|
private fun handlePageChange(redraw: Boolean = false) {
|
||||||
pageChangeEnabled = false
|
pageChangeEnabled = false
|
||||||
pageChangeIndicatorsAlpha = 0f
|
pageChangeIndicatorsAlpha = 0f
|
||||||
|
Reference in New Issue
Block a user