Share native side arrow touch handling
This commit is contained in:
@@ -76,7 +76,7 @@ internal class SamsungHoneyspaceHooks(
|
||||
registerSettingsReceiver()
|
||||
trackNavContainerFrom(navButtonView as? View)
|
||||
|
||||
return@hookMethod handleNativeSideArrowTouch(navButtonView, keyCode, motionEvent) {
|
||||
return@hookMethod sideArrowLongPresses.handleNativeTouch(navButtonView, keyCode, motionEvent) {
|
||||
chain.proceed()
|
||||
}
|
||||
}
|
||||
@@ -366,28 +366,6 @@ internal class SamsungHoneyspaceHooks(
|
||||
restoreHoneyspaceSideArrowDrawables(container)
|
||||
}
|
||||
|
||||
private fun handleNativeSideArrowTouch(
|
||||
view: Any,
|
||||
keyCode: Int,
|
||||
event: MotionEvent,
|
||||
proceed: () -> Any?,
|
||||
): Any? {
|
||||
return when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sideArrowLongPresses.startAfter(view, keyCode, proceed)
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_CANCEL,
|
||||
-> {
|
||||
sideArrowLongPresses.finish(view)
|
||||
proceed()
|
||||
}
|
||||
|
||||
else -> proceed()
|
||||
}
|
||||
}
|
||||
|
||||
private fun markLongClicked(navButtonView: Any) {
|
||||
try {
|
||||
callMethod(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package se.ajpanton.navbuttons
|
||||
|
||||
import android.os.Handler
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import java.util.WeakHashMap
|
||||
|
||||
@@ -27,6 +28,25 @@ internal class SideArrowLongPressController(
|
||||
return result
|
||||
}
|
||||
|
||||
fun handleNativeTouch(
|
||||
target: Any,
|
||||
keyCode: Int,
|
||||
event: MotionEvent,
|
||||
proceed: () -> Any?,
|
||||
): Any? {
|
||||
return when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> startAfter(target, keyCode, proceed)
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_CANCEL,
|
||||
-> {
|
||||
finish(target)
|
||||
proceed()
|
||||
}
|
||||
|
||||
else -> proceed()
|
||||
}
|
||||
}
|
||||
|
||||
fun finish(target: Any): Boolean {
|
||||
val wasTriggered = triggered[target] == true
|
||||
cancel(target)
|
||||
|
||||
@@ -86,7 +86,7 @@ internal class SystemUiNavHooks(
|
||||
registerSettingsReceiver()
|
||||
trackSamsungNavigationBarView(keyButtonView)
|
||||
configureAospSideArrowButton(keyButtonView)
|
||||
return@hookMethod handleNativeSideArrowTouch(keyButtonView, keyCode, motionEvent) {
|
||||
return@hookMethod sideArrowLongPresses.handleNativeTouch(keyButtonView, keyCode, motionEvent) {
|
||||
chain.proceed()
|
||||
}
|
||||
}
|
||||
@@ -205,28 +205,6 @@ internal class SystemUiNavHooks(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNativeSideArrowTouch(
|
||||
view: Any,
|
||||
keyCode: Int,
|
||||
event: MotionEvent,
|
||||
proceed: () -> Any?,
|
||||
): Any? {
|
||||
return when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sideArrowLongPresses.startAfter(view, keyCode, proceed)
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_CANCEL,
|
||||
-> {
|
||||
sideArrowLongPresses.finish(view)
|
||||
proceed()
|
||||
}
|
||||
|
||||
else -> proceed()
|
||||
}
|
||||
}
|
||||
|
||||
private fun markLongClicked(keyButtonView: Any) {
|
||||
try {
|
||||
findField(keyButtonView.javaClass, "mLongClicked").setBoolean(keyButtonView, true)
|
||||
|
||||
Reference in New Issue
Block a user