reuse the main anchor for showing PopupMenu at AllAppsFragment

This commit is contained in:
tibbi 2022-09-22 20:51:17 +02:00
parent 9fba3b56d6
commit 9321db3cec
5 changed files with 14 additions and 21 deletions

View File

@ -234,7 +234,7 @@ class MainActivity : SimpleActivity(), FlingListener {
val clickedGridItem = home_screen_grid.isClickingGridItem(getGridTouchedX(x), getGridTouchedY(y))
if (clickedGridItem != null) {
mLongPressedIcon = clickedGridItem
showHomeIconMenu(x, y, clickedGridItem.packageName)
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem.packageName)
return
}
@ -254,15 +254,15 @@ class MainActivity : SimpleActivity(), FlingListener {
private fun getGridTouchedY(y: Float) = Math.min(Math.max(y.toInt() - home_screen_grid.marginTop, 0), home_screen_grid.height).toInt()
private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) {
fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) {
home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
home_screen_popup_menu_anchor.y = y
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, clickedPackageName)
}
private fun showMainLongPressMenu(x: Float, y: Float) {
home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
PopupMenu(contextTheme, home_screen_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
inflate(R.menu.menu_home_screen)

View File

@ -49,11 +49,13 @@ class LaunchersAdapter(
override fun getItemCount() = launchers.size
private fun calculateIconWidth() {
val currentColumnCount = if (activity.portrait) {
activity.resources.getInteger(R.integer.portrait_column_count)
val currentColumnCount = activity.resources.getInteger(
if (activity.portrait) {
R.integer.portrait_column_count
} else {
activity.resources.getInteger(R.integer.landscape_column_count)
R.integer.landscape_column_count
}
)
val iconWidth = activity.realScreenSize.x / currentColumnCount
iconPadding = (iconWidth * 0.1f).toInt()

View File

@ -13,7 +13,6 @@ import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.extensions.handleGridItemPopupMenu
import com.simplemobiletools.launcher.extensions.launchApp
import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher
@ -122,8 +121,6 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
all_apps_popup_menu_anchor.x = x
all_apps_popup_menu_anchor.y = y
activity?.handleGridItemPopupMenu(all_apps_popup_menu_anchor, packageName)
activity?.showHomeIconMenu(x, y, packageName)
}
}

View File

@ -21,11 +21,4 @@
app:spanCount="@integer/portrait_column_count" />
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
<View
android:id="@+id/all_apps_popup_menu_anchor"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="gone" />
</com.simplemobiletools.launcher.fragments.AllAppsFragment>

View File

@ -1,6 +1,7 @@
<resources>
<dimen name="launcher_icon_size">55dp</dimen>
<dimen name="long_press_anchor_offset_y">70dp</dimen>
<dimen name="icon_long_press_anchor_offset_y">100dp</dimen>
<dimen name="home_long_press_anchor_offset_y">50dp</dimen>
<dimen name="widget_preview_size">140dp</dimen>
<dimen name="icon_side_margin">10dp</dimen>
</resources>