|
|
|
|
|
|
|
|
|
|
public delegate void GestureLongPressUpCallback(); |
|
|
|
|
|
|
|
public delegate void GestureLongPressDragStartCallback(GestureLongPressDragStartDetails details); |
|
|
|
public delegate void GestureLongPressStartCallback(LongPressStartDetails details); |
|
|
|
public delegate void GestureLongPressDragUpdateCallback(GestureLongPressDragUpdateDetails details); |
|
|
|
public delegate void GestureLongPressMoveUpdateCallback(LongPressMoveUpdateDetails details); |
|
|
|
public delegate void GestureLongPressDragUpCallback(GestureLongPressDragUpDetails details); |
|
|
|
public delegate void GestureLongPressEndCallback(LongPressEndDetails details); |
|
|
|
public class GestureLongPressDragStartDetails { |
|
|
|
public GestureLongPressDragStartDetails( |
|
|
|
TimeSpan? sourceTimeStamp = null, |
|
|
|
public class LongPressStartDetails { |
|
|
|
public LongPressStartDetails( |
|
|
|
this.sourceTimeStamp = sourceTimeStamp; |
|
|
|
|
|
|
|
|
|
|
|
public readonly TimeSpan? sourceTimeStamp; |
|
|
|
public class GestureLongPressDragUpdateDetails { |
|
|
|
public GestureLongPressDragUpdateDetails( |
|
|
|
TimeSpan? sourceTimeStamp = null, |
|
|
|
public class LongPressMoveUpdateDetails { |
|
|
|
public LongPressMoveUpdateDetails( |
|
|
|
this.sourceTimeStamp = sourceTimeStamp; |
|
|
|
|
|
|
|
public readonly TimeSpan? sourceTimeStamp; |
|
|
|
|
|
|
|
public readonly Offset globalPosition; |
|
|
|
|
|
|
|
|
|
|
public class GestureLongPressDragUpDetails { |
|
|
|
public GestureLongPressDragUpDetails( |
|
|
|
TimeSpan? sourceTimeStamp = null, |
|
|
|
public class LongPressEndDetails { |
|
|
|
public LongPressEndDetails( |
|
|
|
this.sourceTimeStamp = sourceTimeStamp; |
|
|
|
public readonly TimeSpan? sourceTimeStamp; |
|
|
|
|
|
|
|
public LongPressGestureRecognizer(object debugOwner = null, PointerDeviceKind? kind = null) : |
|
|
|
base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) { |
|
|
|
} |
|
|
|
public LongPressGestureRecognizer( |
|
|
|
float? postAcceptSlopTolerance = null, |
|
|
|
object debugOwner = null, |
|
|
|
PointerDeviceKind? kind = null) : base( |
|
|
|
deadline: Constants.kLongPressTimeout, |
|
|
|
postAcceptSlopTolerance: postAcceptSlopTolerance, |
|
|
|
kind: kind, |
|
|
|
debugOwner: debugOwner) { } |
|
|
|
Offset _longPressOrigin; |
|
|
|
|
|
|
|
public GestureLongPressStartCallback onLongPressStart; |
|
|
|
|
|
|
|
public GestureLongPressMoveUpdateCallback onLongPressMoveUpdate; |
|
|
|
|
|
|
|
|
|
|
|
public GestureLongPressEndCallback onLongPressEnd; |
|
|
|
|
|
|
|
base.acceptGesture(this.primaryPointer); |
|
|
|
if (this.onLongPress != null) { |
|
|
|
this.invokeCallback<object>("onLongPress", () => { |
|
|
|
this.onLongPress(); |
|
|
|
|
|
|
} |
|
|
|
protected override void handlePrimaryPointer(PointerEvent evt) { |
|
|
|
if (evt is PointerUpEvent) { |
|
|
|
if (this._longPressAccepted && this.onLongPressUp != null) { |
|
|
|
this._longPressAccepted = false; |
|
|
|
this.invokeCallback<object>("onLongPressUp", () => { |
|
|
|
this.onLongPressUp(); |
|
|
|
if (this.onLongPressStart != null) { |
|
|
|
this.invokeCallback<object>("onLongPressStart", |
|
|
|
() => { |
|
|
|
this.onLongPressStart(new LongPressStartDetails(globalPosition: this._longPressOrigin)); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.resolve(GestureDisposition.rejected); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (evt is PointerDownEvent || evt is PointerCancelEvent) { |
|
|
|
this._longPressAccepted = false; |
|
|
|
public override string debugDescription { |
|
|
|
get { return "long press"; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class LongPressDragGestureRecognizer : PrimaryPointerGestureRecognizer { |
|
|
|
public LongPressDragGestureRecognizer(object debugOwner = null) : base( |
|
|
|
deadline: Constants.kLongPressTimeout, |
|
|
|
postAcceptSlopTolerance: null, |
|
|
|
debugOwner: debugOwner |
|
|
|
) { |
|
|
|
} |
|
|
|
|
|
|
|
bool _longPressAccepted = false; |
|
|
|
|
|
|
|
Offset _longPressOrigin; |
|
|
|
|
|
|
|
TimeSpan? _longPressStartTimestamp; |
|
|
|
|
|
|
|
public GestureLongPressDragStartCallback onLongPressStart; |
|
|
|
|
|
|
|
public GestureLongPressDragUpdateCallback onLongPressDragUpdate; |
|
|
|
|
|
|
|
public GestureLongPressDragUpCallback onLongPressUp; |
|
|
|
protected override void handlePrimaryPointer(PointerEvent evt) { |
|
|
|
if (evt is PointerUpEvent) { |
|
|
|
if (this._longPressAccepted) { |
|
|
|
if (this.onLongPressUp != null) { |
|
|
|
this.invokeCallback<object>("onLongPressUp", () => { |
|
|
|
this.onLongPressUp(); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
} |
|
|
|
protected override void didExceedDeadline() { |
|
|
|
this.resolve(GestureDisposition.accepted); |
|
|
|
this._longPressAccepted = true; |
|
|
|
base.acceptGesture(this.primaryPointer); |
|
|
|
if (this.onLongPressStart != null) { |
|
|
|
this.invokeCallback<object>("onLongPressStart", () => { |
|
|
|
this.onLongPressStart(new GestureLongPressDragStartDetails( |
|
|
|
sourceTimeStamp: this._longPressStartTimestamp, |
|
|
|
globalPosition: this._longPressOrigin |
|
|
|
)); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.onLongPressEnd != null) { |
|
|
|
this.invokeCallback<object>("onLongPressEnd", () => { |
|
|
|
this.onLongPressEnd(new LongPressEndDetails(globalPosition: evt.position)); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
} |
|
|
|
protected override void handlePrimaryPointer(PointerEvent e) { |
|
|
|
if (e is PointerUpEvent) { |
|
|
|
if (this._longPressAccepted == true && this.onLongPressUp != null) { |
|
|
|
this._longPressAccepted = false; |
|
|
|
this.invokeCallback<object>("onLongPressUp", () => { |
|
|
|
this.onLongPressUp(new GestureLongPressDragUpDetails( |
|
|
|
sourceTimeStamp: e.timeStamp, |
|
|
|
globalPosition: e.position |
|
|
|
)); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
this._longPressAccepted = true; |
|
|
|
else if (e is PointerDownEvent) { |
|
|
|
else if (evt is PointerDownEvent || evt is PointerCancelEvent) { |
|
|
|
this._longPressStartTimestamp = e.timeStamp; |
|
|
|
this._longPressOrigin = e.position; |
|
|
|
this._longPressOrigin = evt.position; |
|
|
|
else if (e is PointerMoveEvent && this._longPressAccepted && this.onLongPressDragUpdate != null) { |
|
|
|
this.invokeCallback<object>("onLongPressDrag", () => { |
|
|
|
this.onLongPressDragUpdate(new GestureLongPressDragUpdateDetails( |
|
|
|
sourceTimeStamp: e.timeStamp, |
|
|
|
globalPosition: e.position, |
|
|
|
offsetFromOrigin: e.position - this._longPressOrigin |
|
|
|
else if (evt is PointerMoveEvent && this._longPressAccepted && this.onLongPressMoveUpdate != null) { |
|
|
|
this.invokeCallback<object>("onLongPressMoveUpdate", () => { |
|
|
|
this.onLongPressMoveUpdate(new LongPressMoveUpdateDetails( |
|
|
|
globalPosition: evt.position, |
|
|
|
offsetFromOrigin: evt.position - this._longPressOrigin |
|
|
|
)); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
|
|
|
public override void acceptGesture(int pointer) { |
|
|
|
} |
|
|
|
|
|
|
|
protected override void didStopTrackingLastPointer(int pointer) { |
|
|
|
this._longPressAccepted = false; |
|
|
|
this._longPressOrigin = null; |
|
|
|
this._longPressStartTimestamp = null; |
|
|
|
base.didStopTrackingLastPointer(pointer); |
|
|
|
} |
|
|
|
|
|
|
|
get { return "long press drag"; } |
|
|
|
get { return "long press"; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |