Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/event: touch events should be timestamped #10448

Open
rakyll opened this issue Apr 14, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@rakyll
Copy link
Member

commented Apr 14, 2015

Touch events should be timestamped to determine the order. Order is critical to determine the direction and the speed of the gesture.

cc/ @crawshaw @hyangah

@rakyll rakyll added the repo-mobile label Apr 14, 2015

@rakyll rakyll self-assigned this Apr 14, 2015

@crawshaw

This comment has been minimized.

Copy link
Contributor

commented Apr 14, 2015

I don't think we can reason about APIs like this. We need example programs that are built, reviewed, and submitted to reason on.

Before working on any more API changes, please build example apps that use them and mail them out. From there hopefully we can all see what is necessary from the APIs.

@rakyll

This comment has been minimized.

Copy link
Member Author

commented Apr 14, 2015

Although I agree that this may not be the ideal way to propose new APIs (or report API bugs), mailing out samples are not ideal either. Gesture detection algorithms are well known algorithms that require event time and identification of events (which will be supported once https://go-review.googlesource.com/#/c/1895/ is submitted).

I want to detect whether user double tapped or not. I shouldn't be reimplementing the event listener to expose event IDs and their timestamps to mail out a sample in order to justify this proposal.

For reference, some of the popular gesture detectors are available on https://android.googlesource.com/platform/development/+/master/ndk/sources/android/ndk_helper/gestureDetector.cpp.

@crawshaw

This comment has been minimized.

Copy link
Contributor

commented Apr 14, 2015

I cannot review an API without seeing how it is used.

@crawshaw crawshaw closed this Apr 14, 2015

@crawshaw crawshaw reopened this Apr 14, 2015

@rsc rsc changed the title mobile/event: touch events should be timestamped x/mobile/event: touch events should be timestamped Apr 14, 2015

@rsc rsc removed the repo-mobile label Apr 14, 2015

@rakyll

This comment has been minimized.

Copy link
Member Author

commented Apr 14, 2015

See the snippet below. I detect it as a single tap iff start and end happens less than a sec in between, and the touch boundary doesn't change significantly.

var lastStartTime time.Time
var lastStartLoc geom.Point

func touch(t event.Touch) {
    switch t.Type {
    case event.TouchStart:
        lastStartTime = time.Now()
        lastStartLoc = t.Loc
    case event.TouchEnd:
        // TODO(jbd): make sure end event is owned by the touch event
        diffX := math.Abs(float64(t.Loc.X) - float64(lastStartLoc.X))
        diffY := math.Abs(float64(t.Loc.Y) - float64(lastStartLoc.Y))
        diffTime := time.Now().Sub(lastStartTime)
        if diffTime < 2*time.Second && diffX < 30 && diffY < 30 {
            log.Println("single tap detected")
        }
    }
}

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 3, 2015

@rakyll rakyll modified the milestones: Go1.5Maybe, Unreleased Jul 9, 2015

@rsc rsc added this to the Unreleased milestone Jul 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.