-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow moving map when filter menu is open
workaround using reflection fixes #155
- Loading branch information
1 parent
efdd0d6
commit 13916b0
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/net/vonforst/evmap/ui/PopupMenuExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |