adding an extra check to avoid clicking through expanded fragments

This commit is contained in:
tibbi 2022-10-02 15:03:03 +02:00
parent 2cf2918538
commit b5433b40a7
4 changed files with 31 additions and 3 deletions

View File

@ -261,6 +261,7 @@ class MainActivity : SimpleActivity(), FlingListener {
}
window.navigationBarColor = resources.getColor(R.color.semitransparent_navigation)
home_screen_grid.fragmentExpanded()
}
private fun hideFragment(fragment: View) {
@ -271,6 +272,7 @@ class MainActivity : SimpleActivity(), FlingListener {
}
window.navigationBarColor = Color.TRANSPARENT
home_screen_grid.fragmentCollapsed()
}
fun homeScreenLongPressed(x: Float, y: Float) {

View File

@ -535,6 +535,18 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
isFirstDraw = false
}
fun fragmentExpanded() {
widgetViews.forEach {
it.ignoreTouches = true
}
}
fun fragmentCollapsed() {
widgetViews.forEach {
it.ignoreTouches = false
}
}
// get the clickable area around the icon, it includes text too
private fun getClickableRect(item: HomeScreenGridItem): Rect {
val clickableLeft = item.left * rowWidth + sideMargins.left

View File

@ -14,9 +14,22 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
private var actionDownCoords = PointF()
private var currentCoords = PointF()
var hasLongPressed = false
var ignoreTouches = false
var longPressListener: ((x: Float, y: Float) -> Unit)? = null
override fun onTouchEvent(event: MotionEvent?): Boolean {
return if (ignoreTouches) {
true
} else {
super.onTouchEvent(event)
}
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
if (ignoreTouches) {
return true
}
if (hasLongPressed) {
hasLongPressed = false
return true
@ -34,7 +47,9 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
currentCoords.x = event.rawX
currentCoords.y = event.rawY
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> longPressHandler.removeCallbacksAndMessages(null)
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
longPressHandler.removeCallbacksAndMessages(null)
}
}
return false

View File

@ -4,8 +4,7 @@
android:id="@+id/all_apps_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/all_apps_background"
android:clickable="true">
android:background="@drawable/all_apps_background">
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
android:id="@+id/all_apps_fastscroller"