Skip to content

Commit

Permalink
Merge pull request #30 from enaboapps/iss22
Browse files Browse the repository at this point in the history
Implement double tap, closes #22
  • Loading branch information
enaboapps authored Jan 11, 2024
2 parents 6c80010 + f4b8b96 commit 5591ab2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.accessibilityservice.GestureDescription
import android.graphics.PointF
import com.enaboapps.switchify.service.SwitchifyAccessibilityService
import com.enaboapps.switchify.service.utils.ScreenUtils
import java.util.Timer

class GestureManager {
// singleton
Expand Down Expand Up @@ -48,6 +49,44 @@ class GestureManager {
}
}

// Function to perform a double tap
fun performDoubleTap() {
try {
val path = android.graphics.Path()
currentPoint?.let { point ->
path.moveTo(point.x, point.y)
}
val gestureDescription = GestureDescription.Builder().addStroke(GestureDescription.StrokeDescription(path, 550, 100)).build()
accessibilityService.let {
it?.dispatchGesture(gestureDescription, object : AccessibilityService.GestureResultCallback() {
override fun onCompleted(gestureDescription: GestureDescription?) {
super.onCompleted(gestureDescription)
val gestureDrawing = GestureDrawing(it)
currentPoint?.let { point ->
gestureDrawing.drawCircleAndRemove(point.x.toInt(), point.y.toInt())
}
Timer().schedule(object : java.util.TimerTask() {
override fun run() {
if (gestureDescription != null) {
it.dispatchGesture(gestureDescription, object : AccessibilityService.GestureResultCallback() {
override fun onCompleted(gestureDescription: GestureDescription?) {
super.onCompleted(gestureDescription)
currentPoint?.let { point ->
gestureDrawing.drawCircleAndRemove(point.x.toInt(), point.y.toInt())
}
}
}, null)
}
}
}, 100)
}
}, null)
}
} catch (e: Exception) {
// Log.e(TAG, "onDoubleTap: ", e)
}
}

// Swipe direction
enum class SwipeDirection {
UP, DOWN, LEFT, RIGHT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class GesturesMenu(accessibilityService: SwitchifyAccessibilityService) {
MenuItem("Tap", {
GestureManager.getInstance().performTap()
}),
MenuItem("Double Tap", {
GestureManager.getInstance().performDoubleTap()
}),
MenuItem("Swipe", {
MenuManager.getInstance().openSwipeMenu()
}),
Expand Down

0 comments on commit 5591ab2

Please sign in to comment.