Skip to content

Commit

Permalink
Allow moving map when filter menu is open
Browse files Browse the repository at this point in the history
workaround using reflection
fixes #155
  • Loading branch information
johan12345 committed Aug 18, 2022
1 parent efdd0d6 commit 13916b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
}
})
})
popup.setTouchModal(false)
popup.show()
}

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/net/vonforst/evmap/ui/PopupMenuExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.vonforst.evmap.ui

import android.annotation.SuppressLint
import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.appcompat.widget.MenuPopupWindow
import androidx.appcompat.widget.PopupMenu

/**
* Reflection workaround to make setTouchModal accessible for
*/
@SuppressLint("RestrictedApi")
fun PopupMenu.setTouchModal(modal: Boolean) {
try {
val mPopup = javaClass.getDeclaredField("mPopup").let { field ->
field.isAccessible = true
field.get(this)
} as MenuPopupHelper
val mPopup2 = mPopup.javaClass.getDeclaredMethod("getPopup").let { method ->
method.isAccessible = true
method.invoke(mPopup)
}
val mPopup3 = mPopup2.javaClass.getDeclaredField("mPopup").let { field ->
field.isAccessible = true
field.get(mPopup2)
} as MenuPopupWindow
mPopup3.setTouchModal(modal)
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: NoSuchMethodException) {
e.printStackTrace()
}
}

0 comments on commit 13916b0

Please sign in to comment.