From b5433b40a7e953962a0e53ba84b73e4b6d71147e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 2 Oct 2022 15:03:03 +0200 Subject: [PATCH] adding an extra check to avoid clicking through expanded fragments --- .../launcher/activities/MainActivity.kt | 2 ++ .../launcher/views/HomeScreenGrid.kt | 12 ++++++++++++ .../launcher/views/MyAppWidgetHostView.kt | 17 ++++++++++++++++- app/src/main/res/layout/all_apps_fragment.xml | 3 +-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index 4daf36f..2d98f76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index 6e476fb..5228208 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt index c02775f..8553974 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt @@ -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 diff --git a/app/src/main/res/layout/all_apps_fragment.xml b/app/src/main/res/layout/all_apps_fragment.xml index 1967d18..0216de9 100644 --- a/app/src/main/res/layout/all_apps_fragment.xml +++ b/app/src/main/res/layout/all_apps_fragment.xml @@ -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">