Move SSD touch action dispatch to typed Kotlin
ober
7ddc03640c6dd22ca41447b240e0f31fe7cc5885
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -1176,7 +1176,9 @@ rotatedDisplayWidthFloat rotatedDisplayHeightFloat viewportCenterOffsetDelta nextRotationDegrees touchMoveExceeded shouldCollectSelectionMatches - selectionUsesRawRect selectionHasMatches) + selectionUsesRawRect selectionHasMatches + motionActionIsDown motionActionIsMove + motionActionIsUp motionActionIsUpOrCancel) (type Int32) (type Float32) (type FloatArray) @@ -1207,6 +1209,19 @@ (not snapSelectionToCells)) (def (selectionHasMatches (matchingCount : Int32)) : Bool (> matchingCount (int32 0))) + (def (motionActionMatches (action : Int32) (expected : Int32)) : Bool + (= action expected)) + (def (motionActionIsDown (action : Int32) (down : Int32)) : Bool + (motionActionMatches action down)) + (def (motionActionIsMove (action : Int32) (move : Int32)) : Bool + (motionActionMatches action move)) + (def (motionActionIsUp (action : Int32) (up : Int32)) : Bool + (motionActionMatches action up)) + (def (motionActionIsUpOrCancel (action : Int32) + (up : Int32) + (cancel : Int32)) : Bool + (or (motionActionMatches action up) + (motionActionMatches action cancel))) (def (clampFloat32 (value : Float32) (minimum : Float32) (maximum : Float32)) : Float32 @@ -7305,8 +7320,7 @@ " scaler.onTouchEvent(event)" " }" " if (event.pointerCount > 1) return true" - " when (event.actionMasked) {" - " MotionEvent.ACTION_DOWN -> {" + " if (motionActionIsDown(event.actionMasked, MotionEvent.ACTION_DOWN)) {" " parent.requestDisallowInterceptTouchEvent(true)" " lastX = event.x" " lastY = event.y" @@ -7318,8 +7332,7 @@ " dragStart = selectionPoint(event)" " dragEnd = dragStart" " }" - " }" - " MotionEvent.ACTION_MOVE -> {" + " } else if (motionActionIsMove(event.actionMasked, MotionEvent.ACTION_MOVE)) {" " val dx = event.x - lastX" " val dy = event.y - lastY" " if (touchMoveExceeded(dx, dy)) moved = true" @@ -7337,11 +7350,10 @@ " lastX = event.x" " lastY = event.y" " invalidate()" - " }" - " MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {" + " } else if (motionActionIsUpOrCancel(event.actionMasked, MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL)) {" " if (selectMode && dragStart != null && dragEnd != null) {" " finishSelection()" - " } else if (!selectMode && !moved && event.actionMasked == MotionEvent.ACTION_UP) {" + " } else if (!selectMode && !moved && motionActionIsUp(event.actionMasked, MotionEvent.ACTION_UP)) {" " val point = viewToImage(event.x, event.y)" " hitGroup(point[0], point[1])?.let {" " selectedGroupId = it" @@ -7351,7 +7363,6 @@ " }" " pointerActive = false" " parent.requestDisallowInterceptTouchEvent(false)" - " }" " }" " return true" " }"