From ef3fe39a1c0b758347da88c809ee3d4886bd9a0d Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 08:06:14 -0700 Subject: [PATCH 01/45] Initial support for a touch manager for interpreting onTouchEvent notifications. --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 50 ++++ SmartDeviceLink/CGPoint_Util.c | 32 +++ SmartDeviceLink/CGPoint_Util.h | 20 ++ SmartDeviceLink/SDLPinchGesture.c | 38 +++ SmartDeviceLink/SDLPinchGesture.h | 32 +++ SmartDeviceLink/SDLProxy.h | 2 + SmartDeviceLink/SDLProxy.m | 12 + SmartDeviceLink/SDLTouch.c | 38 +++ SmartDeviceLink/SDLTouch.h | 39 +++ SmartDeviceLink/SDLTouchManager.h | 45 ++++ SmartDeviceLink/SDLTouchManager.m | 226 ++++++++++++++++++ SmartDeviceLink/SDLTouchManagerListener.h | 25 ++ SmartDeviceLink/dispatch_timer.c | 38 +++ SmartDeviceLink/dispatch_timer.h | 18 ++ 14 files changed, 615 insertions(+) create mode 100644 SmartDeviceLink/CGPoint_Util.c create mode 100644 SmartDeviceLink/CGPoint_Util.h create mode 100644 SmartDeviceLink/SDLPinchGesture.c create mode 100644 SmartDeviceLink/SDLPinchGesture.h create mode 100644 SmartDeviceLink/SDLTouch.c create mode 100644 SmartDeviceLink/SDLTouch.h create mode 100644 SmartDeviceLink/SDLTouchManager.h create mode 100644 SmartDeviceLink/SDLTouchManager.m create mode 100644 SmartDeviceLink/SDLTouchManagerListener.h create mode 100644 SmartDeviceLink/dispatch_timer.c create mode 100644 SmartDeviceLink/dispatch_timer.h diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 33b828300..d4249c7a5 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -786,6 +786,16 @@ 5DEE55C51B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */; }; 5DEE55C61B8666A8004F0D0F /* OHHTTPStubs.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */; }; + DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; }; + DAC572581D1067270004288B /* SDLTouchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572561D1067270004288B /* SDLTouchManager.m */; }; + DAC5725B1D10B81E0004288B /* SDLTouch.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.c */; }; + DAC5725C1D10B81E0004288B /* SDLTouch.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725A1D10B81E0004288B /* SDLTouch.h */; }; + DAC572621D10C5020004288B /* SDLPinchGesture.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572601D10C5020004288B /* SDLPinchGesture.c */; }; + DAC572631D10C5020004288B /* SDLPinchGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572611D10C5020004288B /* SDLPinchGesture.h */; }; + DAC572661D10C5640004288B /* CGPoint_Util.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572641D10C5640004288B /* CGPoint_Util.c */; }; + DAC572671D10C5640004288B /* CGPoint_Util.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572651D10C5640004288B /* CGPoint_Util.h */; }; + DAC5726A1D10D5FC0004288B /* dispatch_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.c */; }; + DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572691D10D5FC0004288B /* dispatch_timer.h */; }; E9C32B861AB20B4300F283AF /* NSThread+ThreadIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */; }; E9C32B871AB20B4300F283AF /* NSThread+ThreadIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = E9C32B851AB20B4300F283AF /* NSThread+ThreadIndex.m */; }; E9C32B911AB20BA200F283AF /* SDLIAPSession.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B891AB20BA200F283AF /* SDLIAPSession.h */; }; @@ -1660,6 +1670,17 @@ 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = Carthage/Build/iOS/OHHTTPStubs.framework; sourceTree = ""; }; 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = OHHTTPStubs.framework.dSYM; path = Carthage/Build/iOS/OHHTTPStubs.framework.dSYM; sourceTree = ""; }; 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = ""; }; + DAC572551D1067270004288B /* SDLTouchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouchManager.h; sourceTree = ""; }; + DAC572561D1067270004288B /* SDLTouchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManager.m; sourceTree = ""; }; + DAC572591D10B81E0004288B /* SDLTouch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDLTouch.c; sourceTree = ""; }; + DAC5725A1D10B81E0004288B /* SDLTouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouch.h; sourceTree = ""; }; + DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLTouchManagerListener.h; sourceTree = ""; }; + DAC572601D10C5020004288B /* SDLPinchGesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDLPinchGesture.c; sourceTree = ""; }; + DAC572611D10C5020004288B /* SDLPinchGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLPinchGesture.h; sourceTree = ""; }; + DAC572641D10C5640004288B /* CGPoint_Util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CGPoint_Util.c; sourceTree = ""; }; + DAC572651D10C5640004288B /* CGPoint_Util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGPoint_Util.h; sourceTree = ""; }; + DAC572681D10D5FC0004288B /* dispatch_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dispatch_timer.c; sourceTree = ""; }; + DAC572691D10D5FC0004288B /* dispatch_timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dispatch_timer.h; sourceTree = ""; }; E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSThread+ThreadIndex.h"; sourceTree = ""; }; E9C32B851AB20B4300F283AF /* NSThread+ThreadIndex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSThread+ThreadIndex.m"; sourceTree = ""; }; E9C32B891AB20BA200F283AF /* SDLIAPSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLIAPSession.h; sourceTree = ""; }; @@ -2666,6 +2687,7 @@ 5D5934F61A85189500687FB9 /* Utilities */ = { isa = PBXGroup; children = ( + DAC5724C1D0FE3B60004288B /* Touches */, 5DCC199D1B8221D2004FFAD9 /* HTTP Connection */, E9C32B831AB20B2900F283AF /* @categories */, 5D5934F71A8519A700687FB9 /* JSON */, @@ -2954,6 +2976,24 @@ name = "HTTP Connection"; sourceTree = ""; }; + DAC5724C1D0FE3B60004288B /* Touches */ = { + isa = PBXGroup; + children = ( + DAC572551D1067270004288B /* SDLTouchManager.h */, + DAC572561D1067270004288B /* SDLTouchManager.m */, + DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */, + DAC572591D10B81E0004288B /* SDLTouch.c */, + DAC5725A1D10B81E0004288B /* SDLTouch.h */, + DAC572601D10C5020004288B /* SDLPinchGesture.c */, + DAC572611D10C5020004288B /* SDLPinchGesture.h */, + DAC572641D10C5640004288B /* CGPoint_Util.c */, + DAC572651D10C5640004288B /* CGPoint_Util.h */, + DAC572681D10D5FC0004288B /* dispatch_timer.c */, + DAC572691D10D5FC0004288B /* dispatch_timer.h */, + ); + name = Touches; + sourceTree = ""; + }; E9C32B831AB20B2900F283AF /* @categories */ = { isa = PBXGroup; children = ( @@ -2986,6 +3026,7 @@ 5DB92D321AC9C8BA00C15BB0 /* SDLRPCStruct.h in Headers */, 5D61FD151A84238C00846EE7 /* SDLOnLockScreenStatus.h in Headers */, 5D61FD291A84238C00846EE7 /* SDLPerformInteraction.h in Headers */, + DAC572571D1067270004288B /* SDLTouchManager.h in Headers */, 5D61FD521A84238C00846EE7 /* SDLProxyFactory.h in Headers */, 5D61FCDA1A84238C00846EE7 /* SDLJingle.h in Headers */, 5D61FE0D1A84238C00846EE7 /* SDLVRCapabilities.h in Headers */, @@ -3035,6 +3076,7 @@ 5D61FD091A84238C00846EE7 /* SDLOnDriverDistraction.h in Headers */, E9C32B9E1AB20C5900F283AF /* EAAccessoryManager+SDLProtocols.h in Headers */, 5D61FC4B1A84238C00846EE7 /* SDLBeltStatus.h in Headers */, + DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */, 5D61FC351A84238C00846EE7 /* SDLAirbagStatus.h in Headers */, 5D61FC8A1A84238C00846EE7 /* SDLDiagnosticMessageResponse.h in Headers */, 5D61FC2D1A84238C00846EE7 /* SDLAddCommand.h in Headers */, @@ -3108,6 +3150,7 @@ 5D61FC981A84238C00846EE7 /* SDLECallInfo.h in Headers */, 5D61FD7B1A84238C00846EE7 /* SDLScrollableMessage.h in Headers */, 5D61FD3D1A84238C00846EE7 /* SDLPrimaryAudioSource.h in Headers */, + DAC5725C1D10B81E0004288B /* SDLTouch.h in Headers */, 5D61FCCD1A84238C00846EE7 /* SDLImage.h in Headers */, 5D61FD481A84238C00846EE7 /* SDLProtocolMessage.h in Headers */, 5D61FC8C1A84238C00846EE7 /* SDLDIDResult.h in Headers */, @@ -3157,6 +3200,7 @@ 5D61FC611A84238C00846EE7 /* SDLChoice.h in Headers */, 5D61FC7C1A84238C00846EE7 /* SDLDeleteInteractionChoiceSetResponse.h in Headers */, 5D61FDB91A84238C00846EE7 /* SDLSyncPDataResponse.h in Headers */, + DAC572631D10C5020004288B /* SDLPinchGesture.h in Headers */, 5D61FC311A84238C00846EE7 /* SDLAddSubMenu.h in Headers */, 5D61FD171A84238C00846EE7 /* SDLOnPermissionsChange.h in Headers */, 5D61FDD51A84238C00846EE7 /* SDLTouchEventCapabilities.h in Headers */, @@ -3224,6 +3268,7 @@ 5D8B174F1AC9D266006A6E1C /* SDLDialNumber.h in Headers */, 5D61FCAD1A84238C00846EE7 /* SDLFunctionID.h in Headers */, 5D61FDF51A84238C00846EE7 /* SDLV1ProtocolHeader.h in Headers */, + DAC572671D10C5640004288B /* CGPoint_Util.h in Headers */, 5D61FDF91A84238C00846EE7 /* SDLV2ProtocolHeader.h in Headers */, 5D61FD4A1A84238C00846EE7 /* SDLProtocolMessageAssembler.h in Headers */, 5D61FD4C1A84238C00846EE7 /* SDLProtocolMessageDisassembler.h in Headers */, @@ -3481,6 +3526,7 @@ 5D61FDB21A84238C00846EE7 /* SDLSubscribeVehicleData.m in Sources */, 5D61FC991A84238C00846EE7 /* SDLECallInfo.m in Sources */, 5D61FD601A84238C00846EE7 /* SDLRegisterAppInterfaceResponse.m in Sources */, + DAC572621D10C5020004288B /* SDLPinchGesture.c in Sources */, 5D61FCF51A84238C00846EE7 /* SDLMaintenanceModeStatus.m in Sources */, 5D61FCD81A84238C00846EE7 /* SDLInteractionMode.m in Sources */, 5D61FCB01A84238C00846EE7 /* SDLGenericResponse.m in Sources */, @@ -3500,6 +3546,7 @@ 5D61FDA41A84238C00846EE7 /* SDLSoftButtonType.m in Sources */, 5D61FC521A84238C00846EE7 /* SDLButtonCapabilities.m in Sources */, 5D61FC791A84238C00846EE7 /* SDLDeleteFileResponse.m in Sources */, + DAC572581D1067270004288B /* SDLTouchManager.m in Sources */, 5D61FC641A84238C00846EE7 /* SDLClusterModeStatus.m in Sources */, 5D61FCF91A84238C00846EE7 /* SDLMenuParams.m in Sources */, 5D61FD7C1A84238C00846EE7 /* SDLScrollableMessage.m in Sources */, @@ -3544,6 +3591,7 @@ 5D61FC3A1A84238C00846EE7 /* SDLAlertManeuver.m in Sources */, 5D61FC5E1A84238C00846EE7 /* SDLChangeRegistrationResponse.m in Sources */, 5D61FC7D1A84238C00846EE7 /* SDLDeleteInteractionChoiceSetResponse.m in Sources */, + DAC572661D10C5640004288B /* CGPoint_Util.c in Sources */, E9C32B9D1AB20C5900F283AF /* EAAccessory+SDLProtocols.m in Sources */, 5D61FCC61A84238C00846EE7 /* SDLHMIZoneCapabilities.m in Sources */, 5D61FD161A84238C00846EE7 /* SDLOnLockScreenStatus.m in Sources */, @@ -3604,6 +3652,7 @@ 5D61FD5C1A84238C00846EE7 /* SDLReadDIDResponse.m in Sources */, 5D61FD321A84238C00846EE7 /* SDLPolicyDataParser.m in Sources */, 5D61FC621A84238C00846EE7 /* SDLChoice.m in Sources */, + DAC5725B1D10B81E0004288B /* SDLTouch.c in Sources */, 5D61FCEB1A84238C00846EE7 /* SDLLayoutMode.m in Sources */, 5D61FC2E1A84238C00846EE7 /* SDLAddCommand.m in Sources */, 5D61FE021A84238C00846EE7 /* SDLVehicleDataNotificationStatus.m in Sources */, @@ -3639,6 +3688,7 @@ 5D61FE0E1A84238C00846EE7 /* SDLVRCapabilities.m in Sources */, 5D61FDC21A84238C00846EE7 /* SDLSystemRequestResponse.m in Sources */, 5D61FD001A84238C00846EE7 /* SDLOnAppInterfaceUnregistered.m in Sources */, + DAC5726A1D10D5FC0004288B /* dispatch_timer.c in Sources */, 5D61FC6C1A84238C00846EE7 /* SDLCreateInteractionChoiceSet.m in Sources */, 5D61FD081A84238C00846EE7 /* SDLOnCommand.m in Sources */, 5D53C46E1B7A99B9003526EA /* SDLStreamingMediaManager.m in Sources */, diff --git a/SmartDeviceLink/CGPoint_Util.c b/SmartDeviceLink/CGPoint_Util.c new file mode 100644 index 000000000..d6f1743eb --- /dev/null +++ b/SmartDeviceLink/CGPoint_Util.c @@ -0,0 +1,32 @@ +// +// CGPoint_Util.c +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#include "CGPoint_Util.h" +#include "math.h" + +CGPoint CGPointAverageOfPoints(CGPoint point1, CGPoint point2) { + CGFloat xAverage = (point1.x + point2.x)/2.0f; + CGFloat yAverage = (point1.y + point2.y)/2.0f; + return CGPointMake(xAverage, yAverage); +} + +CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2) { + CGFloat xCenter = (point1.x + point2.x) / 2.0f; + CGFloat yCenter = (point1.y + point2.y) / 2.0f; + return CGPointMake(xCenter, yCenter); +} + +CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2) { + CGFloat xDisplacement = point1.x - point2.x; + CGFloat yDisplacement = point1.y - point2.y; + return CGPointMake(xDisplacement, yDisplacement); +} + +CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2) { + return hypotf(point1.x - point2.x, point1.y - point2.y); +} \ No newline at end of file diff --git a/SmartDeviceLink/CGPoint_Util.h b/SmartDeviceLink/CGPoint_Util.h new file mode 100644 index 000000000..44b247b54 --- /dev/null +++ b/SmartDeviceLink/CGPoint_Util.h @@ -0,0 +1,20 @@ +// +// CGPoint_Util.h +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#ifndef CGPoint_Util_h +#define CGPoint_Util_h + +#include +#include + +CGPoint CGPointAverageOfPoints(CGPoint point1, CGPoint point2); +CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2); +CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2); +CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2); + +#endif /* CGPoint_Util_h */ diff --git a/SmartDeviceLink/SDLPinchGesture.c b/SmartDeviceLink/SDLPinchGesture.c new file mode 100644 index 000000000..c245ff054 --- /dev/null +++ b/SmartDeviceLink/SDLPinchGesture.c @@ -0,0 +1,38 @@ +// +// SDLPinchGesture.c +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#include "SDLPinchGesture.h" + +SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { + SDLPinchGesture pinchGesture; + pinchGesture.firstTouch = firstTouch; + pinchGesture.secondTouch = secondTouch; + pinchGesture.center = CGPointCenterOfPoints(firstTouch.location, secondTouch.location); + pinchGesture.distance = CGPointDistanceBetweenPoints(firstTouch.location, secondTouch.location); + return pinchGesture; +} + +const SDLPinchGesture SDLPinchGestureZero = {{-1, {0, 0}, -1}, {-1, {0, 0}, -1}, -0, {0, 0}}; + +SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch) { + switch (touch.identifier) { + case SDLTouchIdentifierFirstFinger: + return SDLPinchGestureMake(touch, pinch.secondTouch); + break; + case SDLTouchIdentifierSecondFinger: + return SDLPinchGestureMake(pinch.firstTouch, touch); + break; + default: + return SDLPinchGestureZero; + break; + } +} + +bool SDLPinchGestureIsValid(SDLPinchGesture pinch) { + return SDLTouchIsValid(pinch.firstTouch) && SDLTouchIsValid(pinch.secondTouch); +} \ No newline at end of file diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h new file mode 100644 index 000000000..b16892a65 --- /dev/null +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -0,0 +1,32 @@ +// +// SDLPinchGesture.h +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#ifndef SDLPinchGesture_h +#define SDLPinchGesture_h + +#include + +#include "SDLTouch.h" +#include "CGPoint_Util.h" + +typedef struct { + SDLTouch firstTouch; + SDLTouch secondTouch; + CGFloat distance; + CGPoint center; +} SDLPinchGesture; + +extern const SDLPinchGesture SDLPinchGestureZero; + +SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch); + +SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch); + +bool SDLPinchGestureIsValid(SDLPinchGesture pinch); + +#endif /* SDLPinchGesture_h */ diff --git a/SmartDeviceLink/SDLProxy.h b/SmartDeviceLink/SDLProxy.h index 2d86439b7..4d4d8137a 100644 --- a/SmartDeviceLink/SDLProxy.h +++ b/SmartDeviceLink/SDLProxy.h @@ -9,6 +9,7 @@ @class SDLRPCRequestFactory; @class SDLStreamingMediaManager; @class SDLTimer; +@class SDLTouchManager; #import "SDLProtocolListener.h" #import "SDLProxyListener.h" @@ -28,6 +29,7 @@ @property (copy) NSString *debugConsoleGroupName; @property (readonly, copy) NSString *proxyVersion; @property (nonatomic, strong, readonly) SDLStreamingMediaManager *streamingMediaManager; +@property (nonatomic, strong, readonly) SDLTouchManager* touchManager; - (id)initWithTransport:(SDLAbstractTransport *)transport protocol:(SDLAbstractProtocol *)protocol diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index 2929ebc1d..8fa823b63 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -39,6 +39,7 @@ #import "SDLSystemContext.h" #import "SDLSystemRequest.h" #import "SDLTimer.h" +#import "SDLTouchManager.h" #import "SDLURLSession.h" @@ -57,6 +58,7 @@ @interface SDLProxy () { @property (strong, nonatomic) NSMutableSet *mutableProxyListeners; @property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager; +@property (nonatomic, strong, readwrite) SDLTouchManager *touchManager; @end @@ -98,6 +100,7 @@ - (void)destructObjects { [self.protocol dispose]; [self.transport dispose]; + _touchManager = nil; _transport = nil; _protocol = nil; _mutableProxyListeners = nil; @@ -173,6 +176,15 @@ - (SDLStreamingMediaManager *)streamingMediaManager { return _streamingMediaManager; } +- (SDLTouchManager*)touchManager { + if (_touchManager == nil) { + _touchManager = [[SDLTouchManager alloc] init]; + [self.mutableProxyListeners addObject:_touchManager]; + } + + return _touchManager; +} + #pragma mark - SDLProtocolListener Implementation - (void)onProtocolOpened { diff --git a/SmartDeviceLink/SDLTouch.c b/SmartDeviceLink/SDLTouch.c new file mode 100644 index 000000000..7ca952a7c --- /dev/null +++ b/SmartDeviceLink/SDLTouch.c @@ -0,0 +1,38 @@ +// +// SDLTouch.c +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#include "SDLTouch.h" + +SDLTouch const SDLTouchZero = {-1, {0, 0}, 0}; + +SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp) { + SDLTouch touch; + touch.identifier = identifier; + touch.location = CGPointMake(x, y); + touch.timeStamp = timeStamp; + return touch; +} + +bool SDLTouchEqualToTouch(SDLTouch touch1, SDLTouch touch2) { + bool isEqual = (touch1.identifier == touch2.identifier); + isEqual = (isEqual && CGPointEqualToPoint(touch1.location, touch2.location)); + isEqual = (isEqual && touch1.timeStamp == touch2.timeStamp); + return isEqual; +} + +bool SDLTouchIsValid(SDLTouch touch) { + return SDLTouchEqualToTouch(touch, SDLTouchZero) ? false : true; +} + +bool SDLTouchIsFirstFinger(SDLTouch touch) { + return touch.identifier == SDLTouchIdentifierFirstFinger ? true : false; +} + +bool SDLTouchIsSecondFinger(SDLTouch touch) { + return touch.identifier == SDLTouchIdentifierSecondFinger ? true : false; +} \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h new file mode 100644 index 000000000..c4d49b014 --- /dev/null +++ b/SmartDeviceLink/SDLTouch.h @@ -0,0 +1,39 @@ +// +// SDLTouch.h +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#ifndef SDLTouch_h +#define SDLTouch_h + +#include + +#include + +typedef struct SDLTouch { + unsigned long identifier; + CGPoint location; + unsigned long timeStamp; +} SDLTouch; + +typedef enum { + SDLTouchIdentifierFirstFinger = 0, + SDLTouchIdentifierSecondFinger = 1 +} SDLTouchIdentifier; + +extern const SDLTouch SDLTouchZero; + +SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp); + +bool SDLTouchEqualToTouch(SDLTouch touch1, SDLTouch touch2); + +// Checks if SDLTouch is equal to SDLTouchZero. +bool SDLTouchIsValid(SDLTouch touch); + +bool SDLTouchIsFirstFinger(SDLTouch touch); +bool SDLTouchIsSecondFinger(SDLTouch touch); + +#endif /* SDLTouch_h */ \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h new file mode 100644 index 000000000..c1e78c6f1 --- /dev/null +++ b/SmartDeviceLink/SDLTouchManager.h @@ -0,0 +1,45 @@ +// +// SDLTouchManager.h +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import +#import "SDLTouchManagerListener.h" + +@class SDLOnTouchEvent; + +typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { + SDLPerformingTouchTypeNone, + SDLPerformingTouchTypeSingleTouch, + SDLPerformingTouchTypeMultiTouch, + SDLPerformingTouchTypePanningTouch +}; + + +@interface SDLTouchManager : NSObject + +@property (nonatomic, weak) id touchEventListener; + +/* + * Distance between taps. + */ +@property (nonatomic) CGFloat tapDistanceThreshold; + +/* + * Duration between taps (in milliseconds). + */ +@property (nonatomic) CGFloat tapTimeThreshold; + +/* + * Time between pan events (in milliseconds). + */ +@property (nonatomic) CGFloat panTimeThreshold; + +@property (nonatomic, getter=isTouchEnabled) BOOL touchEnabled; + +@property (nonatomic, readonly) SDLPerformingTouchType performingTouchType; + +@end diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m new file mode 100644 index 000000000..8aadbd783 --- /dev/null +++ b/SmartDeviceLink/SDLTouchManager.m @@ -0,0 +1,226 @@ +// +// SDLTouchManager.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import "SDLTouchManager.h" + +#import "dispatch_timer.h" +#import "SDLOnTouchEvent.h" +#import "SDLPinchGesture.h" +#import "SDLProxyListener.h" +#import "SDLTouch.h" +#import "SDLTouchCoord.h" +#import "SDLTouchEvent.h" +#import "SDLTouchType.h" + +static NSUInteger const kMaximumNumberOfTouches = 2; + +@interface SDLTouchManager () + +@property SDLTouch previousTouch; + +/* + * Only used for caching previous single taps for double tap detection + */ +@property SDLTouch singleTapTouch; + +@property CGFloat previousPinchDistance; + +@property SDLPinchGesture currentPinchGesture; + +@property dispatch_source_t singleTapTimer; + +@end + +@implementation SDLTouchManager + +- (instancetype)init { + if (self = [super init]) { + _panTimeThreshold = 150.0f; + _tapTimeThreshold = 400.0f; + _tapDistanceThreshold = 50.0f; + _previousTouch = SDLTouchZero; + _singleTapTouch = SDLTouchZero; + _touchEnabled = YES; + } + return self; +} + +#pragma mark - SDLProxyListener Delegate +- (void)onProxyOpened { } +- (void)onProxyClosed { } +- (void)onOnHMIStatus:(SDLOnHMIStatus *)notification { } +- (void)onOnDriverDistraction:(SDLOnDriverDistraction *)notification { } + +- (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { + if (!self.isTouchEnabled) { + return; + } + + SDLTouchEvent* touchEvent = notification.event.firstObject; + NSUInteger touchEventID = touchEvent.touchEventId.unsignedIntegerValue; + + if (touchEventID > kMaximumNumberOfTouches) { + return; + } + + SDLTouchCoord* coord = touchEvent.coord.firstObject; + + NSNumber* timeStampNumber = touchEvent.timeStamp.firstObject; + NSUInteger timeStamp = timeStampNumber.unsignedIntegerValue; + + SDLTouch touch = SDLTouchMake(touchEventID, + coord.x.floatValue, + coord.y.floatValue, + timeStamp); + if ([notification.type isEqualToEnum:SDLTouchType.BEGIN]) { + [self sdl_handleBeginTouch:touch]; + } else if ([notification.type isEqualToEnum:SDLTouchType.MOVE]) { + [self sdl_handleBeginTouch:touch]; + } else if ([notification.type isEqualToEnum:SDLTouchType.END]) { + [self sdl_handleEndTouch:touch]; + } +} + +#pragma mark - Private +- (void)sdl_handleBeginTouch:(SDLTouch)touch { + if (!SDLTouchIsFirstFinger(touch) + && !self.isTouchEnabled) { + return; // no-op + } + + _performingTouchType = SDLPerformingTouchTypeSingleTouch; + + switch (touch.identifier) { + case SDLTouchIdentifierFirstFinger: + self.previousTouch = touch; + break; + case SDLTouchIdentifierSecondFinger: + _performingTouchType = SDLPerformingTouchTypeMultiTouch; + self.currentPinchGesture = SDLPinchGestureMake(self.previousTouch, touch); + self.previousPinchDistance = self.currentPinchGesture.distance; + if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidStartAtCenterPoint:)]) { + [self.touchEventListener touchManager:self + pinchDidStartAtCenterPoint:self.currentPinchGesture.center]; + } + break; + } +} + +- (void)sdl_handleMovedTouch:(SDLTouch)touch { + if ((touch.timeStamp - self.previousTouch.timeStamp) <= self.panTimeThreshold + || !self.isTouchEnabled) { + return; // no-op + } + + switch (self.performingTouchType) { + case SDLPerformingTouchTypeMultiTouch: + self.currentPinchGesture = SDLPinchGestureUpdateFromTouch(self.currentPinchGesture, touch); + + if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) { + CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance; + [self.touchEventListener touchManager:self + didReceivePinchAtCenterPoint:self.currentPinchGesture.center + withScale:scale]; + } + + self.previousPinchDistance = self.currentPinchGesture.distance; + break; + case SDLPerformingTouchTypeSingleTouch: + _performingTouchType = SDLPerformingTouchTypePanningTouch; + if ([self.touchEventListener respondsToSelector:@selector(touchManager:panningDidStartAtPoint:)]) { + [self.touchEventListener touchManager:self + panningDidStartAtPoint:touch.location]; + } + break; + case SDLPerformingTouchTypePanningTouch: + if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) { + [self.touchEventListener touchManager:self + didReceivePanningFromPoint:self.previousTouch.location toPoint:touch.location]; + } + break; + case SDLPerformingTouchTypeNone: + break; + } + + self.previousTouch = touch; +} + +- (void)sdl_handleEndTouch:(SDLTouch)touch { + if (!self.isTouchEnabled) { + return; // no-op + } + + switch (self.performingTouchType) { + case SDLPerformingTouchTypeMultiTouch: + self.currentPinchGesture = SDLPinchGestureUpdateFromTouch(self.currentPinchGesture, touch); + + if (SDLPinchGestureIsValid(self.currentPinchGesture)) { + if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidEndAtCenterPoint:)]) { + [self.touchEventListener touchManager:self + pinchDidEndAtCenterPoint:self.currentPinchGesture.center]; + } + self.currentPinchGesture = SDLPinchGestureZero; + } + break; + case SDLPerformingTouchTypePanningTouch: + if ([self.touchEventListener respondsToSelector:@selector(touchManager:panningDidEndAtPoint:)]) { + [self.touchEventListener touchManager:self + panningDidEndAtPoint:touch.location]; + } + break; + case SDLPerformingTouchTypeSingleTouch: + if (!SDLTouchIsValid(self.singleTapTouch)) { // Initial Tap + self.singleTapTouch = touch; + [self sdl_initializeSingleTapTimerAtPoint:self.singleTapTouch.location]; + } else { // Double Tap + [self sdl_cancelSingleTapTimer]; + + NSUInteger timeStampDelta = touch.timeStamp - self.singleTapTouch.timeStamp; + CGFloat xDelta = fabs(touch.location.x - self.singleTapTouch.location.x); + CGFloat yDelta = fabs(touch.location.y - self.singleTapTouch.location.y); + + if (timeStampDelta <= self.tapTimeThreshold + && xDelta <= self.tapDistanceThreshold + && yDelta <= self.tapDistanceThreshold) { + CGPoint averagePoint = CGPointAverageOfPoints(touch.location, + self.singleTapTouch.location); + if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceiveDoubleTapAtPoint:)]) { + [self.touchEventListener touchManager:self + didReceiveDoubleTapAtPoint:averagePoint]; + } + } + + self.singleTapTouch = SDLTouchZero; + } + break; + case SDLPerformingTouchTypeNone: + break; + } + self.previousTouch = SDLTouchZero; + _performingTouchType = SDLPerformingTouchTypeNone; +} + +- (void)sdl_initializeSingleTapTimerAtPoint:(CGPoint)point { + __weak typeof(self) weakSelf = self; + self.singleTapTimer = dispatch_create_timer(self.tapTimeThreshold, NO, ^{ + typeof(weakSelf) strongSelf = weakSelf; + strongSelf.singleTapTouch = SDLTouchZero; + if ([strongSelf.touchEventListener respondsToSelector:@selector(touchManager:didReceiveSingleTapAtPoint:)]) { + [strongSelf.touchEventListener touchManager:strongSelf + didReceiveSingleTapAtPoint:point]; + } + }); + +} + +- (void)sdl_cancelSingleTapTimer { + dispatch_stop_timer(self.singleTapTimer); + self.singleTapTimer = NULL; +} + +@end diff --git a/SmartDeviceLink/SDLTouchManagerListener.h b/SmartDeviceLink/SDLTouchManagerListener.h new file mode 100644 index 000000000..bb911a870 --- /dev/null +++ b/SmartDeviceLink/SDLTouchManagerListener.h @@ -0,0 +1,25 @@ +// +// SDLTouchManagerListener.h +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/14/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +@class SDLTouchManager; + +@protocol SDLTouchManagerListener + +@optional +- (void)touchManager:(SDLTouchManager*)manager didReceiveSingleTapAtPoint:(CGPoint)point; +- (void)touchManager:(SDLTouchManager*)manager didReceiveDoubleTapAtPoint:(CGPoint)point; + +- (void)touchManager:(SDLTouchManager*)manager panningDidStartAtPoint:(CGPoint)point; +- (void)touchManager:(SDLTouchManager*)manager didReceivePanningFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint; +- (void)touchManager:(SDLTouchManager*)manager panningDidEndAtPoint:(CGPoint)point; + +- (void)touchManager:(SDLTouchManager*)manager pinchDidStartAtCenterPoint:(CGPoint)point; +- (void)touchManager:(SDLTouchManager*)manager didReceivePinchAtCenterPoint:(CGPoint)point withScale:(CGFloat)scale; +- (void)touchManager:(SDLTouchManager*)manager pinchDidEndAtCenterPoint:(CGPoint)point; + +@end diff --git a/SmartDeviceLink/dispatch_timer.c b/SmartDeviceLink/dispatch_timer.c new file mode 100644 index 000000000..256489a1d --- /dev/null +++ b/SmartDeviceLink/dispatch_timer.c @@ -0,0 +1,38 @@ +// +// dispatch_timer.c +// MobileNav +// +// Created by Muller, Alexander (A.) on 5/12/16. +// Copyright © 2016 Alex Muller. All rights reserved. +// + +#include "dispatch_timer.h" + +dispatch_source_t dispatch_create_timer(double afterInterval, bool repeating, dispatch_block_t block) { + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, + 0); + dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, + 0, + 0, + queue); + dispatch_source_set_timer(timer, + dispatch_time(DISPATCH_TIME_NOW, afterInterval), + afterInterval, + (1ull * NSEC_PER_SEC) / 10); + dispatch_source_set_event_handler(timer, ^{ + if (!repeating) { + dispatch_stop_timer(timer); + } + if (block) { + block(); + } + }); + dispatch_resume(timer); + + return timer; +} + +void dispatch_stop_timer(dispatch_source_t timer) { + dispatch_source_set_event_handler(timer, NULL); + dispatch_source_cancel(timer); +} diff --git a/SmartDeviceLink/dispatch_timer.h b/SmartDeviceLink/dispatch_timer.h new file mode 100644 index 000000000..a35068390 --- /dev/null +++ b/SmartDeviceLink/dispatch_timer.h @@ -0,0 +1,18 @@ +// +// dispatch_timer.h +// MobileNav +// +// Created by Muller, Alexander (A.) on 5/12/16. +// Copyright © 2016 Alex Muller. All rights reserved. +// + +#ifndef dispatch_timer_h +#define dispatch_timer_h + +#include +#include + +dispatch_source_t dispatch_create_timer(double afterInterval, bool repeating, dispatch_block_t block); +void dispatch_stop_timer(dispatch_source_t timer); + +#endif /* dispatch_timer_h */ From 80ba0135672f0b18a3eeed70ef74e035b50ab7f1 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 09:07:56 -0700 Subject: [PATCH 02/45] Updated SDLTouchManager's header to public --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index d4249c7a5..f46cae398 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -786,7 +786,7 @@ 5DEE55C51B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */; }; 5DEE55C61B8666A8004F0D0F /* OHHTTPStubs.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */; }; - DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; }; + DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAC572581D1067270004288B /* SDLTouchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572561D1067270004288B /* SDLTouchManager.m */; }; DAC5725B1D10B81E0004288B /* SDLTouch.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.c */; }; DAC5725C1D10B81E0004288B /* SDLTouch.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725A1D10B81E0004288B /* SDLTouch.h */; }; @@ -796,6 +796,7 @@ DAC572671D10C5640004288B /* CGPoint_Util.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572651D10C5640004288B /* CGPoint_Util.h */; }; DAC5726A1D10D5FC0004288B /* dispatch_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.c */; }; DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572691D10D5FC0004288B /* dispatch_timer.h */; }; + DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */; settings = {ATTRIBUTES = (Public, ); }; }; E9C32B861AB20B4300F283AF /* NSThread+ThreadIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */; }; E9C32B871AB20B4300F283AF /* NSThread+ThreadIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = E9C32B851AB20B4300F283AF /* NSThread+ThreadIndex.m */; }; E9C32B911AB20BA200F283AF /* SDLIAPSession.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B891AB20BA200F283AF /* SDLIAPSession.h */; }; @@ -3277,6 +3278,7 @@ 5D61FDFB1A84238C00846EE7 /* SDLV2ProtocolMessage.h in Headers */, 5D61FCFC1A84238C00846EE7 /* SDLNames.h in Headers */, 5D61FCFD1A84238C00846EE7 /* SDLObjectWithPriority.h in Headers */, + DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */, 5D61FD3F1A84238C00846EE7 /* SDLPrioritizedObjectCollection.h in Headers */, 5D61FCBF1A84238C00846EE7 /* SDLHexUtility.h in Headers */, 5D61FCA21A84238C00846EE7 /* SDLEncoder.h in Headers */, From 17337c423d1b768f02203345352b661d87bf92f0 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 09:16:57 -0700 Subject: [PATCH 03/45] Added touch manager to SmartDeviceLink.h --- SmartDeviceLink/SmartDeviceLink.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SmartDeviceLink/SmartDeviceLink.h b/SmartDeviceLink/SmartDeviceLink.h index 1bfbcb655..e6e73f895 100644 --- a/SmartDeviceLink/SmartDeviceLink.h +++ b/SmartDeviceLink/SmartDeviceLink.h @@ -17,6 +17,7 @@ FOUNDATION_EXPORT const unsigned char SmartDeviceLinkVersionString[]; #import "SDLProxyFactory.h" #import "SDLProxyListener.h" #import "SDLStreamingMediaManager.h" +#import "SDLTouchManager.h" #import "SDLTTSChunkFactory.h" /***** Debug *****/ @@ -36,6 +37,7 @@ FOUNDATION_EXPORT const unsigned char SmartDeviceLinkVersionString[]; #import "SDLAbstractProtocol.h" #import "SDLProtocol.h" #import "SDLProtocolListener.h" +#import "SDLTouchManagerListener.h" // Header #import "SDLProtocolHeader.h" From 3ca1d55563b855e5b6a84ce0e75e85d02b551b6d Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 16:17:33 -0700 Subject: [PATCH 04/45] Fixed issue relating to using C files in cocoapods. --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 32 +++++++++---------- .../{CGPoint_Util.c => CGPoint_Util.m} | 0 SmartDeviceLink/SDLPinchGesture.h | 1 - .../{SDLPinchGesture.c => SDLPinchGesture.m} | 2 +- SmartDeviceLink/SDLTouch.h | 1 - SmartDeviceLink/{SDLTouch.c => SDLTouch.m} | 2 +- .../{dispatch_timer.c => dispatch_timer.m} | 0 7 files changed, 18 insertions(+), 20 deletions(-) rename SmartDeviceLink/{CGPoint_Util.c => CGPoint_Util.m} (100%) rename SmartDeviceLink/{SDLPinchGesture.c => SDLPinchGesture.m} (92%) rename SmartDeviceLink/{SDLTouch.c => SDLTouch.m} (95%) rename SmartDeviceLink/{dispatch_timer.c => dispatch_timer.m} (100%) diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index f46cae398..75bcd9345 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -788,13 +788,13 @@ 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */; }; DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAC572581D1067270004288B /* SDLTouchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572561D1067270004288B /* SDLTouchManager.m */; }; - DAC5725B1D10B81E0004288B /* SDLTouch.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.c */; }; + DAC5725B1D10B81E0004288B /* SDLTouch.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.m */; }; DAC5725C1D10B81E0004288B /* SDLTouch.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725A1D10B81E0004288B /* SDLTouch.h */; }; - DAC572621D10C5020004288B /* SDLPinchGesture.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572601D10C5020004288B /* SDLPinchGesture.c */; }; + DAC572621D10C5020004288B /* SDLPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572601D10C5020004288B /* SDLPinchGesture.m */; }; DAC572631D10C5020004288B /* SDLPinchGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572611D10C5020004288B /* SDLPinchGesture.h */; }; - DAC572661D10C5640004288B /* CGPoint_Util.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572641D10C5640004288B /* CGPoint_Util.c */; }; + DAC572661D10C5640004288B /* CGPoint_Util.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572641D10C5640004288B /* CGPoint_Util.m */; }; DAC572671D10C5640004288B /* CGPoint_Util.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572651D10C5640004288B /* CGPoint_Util.h */; }; - DAC5726A1D10D5FC0004288B /* dispatch_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.c */; }; + DAC5726A1D10D5FC0004288B /* dispatch_timer.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.m */; }; DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572691D10D5FC0004288B /* dispatch_timer.h */; }; DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */; settings = {ATTRIBUTES = (Public, ); }; }; E9C32B861AB20B4300F283AF /* NSThread+ThreadIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */; }; @@ -1673,14 +1673,14 @@ 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = ""; }; DAC572551D1067270004288B /* SDLTouchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouchManager.h; sourceTree = ""; }; DAC572561D1067270004288B /* SDLTouchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManager.m; sourceTree = ""; }; - DAC572591D10B81E0004288B /* SDLTouch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDLTouch.c; sourceTree = ""; }; + DAC572591D10B81E0004288B /* SDLTouch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouch.m; sourceTree = ""; }; DAC5725A1D10B81E0004288B /* SDLTouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouch.h; sourceTree = ""; }; DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLTouchManagerListener.h; sourceTree = ""; }; - DAC572601D10C5020004288B /* SDLPinchGesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDLPinchGesture.c; sourceTree = ""; }; + DAC572601D10C5020004288B /* SDLPinchGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLPinchGesture.m; sourceTree = ""; }; DAC572611D10C5020004288B /* SDLPinchGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLPinchGesture.h; sourceTree = ""; }; - DAC572641D10C5640004288B /* CGPoint_Util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CGPoint_Util.c; sourceTree = ""; }; + DAC572641D10C5640004288B /* CGPoint_Util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPoint_Util.m; sourceTree = ""; }; DAC572651D10C5640004288B /* CGPoint_Util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGPoint_Util.h; sourceTree = ""; }; - DAC572681D10D5FC0004288B /* dispatch_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dispatch_timer.c; sourceTree = ""; }; + DAC572681D10D5FC0004288B /* dispatch_timer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = dispatch_timer.m; sourceTree = ""; }; DAC572691D10D5FC0004288B /* dispatch_timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dispatch_timer.h; sourceTree = ""; }; E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSThread+ThreadIndex.h"; sourceTree = ""; }; E9C32B851AB20B4300F283AF /* NSThread+ThreadIndex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSThread+ThreadIndex.m"; sourceTree = ""; }; @@ -2983,14 +2983,14 @@ DAC572551D1067270004288B /* SDLTouchManager.h */, DAC572561D1067270004288B /* SDLTouchManager.m */, DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */, - DAC572591D10B81E0004288B /* SDLTouch.c */, DAC5725A1D10B81E0004288B /* SDLTouch.h */, - DAC572601D10C5020004288B /* SDLPinchGesture.c */, + DAC572591D10B81E0004288B /* SDLTouch.m */, DAC572611D10C5020004288B /* SDLPinchGesture.h */, - DAC572641D10C5640004288B /* CGPoint_Util.c */, + DAC572601D10C5020004288B /* SDLPinchGesture.m */, DAC572651D10C5640004288B /* CGPoint_Util.h */, - DAC572681D10D5FC0004288B /* dispatch_timer.c */, + DAC572641D10C5640004288B /* CGPoint_Util.m */, DAC572691D10D5FC0004288B /* dispatch_timer.h */, + DAC572681D10D5FC0004288B /* dispatch_timer.m */, ); name = Touches; sourceTree = ""; @@ -3528,7 +3528,7 @@ 5D61FDB21A84238C00846EE7 /* SDLSubscribeVehicleData.m in Sources */, 5D61FC991A84238C00846EE7 /* SDLECallInfo.m in Sources */, 5D61FD601A84238C00846EE7 /* SDLRegisterAppInterfaceResponse.m in Sources */, - DAC572621D10C5020004288B /* SDLPinchGesture.c in Sources */, + DAC572621D10C5020004288B /* SDLPinchGesture.m in Sources */, 5D61FCF51A84238C00846EE7 /* SDLMaintenanceModeStatus.m in Sources */, 5D61FCD81A84238C00846EE7 /* SDLInteractionMode.m in Sources */, 5D61FCB01A84238C00846EE7 /* SDLGenericResponse.m in Sources */, @@ -3593,7 +3593,7 @@ 5D61FC3A1A84238C00846EE7 /* SDLAlertManeuver.m in Sources */, 5D61FC5E1A84238C00846EE7 /* SDLChangeRegistrationResponse.m in Sources */, 5D61FC7D1A84238C00846EE7 /* SDLDeleteInteractionChoiceSetResponse.m in Sources */, - DAC572661D10C5640004288B /* CGPoint_Util.c in Sources */, + DAC572661D10C5640004288B /* CGPoint_Util.m in Sources */, E9C32B9D1AB20C5900F283AF /* EAAccessory+SDLProtocols.m in Sources */, 5D61FCC61A84238C00846EE7 /* SDLHMIZoneCapabilities.m in Sources */, 5D61FD161A84238C00846EE7 /* SDLOnLockScreenStatus.m in Sources */, @@ -3654,7 +3654,7 @@ 5D61FD5C1A84238C00846EE7 /* SDLReadDIDResponse.m in Sources */, 5D61FD321A84238C00846EE7 /* SDLPolicyDataParser.m in Sources */, 5D61FC621A84238C00846EE7 /* SDLChoice.m in Sources */, - DAC5725B1D10B81E0004288B /* SDLTouch.c in Sources */, + DAC5725B1D10B81E0004288B /* SDLTouch.m in Sources */, 5D61FCEB1A84238C00846EE7 /* SDLLayoutMode.m in Sources */, 5D61FC2E1A84238C00846EE7 /* SDLAddCommand.m in Sources */, 5D61FE021A84238C00846EE7 /* SDLVehicleDataNotificationStatus.m in Sources */, @@ -3690,7 +3690,7 @@ 5D61FE0E1A84238C00846EE7 /* SDLVRCapabilities.m in Sources */, 5D61FDC21A84238C00846EE7 /* SDLSystemRequestResponse.m in Sources */, 5D61FD001A84238C00846EE7 /* SDLOnAppInterfaceUnregistered.m in Sources */, - DAC5726A1D10D5FC0004288B /* dispatch_timer.c in Sources */, + DAC5726A1D10D5FC0004288B /* dispatch_timer.m in Sources */, 5D61FC6C1A84238C00846EE7 /* SDLCreateInteractionChoiceSet.m in Sources */, 5D61FD081A84238C00846EE7 /* SDLOnCommand.m in Sources */, 5D53C46E1B7A99B9003526EA /* SDLStreamingMediaManager.m in Sources */, diff --git a/SmartDeviceLink/CGPoint_Util.c b/SmartDeviceLink/CGPoint_Util.m similarity index 100% rename from SmartDeviceLink/CGPoint_Util.c rename to SmartDeviceLink/CGPoint_Util.m diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h index b16892a65..a02ae6594 100644 --- a/SmartDeviceLink/SDLPinchGesture.h +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -10,7 +10,6 @@ #define SDLPinchGesture_h #include - #include "SDLTouch.h" #include "CGPoint_Util.h" diff --git a/SmartDeviceLink/SDLPinchGesture.c b/SmartDeviceLink/SDLPinchGesture.m similarity index 92% rename from SmartDeviceLink/SDLPinchGesture.c rename to SmartDeviceLink/SDLPinchGesture.m index c245ff054..d1bcb4b8c 100644 --- a/SmartDeviceLink/SDLPinchGesture.c +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -17,7 +17,7 @@ SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { return pinchGesture; } -const SDLPinchGesture SDLPinchGestureZero = {{-1, {0, 0}, -1}, {-1, {0, 0}, -1}, -0, {0, 0}}; +const SDLPinchGesture SDLPinchGestureZero = {SDLTouchZero, SDLTouchZero, -0, {0, 0}}; SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch) { switch (touch.identifier) { diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index c4d49b014..1c0884988 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -10,7 +10,6 @@ #define SDLTouch_h #include - #include typedef struct SDLTouch { diff --git a/SmartDeviceLink/SDLTouch.c b/SmartDeviceLink/SDLTouch.m similarity index 95% rename from SmartDeviceLink/SDLTouch.c rename to SmartDeviceLink/SDLTouch.m index 7ca952a7c..2e6f0a494 100644 --- a/SmartDeviceLink/SDLTouch.c +++ b/SmartDeviceLink/SDLTouch.m @@ -8,7 +8,7 @@ #include "SDLTouch.h" -SDLTouch const SDLTouchZero = {-1, {0, 0}, 0}; +SDLTouch const SDLTouchZero = {0, {0, 0}, 0}; SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp) { SDLTouch touch; diff --git a/SmartDeviceLink/dispatch_timer.c b/SmartDeviceLink/dispatch_timer.m similarity index 100% rename from SmartDeviceLink/dispatch_timer.c rename to SmartDeviceLink/dispatch_timer.m From e704ce71ca46e23cc2740c023be0a4897b28a748 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 16:19:17 -0700 Subject: [PATCH 05/45] Using ULONG_MAX instead of 0 for our unsigned longs in const struct values. --- SmartDeviceLink/SDLPinchGesture.m | 2 +- SmartDeviceLink/SDLTouch.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index d1bcb4b8c..0011f83c4 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -17,7 +17,7 @@ SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { return pinchGesture; } -const SDLPinchGesture SDLPinchGestureZero = {SDLTouchZero, SDLTouchZero, -0, {0, 0}}; +const SDLPinchGesture SDLPinchGestureZero = {{ULONG_MAX, {0, 0}, ULONG_MAX}, {ULONG_MAX, {0, 0}, ULONG_MAX}, 0, {0, 0}}; SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch) { switch (touch.identifier) { diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index 2e6f0a494..5c51f3457 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -8,7 +8,7 @@ #include "SDLTouch.h" -SDLTouch const SDLTouchZero = {0, {0, 0}, 0}; +SDLTouch const SDLTouchZero = {ULONG_MAX, {0, 0}, ULONG_MAX}; SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp) { SDLTouch touch; From 4e3c61356af4d49de586e140f11162e07529983d Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 16:20:02 -0700 Subject: [PATCH 06/45] Updated the tapTimeThreshold to be seconds instead of milliseconds to be easier for developers. --- SmartDeviceLink/SDLTouchManager.h | 2 +- SmartDeviceLink/SDLTouchManager.m | 4 ++-- SmartDeviceLink/dispatch_timer.m | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index c1e78c6f1..dc07ec574 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -29,7 +29,7 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { @property (nonatomic) CGFloat tapDistanceThreshold; /* - * Duration between taps (in milliseconds). + * Duration between taps (in seconds). */ @property (nonatomic) CGFloat tapTimeThreshold; diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 8aadbd783..f118765d2 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -41,7 +41,7 @@ @implementation SDLTouchManager - (instancetype)init { if (self = [super init]) { _panTimeThreshold = 150.0f; - _tapTimeThreshold = 400.0f; + _tapTimeThreshold = 0.4f; _tapDistanceThreshold = 50.0f; _previousTouch = SDLTouchZero; _singleTapTouch = SDLTouchZero; @@ -184,7 +184,7 @@ - (void)sdl_handleEndTouch:(SDLTouch)touch { CGFloat xDelta = fabs(touch.location.x - self.singleTapTouch.location.x); CGFloat yDelta = fabs(touch.location.y - self.singleTapTouch.location.y); - if (timeStampDelta <= self.tapTimeThreshold + if (timeStampDelta <= self.tapTimeThreshold * NSEC_PER_USEC && xDelta <= self.tapDistanceThreshold && yDelta <= self.tapDistanceThreshold) { CGPoint averagePoint = CGPointAverageOfPoints(touch.location, diff --git a/SmartDeviceLink/dispatch_timer.m b/SmartDeviceLink/dispatch_timer.m index 256489a1d..7e2a5bec2 100644 --- a/SmartDeviceLink/dispatch_timer.m +++ b/SmartDeviceLink/dispatch_timer.m @@ -16,8 +16,8 @@ dispatch_source_t dispatch_create_timer(double afterInterval, bool repeating, di 0, queue); dispatch_source_set_timer(timer, - dispatch_time(DISPATCH_TIME_NOW, afterInterval), - afterInterval, + dispatch_time(DISPATCH_TIME_NOW, afterInterval * NSEC_PER_SEC), + afterInterval * NSEC_PER_SEC, (1ull * NSEC_PER_SEC) / 10); dispatch_source_set_event_handler(timer, ^{ if (!repeating) { From 0debf95fb368d90ba9a132d6dbf3314063a1e8e6 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 16:32:22 -0700 Subject: [PATCH 07/45] Fixed function mistype. --- SmartDeviceLink/SDLTouchManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index f118765d2..a27e3da19 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -80,7 +80,7 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { if ([notification.type isEqualToEnum:SDLTouchType.BEGIN]) { [self sdl_handleBeginTouch:touch]; } else if ([notification.type isEqualToEnum:SDLTouchType.MOVE]) { - [self sdl_handleBeginTouch:touch]; + [self sdl_handleMovedTouch:touch]; } else if ([notification.type isEqualToEnum:SDLTouchType.END]) { [self sdl_handleEndTouch:touch]; } From ca030edcf324a3643ce399f6803ef0f0607ab558 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 15 Jun 2016 18:48:11 -0700 Subject: [PATCH 08/45] Added missing header for ULONG_MAX. --- SmartDeviceLink/SDLPinchGesture.m | 1 + SmartDeviceLink/SDLTouch.m | 1 + 2 files changed, 2 insertions(+) diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index 0011f83c4..6dc08fcd0 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -7,6 +7,7 @@ // #include "SDLPinchGesture.h" +#import SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { SDLPinchGesture pinchGesture; diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index 5c51f3457..01c189747 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -7,6 +7,7 @@ // #include "SDLTouch.h" +#import SDLTouch const SDLTouchZero = {ULONG_MAX, {0, 0}, ULONG_MAX}; From e39aeaa0f9fe07cf998b76794d0b4a94022ea2c3 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 10:36:28 -0700 Subject: [PATCH 09/45] Added spec tests for CGPoint_Util. --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 12 +++ SmartDeviceLinkTests/SDLTouchManagerSpec.m | 102 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 SmartDeviceLinkTests/SDLTouchManagerSpec.m diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 75bcd9345..59ddb59d5 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -786,6 +786,7 @@ 5DEE55C51B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */; }; 5DEE55C61B8666A8004F0D0F /* OHHTTPStubs.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */; }; + DA1166DB1D14625200438CEA /* SDLTouchManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */; }; DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAC572581D1067270004288B /* SDLTouchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572561D1067270004288B /* SDLTouchManager.m */; }; DAC5725B1D10B81E0004288B /* SDLTouch.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.m */; }; @@ -1671,6 +1672,7 @@ 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = Carthage/Build/iOS/OHHTTPStubs.framework; sourceTree = ""; }; 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = OHHTTPStubs.framework.dSYM; path = Carthage/Build/iOS/OHHTTPStubs.framework.dSYM; sourceTree = ""; }; 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = ""; }; + DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManagerSpec.m; sourceTree = ""; }; DAC572551D1067270004288B /* SDLTouchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouchManager.h; sourceTree = ""; }; DAC572561D1067270004288B /* SDLTouchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManager.m; sourceTree = ""; }; DAC572591D10B81E0004288B /* SDLTouch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouch.m; sourceTree = ""; }; @@ -2931,6 +2933,7 @@ 5DB92D201AC47AC400C15BB0 /* UtilitiesSpecs */ = { isa = PBXGroup; children = ( + DA1166D71D14601C00438CEA /* Touches */, 5DEE55BE1B8509A5004F0D0F /* HTTP Connection */, 5DB92D2B1AC4A32A00C15BB0 /* Prioritized Objects */, 5DB92D231AC47B2C00C15BB0 /* SDLHexUtilitySpec.m */, @@ -2977,6 +2980,14 @@ name = "HTTP Connection"; sourceTree = ""; }; + DA1166D71D14601C00438CEA /* Touches */ = { + isa = PBXGroup; + children = ( + DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */, + ); + name = Touches; + sourceTree = ""; + }; DAC5724C1D0FE3B60004288B /* Touches */ = { isa = PBXGroup; children = ( @@ -3806,6 +3817,7 @@ 162E83341A9BDE8B00906325 /* SDLPutFileSpec.m in Sources */, 162E837A1A9BDE8B00906325 /* SDLDIDResult.m in Sources */, 162E83171A9BDE8B00906325 /* SDLOnHMIStatusSpec.m in Sources */, + DA1166DB1D14625200438CEA /* SDLTouchManagerSpec.m in Sources */, 5DE372A41ACB336600849FAA /* SDLHMICapabilitiesSpec.m in Sources */, 162E82F71A9BDE8B00906325 /* SDLResultSpec.m in Sources */, 1680B1141A9CD7AD00DBD79E /* SDLV1ProtocolHeaderSpec.m in Sources */, diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m new file mode 100644 index 000000000..ecd9698d4 --- /dev/null +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -0,0 +1,102 @@ +// +// SDLTouchManagerSpec.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 6/17/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import + +#import +#import + +#import "SDLTouchManager.h" +#import "CGPoint_Util.h" + +QuickSpecBegin(SDLTouchManagerSpec) + +describe(@"CGPoint_Util Tests", ^{ + __block CGPoint first; + __block CGPoint second; + context(@"For two positive points", ^{ + beforeEach(^{ + first = CGPointMake(100, 200); + second = CGPointMake(300, 400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@200)); + expect(@(average.y)).to(equal(@300)); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@200)); + expect(@(center.y)).to(equal(@300)); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@(-200))); + expect(@(displacement.y)).to(equal(@(-200))); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); + }); + }); + context(@"For two negative points", ^{ + beforeEach(^{ + first = CGPointMake(-100, -200); + second = CGPointMake(-300, -400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@(-200))); + expect(@(average.y)).to(equal(@(-300))); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@(-200))); + expect(@(center.y)).to(equal(@(-300))); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@200)); + expect(@(displacement.y)).to(equal(@200)); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); + }); + }); + context(@"For one positive and one negative point", ^{ + beforeEach(^{ + first = CGPointMake(100, 200); + second = CGPointMake(-300, -400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@(-100))); + expect(@(average.y)).to(equal(@(-100))); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@(-100))); + expect(@(center.y)).to(equal(@(-100))); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@400)); + expect(@(displacement.y)).to(equal(@600)); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@721.1103).within(0.0001)); + }); + }); +}); + +QuickSpecEnd \ No newline at end of file From 5338b68d996ace3f9b30c4b95a7dac39ccd1735e Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 13:28:43 -0700 Subject: [PATCH 10/45] Updated SDLTouch to use a signed long for identifier, so we may use -1 for SDLTouchZero. --- SmartDeviceLink/SDLPinchGesture.m | 3 +-- SmartDeviceLink/SDLTouch.h | 2 +- SmartDeviceLink/SDLTouch.m | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index 6dc08fcd0..979153310 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -7,7 +7,6 @@ // #include "SDLPinchGesture.h" -#import SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { SDLPinchGesture pinchGesture; @@ -18,7 +17,7 @@ SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { return pinchGesture; } -const SDLPinchGesture SDLPinchGestureZero = {{ULONG_MAX, {0, 0}, ULONG_MAX}, {ULONG_MAX, {0, 0}, ULONG_MAX}, 0, {0, 0}}; +const SDLPinchGesture SDLPinchGestureZero = {{-1, {0, 0}, 0}, {-1, {0, 0}, 0}, 0, {0, 0}}; SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch) { switch (touch.identifier) { diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index 1c0884988..18e9296c3 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -13,7 +13,7 @@ #include typedef struct SDLTouch { - unsigned long identifier; + long identifier; CGPoint location; unsigned long timeStamp; } SDLTouch; diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index 01c189747..7ca952a7c 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -7,9 +7,8 @@ // #include "SDLTouch.h" -#import -SDLTouch const SDLTouchZero = {ULONG_MAX, {0, 0}, ULONG_MAX}; +SDLTouch const SDLTouchZero = {-1, {0, 0}, 0}; SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp) { SDLTouch touch; From d26d4f9597ec61cfa2c5e66f4688c910b5850947 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 13:28:58 -0700 Subject: [PATCH 11/45] Added SDLTouch spec tests. --- SmartDeviceLinkTests/SDLTouchManagerSpec.m | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index ecd9698d4..373fa8872 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -13,6 +13,7 @@ #import "SDLTouchManager.h" #import "CGPoint_Util.h" +#import "SDLTouch.h" QuickSpecBegin(SDLTouchManagerSpec) @@ -99,4 +100,84 @@ }); }); +describe(@"SDLTouch Tests", ^{ + context(@"SDLTouchZero", ^{ + __block SDLTouch touch = SDLTouchZero; + + it(@"should correctly initialize", ^{ + expect(@(touch.identifier)).to(equal(@(-1))); + expect(@(CGPointEqualToPoint(touch.location, CGPointZero))).to(beTruthy()); + expect(@(touch.timeStamp)).to(equal(@0)); + }); + + it(@"should not be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beFalsy()); + }); + + it(@"should not equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + }); + }); + + context(@"For First Finger Identifiers", ^{ + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block SDLTouch touch; + + beforeSuite(^{ + touch = SDLTouchMake(0, 100, 200, timeStamp); + }); + + it(@"should correctly make a SDLTouch struct", ^{ + expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(touch.location.x)).to(equal(@100)); + expect(@(touch.location.y)).to(equal(@200)); + expect(@(touch.timeStamp)).to(equal(@(timeStamp))); + }); + + it(@"should be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beTruthy()); + }); + + it(@"should equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beTruthy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + }); + }); + + context(@"For Second Finger Identifiers", ^{ + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block SDLTouch touch; + + beforeSuite(^{ + touch = SDLTouchMake(1, 100, 200, timeStamp); + }); + + it(@"should correctly make a SDLTouch struct", ^{ + expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(touch.location.x)).to(equal(@100)); + expect(@(touch.location.y)).to(equal(@200)); + expect(@(touch.timeStamp)).to(equal(@(timeStamp))); + }); + + it(@"should be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beTruthy()); + }); + + it(@"should equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beTruthy()); + }); + }); +}); + QuickSpecEnd \ No newline at end of file From 23281cbe852228ab71ed999b0c481796c5cbd022 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 14:09:24 -0700 Subject: [PATCH 12/45] Removed public exposure of SDLTouchEqualToTouch --- SmartDeviceLink/SDLTouch.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index 18e9296c3..7c220d0de 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -27,8 +27,6 @@ extern const SDLTouch SDLTouchZero; SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp); -bool SDLTouchEqualToTouch(SDLTouch touch1, SDLTouch touch2); - // Checks if SDLTouch is equal to SDLTouchZero. bool SDLTouchIsValid(SDLTouch touch); From de8db6e90708eaeb2f88c127d4aa8b7bcdd99b19 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 16:23:15 -0700 Subject: [PATCH 13/45] Added SDLPinchGesture spec tests. --- SmartDeviceLinkTests/SDLTouchManagerSpec.m | 111 ++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index 373fa8872..d3ec1c411 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -14,6 +14,7 @@ #import "SDLTouchManager.h" #import "CGPoint_Util.h" #import "SDLTouch.h" +#import "SDLPinchGesture.h" QuickSpecBegin(SDLTouchManagerSpec) @@ -180,4 +181,112 @@ }); }); -QuickSpecEnd \ No newline at end of file +describe(@"SDLPinchGesture Tests", ^{ + context(@"SDLPinchGestureZero", ^{ + __block SDLPinchGesture pinchGesture = SDLPinchGestureZero; + + it(@"should correctly initialize", ^{ + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(-1))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@0)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@0)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@0)); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(-1))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@0)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@0)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@0)); + }); + + it(@"should not be a valid SDLPinchGesture", ^{ + expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beFalsy()); + }); + }); + + context(@"SDLPinchGestureMake", ^{ + __block SDLPinchGesture pinchGesture; + __block SDLTouch firstTouch; + __block SDLTouch secondTouch; + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block unsigned long secondTimeStamp = timeStamp + 1000; + + beforeEach(^{ + pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); + secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + }); + + it(@"should correctly initialize", ^{ + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@(141.4213)).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@150)); + expect(@(pinchGesture.center.y)).to(equal(@250)); + }); + + it(@"should be a valid SDLPinchGesture", ^{ + expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beTruthy()); + }); + }); + + context(@"updating SDLPinchGesture", ^{ + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block unsigned long secondTimeStamp = timeStamp + 1000; + __block SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); + __block SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + + it(@"should update first point correctly", ^{ + SDLPinchGesture pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + + unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 150, 250, newTimeStamp); + pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@150)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@250)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(newTimeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@175)); + expect(@(pinchGesture.center.y)).to(equal(@275)); + + }); + + it(@"should update second point correctly", ^{ + SDLPinchGesture pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + + unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 150, 250, newTimeStamp); + pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@150)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@250)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(newTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@125)); + expect(@(pinchGesture.center.y)).to(equal(@225)); + }); + }); +}); + +QuickSpecEnd From 4564749f9cd9085c73dc0e853babca1c8aa31456 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 16:59:03 -0700 Subject: [PATCH 14/45] Fixed SDLPinchGesture tests. --- SmartDeviceLinkTests/SDLTouchManagerSpec.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index d3ec1c411..6a24d0cc8 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -210,9 +210,9 @@ __block unsigned long secondTimeStamp = timeStamp + 1000; beforeEach(^{ - pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); }); it(@"should correctly initialize", ^{ @@ -237,14 +237,17 @@ }); context(@"updating SDLPinchGesture", ^{ + __block SDLPinchGesture pinchGesture; __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; __block unsigned long secondTimeStamp = timeStamp + 1000; - __block SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); - __block SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); - + + beforeEach(^{ + SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); + SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + }); + it(@"should update first point correctly", ^{ - SDLPinchGesture pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); - unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 150, 250, newTimeStamp); pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); @@ -265,9 +268,7 @@ }); - it(@"should update second point correctly", ^{ - SDLPinchGesture pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); - + it(@"should update second point correctly", ^{ unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 150, 250, newTimeStamp); pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); From ef754ee369590188d6f3070d8e443fe96995cdbe Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 16:59:09 -0700 Subject: [PATCH 15/45] Added dispatch_timer spec tests. --- SmartDeviceLinkTests/SDLTouchManagerSpec.m | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index 6a24d0cc8..4052e6e58 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -15,6 +15,7 @@ #import "CGPoint_Util.h" #import "SDLTouch.h" #import "SDLPinchGesture.h" +#import "dispatch_timer.h" QuickSpecBegin(SDLTouchManagerSpec) @@ -290,4 +291,32 @@ }); }); +describe(@"dispatch_timer Tests", ^{ + context(@"Creating", ^{ + it(@"should be successful within specified time", ^{ + waitUntilTimeout(4, ^(void (^done)(void)) { + __block double currentTime = [[NSDate date] timeIntervalSince1970]; + dispatch_create_timer(2.5, false, ^{ + double difference = [[NSDate date] timeIntervalSince1970] - currentTime; + expect(@(difference)).to(beCloseTo(@(2.5)).within(0.1)); + done(); + }); + }); + }); + + it(@"should be cancellable and not fire", ^{ + __block dispatch_source_t timer; + waitUntilTimeout(2, ^(void (^done)(void)) { + timer = dispatch_create_timer(2.5, false, ^{ + fail(); + }); + [NSThread sleepForTimeInterval:0.5]; + dispatch_stop_timer(timer); + done(); + }); + expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@(0))); + }); + }); +}); + QuickSpecEnd From 116008b0d1efa9705e7e9ea315c9147d7a6958f6 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 17 Jun 2016 17:03:31 -0700 Subject: [PATCH 16/45] removed unecessary @class --- SmartDeviceLink/SDLTouchManager.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index dc07ec574..88ec47f5d 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -9,8 +9,6 @@ #import #import "SDLTouchManagerListener.h" -@class SDLOnTouchEvent; - typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { SDLPerformingTouchTypeNone, SDLPerformingTouchTypeSingleTouch, From 8199fcfa84e03568333b6c0bfb88c78d45916a94 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 23 Jun 2016 17:20:35 -0700 Subject: [PATCH 17/45] Reduced pan time threshold to a lower value to improve panning delay. --- SmartDeviceLink/SDLTouchManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index a27e3da19..b6628469f 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -40,7 +40,7 @@ @implementation SDLTouchManager - (instancetype)init { if (self = [super init]) { - _panTimeThreshold = 150.0f; + _panTimeThreshold = 50.0f; _tapTimeThreshold = 0.4f; _tapDistanceThreshold = 50.0f; _previousTouch = SDLTouchZero; From ef7d601f2c7139d8809f1993d8c74118f0b00484 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 24 Jun 2016 10:33:31 -0700 Subject: [PATCH 18/45] Adding check in the event we receive an invalid timestamp object from Core, we will use device's timestamp. --- SmartDeviceLink/SDLTouchManager.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index b6628469f..58e497ef8 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -71,7 +71,13 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { SDLTouchCoord* coord = touchEvent.coord.firstObject; NSNumber* timeStampNumber = touchEvent.timeStamp.firstObject; - NSUInteger timeStamp = timeStampNumber.unsignedIntegerValue; + NSUInteger timeStamp; + // In the event we receive a null timestamp, we will supply a device timestamp. + if (timeStampNumber != [NSNull null]) { + timeStamp = timeStampNumber.unsignedIntegerValue; + } else { + timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + } SDLTouch touch = SDLTouchMake(touchEventID, coord.x.floatValue, From 301f21fe6eb64b2db786bbceede7a5334ed1698c Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 28 Jun 2016 14:50:05 -0700 Subject: [PATCH 19/45] Made performingTouchType internal because necessity of it for developers is minimal. --- SmartDeviceLink/SDLTouchManager.h | 10 ---------- SmartDeviceLink/SDLTouchManager.m | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 88ec47f5d..78bbca3cb 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -9,14 +9,6 @@ #import #import "SDLTouchManagerListener.h" -typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { - SDLPerformingTouchTypeNone, - SDLPerformingTouchTypeSingleTouch, - SDLPerformingTouchTypeMultiTouch, - SDLPerformingTouchTypePanningTouch -}; - - @interface SDLTouchManager : NSObject @property (nonatomic, weak) id touchEventListener; @@ -38,6 +30,4 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { @property (nonatomic, getter=isTouchEnabled) BOOL touchEnabled; -@property (nonatomic, readonly) SDLPerformingTouchType performingTouchType; - @end diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 58e497ef8..d4683c5df 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -17,6 +17,13 @@ #import "SDLTouchEvent.h" #import "SDLTouchType.h" +typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { + SDLPerformingTouchTypeNone, + SDLPerformingTouchTypeSingleTouch, + SDLPerformingTouchTypeMultiTouch, + SDLPerformingTouchTypePanningTouch +}; + static NSUInteger const kMaximumNumberOfTouches = 2; @interface SDLTouchManager () @@ -34,6 +41,8 @@ @interface SDLTouchManager () @property dispatch_source_t singleTapTimer; +@property SDLPerformingTouchType performingTouchType; + @end @implementation SDLTouchManager From 565d10fdda67169d9f3117e86fab98c3e3de0b0b Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 28 Jun 2016 14:50:40 -0700 Subject: [PATCH 20/45] Added multiple structs/notifications to be visible to testing target. --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 59ddb59d5..32807e6e9 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -798,6 +798,10 @@ DAC5726A1D10D5FC0004288B /* dispatch_timer.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.m */; }; DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572691D10D5FC0004288B /* dispatch_timer.h */; }; DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DACBA1DC1D22D46D002356F8 /* SDLOnTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB331A84238B00846EE7 /* SDLOnTouchEvent.m */; }; + DACBA1DE1D22D642002356F8 /* SDLTouchType.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FBEB1A84238C00846EE7 /* SDLTouchType.m */; }; + DACBA1DF1D22D6CE002356F8 /* SDLTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FBE71A84238C00846EE7 /* SDLTouchEvent.m */; }; + DACBA1E01D22E856002356F8 /* SDLTouchCoord.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FBE51A84238C00846EE7 /* SDLTouchCoord.m */; }; E9C32B861AB20B4300F283AF /* NSThread+ThreadIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B841AB20B4300F283AF /* NSThread+ThreadIndex.h */; }; E9C32B871AB20B4300F283AF /* NSThread+ThreadIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = E9C32B851AB20B4300F283AF /* NSThread+ThreadIndex.m */; }; E9C32B911AB20BA200F283AF /* SDLIAPSession.h in Headers */ = {isa = PBXBuildFile; fileRef = E9C32B891AB20BA200F283AF /* SDLIAPSession.h */; }; @@ -3780,6 +3784,7 @@ 162E83121A9BDE8B00906325 /* SDLOnButtonPressSpec.m in Sources */, 162E838D1A9BDE8B00906325 /* SDLStartTimeSpec.m in Sources */, 162E836E1A9BDE8B00906325 /* SDLUnsubscribeButtonResponseSpec.m in Sources */, + DACBA1DC1D22D46D002356F8 /* SDLOnTouchEvent.m in Sources */, 162E835B1A9BDE8B00906325 /* SDLPerformInteractionResponseSpec.m in Sources */, 162E832D1A9BDE8B00906325 /* SDLEncodedSyncPDataSpec.m in Sources */, 5DB92D241AC47B2C00C15BB0 /* SDLHexUtilitySpec.m in Sources */, @@ -3872,6 +3877,7 @@ 162E82CD1A9BDE8A00906325 /* SDLAudioStreamingStateSpec.m in Sources */, 162E831A1A9BDE8B00906325 /* SDLOnLockScreenStatusSpec.m in Sources */, 162E83431A9BDE8B00906325 /* SDLSyncPDataSpec.m in Sources */, + DACBA1E01D22E856002356F8 /* SDLTouchCoord.m in Sources */, 167ED9461A9BCE5D00797BE5 /* SwiftSpec.swift in Sources */, 162E838B1A9BDE8B00906325 /* SDLSoftButtonCapabilitiesSpec.m in Sources */, 162E834C1A9BDE8B00906325 /* SDLAlertResponseSpec.m in Sources */, @@ -3952,6 +3958,7 @@ 162E83561A9BDE8B00906325 /* SDLGenericResponseSpec.m in Sources */, 162E82D51A9BDE8A00906325 /* SDLCompassDirectionSpec.m in Sources */, 162E83861A9BDE8B00906325 /* SDLParameterPermissionsSpec.m in Sources */, + DACBA1DF1D22D6CE002356F8 /* SDLTouchEvent.m in Sources */, 162E831B1A9BDE8B00906325 /* SDLOnPermissionsChangeSpec.m in Sources */, 162E83711A9BDE8B00906325 /* SDLAirbagStatusSpec.m in Sources */, 162E82CF1A9BDE8A00906325 /* SDLBitsPerSampleSpec.m in Sources */, @@ -3967,6 +3974,7 @@ 162E82F41A9BDE8B00906325 /* SDLPrimaryAudioSource.m in Sources */, 162E83461A9BDE8B00906325 /* SDLUnsubscribeButtonSpec.m in Sources */, 162E82EB1A9BDE8B00906325 /* SDLLayoutModeSpec.m in Sources */, + DACBA1DE1D22D642002356F8 /* SDLTouchType.m in Sources */, 1680B1181A9CD7AD00DBD79E /* SDLV1ProtocolMessageSpec.m in Sources */, 162E82EC1A9BDE8B00906325 /* SDLLockScreenStatusSpec.m in Sources */, 162E832F1A9BDE8B00906325 /* SDLGetDTCsSpec.m in Sources */, From b11680bcd591572baec21d9638bb799ce93fa5c6 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 28 Jun 2016 14:50:50 -0700 Subject: [PATCH 21/45] Added tests for all touch events. --- SmartDeviceLinkTests/SDLTouchManagerSpec.m | 514 ++++++++++++++++++++- 1 file changed, 510 insertions(+), 4 deletions(-) diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/SDLTouchManagerSpec.m index 4052e6e58..0bf22f41e 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/SDLTouchManagerSpec.m @@ -10,8 +10,13 @@ #import #import +#import +#import "SDLOnTouchEvent.h" +#import "SDLTouchCoord.h" +#import "SDLTouchEvent.h" #import "SDLTouchManager.h" +#import "SDLTouchType.h" #import "CGPoint_Util.h" #import "SDLTouch.h" #import "SDLPinchGesture.h" @@ -19,6 +24,8 @@ QuickSpecBegin(SDLTouchManagerSpec) +typedef void (^DelegateCallbackBlock)(NSInvocation* invocation); + describe(@"CGPoint_Util Tests", ^{ __block CGPoint first; __block CGPoint second; @@ -227,7 +234,7 @@ expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); - expect(@(pinchGesture.distance)).to(beCloseTo(@(141.4213)).within(0.0001)); + expect(@(pinchGesture.distance)).to(beCloseTo(@141.4213).within(0.0001)); expect(@(pinchGesture.center.x)).to(equal(@150)); expect(@(pinchGesture.center.y)).to(equal(@250)); }); @@ -284,7 +291,7 @@ expect(@(pinchGesture.secondTouch.location.y)).to(equal(@250)); expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(newTimeStamp))); - expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); + expect(@(pinchGesture.distance)).to(beCloseTo(@70.7107).within(0.0001)); expect(@(pinchGesture.center.x)).to(equal(@125)); expect(@(pinchGesture.center.y)).to(equal(@225)); }); @@ -298,7 +305,7 @@ __block double currentTime = [[NSDate date] timeIntervalSince1970]; dispatch_create_timer(2.5, false, ^{ double difference = [[NSDate date] timeIntervalSince1970] - currentTime; - expect(@(difference)).to(beCloseTo(@(2.5)).within(0.1)); + expect(@(difference)).to(beCloseTo(@2.5).within(0.1)); done(); }); }); @@ -314,9 +321,508 @@ dispatch_stop_timer(timer); done(); }); - expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@(0))); + expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@0)); }); }); }); +describe(@"SDLTouchManager Tests", ^{ + + __block SDLTouchManager* touchManager; + __block id delegateMock; + __block NSUInteger timeStamp; + __block CGPoint controlPoint; + __block SDLTouchCoord* touchCoord; + __block SDLTouchEvent* touchEvent; + __block SDLOnTouchEvent* beginOnTouchEvent; + __block SDLOnTouchEvent* moveOnTouchEvent; + __block SDLOnTouchEvent* endOnTouchEvent; + __block BOOL didCallSingleTap; + __block BOOL didCallDoubleTap; + __block BOOL didCallBeginPan; + __block BOOL didCallMovePan; + __block BOOL didCallEndPan; + __block BOOL didCallBeginPinch; + __block BOOL didCallMovePinch; + __block BOOL didCallEndPinch; + + __block DelegateCallbackBlock singleTapTests; + __block DelegateCallbackBlock doubleTapTests; + __block DelegateCallbackBlock panStartTests; + __block DelegateCallbackBlock panMoveTests; + __block DelegateCallbackBlock panEndTests; + __block DelegateCallbackBlock pinchStartTests; + __block DelegateCallbackBlock pinchMoveTests; + __block DelegateCallbackBlock pinchEndTests; + + __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) { + SEL onOnTouchEvent = @selector(onOnTouchEvent:); + ((void (*)(id, SEL, id))[touchManager methodForSelector:onOnTouchEvent])(touchManager, onOnTouchEvent, onTouchEvent); + }; + + context(@"Initializing", ^{ + it(@"should correctly have default properties", ^{ + SDLTouchManager* touchManager = [[SDLTouchManager alloc] init]; + expect(touchManager.touchEventListener).to(beNil()); + expect(@(touchManager.tapDistanceThreshold)).to(equal(@50)); + expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001)); + expect(@(touchManager.panTimeThreshold)).to(equal(@50)); + expect(@(touchManager.isTouchEnabled)).to(beTruthy()); + }); + + }); + describe(@"touch events", ^{ + beforeEach(^{ + touchManager = [[SDLTouchManager alloc] init]; + delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerListener)); + touchManager.touchEventListener = delegateMock; + timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + controlPoint = CGPointMake(100, 200); + + touchCoord = [[SDLTouchCoord alloc] init]; + touchCoord.x = @(controlPoint.x); + touchCoord.y = @(controlPoint.y); + + touchEvent = [[SDLTouchEvent alloc] init]; + touchEvent.touchEventId = @0; + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + beginOnTouchEvent.type = SDLTouchType.BEGIN; + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + + moveOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + moveOnTouchEvent.type = SDLTouchType.MOVE; + + endOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + endOnTouchEvent.type = SDLTouchType.END; + + didCallSingleTap = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallSingleTap = YES; + + singleTapTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceiveSingleTapAtPoint:CGPointZero]; + + singleTapTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallDoubleTap = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallDoubleTap = YES; + + doubleTapTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceiveDoubleTapAtPoint:CGPointZero]; + + doubleTapTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallBeginPan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallBeginPan = YES; + + panStartTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] panningDidStartAtPoint:CGPointZero]; + + panStartTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallMovePan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallMovePan = YES; + + panMoveTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceivePanningFromPoint:CGPointZero toPoint:CGPointZero]; + + panMoveTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallEndPan = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallEndPan = YES; + + panEndTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] panningDidEndAtPoint:CGPointZero]; + + panEndTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallBeginPinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallBeginPinch = YES; + + pinchStartTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] pinchDidStartAtCenterPoint:CGPointZero]; + + pinchStartTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallMovePinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallMovePinch = YES; + + pinchMoveTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] didReceivePinchAtCenterPoint:CGPointZero withScale:0]; + + pinchMoveTests = ^(NSInvocation* invocation) { + fail(); + }; + + didCallEndPinch = NO; + [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { + didCallEndPinch = YES; + + pinchEndTests(invocation); + }] ignoringNonObjectArgs] touchManager:[OCMArg any] pinchDidEndAtCenterPoint:CGPointZero]; + + pinchEndTests = ^(NSInvocation* invocation) { + fail(); + }; + }); + + context(@"when receiving a single tap", ^{ + it(@"should correctly handle a single tap", ^{ + singleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); + }; + + // Begin Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + + context(@"when receiving a double tap", ^{ + it(@"should correctly handle a double tap near same point", ^{ + __block CGPoint averagePoint; + + doubleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, averagePoint))).to(beTruthy()); + }; + + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End First Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + // Start Second Touch + touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold); + touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold); + + averagePoint = CGPointAverageOfPoints(controlPoint, + CGPointMake(touchCoord.x.floatValue, + touchCoord.y.floatValue)); + + timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; + + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Second Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + + it(@"should correctly not handle a double tap", ^{ + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // End First Touch + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + // Start Second Touch + timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; + + touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold + 1); + touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold + 1); + + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + // End Second Touch + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + context(@"when receiving a pan", ^{ + __block CGPoint panStartPoint; + __block CGPoint panMovePoint; + __block CGPoint panEndPoint; + + it(@"should correctly give all pan callbacks", ^{ + __block CGFloat distanceMoveX = 10; + __block CGFloat distanceMoveY = 20; + + panStartTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, panStartPoint))).to(beTruthy()); + }; + + panMoveTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint startPoint; + CGPoint endPoint; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&startPoint atIndex:3]; + [invocation getArgument:&endPoint atIndex:4]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(startPoint, panStartPoint))).to(beTruthy()); + expect(@(CGPointEqualToPoint(endPoint, panMovePoint))).to(beTruthy()); + }; + + panEndTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, panEndPoint))).to(beTruthy()); + }; + + // Begin Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // Move Touch + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panStartPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // Move Touch 2 + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panMovePoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // End Touch + touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); + touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); + touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + panEndPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + + timeStamp += (touchManager.panTimeThreshold * 1000); + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + context(@"when receiving a pinch", ^{ + it(@"should correctly give all pinch callbacks", ^{ + __block CGPoint pinchStartCenter; + __block CGPoint pinchMoveCenter; + __block CGFloat pinchMoveScale; + __block CGPoint pinchEndCenter; + + pinchStartTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchStartCenter))).to(beTruthy()); + }; + + pinchMoveTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + CGFloat scale; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + [invocation getArgument:&scale atIndex:4]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchMoveCenter))).to(beTruthy()); + expect(@(scale)).to(beCloseTo(@(pinchMoveScale)).within(0.0001)); + }; + + pinchEndTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, pinchEndCenter))).to(beTruthy()); + }; + + // Begin First Touch + performTouchEvent(touchManager, beginOnTouchEvent); + + // Begin Second Touch + SDLTouchCoord* secondTouchCoord = [[SDLTouchCoord alloc] init]; + secondTouchCoord.x = @(controlPoint.x + 100); + secondTouchCoord.y = @(controlPoint.y + 100); + + CGPoint firstPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); + CGPoint secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchStartCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + CGFloat pinchStartDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); + + touchEvent.touchEventId = @1; + touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, beginOnTouchEvent); + + + // Move Second Finger + secondTouchCoord.x = @(secondTouchCoord.x.floatValue - 30); + secondTouchCoord.y = @(secondTouchCoord.y.floatValue - 40); + + secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchMoveCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + CGFloat pinchMoveDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); + pinchMoveScale = pinchMoveDistance / pinchStartDistance; + + timeStamp += touchManager.panTimeThreshold * 1000; + + touchEvent.touchEventId = @1; + touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, moveOnTouchEvent); + + // End First Finger + timeStamp += touchManager.panTimeThreshold * 1000; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); + + pinchEndCenter = CGPointCenterOfPoints(firstPoint, secondPoint); + + endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; + performTouchEvent(touchManager, endOnTouchEvent); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + }); + }); + }); +}); + QuickSpecEnd From c8d0846b78423130a4296fdc2131dfc098e2ec03 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 1 Jul 2016 18:15:10 -0400 Subject: [PATCH 22/45] Moved all helper class tests to separate files. --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 24 +- .../UtilitiesSpecs/Touches/CGPointUtilSpec.m | 102 ++++++ .../Touches/DispatchTimerSpec.m | 47 +++ .../Touches/SDLPinchGestureSpec.m | 128 ++++++++ .../Touches}/SDLTouchManagerSpec.m | 303 ------------------ .../UtilitiesSpecs/Touches/SDLTouchSpec.m | 99 ++++++ 6 files changed, 396 insertions(+), 307 deletions(-) create mode 100644 SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m create mode 100644 SmartDeviceLinkTests/UtilitiesSpecs/Touches/DispatchTimerSpec.m create mode 100644 SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m rename SmartDeviceLinkTests/{ => UtilitiesSpecs/Touches}/SDLTouchManagerSpec.m (66%) create mode 100644 SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 32807e6e9..2f9416c14 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -786,7 +786,11 @@ 5DEE55C51B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */; }; 5DEE55C61B8666A8004F0D0F /* OHHTTPStubs.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */; }; - DA1166DB1D14625200438CEA /* SDLTouchManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */; }; + DA4353DF1D271FD10099B8C4 /* CGPointUtilSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353DE1D271FD10099B8C4 /* CGPointUtilSpec.m */; }; + DA4353E31D2720A30099B8C4 /* SDLPinchGestureSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E21D2720A30099B8C4 /* SDLPinchGestureSpec.m */; }; + DA4353E91D2721680099B8C4 /* DispatchTimerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E61D2721680099B8C4 /* DispatchTimerSpec.m */; }; + DA4353EA1D2721680099B8C4 /* SDLTouchManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E71D2721680099B8C4 /* SDLTouchManagerSpec.m */; }; + DA4353EB1D2721680099B8C4 /* SDLTouchSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E81D2721680099B8C4 /* SDLTouchSpec.m */; }; DAC572571D1067270004288B /* SDLTouchManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572551D1067270004288B /* SDLTouchManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAC572581D1067270004288B /* SDLTouchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572561D1067270004288B /* SDLTouchManager.m */; }; DAC5725B1D10B81E0004288B /* SDLTouch.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572591D10B81E0004288B /* SDLTouch.m */; }; @@ -1676,7 +1680,11 @@ 5DEE55C11B864A7D004F0D0F /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = Carthage/Build/iOS/OHHTTPStubs.framework; sourceTree = ""; }; 5DEE55C41B864AB3004F0D0F /* OHHTTPStubs.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = OHHTTPStubs.framework.dSYM; path = Carthage/Build/iOS/OHHTTPStubs.framework.dSYM; sourceTree = ""; }; 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = ""; }; - DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManagerSpec.m; sourceTree = ""; }; + DA4353DE1D271FD10099B8C4 /* CGPointUtilSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CGPointUtilSpec.m; path = UtilitiesSpecs/Touches/CGPointUtilSpec.m; sourceTree = ""; }; + DA4353E21D2720A30099B8C4 /* SDLPinchGestureSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLPinchGestureSpec.m; path = UtilitiesSpecs/Touches/SDLPinchGestureSpec.m; sourceTree = ""; }; + DA4353E61D2721680099B8C4 /* DispatchTimerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DispatchTimerSpec.m; path = UtilitiesSpecs/Touches/DispatchTimerSpec.m; sourceTree = ""; }; + DA4353E71D2721680099B8C4 /* SDLTouchManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLTouchManagerSpec.m; path = UtilitiesSpecs/Touches/SDLTouchManagerSpec.m; sourceTree = ""; }; + DA4353E81D2721680099B8C4 /* SDLTouchSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLTouchSpec.m; path = UtilitiesSpecs/Touches/SDLTouchSpec.m; sourceTree = ""; }; DAC572551D1067270004288B /* SDLTouchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouchManager.h; sourceTree = ""; }; DAC572561D1067270004288B /* SDLTouchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManager.m; sourceTree = ""; }; DAC572591D10B81E0004288B /* SDLTouch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouch.m; sourceTree = ""; }; @@ -2987,7 +2995,11 @@ DA1166D71D14601C00438CEA /* Touches */ = { isa = PBXGroup; children = ( - DA1166DA1D14625200438CEA /* SDLTouchManagerSpec.m */, + DA4353E61D2721680099B8C4 /* DispatchTimerSpec.m */, + DA4353E71D2721680099B8C4 /* SDLTouchManagerSpec.m */, + DA4353E81D2721680099B8C4 /* SDLTouchSpec.m */, + DA4353DE1D271FD10099B8C4 /* CGPointUtilSpec.m */, + DA4353E21D2720A30099B8C4 /* SDLPinchGestureSpec.m */, ); name = Touches; sourceTree = ""; @@ -3810,6 +3822,7 @@ 162E83811A9BDE8B00906325 /* SDLImageFieldSpec.m in Sources */, 162E834F1A9BDE8B00906325 /* SDLDeleteCommandResponseSpec.m in Sources */, 162E83231A9BDE8B00906325 /* SDLAddSubMenuSpec.m in Sources */, + DA4353E91D2721680099B8C4 /* DispatchTimerSpec.m in Sources */, 162E82F21A9BDE8B00906325 /* SDLPredefinedLayoutSpec.m in Sources */, 162E83521A9BDE8B00906325 /* SDLDeleteSubMenuResponseSpec.m in Sources */, 162E82E91A9BDE8B00906325 /* SDLKeypressModeSpec.m in Sources */, @@ -3822,7 +3835,6 @@ 162E83341A9BDE8B00906325 /* SDLPutFileSpec.m in Sources */, 162E837A1A9BDE8B00906325 /* SDLDIDResult.m in Sources */, 162E83171A9BDE8B00906325 /* SDLOnHMIStatusSpec.m in Sources */, - DA1166DB1D14625200438CEA /* SDLTouchManagerSpec.m in Sources */, 5DE372A41ACB336600849FAA /* SDLHMICapabilitiesSpec.m in Sources */, 162E82F71A9BDE8B00906325 /* SDLResultSpec.m in Sources */, 1680B1141A9CD7AD00DBD79E /* SDLV1ProtocolHeaderSpec.m in Sources */, @@ -3832,6 +3844,7 @@ 162E83831A9BDE8B00906325 /* SDLKeyboardPropertiesSpec.m in Sources */, 162E82D11A9BDE8A00906325 /* SDLButtonNameSpec.m in Sources */, 162E839E1A9BDE8B00906325 /* SDLRPCStructSpec.m in Sources */, + DA4353DF1D271FD10099B8C4 /* CGPointUtilSpec.m in Sources */, 162E83291A9BDE8B00906325 /* SDLDeleteFileSpec.m in Sources */, 1680B11D1A9CD7AD00DBD79E /* SDLProtocolMessageDisassemblerSpec.m in Sources */, 162E838E1A9BDE8B00906325 /* SDLSyncMsgVersionSpec.m in Sources */, @@ -3865,6 +3878,7 @@ 5DF2BB9D1B94E38A00CE5994 /* SDLURLSessionSpec.m in Sources */, 162E83381A9BDE8B00906325 /* SDLScrollableMessageSpec.m in Sources */, 162E82E81A9BDE8B00906325 /* SDLKeyboardLayoutSpec.m in Sources */, + DA4353EB1D2721680099B8C4 /* SDLTouchSpec.m in Sources */, 162E83541A9BDE8B00906325 /* SDLEncodedSyncPDataResponseSpec.m in Sources */, 162E83161A9BDE8B00906325 /* SDLOnHashChangeSpec.m in Sources */, 162E82FE1A9BDE8B00906325 /* SDLTBTStateSpec.m in Sources */, @@ -3890,6 +3904,7 @@ 162E83741A9BDE8B00906325 /* SDLBodyInformationSpec.m in Sources */, 162E83641A9BDE8B00906325 /* SDLSetMediaClockTimerResponseSpec.m in Sources */, 162E839C1A9BDE8B00906325 /* SDLRPCRequestSpec.m in Sources */, + DA4353E31D2720A30099B8C4 /* SDLPinchGestureSpec.m in Sources */, 5D8B17561AC9E399006A6E1C /* SDLDialNumberSpec.m in Sources */, 162E833D1A9BDE8B00906325 /* SDLShowConstantTBTSpec.m in Sources */, 162E83651A9BDE8B00906325 /* SDLShowConstantTBTResponseSpec.m in Sources */, @@ -3939,6 +3954,7 @@ 162E83891A9BDE8B00906325 /* SDLScreenParamsSpec.m in Sources */, 162E83441A9BDE8B00906325 /* SDLSystemRequestSpec.m in Sources */, 162E83001A9BDE8B00906325 /* SDLTextFieldNameSpec.m in Sources */, + DA4353EA1D2721680099B8C4 /* SDLTouchManagerSpec.m in Sources */, 162E82FC1A9BDE8B00906325 /* SDLSystemAction.m in Sources */, 162E82CC1A9BDE8A00906325 /* SDLAppInterfaceUnregisteredReasonSpec.m in Sources */, 162E83321A9BDE8B00906325 /* SDLPerformAudioPassThruSpec.m in Sources */, diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m new file mode 100644 index 000000000..a58419ee3 --- /dev/null +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m @@ -0,0 +1,102 @@ +// +// CGPointUtilSpec.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 7/1/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import + +#import +#import +#import + +#import "CGPoint_Util.h" + +QuickSpecBegin(CGPointUtilSpec) + +describe(@"CGPoint_Util Tests", ^{ + __block CGPoint first; + __block CGPoint second; + context(@"For two positive points", ^{ + beforeEach(^{ + first = CGPointMake(100, 200); + second = CGPointMake(300, 400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@200)); + expect(@(average.y)).to(equal(@300)); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@200)); + expect(@(center.y)).to(equal(@300)); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@(-200))); + expect(@(displacement.y)).to(equal(@(-200))); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); + }); + }); + context(@"For two negative points", ^{ + beforeEach(^{ + first = CGPointMake(-100, -200); + second = CGPointMake(-300, -400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@(-200))); + expect(@(average.y)).to(equal(@(-300))); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@(-200))); + expect(@(center.y)).to(equal(@(-300))); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@200)); + expect(@(displacement.y)).to(equal(@200)); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); + }); + }); + context(@"For one positive and one negative point", ^{ + beforeEach(^{ + first = CGPointMake(100, 200); + second = CGPointMake(-300, -400); + }); + + it(@"should properly calculate the average between points", ^{ + CGPoint average = CGPointAverageOfPoints(first, second); + expect(@(average.x)).to(equal(@(-100))); + expect(@(average.y)).to(equal(@(-100))); + }); + it(@"should properly calculate the center between points", ^{ + CGPoint center = CGPointCenterOfPoints(first, second); + expect(@(center.x)).to(equal(@(-100))); + expect(@(center.y)).to(equal(@(-100))); + }); + it(@"should properly calculate the displacement between points", ^{ + CGPoint displacement = CGPointDisplacementOfPoints(first, second); + expect(@(displacement.x)).to(equal(@400)); + expect(@(displacement.y)).to(equal(@600)); + }); + it(@"should properly calculate the distance between points", ^{ + CGFloat distance = CGPointDistanceBetweenPoints(first, second); + expect(@(distance)).to(beCloseTo(@721.1103).within(0.0001)); + }); + }); +}); + +QuickSpecEnd \ No newline at end of file diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/DispatchTimerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/DispatchTimerSpec.m new file mode 100644 index 000000000..771d2c4bb --- /dev/null +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/DispatchTimerSpec.m @@ -0,0 +1,47 @@ +// +// DispatchTimerSpec.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 7/1/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import + +#import +#import +#import + +#import "dispatch_timer.h" + +QuickSpecBegin(DispatchTimerSpec) + +describe(@"dispatch_timer Tests", ^{ + context(@"Creating", ^{ + it(@"should be successful within specified time", ^{ + waitUntilTimeout(4, ^(void (^done)(void)) { + __block double currentTime = [[NSDate date] timeIntervalSince1970]; + dispatch_create_timer(2.5, false, ^{ + double difference = [[NSDate date] timeIntervalSince1970] - currentTime; + expect(@(difference)).to(beCloseTo(@2.5).within(0.1)); + done(); + }); + }); + }); + + it(@"should be cancellable and not fire", ^{ + __block dispatch_source_t timer; + waitUntilTimeout(2, ^(void (^done)(void)) { + timer = dispatch_create_timer(2.5, false, ^{ + fail(); + }); + [NSThread sleepForTimeInterval:0.5]; + dispatch_stop_timer(timer); + done(); + }); + expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@0)); + }); + }); +}); + +QuickSpecEnd \ No newline at end of file diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m new file mode 100644 index 000000000..1a41b537d --- /dev/null +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m @@ -0,0 +1,128 @@ +// +// SDLPinchGestureSpec.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 7/1/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import + +#import +#import +#import + +#import "SDLPinchGesture.h" + +QuickSpecBegin(SDLPinchGestureSpec) + +describe(@"SDLPinchGesture Tests", ^{ + context(@"SDLPinchGestureZero", ^{ + __block SDLPinchGesture pinchGesture = SDLPinchGestureZero; + + it(@"should correctly initialize", ^{ + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(-1))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@0)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@0)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@0)); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(-1))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@0)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@0)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@0)); + }); + + it(@"should not be a valid SDLPinchGesture", ^{ + expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beFalsy()); + }); + }); + + context(@"SDLPinchGestureMake", ^{ + __block SDLPinchGesture pinchGesture; + __block SDLTouch firstTouch; + __block SDLTouch secondTouch; + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block unsigned long secondTimeStamp = timeStamp + 1000; + + beforeEach(^{ + firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); + secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + }); + + it(@"should correctly initialize", ^{ + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@141.4213).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@150)); + expect(@(pinchGesture.center.y)).to(equal(@250)); + }); + + it(@"should be a valid SDLPinchGesture", ^{ + expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beTruthy()); + }); + }); + + context(@"updating SDLPinchGesture", ^{ + __block SDLPinchGesture pinchGesture; + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block unsigned long secondTimeStamp = timeStamp + 1000; + + beforeEach(^{ + SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); + SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); + pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + }); + + it(@"should update first point correctly", ^{ + unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 150, 250, newTimeStamp); + pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@150)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@250)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(newTimeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@175)); + expect(@(pinchGesture.center.y)).to(equal(@275)); + + }); + + it(@"should update second point correctly", ^{ + unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 150, 250, newTimeStamp); + pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + + expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); + expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); + expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); + + expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(pinchGesture.secondTouch.location.x)).to(equal(@150)); + expect(@(pinchGesture.secondTouch.location.y)).to(equal(@250)); + expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(newTimeStamp))); + + expect(@(pinchGesture.distance)).to(beCloseTo(@70.7107).within(0.0001)); + expect(@(pinchGesture.center.x)).to(equal(@125)); + expect(@(pinchGesture.center.y)).to(equal(@225)); + }); + }); +}); + +QuickSpecEnd \ No newline at end of file diff --git a/SmartDeviceLinkTests/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m similarity index 66% rename from SmartDeviceLinkTests/SDLTouchManagerSpec.m rename to SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index 0bf22f41e..f26c4650c 100644 --- a/SmartDeviceLinkTests/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -18,314 +18,11 @@ #import "SDLTouchManager.h" #import "SDLTouchType.h" #import "CGPoint_Util.h" -#import "SDLTouch.h" -#import "SDLPinchGesture.h" -#import "dispatch_timer.h" QuickSpecBegin(SDLTouchManagerSpec) typedef void (^DelegateCallbackBlock)(NSInvocation* invocation); -describe(@"CGPoint_Util Tests", ^{ - __block CGPoint first; - __block CGPoint second; - context(@"For two positive points", ^{ - beforeEach(^{ - first = CGPointMake(100, 200); - second = CGPointMake(300, 400); - }); - - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@200)); - expect(@(average.y)).to(equal(@300)); - }); - it(@"should properly calculate the center between points", ^{ - CGPoint center = CGPointCenterOfPoints(first, second); - expect(@(center.x)).to(equal(@200)); - expect(@(center.y)).to(equal(@300)); - }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@(-200))); - expect(@(displacement.y)).to(equal(@(-200))); - }); - it(@"should properly calculate the distance between points", ^{ - CGFloat distance = CGPointDistanceBetweenPoints(first, second); - expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); - }); - }); - context(@"For two negative points", ^{ - beforeEach(^{ - first = CGPointMake(-100, -200); - second = CGPointMake(-300, -400); - }); - - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@(-200))); - expect(@(average.y)).to(equal(@(-300))); - }); - it(@"should properly calculate the center between points", ^{ - CGPoint center = CGPointCenterOfPoints(first, second); - expect(@(center.x)).to(equal(@(-200))); - expect(@(center.y)).to(equal(@(-300))); - }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@200)); - expect(@(displacement.y)).to(equal(@200)); - }); - it(@"should properly calculate the distance between points", ^{ - CGFloat distance = CGPointDistanceBetweenPoints(first, second); - expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); - }); - }); - context(@"For one positive and one negative point", ^{ - beforeEach(^{ - first = CGPointMake(100, 200); - second = CGPointMake(-300, -400); - }); - - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@(-100))); - expect(@(average.y)).to(equal(@(-100))); - }); - it(@"should properly calculate the center between points", ^{ - CGPoint center = CGPointCenterOfPoints(first, second); - expect(@(center.x)).to(equal(@(-100))); - expect(@(center.y)).to(equal(@(-100))); - }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@400)); - expect(@(displacement.y)).to(equal(@600)); - }); - it(@"should properly calculate the distance between points", ^{ - CGFloat distance = CGPointDistanceBetweenPoints(first, second); - expect(@(distance)).to(beCloseTo(@721.1103).within(0.0001)); - }); - }); -}); - -describe(@"SDLTouch Tests", ^{ - context(@"SDLTouchZero", ^{ - __block SDLTouch touch = SDLTouchZero; - - it(@"should correctly initialize", ^{ - expect(@(touch.identifier)).to(equal(@(-1))); - expect(@(CGPointEqualToPoint(touch.location, CGPointZero))).to(beTruthy()); - expect(@(touch.timeStamp)).to(equal(@0)); - }); - - it(@"should not be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beFalsy()); - }); - - it(@"should not equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); - }); - - it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); - }); - }); - - context(@"For First Finger Identifiers", ^{ - __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block SDLTouch touch; - - beforeSuite(^{ - touch = SDLTouchMake(0, 100, 200, timeStamp); - }); - - it(@"should correctly make a SDLTouch struct", ^{ - expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); - expect(@(touch.location.x)).to(equal(@100)); - expect(@(touch.location.y)).to(equal(@200)); - expect(@(touch.timeStamp)).to(equal(@(timeStamp))); - }); - - it(@"should be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beTruthy()); - }); - - it(@"should equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beTruthy()); - }); - - it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); - }); - }); - - context(@"For Second Finger Identifiers", ^{ - __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block SDLTouch touch; - - beforeSuite(^{ - touch = SDLTouchMake(1, 100, 200, timeStamp); - }); - - it(@"should correctly make a SDLTouch struct", ^{ - expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); - expect(@(touch.location.x)).to(equal(@100)); - expect(@(touch.location.y)).to(equal(@200)); - expect(@(touch.timeStamp)).to(equal(@(timeStamp))); - }); - - it(@"should be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beTruthy()); - }); - - it(@"should equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); - }); - - it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beTruthy()); - }); - }); -}); - -describe(@"SDLPinchGesture Tests", ^{ - context(@"SDLPinchGestureZero", ^{ - __block SDLPinchGesture pinchGesture = SDLPinchGestureZero; - - it(@"should correctly initialize", ^{ - expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(-1))); - expect(@(pinchGesture.firstTouch.location.x)).to(equal(@0)); - expect(@(pinchGesture.firstTouch.location.y)).to(equal(@0)); - expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@0)); - - expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(-1))); - expect(@(pinchGesture.secondTouch.location.x)).to(equal(@0)); - expect(@(pinchGesture.secondTouch.location.y)).to(equal(@0)); - expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@0)); - }); - - it(@"should not be a valid SDLPinchGesture", ^{ - expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beFalsy()); - }); - }); - - context(@"SDLPinchGestureMake", ^{ - __block SDLPinchGesture pinchGesture; - __block SDLTouch firstTouch; - __block SDLTouch secondTouch; - __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block unsigned long secondTimeStamp = timeStamp + 1000; - - beforeEach(^{ - firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); - secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); - pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); - }); - - it(@"should correctly initialize", ^{ - expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); - expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); - expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); - expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); - - expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); - expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); - expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); - expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); - - expect(@(pinchGesture.distance)).to(beCloseTo(@141.4213).within(0.0001)); - expect(@(pinchGesture.center.x)).to(equal(@150)); - expect(@(pinchGesture.center.y)).to(equal(@250)); - }); - - it(@"should be a valid SDLPinchGesture", ^{ - expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beTruthy()); - }); - }); - - context(@"updating SDLPinchGesture", ^{ - __block SDLPinchGesture pinchGesture; - __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block unsigned long secondTimeStamp = timeStamp + 1000; - - beforeEach(^{ - SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); - SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); - pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); - }); - - it(@"should update first point correctly", ^{ - unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 150, 250, newTimeStamp); - pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); - - expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); - expect(@(pinchGesture.firstTouch.location.x)).to(equal(@150)); - expect(@(pinchGesture.firstTouch.location.y)).to(equal(@250)); - expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(newTimeStamp))); - - expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); - expect(@(pinchGesture.secondTouch.location.x)).to(equal(@200)); - expect(@(pinchGesture.secondTouch.location.y)).to(equal(@300)); - expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(secondTimeStamp))); - - expect(@(pinchGesture.distance)).to(beCloseTo(@(70.7107)).within(0.0001)); - expect(@(pinchGesture.center.x)).to(equal(@175)); - expect(@(pinchGesture.center.y)).to(equal(@275)); - - }); - - it(@"should update second point correctly", ^{ - unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 150, 250, newTimeStamp); - pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); - - expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); - expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); - expect(@(pinchGesture.firstTouch.location.y)).to(equal(@200)); - expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@(timeStamp))); - - expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); - expect(@(pinchGesture.secondTouch.location.x)).to(equal(@150)); - expect(@(pinchGesture.secondTouch.location.y)).to(equal(@250)); - expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@(newTimeStamp))); - - expect(@(pinchGesture.distance)).to(beCloseTo(@70.7107).within(0.0001)); - expect(@(pinchGesture.center.x)).to(equal(@125)); - expect(@(pinchGesture.center.y)).to(equal(@225)); - }); - }); -}); - -describe(@"dispatch_timer Tests", ^{ - context(@"Creating", ^{ - it(@"should be successful within specified time", ^{ - waitUntilTimeout(4, ^(void (^done)(void)) { - __block double currentTime = [[NSDate date] timeIntervalSince1970]; - dispatch_create_timer(2.5, false, ^{ - double difference = [[NSDate date] timeIntervalSince1970] - currentTime; - expect(@(difference)).to(beCloseTo(@2.5).within(0.1)); - done(); - }); - }); - }); - - it(@"should be cancellable and not fire", ^{ - __block dispatch_source_t timer; - waitUntilTimeout(2, ^(void (^done)(void)) { - timer = dispatch_create_timer(2.5, false, ^{ - fail(); - }); - [NSThread sleepForTimeInterval:0.5]; - dispatch_stop_timer(timer); - done(); - }); - expect(@(dispatch_source_testcancel(timer))).to(beGreaterThan(@0)); - }); - }); -}); - describe(@"SDLTouchManager Tests", ^{ __block SDLTouchManager* touchManager; diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m new file mode 100644 index 000000000..4831f7d3c --- /dev/null +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m @@ -0,0 +1,99 @@ +// +// SDLTouchSpecs.m +// SmartDeviceLink-iOS +// +// Created by Muller, Alexander (A.) on 7/1/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import + +#import +#import +#import + +#import "SDLTouch.h" + +QuickSpecBegin(SDLTouchSpec) + +describe(@"SDLTouch Tests", ^{ + context(@"SDLTouchZero", ^{ + __block SDLTouch touch = SDLTouchZero; + + it(@"should correctly initialize", ^{ + expect(@(touch.identifier)).to(equal(@(-1))); + expect(@(CGPointEqualToPoint(touch.location, CGPointZero))).to(beTruthy()); + expect(@(touch.timeStamp)).to(equal(@0)); + }); + + it(@"should not be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beFalsy()); + }); + + it(@"should not equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + }); + }); + + context(@"For First Finger Identifiers", ^{ + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block SDLTouch touch; + + beforeSuite(^{ + touch = SDLTouchMake(0, 100, 200, timeStamp); + }); + + it(@"should correctly make a SDLTouch struct", ^{ + expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); + expect(@(touch.location.x)).to(equal(@100)); + expect(@(touch.location.y)).to(equal(@200)); + expect(@(touch.timeStamp)).to(equal(@(timeStamp))); + }); + + it(@"should be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beTruthy()); + }); + + it(@"should equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beTruthy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + }); + }); + + context(@"For Second Finger Identifiers", ^{ + __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + __block SDLTouch touch; + + beforeSuite(^{ + touch = SDLTouchMake(1, 100, 200, timeStamp); + }); + + it(@"should correctly make a SDLTouch struct", ^{ + expect(@(touch.identifier)).to(equal(@(SDLTouchIdentifierSecondFinger))); + expect(@(touch.location.x)).to(equal(@100)); + expect(@(touch.location.y)).to(equal(@200)); + expect(@(touch.timeStamp)).to(equal(@(timeStamp))); + }); + + it(@"should be a valid SDLTouch", ^{ + expect(@(SDLTouchIsValid(touch))).to(beTruthy()); + }); + + it(@"should equal First Finger Identifier", ^{ + expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + }); + + it(@"should not equal Second Finger Identifier", ^{ + expect(@(SDLTouchIsSecondFinger(touch))).to(beTruthy()); + }); + }); +}); + +QuickSpecEnd \ No newline at end of file From ac2dcf5dac12a4610ccddb83fb95360f4dac557f Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 1 Jul 2016 18:16:44 -0400 Subject: [PATCH 23/45] Using NSSelectorFromString instead of @selector to silence warning. --- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index f26c4650c..71ac916ab 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -53,7 +53,7 @@ __block DelegateCallbackBlock pinchEndTests; __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) { - SEL onOnTouchEvent = @selector(onOnTouchEvent:); + SEL onOnTouchEvent = NSSelectorFromString(@"onOnTouchEvent:"); ((void (*)(id, SEL, id))[touchManager methodForSelector:onOnTouchEvent])(touchManager, onOnTouchEvent, onTouchEvent); }; From 1ff49f62bec2e2f122cfd4a509141ecba95047cb Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 1 Jul 2016 22:06:54 -0400 Subject: [PATCH 24/45] Rewrote SDLTouchManager tests to extract variables out of the tests and into beforeEaches. --- .../Touches/SDLTouchManagerSpec.m | 607 ++++++++++-------- 1 file changed, 345 insertions(+), 262 deletions(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index 71ac916ab..e7125fca1 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -17,47 +17,15 @@ #import "SDLTouchEvent.h" #import "SDLTouchManager.h" #import "SDLTouchType.h" -#import "CGPoint_Util.h" +//#import "CGPoint_Util.h" QuickSpecBegin(SDLTouchManagerSpec) -typedef void (^DelegateCallbackBlock)(NSInvocation* invocation); - describe(@"SDLTouchManager Tests", ^{ __block SDLTouchManager* touchManager; - __block id delegateMock; - __block NSUInteger timeStamp; - __block CGPoint controlPoint; - __block SDLTouchCoord* touchCoord; - __block SDLTouchEvent* touchEvent; - __block SDLOnTouchEvent* beginOnTouchEvent; - __block SDLOnTouchEvent* moveOnTouchEvent; - __block SDLOnTouchEvent* endOnTouchEvent; - __block BOOL didCallSingleTap; - __block BOOL didCallDoubleTap; - __block BOOL didCallBeginPan; - __block BOOL didCallMovePan; - __block BOOL didCallEndPan; - __block BOOL didCallBeginPinch; - __block BOOL didCallMovePinch; - __block BOOL didCallEndPinch; - - __block DelegateCallbackBlock singleTapTests; - __block DelegateCallbackBlock doubleTapTests; - __block DelegateCallbackBlock panStartTests; - __block DelegateCallbackBlock panMoveTests; - __block DelegateCallbackBlock panEndTests; - __block DelegateCallbackBlock pinchStartTests; - __block DelegateCallbackBlock pinchMoveTests; - __block DelegateCallbackBlock pinchEndTests; - - __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) { - SEL onOnTouchEvent = NSSelectorFromString(@"onOnTouchEvent:"); - ((void (*)(id, SEL, id))[touchManager methodForSelector:onOnTouchEvent])(touchManager, onOnTouchEvent, onTouchEvent); - }; - context(@"Initializing", ^{ + context(@"initializing", ^{ it(@"should correctly have default properties", ^{ SDLTouchManager* touchManager = [[SDLTouchManager alloc] init]; expect(touchManager.touchEventListener).to(beNil()); @@ -68,33 +36,41 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent }); }); + describe(@"touch events", ^{ + typedef void (^DelegateCallbackBlock)(NSInvocation* invocation); + + __block id delegateMock; + __block CGPoint controlPoint; + __block BOOL didCallSingleTap; + __block BOOL didCallDoubleTap; + __block BOOL didCallBeginPan; + __block BOOL didCallMovePan; + __block BOOL didCallEndPan; + __block BOOL didCallBeginPinch; + __block BOOL didCallMovePinch; + __block BOOL didCallEndPinch; + + __block DelegateCallbackBlock singleTapTests; + __block DelegateCallbackBlock doubleTapTests; + __block DelegateCallbackBlock panStartTests; + __block DelegateCallbackBlock panMoveTests; + __block DelegateCallbackBlock panEndTests; + __block DelegateCallbackBlock pinchStartTests; + __block DelegateCallbackBlock pinchMoveTests; + __block DelegateCallbackBlock pinchEndTests; + + __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) { + SEL onOnTouchEvent = NSSelectorFromString(@"onOnTouchEvent:"); + ((void (*)(id, SEL, id))[touchManager methodForSelector:onOnTouchEvent])(touchManager, onOnTouchEvent, onTouchEvent); + }; + beforeEach(^{ touchManager = [[SDLTouchManager alloc] init]; delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerListener)); touchManager.touchEventListener = delegateMock; - timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; controlPoint = CGPointMake(100, 200); - touchCoord = [[SDLTouchCoord alloc] init]; - touchCoord.x = @(controlPoint.x); - touchCoord.y = @(controlPoint.y); - - touchEvent = [[SDLTouchEvent alloc] init]; - touchEvent.touchEventId = @0; - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - - beginOnTouchEvent = [[SDLOnTouchEvent alloc] init]; - beginOnTouchEvent.type = SDLTouchType.BEGIN; - beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - - moveOnTouchEvent = [[SDLOnTouchEvent alloc] init]; - moveOnTouchEvent.type = SDLTouchType.MOVE; - - endOnTouchEvent = [[SDLOnTouchEvent alloc] init]; - endOnTouchEvent.type = SDLTouchType.END; - didCallSingleTap = NO; [[[[delegateMock stub] andDo:^(NSInvocation* invocation) { didCallSingleTap = YES; @@ -184,142 +160,246 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent }; }); - context(@"when receiving a single tap", ^{ - it(@"should correctly handle a single tap", ^{ - singleTapTests = ^(NSInvocation* invocation) { - __unsafe_unretained SDLTouchManager* touchManagerCallback; - - CGPoint point; - - [invocation getArgument:&touchManagerCallback atIndex:2]; - [invocation getArgument:&point atIndex:3]; - - expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); - }; + describe(@"single finger", ^{ + __block SDLTouchCoord* firstTouchCoord; + __block NSUInteger firstTouchTimeStamp; + + __block SDLOnTouchEvent* firstOnTouchEventStart; + __block SDLOnTouchEvent* firstOnTouchEventEnd; + + beforeEach(^{ + firstTouchCoord = [[SDLTouchCoord alloc] init]; + firstTouchCoord.x = @(controlPoint.x); + firstTouchCoord.y = @(controlPoint.y); - // Begin Touch - performTouchEvent(touchManager, beginOnTouchEvent); + firstTouchTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; - // End Touch - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + SDLTouchEvent* touchEvent = [[SDLTouchEvent alloc] init]; + touchEvent.touchEventId = @0; + touchEvent.coord = [NSMutableArray arrayWithObject:firstTouchCoord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(firstTouchTimeStamp)]; - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + firstOnTouchEventStart = [[SDLOnTouchEvent alloc] init]; + firstOnTouchEventStart.type = SDLTouchType.BEGIN; + firstOnTouchEventStart.event = [NSMutableArray arrayWithObject:touchEvent]; - expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); - expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + firstOnTouchEventEnd = [[SDLOnTouchEvent alloc] init]; + firstOnTouchEventEnd.type = SDLTouchType.END; + firstOnTouchEventEnd.event = [NSMutableArray arrayWithObject:touchEvent]; }); - }); - - context(@"when receiving a double tap", ^{ - it(@"should correctly handle a double tap near same point", ^{ + + describe(@"when receiving a single tap", ^{ + it(@"should correctly handle a single tap", ^{ + + singleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); + }; + + performTouchEvent(touchManager, firstOnTouchEventStart); + + performTouchEvent(touchManager, firstOnTouchEventEnd); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + + describe(@"when receiving a double tap", ^{ __block CGPoint averagePoint; - doubleTapTests = ^(NSInvocation* invocation) { - __unsafe_unretained SDLTouchManager* touchManagerCallback; + __block SDLTouchEvent* secondTouchEvent; + + __block SDLOnTouchEvent* secondOnTouchEventStart; + __block SDLOnTouchEvent* secondOnTouchEventEnd; + + beforeEach(^{ + secondOnTouchEventStart = [[SDLOnTouchEvent alloc] init]; + secondOnTouchEventStart.type = SDLTouchType.BEGIN; - CGPoint point; + secondOnTouchEventEnd = [[SDLOnTouchEvent alloc] init]; + secondOnTouchEventEnd.type = SDLTouchType.END; - [invocation getArgument:&touchManagerCallback atIndex:2]; - [invocation getArgument:&point atIndex:3]; + secondTouchEvent = [[SDLTouchEvent alloc] init]; + secondTouchEvent.touchEventId = @0; + NSUInteger secondTouchTimeStamp = firstTouchTimeStamp + (touchManager.tapTimeThreshold - 0.1) * 1000; + secondTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondTouchTimeStamp)]; + }); + + context(@"near the same point", ^{ + beforeEach(^{ + SDLTouchCoord* touchCoord = [[SDLTouchCoord alloc] init]; + touchCoord.x = @(firstTouchCoord.x.floatValue + touchManager.tapDistanceThreshold); + touchCoord.y = @(firstTouchCoord.y.floatValue + touchManager.tapDistanceThreshold); + + secondTouchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + secondOnTouchEventStart.event = [NSMutableArray arrayWithObject:secondTouchEvent]; + + secondOnTouchEventEnd.event = [NSMutableArray arrayWithObject:secondTouchEvent]; + + averagePoint = CGPointMake((firstTouchCoord.x.floatValue + touchCoord.x.floatValue) / 2.0f, + (firstTouchCoord.y.floatValue + touchCoord.y.floatValue) / 2.0f); + }); - expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, averagePoint))).to(beTruthy()); - }; + it(@"should issue delegate callbacks", ^{ + doubleTapTests = ^(NSInvocation* invocation) { + __unsafe_unretained SDLTouchManager* touchManagerCallback; + + CGPoint point; + + [invocation getArgument:&touchManagerCallback atIndex:2]; + [invocation getArgument:&point atIndex:3]; + + expect(touchManagerCallback).to(equal(touchManager)); + expect(@(CGPointEqualToPoint(point, averagePoint))).to(beTruthy()); + }; + + performTouchEvent(touchManager, firstOnTouchEventStart); + performTouchEvent(touchManager, firstOnTouchEventEnd); + performTouchEvent(touchManager, secondOnTouchEventStart); + performTouchEvent(touchManager, secondOnTouchEventEnd); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + + context(@"not near the same point", ^{ + beforeEach(^{ + SDLTouchCoord* touchCoord = [[SDLTouchCoord alloc] init]; + touchCoord.x = @(firstTouchCoord.x.floatValue + touchManager.tapDistanceThreshold + 1); + touchCoord.y = @(firstTouchCoord.y.floatValue + touchManager.tapDistanceThreshold + 1); + + secondTouchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; + + secondOnTouchEventStart.event = [NSMutableArray arrayWithObject:secondTouchEvent]; + + secondOnTouchEventEnd.event = [NSMutableArray arrayWithObject:secondTouchEvent]; + }); + + it(@"should should not issue delegate callbacks", ^{ + performTouchEvent(touchManager, firstOnTouchEventStart); + performTouchEvent(touchManager, firstOnTouchEventEnd); + performTouchEvent(touchManager, secondOnTouchEventStart); + performTouchEvent(touchManager, secondOnTouchEventEnd); + + expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); + }); + }); + }); + context(@"when receiving a pan", ^{ + __block CGPoint panStartPoint; + __block CGPoint panMovePoint; + __block CGPoint panSecondMovePoint; + __block CGPoint panEndPoint; + + __block CGFloat distanceMoveX = 10; + __block CGFloat distanceMoveY = 20; + + __block SDLOnTouchEvent* panStartOnTouchEvent; + __block SDLOnTouchEvent* panMoveOnTouchEvent; + __block SDLOnTouchEvent* panSecondMoveOnTouchEvent; + __block SDLOnTouchEvent* panEndOnTouchEvent; + + beforeEach(^{ + // Finger touch down + panStartPoint = controlPoint; + + SDLTouchCoord* panStartTouchCoord = [[SDLTouchCoord alloc] init]; + panStartTouchCoord.x = @(panStartPoint.x); + panStartTouchCoord.y = @(panStartPoint.y); - // Begin First Touch - performTouchEvent(touchManager, beginOnTouchEvent); + NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] + touchManager.panTimeThreshold) * 1000; - // End First Touch - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + SDLTouchEvent* panStartTouchEvent = [[SDLTouchEvent alloc] init]; + panStartTouchEvent.coord = [NSMutableArray arrayWithObject:panStartTouchCoord]; + panStartTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(panStartTimeStamp)]; - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + panStartOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + panStartOnTouchEvent.event = [NSMutableArray arrayWithObject:panStartTouchEvent]; + panStartOnTouchEvent.type = SDLTouchType.BEGIN; - // Start Second Touch - touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold); - touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold); + // Finger Move + panMovePoint = CGPointMake(panStartPoint.x + distanceMoveX, panStartPoint.y + distanceMoveY); - averagePoint = CGPointAverageOfPoints(controlPoint, - CGPointMake(touchCoord.x.floatValue, - touchCoord.y.floatValue)); - - timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; - - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + SDLTouchCoord* panMoveTouchCoord = [[SDLTouchCoord alloc] init]; + panMoveTouchCoord.x = @(panMovePoint.x); + panMoveTouchCoord.y = @(panMovePoint.y); - beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, beginOnTouchEvent); + NSUInteger panMoveTimeStamp = panStartTimeStamp + (touchManager.panTimeThreshold * 1000); - // End Second Touch - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + SDLTouchEvent* panMoveTouchEvent = [[SDLTouchEvent alloc] init]; + panMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panMoveTouchCoord]; + panMoveTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(panMoveTimeStamp)]; - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + panMoveOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + panMoveOnTouchEvent.event = [NSMutableArray arrayWithObject:panMoveTouchEvent]; + panMoveOnTouchEvent.type = SDLTouchType.MOVE; - expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beTruthy()); - expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - }); - - it(@"should correctly not handle a double tap", ^{ - // Begin First Touch - performTouchEvent(touchManager, beginOnTouchEvent); + // Finger Move + panSecondMovePoint = CGPointMake(panMovePoint.x + distanceMoveX, panMovePoint.y + distanceMoveY); - // End First Touch - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + SDLTouchCoord* panSecondMoveTouchCoord = [[SDLTouchCoord alloc] init]; + panSecondMoveTouchCoord.x = @(panSecondMovePoint.x); + panSecondMoveTouchCoord.y = @(panSecondMovePoint.y); - // Start Second Touch - timeStamp += (touchManager.tapTimeThreshold - 0.1) * 1000; + NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + (touchManager.panTimeThreshold * 1000); - touchCoord.x = @(touchCoord.x.floatValue + touchManager.tapDistanceThreshold + 1); - touchCoord.y = @(touchCoord.y.floatValue + touchManager.tapDistanceThreshold + 1); + SDLTouchEvent* panSecondMoveTouchEvent = [[SDLTouchEvent alloc] init]; + panSecondMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panSecondMoveTouchCoord]; + panSecondMoveTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(panSecondMoveTimeStamp)]; - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + panSecondMoveOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + panSecondMoveOnTouchEvent.event = [NSMutableArray arrayWithObject:panSecondMoveTouchEvent]; + panSecondMoveOnTouchEvent.type = SDLTouchType.MOVE; - beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, beginOnTouchEvent); + // Finger End + panEndPoint = CGPointMake(panSecondMovePoint.x, panSecondMovePoint.y); + + SDLTouchCoord* panEndTouchCoord = [[SDLTouchCoord alloc] init]; + panEndTouchCoord.x = @(panEndPoint.x); + panEndTouchCoord.y = @(panEndPoint.y); - // End Second Touch - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + (touchManager.panTimeThreshold * 1000); - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + SDLTouchEvent* panEndTouchEvent = [[SDLTouchEvent alloc] init]; + panEndTouchEvent.coord = [NSMutableArray arrayWithObject:panEndTouchCoord]; + panEndTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(panEndTimeStamp)]; - expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallBeginPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPan)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); - expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + panEndOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + panEndOnTouchEvent.event = [NSMutableArray arrayWithObject:panEndTouchEvent]; + panEndOnTouchEvent.type = SDLTouchType.END; }); - }); - context(@"when receiving a pan", ^{ - __block CGPoint panStartPoint; - __block CGPoint panMovePoint; - __block CGPoint panEndPoint; it(@"should correctly give all pan callbacks", ^{ - __block CGFloat distanceMoveX = 10; - __block CGFloat distanceMoveY = 20; - panStartTests = ^(NSInvocation* invocation) { __unsafe_unretained SDLTouchManager* touchManagerCallback; @@ -329,9 +409,9 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent [invocation getArgument:&point atIndex:3]; expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(point, panStartPoint))).to(beTruthy()); + expect(@(CGPointEqualToPoint(point, panMovePoint))).to(beTruthy()); }; - + panMoveTests = ^(NSInvocation* invocation) { __unsafe_unretained SDLTouchManager* touchManagerCallback; @@ -343,8 +423,8 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent [invocation getArgument:&endPoint atIndex:4]; expect(touchManagerCallback).to(equal(touchManager)); - expect(@(CGPointEqualToPoint(startPoint, panStartPoint))).to(beTruthy()); - expect(@(CGPointEqualToPoint(endPoint, panMovePoint))).to(beTruthy()); + expect(@(CGPointEqualToPoint(startPoint, panMovePoint))).to(beTruthy()); + expect(@(CGPointEqualToPoint(endPoint, panSecondMovePoint))).to(beTruthy()); }; panEndTests = ^(NSInvocation* invocation) { @@ -358,48 +438,11 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expect(touchManagerCallback).to(equal(touchManager)); expect(@(CGPointEqualToPoint(point, panEndPoint))).to(beTruthy()); }; - - // Begin Touch - performTouchEvent(touchManager, beginOnTouchEvent); - - // Move Touch - touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); - touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - - panStartPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); - - timeStamp += (touchManager.panTimeThreshold * 1000); - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - - moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, moveOnTouchEvent); - - // Move Touch 2 - touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); - touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - - panMovePoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); - - timeStamp += (touchManager.panTimeThreshold * 1000); - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - - moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, moveOnTouchEvent); - - // End Touch - touchCoord.x = @(touchCoord.x.floatValue + distanceMoveX); - touchCoord.y = @(touchCoord.y.floatValue + distanceMoveY); - touchEvent.coord = [NSMutableArray arrayWithObject:touchCoord]; - - panEndPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); - - timeStamp += (touchManager.panTimeThreshold * 1000); - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + performTouchEvent(touchManager, panStartOnTouchEvent); + performTouchEvent(touchManager, panMoveOnTouchEvent); + performTouchEvent(touchManager, panSecondMoveOnTouchEvent); + performTouchEvent(touchManager, panEndOnTouchEvent); expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); @@ -409,15 +452,102 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expect(@(didCallBeginPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); expect(@(didCallMovePinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); expect(@(didCallEndPinch)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); + }); }); context(@"when receiving a pinch", ^{ - it(@"should correctly give all pinch callbacks", ^{ - __block CGPoint pinchStartCenter; - __block CGPoint pinchMoveCenter; - __block CGFloat pinchMoveScale; - __block CGPoint pinchEndCenter; + + __block CGPoint pinchStartCenter; + __block CGPoint pinchMoveCenter; + __block CGFloat pinchMoveScale; + __block CGPoint pinchEndCenter; + + __block SDLOnTouchEvent* pinchStartFirstFingerOnTouchEvent; + __block SDLOnTouchEvent* pinchStartSecondFingerOnTouchEvent; + __block SDLOnTouchEvent* pinchMoveSecondFingerOnTouchEvent; + __block SDLOnTouchEvent* pinchEndSecondFingerOnTouchEvent; + + beforeEach(^{ + // First finger touch down + SDLTouchCoord* firstFingerTouchCoord = [[SDLTouchCoord alloc] init]; + firstFingerTouchCoord.x = @(controlPoint.x); + firstFingerTouchCoord.y = @(controlPoint.y); + + NSUInteger firstFingerTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; + + SDLTouchEvent* firstFingerTouchEvent = [[SDLTouchEvent alloc] init]; + firstFingerTouchEvent.coord = [NSMutableArray arrayWithObject:firstFingerTouchCoord]; + firstFingerTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(firstFingerTimeStamp)]; + + pinchStartFirstFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + pinchStartFirstFingerOnTouchEvent.event = [NSMutableArray arrayWithObject:firstFingerTouchEvent]; + pinchStartFirstFingerOnTouchEvent.type = SDLTouchType.BEGIN; + + // Second finger touch down + SDLTouchCoord* secondFingerTouchCoord = [[SDLTouchCoord alloc] init]; + secondFingerTouchCoord.x = @(firstFingerTouchCoord.x.floatValue + 100); + secondFingerTouchCoord.y = @(firstFingerTouchCoord.y.floatValue + 100); + + NSUInteger secondFingerTimeStamp = firstFingerTimeStamp; + SDLTouchEvent* secondFingerTouchEvent = [[SDLTouchEvent alloc] init]; + secondFingerTouchEvent.touchEventId = @1; + secondFingerTouchEvent.coord = [NSMutableArray arrayWithObject:secondFingerTouchCoord]; + secondFingerTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondFingerTimeStamp)]; + + pinchStartSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + pinchStartSecondFingerOnTouchEvent.event = [NSMutableArray arrayWithObject:secondFingerTouchEvent]; + pinchStartSecondFingerOnTouchEvent.type = SDLTouchType.BEGIN; + + pinchStartCenter = CGPointMake((firstFingerTouchCoord.x.floatValue + secondFingerTouchCoord.x.floatValue) / 2.0f, + (firstFingerTouchCoord.y.floatValue + secondFingerTouchCoord.y.floatValue) / 2.0f); + + CGFloat pinchStartDistance = hypotf(firstFingerTouchCoord.x.floatValue - secondFingerTouchCoord.x.floatValue, + firstFingerTouchCoord.y.floatValue - secondFingerTouchCoord.y.floatValue); + + // Second finger move + SDLTouchCoord* secondFingerMoveTouchCoord = [[SDLTouchCoord alloc] init]; + secondFingerMoveTouchCoord.x = @(secondFingerTouchCoord.x.floatValue - 50); + secondFingerMoveTouchCoord.y = @(secondFingerTouchCoord.y.floatValue - 40); + + NSUInteger secondFingerMoveTimeStamp = secondFingerTimeStamp + (touchManager.panTimeThreshold * 1000); + + SDLTouchEvent* secondFingerMoveTouchEvent = [[SDLTouchEvent alloc] init]; + secondFingerMoveTouchEvent.touchEventId = @1; + secondFingerMoveTouchEvent.coord = [NSMutableArray arrayWithObject:secondFingerMoveTouchCoord]; + secondFingerMoveTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondFingerMoveTimeStamp)]; + + pinchMoveSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + pinchMoveSecondFingerOnTouchEvent.event = [NSMutableArray arrayWithObject:secondFingerMoveTouchEvent]; + pinchMoveSecondFingerOnTouchEvent.type = SDLTouchType.MOVE; + + pinchMoveCenter = CGPointMake((firstFingerTouchCoord.x.floatValue + secondFingerMoveTouchCoord.x.floatValue) / 2.0f, + (firstFingerTouchCoord.y.floatValue + secondFingerMoveTouchCoord.y.floatValue) / 2.0f); + + CGFloat pinchMoveDistance = hypotf(firstFingerTouchCoord.x.floatValue - secondFingerMoveTouchCoord.x.floatValue, + firstFingerTouchCoord.y.floatValue - secondFingerMoveTouchCoord.y.floatValue); + + pinchMoveScale = pinchMoveDistance / pinchStartDistance; + + // Second finger end + SDLTouchCoord* secondFingerEndTouchCoord = secondFingerMoveTouchCoord; + + NSUInteger secondFingerEndTimeStamp = secondFingerMoveTimeStamp + (touchManager.panTimeThreshold * 1000); + + SDLTouchEvent* secondFingerEndTouchEvent = [[SDLTouchEvent alloc] init]; + secondFingerEndTouchEvent.touchEventId = @1; + secondFingerEndTouchEvent.coord = [NSMutableArray arrayWithObject:secondFingerEndTouchCoord]; + secondFingerEndTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondFingerEndTimeStamp)]; + + pinchEndSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init]; + pinchEndSecondFingerOnTouchEvent.event = [NSMutableArray arrayWithObject:secondFingerEndTouchEvent]; + pinchEndSecondFingerOnTouchEvent.type = SDLTouchType.END; + + pinchEndCenter = CGPointMake((firstFingerTouchCoord.x.floatValue + secondFingerEndTouchCoord.x.floatValue) / 2.0f, + (firstFingerTouchCoord.y.floatValue + secondFingerEndTouchCoord.y.floatValue) / 2.0f); + }); + + it(@"should correctly give all pinch callback", ^{ pinchStartTests = ^(NSInvocation* invocation) { __unsafe_unretained SDLTouchManager* touchManagerCallback; @@ -444,7 +574,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expect(@(CGPointEqualToPoint(point, pinchMoveCenter))).to(beTruthy()); expect(@(scale)).to(beCloseTo(@(pinchMoveScale)).within(0.0001)); }; - + pinchEndTests = ^(NSInvocation* invocation) { __unsafe_unretained SDLTouchManager* touchManagerCallback; @@ -456,58 +586,11 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expect(touchManagerCallback).to(equal(touchManager)); expect(@(CGPointEqualToPoint(point, pinchEndCenter))).to(beTruthy()); }; - - // Begin First Touch - performTouchEvent(touchManager, beginOnTouchEvent); - - // Begin Second Touch - SDLTouchCoord* secondTouchCoord = [[SDLTouchCoord alloc] init]; - secondTouchCoord.x = @(controlPoint.x + 100); - secondTouchCoord.y = @(controlPoint.y + 100); - - CGPoint firstPoint = CGPointMake(touchCoord.x.floatValue, touchCoord.y.floatValue); - CGPoint secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); - - pinchStartCenter = CGPointCenterOfPoints(firstPoint, secondPoint); - CGFloat pinchStartDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); - - touchEvent.touchEventId = @1; - touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - - beginOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, beginOnTouchEvent); - - - // Move Second Finger - secondTouchCoord.x = @(secondTouchCoord.x.floatValue - 30); - secondTouchCoord.y = @(secondTouchCoord.y.floatValue - 40); - - secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); - - pinchMoveCenter = CGPointCenterOfPoints(firstPoint, secondPoint); - CGFloat pinchMoveDistance = CGPointDistanceBetweenPoints(firstPoint, secondPoint); - pinchMoveScale = pinchMoveDistance / pinchStartDistance; - - timeStamp += touchManager.panTimeThreshold * 1000; - - touchEvent.touchEventId = @1; - touchEvent.coord = [NSMutableArray arrayWithObject:secondTouchCoord]; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - - moveOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, moveOnTouchEvent); - - // End First Finger - timeStamp += touchManager.panTimeThreshold * 1000; - touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; - secondPoint = CGPointMake(secondTouchCoord.x.floatValue, secondTouchCoord.y.floatValue); - - pinchEndCenter = CGPointCenterOfPoints(firstPoint, secondPoint); - - endOnTouchEvent.event = [NSMutableArray arrayWithObject:touchEvent]; - performTouchEvent(touchManager, endOnTouchEvent); + performTouchEvent(touchManager, pinchStartFirstFingerOnTouchEvent); + performTouchEvent(touchManager, pinchStartSecondFingerOnTouchEvent); + performTouchEvent(touchManager, pinchMoveSecondFingerOnTouchEvent); + performTouchEvent(touchManager, pinchEndSecondFingerOnTouchEvent); expect(@(didCallSingleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); expect(@(didCallDoubleTap)).withTimeout(touchManager.tapTimeThreshold + 0.1).toEventually(beFalsy()); From 0baeebb2b6eba28220487c17303c091d7291c249 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 12:28:06 -0700 Subject: [PATCH 25/45] Replaced structs for SDLTouch & SDLPinchGesture in favor of classes. --- SmartDeviceLink/SDLPinchGesture.h | 27 ++--- SmartDeviceLink/SDLPinchGesture.m | 84 +++++++++---- SmartDeviceLink/SDLTouch.h | 27 ++--- SmartDeviceLink/SDLTouch.m | 61 ++++++---- SmartDeviceLink/SDLTouchManager.m | 75 ++++++------ .../Touches/SDLPinchGestureSpec.m | 110 +++++++++++++----- .../UtilitiesSpecs/Touches/SDLTouchSpec.m | 54 +++++---- 7 files changed, 270 insertions(+), 168 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h index a02ae6594..c7e7cb577 100644 --- a/SmartDeviceLink/SDLPinchGesture.h +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -6,26 +6,19 @@ // Copyright © 2016 smartdevicelink. All rights reserved. // -#ifndef SDLPinchGesture_h -#define SDLPinchGesture_h +#import -#include -#include "SDLTouch.h" -#include "CGPoint_Util.h" +#import "SDLTouch.h" -typedef struct { - SDLTouch firstTouch; - SDLTouch secondTouch; - CGFloat distance; - CGPoint center; -} SDLPinchGesture; +@interface SDLPinchGesture : NSObject -extern const SDLPinchGesture SDLPinchGestureZero; +- (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch; -SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch); +@property (nonatomic, strong) SDLTouch* firstTouch; +@property (nonatomic, strong) SDLTouch* secondTouch; -SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch); +@property (nonatomic, readonly) CGFloat distance; +@property (nonatomic, readonly) CGPoint center; +@property (nonatomic, readonly) BOOL isValid; -bool SDLPinchGestureIsValid(SDLPinchGesture pinch); - -#endif /* SDLPinchGesture_h */ +@end diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index 979153310..15a65ce55 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -1,38 +1,72 @@ // -// SDLPinchGesture.c +// SDLPinchGesture.m // SmartDeviceLink-iOS // // Created by Muller, Alexander (A.) on 6/14/16. // Copyright © 2016 smartdevicelink. All rights reserved. // -#include "SDLPinchGesture.h" +#import "SDLPinchGesture.h" -SDLPinchGesture SDLPinchGestureMake(SDLTouch firstTouch, SDLTouch secondTouch) { - SDLPinchGesture pinchGesture; - pinchGesture.firstTouch = firstTouch; - pinchGesture.secondTouch = secondTouch; - pinchGesture.center = CGPointCenterOfPoints(firstTouch.location, secondTouch.location); - pinchGesture.distance = CGPointDistanceBetweenPoints(firstTouch.location, secondTouch.location); - return pinchGesture; +#import "SDLTouch.h" +#import "CGPoint_Util.h" + +@implementation SDLPinchGesture + +@synthesize distance = _distance; +@synthesize center = _center; + +- (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch { + self = [super init]; + if (self) { + _firstTouch = firstTouch; + _secondTouch = secondTouch; + _distance = -1; + _center = CGPointZero; + } + return self; } -const SDLPinchGesture SDLPinchGestureZero = {{-1, {0, 0}, 0}, {-1, {0, 0}, 0}, 0, {0, 0}}; - -SDLPinchGesture SDLPinchGestureUpdateFromTouch(SDLPinchGesture pinch, SDLTouch touch) { - switch (touch.identifier) { - case SDLTouchIdentifierFirstFinger: - return SDLPinchGestureMake(touch, pinch.secondTouch); - break; - case SDLTouchIdentifierSecondFinger: - return SDLPinchGestureMake(pinch.firstTouch, touch); - break; - default: - return SDLPinchGestureZero; - break; +#pragma mark - Setters +- (void)setFirstTouch:(SDLTouch *)firstTouch { + if (firstTouch.identifier == SDLTouchIdentifierFirstFinger) { + _firstTouch = firstTouch; + [self sdl_invalidate]; } } -bool SDLPinchGestureIsValid(SDLPinchGesture pinch) { - return SDLTouchIsValid(pinch.firstTouch) && SDLTouchIsValid(pinch.secondTouch); -} \ No newline at end of file +- (void)setSecondTouch:(SDLTouch *)secondTouch { + if (secondTouch.identifier == SDLTouchIdentifierSecondFinger) { + _secondTouch = secondTouch; + [self sdl_invalidate]; + } +} + +#pragma mark - Getters +- (CGFloat)distance { + if (_distance == -1) { + _distance = CGPointDistanceBetweenPoints(self.firstTouch.location, + self.secondTouch.location); + } + return _distance; +} + +- (CGPoint)center { + if (CGPointEqualToPoint(_center, CGPointZero)) { + _center = CGPointCenterOfPoints(self.firstTouch.location, + self.secondTouch.location); + } + return _center; +} + +- (BOOL)isValid { + return (self.firstTouch != nil) && (self.secondTouch != nil); +} + +#pragma mark - Private +- (void)sdl_invalidate { + _distance = -1; + _center = CGPointZero; +} + +@end \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index 7c220d0de..18a378853 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -6,31 +6,24 @@ // Copyright © 2016 smartdevicelink. All rights reserved. // -#ifndef SDLTouch_h -#define SDLTouch_h +#import -#include -#include - -typedef struct SDLTouch { - long identifier; - CGPoint location; - unsigned long timeStamp; -} SDLTouch; +@class SDLTouchEvent; typedef enum { SDLTouchIdentifierFirstFinger = 0, SDLTouchIdentifierSecondFinger = 1 } SDLTouchIdentifier; -extern const SDLTouch SDLTouchZero; +@interface SDLTouch : NSObject -SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp); +- (instancetype)initWithTouchEvent:(SDLTouchEvent*)touchEvent; -// Checks if SDLTouch is equal to SDLTouchZero. -bool SDLTouchIsValid(SDLTouch touch); +@property (nonatomic, readonly) NSInteger identifier; +@property (nonatomic, readonly) CGPoint location; +@property (nonatomic, readonly) NSUInteger timeStamp; -bool SDLTouchIsFirstFinger(SDLTouch touch); -bool SDLTouchIsSecondFinger(SDLTouch touch); +@property (nonatomic, readonly) BOOL isFirstFinger; +@property (nonatomic, readonly) BOOL isSecondFinger; -#endif /* SDLTouch_h */ \ No newline at end of file +@end \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index 7ca952a7c..dc8b27bf6 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -1,38 +1,57 @@ // -// SDLTouch.c +// SDLTouch.m // SmartDeviceLink-iOS // // Created by Muller, Alexander (A.) on 6/14/16. // Copyright © 2016 smartdevicelink. All rights reserved. // -#include "SDLTouch.h" +#import "SDLTouch.h" -SDLTouch const SDLTouchZero = {-1, {0, 0}, 0}; +#import "SDLTouchEvent.h" +#import "SDLTouchCoord.h" -SDLTouch SDLTouchMake(unsigned long identifier, float x, float y, unsigned long timeStamp) { - SDLTouch touch; - touch.identifier = identifier; - touch.location = CGPointMake(x, y); - touch.timeStamp = timeStamp; - return touch; +@implementation SDLTouch + +- (instancetype)init { + self = [super init]; + if (self) { + _identifier = -1; + _location = CGPointZero; + _timeStamp = 0; + } + return self; } -bool SDLTouchEqualToTouch(SDLTouch touch1, SDLTouch touch2) { - bool isEqual = (touch1.identifier == touch2.identifier); - isEqual = (isEqual && CGPointEqualToPoint(touch1.location, touch2.location)); - isEqual = (isEqual && touch1.timeStamp == touch2.timeStamp); - return isEqual; +- (instancetype)initWithTouchEvent:(SDLTouchEvent*)touchEvent { + self = [self init]; + if (self) { + _identifier = touchEvent.touchEventId.unsignedIntegerValue; + + id firstTimeStamp = touchEvent.timeStamp.firstObject; + // In the event we receive a null timestamp, we will supply a device timestamp. + if ([firstTimeStamp isKindOfClass:[NSNull class]] + && [firstTimeStamp isEqual:[NSNull null]]) { + _timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + } else { + NSNumber* timeStampNumber = (NSNumber*)firstTimeStamp; + _timeStamp = timeStampNumber.unsignedIntegerValue; + } + + SDLTouchCoord* coord = touchEvent.coord.firstObject; + _location = CGPointMake(coord.x.floatValue, + coord.y.floatValue); + } + return self; } -bool SDLTouchIsValid(SDLTouch touch) { - return SDLTouchEqualToTouch(touch, SDLTouchZero) ? false : true; +#pragma mark - Getters +- (BOOL)isFirstFinger { + return self.identifier == SDLTouchIdentifierFirstFinger; } -bool SDLTouchIsFirstFinger(SDLTouch touch) { - return touch.identifier == SDLTouchIdentifierFirstFinger ? true : false; +- (BOOL)isSecondFinger { + return self.identifier == SDLTouchIdentifierSecondFinger; } -bool SDLTouchIsSecondFinger(SDLTouch touch) { - return touch.identifier == SDLTouchIdentifierSecondFinger ? true : false; -} \ No newline at end of file +@end \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index d4683c5df..77b6cf248 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -9,6 +9,8 @@ #import "SDLTouchManager.h" #import "dispatch_timer.h" +#import "CGPoint_Util.h" + #import "SDLOnTouchEvent.h" #import "SDLPinchGesture.h" #import "SDLProxyListener.h" @@ -28,16 +30,16 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { @interface SDLTouchManager () -@property SDLTouch previousTouch; +@property SDLTouch* previousTouch; /* * Only used for caching previous single taps for double tap detection */ -@property SDLTouch singleTapTouch; +@property SDLTouch* singleTapTouch; @property CGFloat previousPinchDistance; -@property SDLPinchGesture currentPinchGesture; +@property SDLPinchGesture* currentPinchGesture; @property dispatch_source_t singleTapTimer; @@ -52,8 +54,6 @@ - (instancetype)init { _panTimeThreshold = 50.0f; _tapTimeThreshold = 0.4f; _tapDistanceThreshold = 50.0f; - _previousTouch = SDLTouchZero; - _singleTapTouch = SDLTouchZero; _touchEnabled = YES; } return self; @@ -71,27 +71,13 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { } SDLTouchEvent* touchEvent = notification.event.firstObject; - NSUInteger touchEventID = touchEvent.touchEventId.unsignedIntegerValue; - if (touchEventID > kMaximumNumberOfTouches) { - return; - } + SDLTouch* touch = [[SDLTouch alloc] initWithTouchEvent:touchEvent]; - SDLTouchCoord* coord = touchEvent.coord.firstObject; - - NSNumber* timeStampNumber = touchEvent.timeStamp.firstObject; - NSUInteger timeStamp; - // In the event we receive a null timestamp, we will supply a device timestamp. - if (timeStampNumber != [NSNull null]) { - timeStamp = timeStampNumber.unsignedIntegerValue; - } else { - timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + if (touch.identifier > kMaximumNumberOfTouches) { + return; } - SDLTouch touch = SDLTouchMake(touchEventID, - coord.x.floatValue, - coord.y.floatValue, - timeStamp); if ([notification.type isEqualToEnum:SDLTouchType.BEGIN]) { [self sdl_handleBeginTouch:touch]; } else if ([notification.type isEqualToEnum:SDLTouchType.MOVE]) { @@ -102,8 +88,8 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { } #pragma mark - Private -- (void)sdl_handleBeginTouch:(SDLTouch)touch { - if (!SDLTouchIsFirstFinger(touch) +- (void)sdl_handleBeginTouch:(SDLTouch*)touch { + if (!touch.isFirstFinger && !self.isTouchEnabled) { return; // no-op } @@ -116,7 +102,8 @@ - (void)sdl_handleBeginTouch:(SDLTouch)touch { break; case SDLTouchIdentifierSecondFinger: _performingTouchType = SDLPerformingTouchTypeMultiTouch; - self.currentPinchGesture = SDLPinchGestureMake(self.previousTouch, touch); + self.currentPinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:self.previousTouch + secondTouch:touch]; self.previousPinchDistance = self.currentPinchGesture.distance; if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidStartAtCenterPoint:)]) { [self.touchEventListener touchManager:self @@ -126,7 +113,7 @@ - (void)sdl_handleBeginTouch:(SDLTouch)touch { } } -- (void)sdl_handleMovedTouch:(SDLTouch)touch { +- (void)sdl_handleMovedTouch:(SDLTouch*)touch { if ((touch.timeStamp - self.previousTouch.timeStamp) <= self.panTimeThreshold || !self.isTouchEnabled) { return; // no-op @@ -134,7 +121,15 @@ - (void)sdl_handleMovedTouch:(SDLTouch)touch { switch (self.performingTouchType) { case SDLPerformingTouchTypeMultiTouch: - self.currentPinchGesture = SDLPinchGestureUpdateFromTouch(self.currentPinchGesture, touch); + switch (touch.identifier) { + case SDLTouchIdentifierFirstFinger: + self.currentPinchGesture.firstTouch = touch; + break; + case SDLTouchIdentifierSecondFinger: + self.currentPinchGesture.secondTouch = touch; + break; + } + if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) { CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance; @@ -165,21 +160,28 @@ - (void)sdl_handleMovedTouch:(SDLTouch)touch { self.previousTouch = touch; } -- (void)sdl_handleEndTouch:(SDLTouch)touch { +- (void)sdl_handleEndTouch:(SDLTouch*)touch { if (!self.isTouchEnabled) { return; // no-op } switch (self.performingTouchType) { case SDLPerformingTouchTypeMultiTouch: - self.currentPinchGesture = SDLPinchGestureUpdateFromTouch(self.currentPinchGesture, touch); + switch (touch.identifier) { + case SDLTouchIdentifierFirstFinger: + self.currentPinchGesture.firstTouch = touch; + break; + case SDLTouchIdentifierSecondFinger: + self.currentPinchGesture.secondTouch = touch; + break; + } - if (SDLPinchGestureIsValid(self.currentPinchGesture)) { + if (self.currentPinchGesture.isValid) { if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidEndAtCenterPoint:)]) { [self.touchEventListener touchManager:self pinchDidEndAtCenterPoint:self.currentPinchGesture.center]; } - self.currentPinchGesture = SDLPinchGestureZero; + self.currentPinchGesture = nil; } break; case SDLPerformingTouchTypePanningTouch: @@ -189,7 +191,7 @@ - (void)sdl_handleEndTouch:(SDLTouch)touch { } break; case SDLPerformingTouchTypeSingleTouch: - if (!SDLTouchIsValid(self.singleTapTouch)) { // Initial Tap + if (self.singleTapTimer == nil) { // Initial Tap self.singleTapTouch = touch; [self sdl_initializeSingleTapTimerAtPoint:self.singleTapTouch.location]; } else { // Double Tap @@ -209,14 +211,14 @@ - (void)sdl_handleEndTouch:(SDLTouch)touch { didReceiveDoubleTapAtPoint:averagePoint]; } } - - self.singleTapTouch = SDLTouchZero; + + self.singleTapTouch = nil; } break; case SDLPerformingTouchTypeNone: break; } - self.previousTouch = SDLTouchZero; + self.previousTouch = nil; _performingTouchType = SDLPerformingTouchTypeNone; } @@ -224,13 +226,12 @@ - (void)sdl_initializeSingleTapTimerAtPoint:(CGPoint)point { __weak typeof(self) weakSelf = self; self.singleTapTimer = dispatch_create_timer(self.tapTimeThreshold, NO, ^{ typeof(weakSelf) strongSelf = weakSelf; - strongSelf.singleTapTouch = SDLTouchZero; + strongSelf.singleTapTouch = nil; if ([strongSelf.touchEventListener respondsToSelector:@selector(touchManager:didReceiveSingleTapAtPoint:)]) { [strongSelf.touchEventListener touchManager:strongSelf didReceiveSingleTapAtPoint:point]; } }); - } - (void)sdl_cancelSingleTapTimer { diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m index 1a41b537d..99293ac8c 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLPinchGestureSpec.m @@ -13,41 +13,57 @@ #import #import "SDLPinchGesture.h" +#import "SDLTouchCoord.h" +#import "SDLTouchEvent.h" QuickSpecBegin(SDLPinchGestureSpec) describe(@"SDLPinchGesture Tests", ^{ context(@"SDLPinchGestureZero", ^{ - __block SDLPinchGesture pinchGesture = SDLPinchGestureZero; + __block SDLPinchGesture* pinchGesture = [[SDLPinchGesture alloc] init];; it(@"should correctly initialize", ^{ - expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(-1))); - expect(@(pinchGesture.firstTouch.location.x)).to(equal(@0)); - expect(@(pinchGesture.firstTouch.location.y)).to(equal(@0)); - expect(@(pinchGesture.firstTouch.timeStamp)).to(equal(@0)); - - expect(@(pinchGesture.secondTouch.identifier)).to(equal(@(-1))); - expect(@(pinchGesture.secondTouch.location.x)).to(equal(@0)); - expect(@(pinchGesture.secondTouch.location.y)).to(equal(@0)); - expect(@(pinchGesture.secondTouch.timeStamp)).to(equal(@0)); + expect(pinchGesture.firstTouch).to(beNil()); + expect(pinchGesture.secondTouch).to(beNil()); + expect(@(pinchGesture.distance)).to(equal(@0)); + expect(@(CGPointEqualToPoint(pinchGesture.center, CGPointZero))).to(beTruthy()); }); it(@"should not be a valid SDLPinchGesture", ^{ - expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beFalsy()); + expect(@(pinchGesture.isValid)).to(beFalsy()); }); }); context(@"SDLPinchGestureMake", ^{ - __block SDLPinchGesture pinchGesture; - __block SDLTouch firstTouch; - __block SDLTouch secondTouch; + __block SDLPinchGesture* pinchGesture; __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; __block unsigned long secondTimeStamp = timeStamp + 1000; beforeEach(^{ - firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); - secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); - pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + SDLTouchCoord* firstCoord = [[SDLTouchCoord alloc] init]; + firstCoord.x = @100; + firstCoord.y = @200; + + SDLTouchEvent* firstTouchEvent = [[SDLTouchEvent alloc] init]; + firstTouchEvent.touchEventId = @0; + firstTouchEvent.coord = [NSMutableArray arrayWithObject:firstCoord]; + firstTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + SDLTouch* firstTouch = [[SDLTouch alloc] initWithTouchEvent:firstTouchEvent]; + + SDLTouchCoord* secondCoord = [[SDLTouchCoord alloc] init]; + secondCoord.x = @200; + secondCoord.y = @300; + + SDLTouchEvent* secondTouchEvent = [[SDLTouchEvent alloc] init]; + secondTouchEvent.touchEventId = @1; + secondTouchEvent.coord = [NSMutableArray arrayWithObject:secondCoord]; + secondTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondTimeStamp)]; + + SDLTouch* secondTouch = [[SDLTouch alloc] initWithTouchEvent:secondTouchEvent]; + + pinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:firstTouch + secondTouch:secondTouch]; }); it(@"should correctly initialize", ^{ @@ -67,25 +83,65 @@ }); it(@"should be a valid SDLPinchGesture", ^{ - expect(@(SDLPinchGestureIsValid(pinchGesture))).to(beTruthy()); + expect(@(pinchGesture.isValid)).to(beTruthy()); }); }); context(@"updating SDLPinchGesture", ^{ - __block SDLPinchGesture pinchGesture; + __block SDLPinchGesture* pinchGesture; __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; __block unsigned long secondTimeStamp = timeStamp + 1000; + __block unsigned long newTimeStamp = timeStamp + 1000; + + __block SDLTouch* newFirstTouch; + __block SDLTouch* newSecondTouch; beforeEach(^{ - SDLTouch firstTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 100, 200, timeStamp); - SDLTouch secondTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 200, 300, secondTimeStamp); - pinchGesture = SDLPinchGestureMake(firstTouch, secondTouch); + SDLTouchCoord* firstCoord = [[SDLTouchCoord alloc] init]; + firstCoord.x = @100; + firstCoord.y = @200; + + SDLTouchEvent* firstTouchEvent = [[SDLTouchEvent alloc] init]; + firstTouchEvent.touchEventId = @0; + firstTouchEvent.coord = [NSMutableArray arrayWithObject:firstCoord]; + firstTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + SDLTouch* firstTouch = [[SDLTouch alloc] initWithTouchEvent:firstTouchEvent]; + + SDLTouchCoord* secondCoord = [[SDLTouchCoord alloc] init]; + secondCoord.x = @200; + secondCoord.y = @300; + + SDLTouchEvent* secondTouchEvent = [[SDLTouchEvent alloc] init]; + secondTouchEvent.touchEventId = @1; + secondTouchEvent.coord = [NSMutableArray arrayWithObject:secondCoord]; + secondTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(secondTimeStamp)]; + + SDLTouch* secondTouch = [[SDLTouch alloc] initWithTouchEvent:secondTouchEvent]; + + pinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:firstTouch + secondTouch:secondTouch]; + + SDLTouchCoord* newCoord = [[SDLTouchCoord alloc] init]; + newCoord.x = @150; + newCoord.y = @250; + + SDLTouchEvent* newFirstTouchEvent = [[SDLTouchEvent alloc] init]; + newFirstTouchEvent.touchEventId = @0; + newFirstTouchEvent.coord = [NSMutableArray arrayWithObject:newCoord]; + newFirstTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(newTimeStamp)]; + + SDLTouchEvent* newSecondTouchEvent = [[SDLTouchEvent alloc] init]; + newSecondTouchEvent.touchEventId = @1; + newSecondTouchEvent.coord = [NSMutableArray arrayWithObject:newCoord]; + newSecondTouchEvent.timeStamp = [NSMutableArray arrayWithObject:@(newTimeStamp)]; + + newFirstTouch = [[SDLTouch alloc] initWithTouchEvent:newFirstTouchEvent]; + newSecondTouch = [[SDLTouch alloc] initWithTouchEvent:newSecondTouchEvent]; }); it(@"should update first point correctly", ^{ - unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierFirstFinger, 150, 250, newTimeStamp); - pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + pinchGesture.firstTouch = newFirstTouch; expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); expect(@(pinchGesture.firstTouch.location.x)).to(equal(@150)); @@ -104,9 +160,7 @@ }); it(@"should update second point correctly", ^{ - unsigned long newTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - SDLTouch newTouch = SDLTouchMake(SDLTouchIdentifierSecondFinger, 150, 250, newTimeStamp); - pinchGesture = SDLPinchGestureUpdateFromTouch(pinchGesture, newTouch); + pinchGesture.secondTouch = newSecondTouch; expect(@(pinchGesture.firstTouch.identifier)).to(equal(@(SDLTouchIdentifierFirstFinger))); expect(@(pinchGesture.firstTouch.location.x)).to(equal(@100)); diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m index 4831f7d3c..c629cd72e 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchSpec.m @@ -12,13 +12,15 @@ #import #import +#import "SDLTouchEvent.h" +#import "SDLTouchCoord.h" #import "SDLTouch.h" QuickSpecBegin(SDLTouchSpec) describe(@"SDLTouch Tests", ^{ context(@"SDLTouchZero", ^{ - __block SDLTouch touch = SDLTouchZero; + __block SDLTouch* touch = [[SDLTouch alloc] init]; it(@"should correctly initialize", ^{ expect(@(touch.identifier)).to(equal(@(-1))); @@ -26,25 +28,30 @@ expect(@(touch.timeStamp)).to(equal(@0)); }); - it(@"should not be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beFalsy()); - }); - it(@"should not equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + expect(@(touch.isFirstFinger)).to(beFalsy()); }); it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + expect(@(touch.isSecondFinger)).to(beFalsy()); }); }); context(@"For First Finger Identifiers", ^{ __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block SDLTouch touch; + __block SDLTouch* touch; beforeSuite(^{ - touch = SDLTouchMake(0, 100, 200, timeStamp); + SDLTouchCoord* coord = [[SDLTouchCoord alloc] init]; + coord.x = @100; + coord.y = @200; + + SDLTouchEvent* touchEvent = [[SDLTouchEvent alloc] init]; + touchEvent.touchEventId = @0; + touchEvent.coord = [NSMutableArray arrayWithObject:coord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + touch = [[SDLTouch alloc] initWithTouchEvent:touchEvent]; }); it(@"should correctly make a SDLTouch struct", ^{ @@ -54,25 +61,30 @@ expect(@(touch.timeStamp)).to(equal(@(timeStamp))); }); - it(@"should be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beTruthy()); - }); - it(@"should equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beTruthy()); + expect(@(touch.isFirstFinger)).to(beTruthy()); }); it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beFalsy()); + expect(@(touch.isSecondFinger)).to(beFalsy()); }); }); context(@"For Second Finger Identifiers", ^{ __block unsigned long timeStamp = [[NSDate date] timeIntervalSince1970] * 1000; - __block SDLTouch touch; + __block SDLTouch* touch; beforeSuite(^{ - touch = SDLTouchMake(1, 100, 200, timeStamp); + SDLTouchCoord* coord = [[SDLTouchCoord alloc] init]; + coord.x = @100; + coord.y = @200; + + SDLTouchEvent* touchEvent = [[SDLTouchEvent alloc] init]; + touchEvent.touchEventId = @1; + touchEvent.coord = [NSMutableArray arrayWithObject:coord]; + touchEvent.timeStamp = [NSMutableArray arrayWithObject:@(timeStamp)]; + + touch = [[SDLTouch alloc] initWithTouchEvent:touchEvent]; }); it(@"should correctly make a SDLTouch struct", ^{ @@ -82,16 +94,12 @@ expect(@(touch.timeStamp)).to(equal(@(timeStamp))); }); - it(@"should be a valid SDLTouch", ^{ - expect(@(SDLTouchIsValid(touch))).to(beTruthy()); - }); - it(@"should equal First Finger Identifier", ^{ - expect(@(SDLTouchIsFirstFinger(touch))).to(beFalsy()); + expect(@(touch.isFirstFinger)).to(beFalsy()); }); it(@"should not equal Second Finger Identifier", ^{ - expect(@(SDLTouchIsSecondFinger(touch))).to(beTruthy()); + expect(@(touch.isSecondFinger)).to(beTruthy()); }); }); }); From 83d93f65cf0f4efcd5fabafda631d221f053f99a Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 12:38:59 -0700 Subject: [PATCH 26/45] Removed "k" from internal constant. --- SmartDeviceLink/SDLTouchManager.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 77b6cf248..e733dc5f3 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -26,7 +26,7 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { SDLPerformingTouchTypePanningTouch }; -static NSUInteger const kMaximumNumberOfTouches = 2; +static NSUInteger const MaximumNumberOfTouches = 2; @interface SDLTouchManager () @@ -73,8 +73,8 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { SDLTouchEvent* touchEvent = notification.event.firstObject; SDLTouch* touch = [[SDLTouch alloc] initWithTouchEvent:touchEvent]; - - if (touch.identifier > kMaximumNumberOfTouches) { + + if (touch.identifier > MaximumNumberOfTouches) { return; } From a4dc92e83cb73ff0b9e2408ccae5caa47ae8706c Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 13:07:17 -0700 Subject: [PATCH 27/45] Updated panTimeThreshold to seconds instead of milliseconds. Also renamed to movementTimeThreshold. --- SmartDeviceLink/SDLTouchManager.h | 4 ++-- SmartDeviceLink/SDLTouchManager.m | 4 ++-- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 78bbca3cb..f476b3314 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -24,9 +24,9 @@ @property (nonatomic) CGFloat tapTimeThreshold; /* - * Time between pan events (in milliseconds). + * Time between pan events (in seconds). */ -@property (nonatomic) CGFloat panTimeThreshold; +@property (nonatomic) CGFloat movementTimeThreshold; @property (nonatomic, getter=isTouchEnabled) BOOL touchEnabled; diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index e733dc5f3..e86b6fff2 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -51,7 +51,7 @@ @implementation SDLTouchManager - (instancetype)init { if (self = [super init]) { - _panTimeThreshold = 50.0f; + _movementTimeThreshold = 0.5f; _tapTimeThreshold = 0.4f; _tapDistanceThreshold = 50.0f; _touchEnabled = YES; @@ -114,7 +114,7 @@ - (void)sdl_handleBeginTouch:(SDLTouch*)touch { } - (void)sdl_handleMovedTouch:(SDLTouch*)touch { - if ((touch.timeStamp - self.previousTouch.timeStamp) <= self.panTimeThreshold + if ((touch.timeStamp - self.previousTouch.timeStamp) <= (self.movementTimeThreshold * NSEC_PER_USEC) || !self.isTouchEnabled) { return; // no-op } diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index e7125fca1..d00b3768c 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -31,7 +31,7 @@ expect(touchManager.touchEventListener).to(beNil()); expect(@(touchManager.tapDistanceThreshold)).to(equal(@50)); expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001)); - expect(@(touchManager.panTimeThreshold)).to(equal(@50)); + expect(@(touchManager.movementTimeThreshold)).to(beCloseTo(@0.5).within(0.0001)); expect(@(touchManager.isTouchEnabled)).to(beTruthy()); }); @@ -337,7 +337,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panStartTouchCoord.x = @(panStartPoint.x); panStartTouchCoord.y = @(panStartPoint.y); - NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] + touchManager.panTimeThreshold) * 1000; + NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] + ((touchManager.movementTimeThreshold + .1) * 1000)) * 1000; SDLTouchEvent* panStartTouchEvent = [[SDLTouchEvent alloc] init]; panStartTouchEvent.coord = [NSMutableArray arrayWithObject:panStartTouchCoord]; @@ -354,7 +354,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panMoveTouchCoord.x = @(panMovePoint.x); panMoveTouchCoord.y = @(panMovePoint.y); - NSUInteger panMoveTimeStamp = panStartTimeStamp + (touchManager.panTimeThreshold * 1000); + NSUInteger panMoveTimeStamp = panStartTimeStamp + (touchManager.movementTimeThreshold * 1000); SDLTouchEvent* panMoveTouchEvent = [[SDLTouchEvent alloc] init]; panMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panMoveTouchCoord]; @@ -371,7 +371,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panSecondMoveTouchCoord.x = @(panSecondMovePoint.x); panSecondMoveTouchCoord.y = @(panSecondMovePoint.y); - NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + (touchManager.panTimeThreshold * 1000); + NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + (touchManager.movementTimeThreshold * 1000); SDLTouchEvent* panSecondMoveTouchEvent = [[SDLTouchEvent alloc] init]; panSecondMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panSecondMoveTouchCoord]; @@ -388,7 +388,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panEndTouchCoord.x = @(panEndPoint.x); panEndTouchCoord.y = @(panEndPoint.y); - NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + (touchManager.panTimeThreshold * 1000); + NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + (touchManager.movementTimeThreshold * 1000); SDLTouchEvent* panEndTouchEvent = [[SDLTouchEvent alloc] init]; panEndTouchEvent.coord = [NSMutableArray arrayWithObject:panEndTouchCoord]; @@ -510,7 +510,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent secondFingerMoveTouchCoord.x = @(secondFingerTouchCoord.x.floatValue - 50); secondFingerMoveTouchCoord.y = @(secondFingerTouchCoord.y.floatValue - 40); - NSUInteger secondFingerMoveTimeStamp = secondFingerTimeStamp + (touchManager.panTimeThreshold * 1000); + NSUInteger secondFingerMoveTimeStamp = secondFingerTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000); SDLTouchEvent* secondFingerMoveTouchEvent = [[SDLTouchEvent alloc] init]; secondFingerMoveTouchEvent.touchEventId = @1; @@ -532,7 +532,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent // Second finger end SDLTouchCoord* secondFingerEndTouchCoord = secondFingerMoveTouchCoord; - NSUInteger secondFingerEndTimeStamp = secondFingerMoveTimeStamp + (touchManager.panTimeThreshold * 1000); + NSUInteger secondFingerEndTimeStamp = secondFingerMoveTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000); SDLTouchEvent* secondFingerEndTouchEvent = [[SDLTouchEvent alloc] init]; secondFingerEndTouchEvent.touchEventId = @1; From e7b94812725855e03f39fb39dc19972cb60d1c44 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 14:27:02 -0700 Subject: [PATCH 28/45] Updated inits to avoid right shift. --- SmartDeviceLink/SDLPinchGesture.m | 13 ++++++++----- SmartDeviceLink/SDLTouch.m | 11 +++++++---- SmartDeviceLink/SDLTouchManager.m | 14 +++++++++----- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index 15a65ce55..6d1bd959b 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -18,12 +18,15 @@ @implementation SDLPinchGesture - (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch { self = [super init]; - if (self) { - _firstTouch = firstTouch; - _secondTouch = secondTouch; - _distance = -1; - _center = CGPointZero; + if (!self) { + return nil; } + + _firstTouch = firstTouch; + _secondTouch = secondTouch; + _distance = -1; + _center = CGPointZero; + return self; } diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index dc8b27bf6..b4b198458 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -15,11 +15,14 @@ @implementation SDLTouch - (instancetype)init { self = [super init]; - if (self) { - _identifier = -1; - _location = CGPointZero; - _timeStamp = 0; + if (!self) { + return nil; } + + _identifier = -1; + _location = CGPointZero; + _timeStamp = 0; + return self; } diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index e86b6fff2..839a5433a 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -50,12 +50,16 @@ @interface SDLTouchManager () @implementation SDLTouchManager - (instancetype)init { - if (self = [super init]) { - _movementTimeThreshold = 0.5f; - _tapTimeThreshold = 0.4f; - _tapDistanceThreshold = 50.0f; - _touchEnabled = YES; + self = [super init]; + if (!self) { + return nil; } + + _movementTimeThreshold = 0.5f; + _tapTimeThreshold = 0.4f; + _tapDistanceThreshold = 50.0f; + _touchEnabled = YES; + return self; } From c3dfc9818c1bdd8bac4e54c870a03c9e7fe3e204 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 14:49:07 -0700 Subject: [PATCH 29/45] Fixed issue causing Panning tests to sometimes fail. --- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index d00b3768c..f19c83b20 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -354,7 +354,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panMoveTouchCoord.x = @(panMovePoint.x); panMoveTouchCoord.y = @(panMovePoint.y); - NSUInteger panMoveTimeStamp = panStartTimeStamp + (touchManager.movementTimeThreshold * 1000); + NSUInteger panMoveTimeStamp = panStartTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); SDLTouchEvent* panMoveTouchEvent = [[SDLTouchEvent alloc] init]; panMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panMoveTouchCoord]; @@ -371,7 +371,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panSecondMoveTouchCoord.x = @(panSecondMovePoint.x); panSecondMoveTouchCoord.y = @(panSecondMovePoint.y); - NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + (touchManager.movementTimeThreshold * 1000); + NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); SDLTouchEvent* panSecondMoveTouchEvent = [[SDLTouchEvent alloc] init]; panSecondMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panSecondMoveTouchCoord]; @@ -388,7 +388,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panEndTouchCoord.x = @(panEndPoint.x); panEndTouchCoord.y = @(panEndPoint.y); - NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + (touchManager.movementTimeThreshold * 1000); + NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); SDLTouchEvent* panEndTouchEvent = [[SDLTouchEvent alloc] init]; panEndTouchEvent.coord = [NSMutableArray arrayWithObject:panEndTouchCoord]; From 1ed1b8e331969d122def61e681dcbd54321493ba Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 14:52:37 -0700 Subject: [PATCH 30/45] Added missing non-null audited regions. Updated all properties to contain necessary attributes. --- SmartDeviceLink/SDLPinchGesture.h | 14 +++++++++----- SmartDeviceLink/SDLPinchGesture.m | 6 +++++- SmartDeviceLink/SDLTouch.h | 16 ++++++++++------ SmartDeviceLink/SDLTouch.m | 6 +++++- SmartDeviceLink/SDLTouchManager.h | 14 +++++++++----- SmartDeviceLink/SDLTouchManager.m | 16 ++++++++++------ SmartDeviceLink/SDLTouchManagerListener.h | 4 ++++ 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h index c7e7cb577..69ffec09a 100644 --- a/SmartDeviceLink/SDLPinchGesture.h +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -10,15 +10,19 @@ #import "SDLTouch.h" +NS_ASSUME_NONNULL_BEGIN + @interface SDLPinchGesture : NSObject - (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch; -@property (nonatomic, strong) SDLTouch* firstTouch; -@property (nonatomic, strong) SDLTouch* secondTouch; +@property (nonatomic, copy) SDLTouch* firstTouch; +@property (nonatomic, copy) SDLTouch* secondTouch; -@property (nonatomic, readonly) CGFloat distance; -@property (nonatomic, readonly) CGPoint center; -@property (nonatomic, readonly) BOOL isValid; +@property (nonatomic, assign, readonly) CGFloat distance; +@property (nonatomic, assign, readonly) CGPoint center; +@property (nonatomic, assign, readonly) BOOL isValid; @end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLPinchGesture.m b/SmartDeviceLink/SDLPinchGesture.m index 6d1bd959b..3e522f8dd 100644 --- a/SmartDeviceLink/SDLPinchGesture.m +++ b/SmartDeviceLink/SDLPinchGesture.m @@ -11,6 +11,8 @@ #import "SDLTouch.h" #import "CGPoint_Util.h" +NS_ASSUME_NONNULL_BEGIN + @implementation SDLPinchGesture @synthesize distance = _distance; @@ -72,4 +74,6 @@ - (void)sdl_invalidate { _center = CGPointZero; } -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index 18a378853..4d5553eb6 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -15,15 +15,19 @@ typedef enum { SDLTouchIdentifierSecondFinger = 1 } SDLTouchIdentifier; +NS_ASSUME_NONNULL_BEGIN + @interface SDLTouch : NSObject - (instancetype)initWithTouchEvent:(SDLTouchEvent*)touchEvent; -@property (nonatomic, readonly) NSInteger identifier; -@property (nonatomic, readonly) CGPoint location; -@property (nonatomic, readonly) NSUInteger timeStamp; +@property (nonatomic, assign, readonly) NSInteger identifier; +@property (nonatomic, assign, readonly) CGPoint location; +@property (nonatomic, assign, readonly) NSUInteger timeStamp; + +@property (nonatomic, assign, readonly) BOOL isFirstFinger; +@property (nonatomic, assign, readonly) BOOL isSecondFinger; -@property (nonatomic, readonly) BOOL isFirstFinger; -@property (nonatomic, readonly) BOOL isSecondFinger; +@end -@end \ No newline at end of file +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouch.m b/SmartDeviceLink/SDLTouch.m index b4b198458..2481ee69a 100644 --- a/SmartDeviceLink/SDLTouch.m +++ b/SmartDeviceLink/SDLTouch.m @@ -11,6 +11,8 @@ #import "SDLTouchEvent.h" #import "SDLTouchCoord.h" +NS_ASSUME_NONNULL_BEGIN + @implementation SDLTouch - (instancetype)init { @@ -57,4 +59,6 @@ - (BOOL)isSecondFinger { return self.identifier == SDLTouchIdentifierSecondFinger; } -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index f476b3314..6377a2022 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -9,25 +9,29 @@ #import #import "SDLTouchManagerListener.h" +NS_ASSUME_NONNULL_BEGIN + @interface SDLTouchManager : NSObject -@property (nonatomic, weak) id touchEventListener; +@property (nonatomic, weak, nullable) id touchEventListener; /* * Distance between taps. */ -@property (nonatomic) CGFloat tapDistanceThreshold; +@property (nonatomic, assign) CGFloat tapDistanceThreshold; /* * Duration between taps (in seconds). */ -@property (nonatomic) CGFloat tapTimeThreshold; +@property (nonatomic, assign) CGFloat tapTimeThreshold; /* * Time between pan events (in seconds). */ -@property (nonatomic) CGFloat movementTimeThreshold; +@property (nonatomic, assign) CGFloat movementTimeThreshold; -@property (nonatomic, getter=isTouchEnabled) BOOL touchEnabled; +@property (nonatomic, assign, getter=isTouchEnabled) BOOL touchEnabled; @end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 839a5433a..3cd5ab989 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -19,6 +19,8 @@ #import "SDLTouchEvent.h" #import "SDLTouchType.h" +NS_ASSUME_NONNULL_BEGIN + typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { SDLPerformingTouchTypeNone, SDLPerformingTouchTypeSingleTouch, @@ -30,20 +32,20 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { @interface SDLTouchManager () -@property SDLTouch* previousTouch; +@property (nonatomic, strong, nullable) SDLTouch* previousTouch; /* * Only used for caching previous single taps for double tap detection */ -@property SDLTouch* singleTapTouch; +@property (nonatomic, strong, nullable) SDLTouch* singleTapTouch; -@property CGFloat previousPinchDistance; +@property (nonatomic, assign) CGFloat previousPinchDistance; -@property SDLPinchGesture* currentPinchGesture; +@property (nonatomic, strong, nullable) SDLPinchGesture* currentPinchGesture; -@property dispatch_source_t singleTapTimer; +@property (nonatomic, strong, nullable) dispatch_source_t singleTapTimer; -@property SDLPerformingTouchType performingTouchType; +@property (nonatomic, assign) SDLPerformingTouchType performingTouchType; @end @@ -244,3 +246,5 @@ - (void)sdl_cancelSingleTapTimer { } @end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManagerListener.h b/SmartDeviceLink/SDLTouchManagerListener.h index bb911a870..5d8ab95bf 100644 --- a/SmartDeviceLink/SDLTouchManagerListener.h +++ b/SmartDeviceLink/SDLTouchManagerListener.h @@ -8,6 +8,8 @@ @class SDLTouchManager; +NS_ASSUME_NONNULL_BEGIN + @protocol SDLTouchManagerListener @optional @@ -23,3 +25,5 @@ - (void)touchManager:(SDLTouchManager*)manager pinchDidEndAtCenterPoint:(CGPoint)point; @end + +NS_ASSUME_NONNULL_END \ No newline at end of file From 4c7fc6736d262513c4bf428e43ed4fd0f0050afc Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 15:17:33 -0700 Subject: [PATCH 31/45] Removed duplicate function. --- SmartDeviceLink/CGPoint_Util.h | 1 - SmartDeviceLink/CGPoint_Util.m | 6 ------ SmartDeviceLink/SDLTouchManager.m | 6 +++--- .../UtilitiesSpecs/Touches/CGPointUtilSpec.m | 15 --------------- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/SmartDeviceLink/CGPoint_Util.h b/SmartDeviceLink/CGPoint_Util.h index 44b247b54..c960c3bb5 100644 --- a/SmartDeviceLink/CGPoint_Util.h +++ b/SmartDeviceLink/CGPoint_Util.h @@ -12,7 +12,6 @@ #include #include -CGPoint CGPointAverageOfPoints(CGPoint point1, CGPoint point2); CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2); CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2); CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2); diff --git a/SmartDeviceLink/CGPoint_Util.m b/SmartDeviceLink/CGPoint_Util.m index d6f1743eb..5df92d5d0 100644 --- a/SmartDeviceLink/CGPoint_Util.m +++ b/SmartDeviceLink/CGPoint_Util.m @@ -9,12 +9,6 @@ #include "CGPoint_Util.h" #include "math.h" -CGPoint CGPointAverageOfPoints(CGPoint point1, CGPoint point2) { - CGFloat xAverage = (point1.x + point2.x)/2.0f; - CGFloat yAverage = (point1.y + point2.y)/2.0f; - return CGPointMake(xAverage, yAverage); -} - CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2) { CGFloat xCenter = (point1.x + point2.x) / 2.0f; CGFloat yCenter = (point1.y + point2.y) / 2.0f; diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 3cd5ab989..01d024bdb 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -210,11 +210,11 @@ - (void)sdl_handleEndTouch:(SDLTouch*)touch { if (timeStampDelta <= self.tapTimeThreshold * NSEC_PER_USEC && xDelta <= self.tapDistanceThreshold && yDelta <= self.tapDistanceThreshold) { - CGPoint averagePoint = CGPointAverageOfPoints(touch.location, - self.singleTapTouch.location); + CGPoint centerPoint = CGPointCenterOfPoints(touch.location, + self.singleTapTouch.location); if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceiveDoubleTapAtPoint:)]) { [self.touchEventListener touchManager:self - didReceiveDoubleTapAtPoint:averagePoint]; + didReceiveDoubleTapAtPoint:centerPoint]; } } diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m index a58419ee3..c39e8c6b6 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m @@ -25,11 +25,6 @@ second = CGPointMake(300, 400); }); - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@200)); - expect(@(average.y)).to(equal(@300)); - }); it(@"should properly calculate the center between points", ^{ CGPoint center = CGPointCenterOfPoints(first, second); expect(@(center.x)).to(equal(@200)); @@ -51,11 +46,6 @@ second = CGPointMake(-300, -400); }); - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@(-200))); - expect(@(average.y)).to(equal(@(-300))); - }); it(@"should properly calculate the center between points", ^{ CGPoint center = CGPointCenterOfPoints(first, second); expect(@(center.x)).to(equal(@(-200))); @@ -77,11 +67,6 @@ second = CGPointMake(-300, -400); }); - it(@"should properly calculate the average between points", ^{ - CGPoint average = CGPointAverageOfPoints(first, second); - expect(@(average.x)).to(equal(@(-100))); - expect(@(average.y)).to(equal(@(-100))); - }); it(@"should properly calculate the center between points", ^{ CGPoint center = CGPointCenterOfPoints(first, second); expect(@(center.x)).to(equal(@(-100))); From 469648112a3950277c77d47b77be15ef5b4f4238 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 15:22:42 -0700 Subject: [PATCH 32/45] Removed unneeded function. --- SmartDeviceLink/CGPoint_Util.h | 1 - SmartDeviceLink/CGPoint_Util.m | 6 ------ .../UtilitiesSpecs/Touches/CGPointUtilSpec.m | 15 --------------- 3 files changed, 22 deletions(-) diff --git a/SmartDeviceLink/CGPoint_Util.h b/SmartDeviceLink/CGPoint_Util.h index c960c3bb5..8b5815e0f 100644 --- a/SmartDeviceLink/CGPoint_Util.h +++ b/SmartDeviceLink/CGPoint_Util.h @@ -13,7 +13,6 @@ #include CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2); -CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2); CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2); #endif /* CGPoint_Util_h */ diff --git a/SmartDeviceLink/CGPoint_Util.m b/SmartDeviceLink/CGPoint_Util.m index 5df92d5d0..67be5c9fc 100644 --- a/SmartDeviceLink/CGPoint_Util.m +++ b/SmartDeviceLink/CGPoint_Util.m @@ -15,12 +15,6 @@ CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2) { return CGPointMake(xCenter, yCenter); } -CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2) { - CGFloat xDisplacement = point1.x - point2.x; - CGFloat yDisplacement = point1.y - point2.y; - return CGPointMake(xDisplacement, yDisplacement); -} - CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2) { return hypotf(point1.x - point2.x, point1.y - point2.y); } \ No newline at end of file diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m index c39e8c6b6..f4c227291 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m @@ -30,11 +30,6 @@ expect(@(center.x)).to(equal(@200)); expect(@(center.y)).to(equal(@300)); }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@(-200))); - expect(@(displacement.y)).to(equal(@(-200))); - }); it(@"should properly calculate the distance between points", ^{ CGFloat distance = CGPointDistanceBetweenPoints(first, second); expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); @@ -51,11 +46,6 @@ expect(@(center.x)).to(equal(@(-200))); expect(@(center.y)).to(equal(@(-300))); }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@200)); - expect(@(displacement.y)).to(equal(@200)); - }); it(@"should properly calculate the distance between points", ^{ CGFloat distance = CGPointDistanceBetweenPoints(first, second); expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001)); @@ -72,11 +62,6 @@ expect(@(center.x)).to(equal(@(-100))); expect(@(center.y)).to(equal(@(-100))); }); - it(@"should properly calculate the displacement between points", ^{ - CGPoint displacement = CGPointDisplacementOfPoints(first, second); - expect(@(displacement.x)).to(equal(@400)); - expect(@(displacement.y)).to(equal(@600)); - }); it(@"should properly calculate the distance between points", ^{ CGFloat distance = CGPointDistanceBetweenPoints(first, second); expect(@(distance)).to(beCloseTo(@721.1103).within(0.0001)); From f822b52cdd133ada19727f2d118768e50030b794 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 15:28:26 -0700 Subject: [PATCH 33/45] Added documentation --- SmartDeviceLink/CGPoint_Util.h | 21 +++++++ SmartDeviceLink/SDLPinchGesture.h | 34 ++++++++++ SmartDeviceLink/SDLTouch.h | 32 ++++++++++ SmartDeviceLink/SDLTouchManager.h | 30 +++++++-- SmartDeviceLink/SDLTouchManager.m | 29 ++++++++- SmartDeviceLink/SDLTouchManagerListener.h | 75 +++++++++++++++++++++++ 6 files changed, 213 insertions(+), 8 deletions(-) diff --git a/SmartDeviceLink/CGPoint_Util.h b/SmartDeviceLink/CGPoint_Util.h index 8b5815e0f..9ea06e1b6 100644 --- a/SmartDeviceLink/CGPoint_Util.h +++ b/SmartDeviceLink/CGPoint_Util.h @@ -12,7 +12,28 @@ #include #include +/** + * @abstract + * Calculate the center of two points. + * @param point1 + * First point. + * @param point2 + * Second point. + * @return CGPoint + * Center of the points. + */ CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2); + +/** + * @abstract + * Calculate the distance between two points. + * @param point1 + * First point. + * @param point2 + * Second point. + * @return CGFloat + * Distance between the points. + */ CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2); #endif /* CGPoint_Util_h */ diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h index 69ffec09a..ed1533759 100644 --- a/SmartDeviceLink/SDLPinchGesture.h +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -14,13 +14,47 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLPinchGesture : NSObject +/** + * @abstract + * Initializes a pinch gesture. + * @param firstTouch + * First touch of the gesture + * @param secondTouch + * Second touch of the gesture + * @return SDLPinchGesture + * Instance of SDLPinchGesture. + */ - (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch; +/** + * @abstract + * First touch of a pinch gesture. + */ @property (nonatomic, copy) SDLTouch* firstTouch; + +/** + * @abstract + * Second touch of a pinch gesture. + */ @property (nonatomic, copy) SDLTouch* secondTouch; +/** + * @abstract + * Distance between first and second touches. + */ @property (nonatomic, assign, readonly) CGFloat distance; + +/** + * @abstract + * Center point between first and second touches. + */ @property (nonatomic, assign, readonly) CGPoint center; + +/** + * @abstract + * Returns whether or not the pinch gesture is valid. This is true if both touches + * are non null. + */ @property (nonatomic, assign, readonly) BOOL isValid; @end diff --git a/SmartDeviceLink/SDLTouch.h b/SmartDeviceLink/SDLTouch.h index 4d5553eb6..6cfb1f2db 100644 --- a/SmartDeviceLink/SDLTouch.h +++ b/SmartDeviceLink/SDLTouch.h @@ -19,13 +19,45 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLTouch : NSObject +/** + * @abstract + * Initializes a touch. + * @param touchEvent + * Incoming touch event from onOnTouchEvent notification. + * @return SDLTouch + * Instance of SDLTouch. + */ - (instancetype)initWithTouchEvent:(SDLTouchEvent*)touchEvent; +/** + * @abstract + * Identifier of the touch's finger. Refer to SDLTouchIdentifier for valid + * identifiers. + */ @property (nonatomic, assign, readonly) NSInteger identifier; + +/** + * @abstract + * Location of touch point, in the head unit's coordinate system. + */ @property (nonatomic, assign, readonly) CGPoint location; + +/** + * @abstract + * Timestamp in which the touch occured. + */ @property (nonatomic, assign, readonly) NSUInteger timeStamp; +/** + * @abstract + * Returns whether or not this touch is a first finger. + */ @property (nonatomic, assign, readonly) BOOL isFirstFinger; + +/** + * @abstract + * Returns whether or not this touch is a second finger. + */ @property (nonatomic, assign, readonly) BOOL isSecondFinger; @end diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 6377a2022..c46eae6cf 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -15,21 +15,39 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak, nullable) id touchEventListener; -/* - * Distance between taps. +/** + * @abstract + * Distance between two taps on the screen, in the head unit's coordinate system, used + * for registering double-tap callbacks. + * @remark + * Default is 50 pixels. */ @property (nonatomic, assign) CGFloat tapDistanceThreshold; -/* - * Duration between taps (in seconds). +/** + * @abstract + * Time (in seconds) between tap events to register a double-tap callback. + * @remark + * Default is 0.4 seconds. */ @property (nonatomic, assign) CGFloat tapTimeThreshold; -/* - * Time between pan events (in seconds). +/** + * @abstract + * Time (in seconds) between movement events to register panning or pinching + * callbacks. + * @remark + * Default is 0.5 seconds. */ @property (nonatomic, assign) CGFloat movementTimeThreshold; +/** + * @abstract + * Boolean denoting whether or not the touch manager should deliver touch event + * callbacks. + * @remark + * Default is true. + */ @property (nonatomic, assign, getter=isTouchEnabled) BOOL touchEnabled; @end diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 01d024bdb..496c1ea82 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -28,23 +28,48 @@ typedef NS_ENUM(NSUInteger, SDLPerformingTouchType) { SDLPerformingTouchTypePanningTouch }; +/*! + * @abstract + * Touch Manager will ignore touches that represent more than 2 fingers on the screen. + */ static NSUInteger const MaximumNumberOfTouches = 2; @interface SDLTouchManager () +/*! + * @abstract + * First Touch received from onOnTouchEvent. + */ @property (nonatomic, strong, nullable) SDLTouch* previousTouch; -/* - * Only used for caching previous single taps for double tap detection +/*! + * @abstract + * Cached previous single tap used for double tap detection. */ @property (nonatomic, strong, nullable) SDLTouch* singleTapTouch; +/*! + * @abstract + * Distance of a previously generated pinch event. Used to calculate the scale of zoom motion. + */ @property (nonatomic, assign) CGFloat previousPinchDistance; +/*! + * @abstract + * Current in-progress pinch gesture. + */ @property (nonatomic, strong, nullable) SDLPinchGesture* currentPinchGesture; +/*! + * @abstract + * Timer used for distinguishing between single & double taps. + */ @property (nonatomic, strong, nullable) dispatch_source_t singleTapTimer; +/*! + * @abstract + * Current touch type being performed. + */ @property (nonatomic, assign) SDLPerformingTouchType performingTouchType; @end diff --git a/SmartDeviceLink/SDLTouchManagerListener.h b/SmartDeviceLink/SDLTouchManagerListener.h index 5d8ab95bf..743e238b1 100644 --- a/SmartDeviceLink/SDLTouchManagerListener.h +++ b/SmartDeviceLink/SDLTouchManagerListener.h @@ -13,15 +13,90 @@ NS_ASSUME_NONNULL_BEGIN @protocol SDLTouchManagerListener @optional + +/** + * @abstract + * Single tap was received. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Location of the single tap in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager didReceiveSingleTapAtPoint:(CGPoint)point; + +/** + * @abstract + * Double tap was received. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Location of the double tap in the head unit's coordinate system. This is the + * average of the first and second tap. + */ - (void)touchManager:(SDLTouchManager*)manager didReceiveDoubleTapAtPoint:(CGPoint)point; +/** + * @abstract + * Panning did start. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Location of the panning start point in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager panningDidStartAtPoint:(CGPoint)point; + +/** + * @abstract + * Panning did move. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param fromPoint + * Location of the panning's previous point in the head unit's coordinate system. + * @param toPoint + * Location of the panning's new point in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager didReceivePanningFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint; + +/** + * @abstract + * Panning did end. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Location of the panning's end point in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager panningDidEndAtPoint:(CGPoint)point; +/** + * @abstract + * Pinch did start. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Center point of the pinch in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager pinchDidStartAtCenterPoint:(CGPoint)point; + +/** + * @abstract + * Pinch did move. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Center point of the pinch in the head unit's coordinate system. + * @param scale + * Scale relative to the distance between touch points. + */ - (void)touchManager:(SDLTouchManager*)manager didReceivePinchAtCenterPoint:(CGPoint)point withScale:(CGFloat)scale; + +/** + * @abstract + * Pinch did end. + * @param manager + * Current initalized SDLTouchManager issuing the callback. + * @param point + * Center point of the pinch in the head unit's coordinate system. + */ - (void)touchManager:(SDLTouchManager*)manager pinchDidEndAtCenterPoint:(CGPoint)point; @end From 34e444116d73ff9825557a370be74c5b089a9461 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Sun, 17 Jul 2016 15:31:37 -0700 Subject: [PATCH 34/45] Renamed SDLTouchManagerListener to SDLTouchManagerDelegate --- SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 8 ++++---- SmartDeviceLink/SDLTouchManager.h | 4 ++-- ...DLTouchManagerListener.h => SDLTouchManagerDelegate.h} | 4 ++-- SmartDeviceLink/SmartDeviceLink.h | 2 +- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 3 +-- 5 files changed, 10 insertions(+), 11 deletions(-) rename SmartDeviceLink/{SDLTouchManagerListener.h => SDLTouchManagerDelegate.h} (96%) diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 2f9416c14..6267e02ba 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -801,7 +801,7 @@ DAC572671D10C5640004288B /* CGPoint_Util.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572651D10C5640004288B /* CGPoint_Util.h */; }; DAC5726A1D10D5FC0004288B /* dispatch_timer.m in Sources */ = {isa = PBXBuildFile; fileRef = DAC572681D10D5FC0004288B /* dispatch_timer.m */; }; DAC5726B1D10D5FC0004288B /* dispatch_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC572691D10D5FC0004288B /* dispatch_timer.h */; }; - DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DAC5726C1D11B4840004288B /* SDLTouchManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC5725F1D10BD690004288B /* SDLTouchManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACBA1DC1D22D46D002356F8 /* SDLOnTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB331A84238B00846EE7 /* SDLOnTouchEvent.m */; }; DACBA1DE1D22D642002356F8 /* SDLTouchType.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FBEB1A84238C00846EE7 /* SDLTouchType.m */; }; DACBA1DF1D22D6CE002356F8 /* SDLTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FBE71A84238C00846EE7 /* SDLTouchEvent.m */; }; @@ -1689,7 +1689,7 @@ DAC572561D1067270004288B /* SDLTouchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouchManager.m; sourceTree = ""; }; DAC572591D10B81E0004288B /* SDLTouch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLTouch.m; sourceTree = ""; }; DAC5725A1D10B81E0004288B /* SDLTouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLTouch.h; sourceTree = ""; }; - DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLTouchManagerListener.h; sourceTree = ""; }; + DAC5725F1D10BD690004288B /* SDLTouchManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLTouchManagerDelegate.h; sourceTree = ""; }; DAC572601D10C5020004288B /* SDLPinchGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLPinchGesture.m; sourceTree = ""; }; DAC572611D10C5020004288B /* SDLPinchGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLPinchGesture.h; sourceTree = ""; }; DAC572641D10C5640004288B /* CGPoint_Util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPoint_Util.m; sourceTree = ""; }; @@ -3009,7 +3009,7 @@ children = ( DAC572551D1067270004288B /* SDLTouchManager.h */, DAC572561D1067270004288B /* SDLTouchManager.m */, - DAC5725F1D10BD690004288B /* SDLTouchManagerListener.h */, + DAC5725F1D10BD690004288B /* SDLTouchManagerDelegate.h */, DAC5725A1D10B81E0004288B /* SDLTouch.h */, DAC572591D10B81E0004288B /* SDLTouch.m */, DAC572611D10C5020004288B /* SDLPinchGesture.h */, @@ -3305,7 +3305,7 @@ 5D61FDFB1A84238C00846EE7 /* SDLV2ProtocolMessage.h in Headers */, 5D61FCFC1A84238C00846EE7 /* SDLNames.h in Headers */, 5D61FCFD1A84238C00846EE7 /* SDLObjectWithPriority.h in Headers */, - DAC5726C1D11B4840004288B /* SDLTouchManagerListener.h in Headers */, + DAC5726C1D11B4840004288B /* SDLTouchManagerDelegate.h in Headers */, 5D61FD3F1A84238C00846EE7 /* SDLPrioritizedObjectCollection.h in Headers */, 5D61FCBF1A84238C00846EE7 /* SDLHexUtility.h in Headers */, 5D61FCA21A84238C00846EE7 /* SDLEncoder.h in Headers */, diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index c46eae6cf..3593696e3 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -7,13 +7,13 @@ // #import -#import "SDLTouchManagerListener.h" +#import "SDLTouchManagerDelegate.h" NS_ASSUME_NONNULL_BEGIN @interface SDLTouchManager : NSObject -@property (nonatomic, weak, nullable) id touchEventListener; +@property (nonatomic, weak, nullable) id touchEventListener; /** * @abstract diff --git a/SmartDeviceLink/SDLTouchManagerListener.h b/SmartDeviceLink/SDLTouchManagerDelegate.h similarity index 96% rename from SmartDeviceLink/SDLTouchManagerListener.h rename to SmartDeviceLink/SDLTouchManagerDelegate.h index 743e238b1..f23a4ec6d 100644 --- a/SmartDeviceLink/SDLTouchManagerListener.h +++ b/SmartDeviceLink/SDLTouchManagerDelegate.h @@ -1,5 +1,5 @@ // -// SDLTouchManagerListener.h +// SDLTouchManagerDelegate.h // SmartDeviceLink-iOS // // Created by Muller, Alexander (A.) on 6/14/16. @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@protocol SDLTouchManagerListener +@protocol SDLTouchManagerDelegate @optional diff --git a/SmartDeviceLink/SmartDeviceLink.h b/SmartDeviceLink/SmartDeviceLink.h index e6e73f895..8d1e65c1c 100644 --- a/SmartDeviceLink/SmartDeviceLink.h +++ b/SmartDeviceLink/SmartDeviceLink.h @@ -37,7 +37,7 @@ FOUNDATION_EXPORT const unsigned char SmartDeviceLinkVersionString[]; #import "SDLAbstractProtocol.h" #import "SDLProtocol.h" #import "SDLProtocolListener.h" -#import "SDLTouchManagerListener.h" +#import "SDLTouchManagerDelegate.h" // Header #import "SDLProtocolHeader.h" diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index f19c83b20..c9ab866b8 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -17,7 +17,6 @@ #import "SDLTouchEvent.h" #import "SDLTouchManager.h" #import "SDLTouchType.h" -//#import "CGPoint_Util.h" QuickSpecBegin(SDLTouchManagerSpec) @@ -67,7 +66,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent beforeEach(^{ touchManager = [[SDLTouchManager alloc] init]; - delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerListener)); + delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerDelegate)); touchManager.touchEventListener = delegateMock; controlPoint = CGPointMake(100, 200); From 37c33511b7a03b81f0ba44941cafcb7324d489c4 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 19 Jul 2016 12:03:36 -0700 Subject: [PATCH 35/45] Updated variable from "Listener" to "Delegate. --- SmartDeviceLink/SDLTouchManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 3593696e3..e04f0e53f 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLTouchManager : NSObject -@property (nonatomic, weak, nullable) id touchEventListener; +@property (nonatomic, weak, nullable) id touchEventDelegate; /** * @abstract From adaa29e257bf1765b42f20d9c23aa853f12b2076 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Tue, 19 Jul 2016 12:05:36 -0700 Subject: [PATCH 36/45] Renamed touchEventListener to touchEventDelegate. --- SmartDeviceLink/SDLTouchManager.m | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 496c1ea82..c22bf2195 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -136,8 +136,8 @@ - (void)sdl_handleBeginTouch:(SDLTouch*)touch { self.currentPinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:self.previousTouch secondTouch:touch]; self.previousPinchDistance = self.currentPinchGesture.distance; - if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidStartAtCenterPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidStartAtCenterPoint:)]) { + [self.touchEventDelegate touchManager:self pinchDidStartAtCenterPoint:self.currentPinchGesture.center]; } break; @@ -162,9 +162,9 @@ - (void)sdl_handleMovedTouch:(SDLTouch*)touch { } - if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) { + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) { CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance; - [self.touchEventListener touchManager:self + [self.touchEventDelegate touchManager:self didReceivePinchAtCenterPoint:self.currentPinchGesture.center withScale:scale]; } @@ -173,14 +173,14 @@ - (void)sdl_handleMovedTouch:(SDLTouch*)touch { break; case SDLPerformingTouchTypeSingleTouch: _performingTouchType = SDLPerformingTouchTypePanningTouch; - if ([self.touchEventListener respondsToSelector:@selector(touchManager:panningDidStartAtPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidStartAtPoint:)]) { + [self.touchEventDelegate touchManager:self panningDidStartAtPoint:touch.location]; } break; case SDLPerformingTouchTypePanningTouch: - if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) { + [self.touchEventDelegate touchManager:self didReceivePanningFromPoint:self.previousTouch.location toPoint:touch.location]; } break; @@ -208,16 +208,16 @@ - (void)sdl_handleEndTouch:(SDLTouch*)touch { } if (self.currentPinchGesture.isValid) { - if ([self.touchEventListener respondsToSelector:@selector(touchManager:pinchDidEndAtCenterPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidEndAtCenterPoint:)]) { + [self.touchEventDelegate touchManager:self pinchDidEndAtCenterPoint:self.currentPinchGesture.center]; } self.currentPinchGesture = nil; } break; case SDLPerformingTouchTypePanningTouch: - if ([self.touchEventListener respondsToSelector:@selector(touchManager:panningDidEndAtPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidEndAtPoint:)]) { + [self.touchEventDelegate touchManager:self panningDidEndAtPoint:touch.location]; } break; @@ -237,8 +237,8 @@ - (void)sdl_handleEndTouch:(SDLTouch*)touch { && yDelta <= self.tapDistanceThreshold) { CGPoint centerPoint = CGPointCenterOfPoints(touch.location, self.singleTapTouch.location); - if ([self.touchEventListener respondsToSelector:@selector(touchManager:didReceiveDoubleTapAtPoint:)]) { - [self.touchEventListener touchManager:self + if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveDoubleTapAtPoint:)]) { + [self.touchEventDelegate touchManager:self didReceiveDoubleTapAtPoint:centerPoint]; } } @@ -258,8 +258,8 @@ - (void)sdl_initializeSingleTapTimerAtPoint:(CGPoint)point { self.singleTapTimer = dispatch_create_timer(self.tapTimeThreshold, NO, ^{ typeof(weakSelf) strongSelf = weakSelf; strongSelf.singleTapTouch = nil; - if ([strongSelf.touchEventListener respondsToSelector:@selector(touchManager:didReceiveSingleTapAtPoint:)]) { - [strongSelf.touchEventListener touchManager:strongSelf + if ([strongSelf.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveSingleTapAtPoint:)]) { + [strongSelf.touchEventDelegate touchManager:strongSelf didReceiveSingleTapAtPoint:point]; } }); From 7dd3744e0159c2b43b3a5fafba5664f0deaf3f2e Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Mon, 25 Jul 2016 14:31:31 -0700 Subject: [PATCH 37/45] Fixed issue with default movementTimeThreshold being off by a tenth resulting in no panning callbacks. --- SmartDeviceLink/SDLTouchManager.h | 2 +- SmartDeviceLink/SDLTouchManager.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index e04f0e53f..c15f12cb3 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN * Time (in seconds) between movement events to register panning or pinching * callbacks. * @remark - * Default is 0.5 seconds. + * Default is 0.05 seconds. */ @property (nonatomic, assign) CGFloat movementTimeThreshold; diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index c22bf2195..fc75e5b38 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -82,7 +82,7 @@ - (instancetype)init { return nil; } - _movementTimeThreshold = 0.5f; + _movementTimeThreshold = 0.05f; _tapTimeThreshold = 0.4f; _tapDistanceThreshold = 50.0f; _touchEnabled = YES; From a353f9659242048b3420ea73924c2bd799d04341 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 08:50:44 -0700 Subject: [PATCH 38/45] Renamed internal methods to make them more readable. --- SmartDeviceLink/SDLTouchManager.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index fc75e5b38..2e75bad43 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -110,16 +110,16 @@ - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { } if ([notification.type isEqualToEnum:SDLTouchType.BEGIN]) { - [self sdl_handleBeginTouch:touch]; + [self sdl_handleTouchBegan:touch]; } else if ([notification.type isEqualToEnum:SDLTouchType.MOVE]) { - [self sdl_handleMovedTouch:touch]; + [self sdl_handleTouchMoved:touch]; } else if ([notification.type isEqualToEnum:SDLTouchType.END]) { - [self sdl_handleEndTouch:touch]; + [self sdl_handleTouchEnded:touch]; } } #pragma mark - Private -- (void)sdl_handleBeginTouch:(SDLTouch*)touch { +- (void)sdl_handleTouchBegan:(SDLTouch*)touch { if (!touch.isFirstFinger && !self.isTouchEnabled) { return; // no-op @@ -144,7 +144,7 @@ - (void)sdl_handleBeginTouch:(SDLTouch*)touch { } } -- (void)sdl_handleMovedTouch:(SDLTouch*)touch { +- (void)sdl_handleTouchMoved:(SDLTouch*)touch { if ((touch.timeStamp - self.previousTouch.timeStamp) <= (self.movementTimeThreshold * NSEC_PER_USEC) || !self.isTouchEnabled) { return; // no-op @@ -191,7 +191,7 @@ - (void)sdl_handleMovedTouch:(SDLTouch*)touch { self.previousTouch = touch; } -- (void)sdl_handleEndTouch:(SDLTouch*)touch { +- (void)sdl_handleTouchEnded:(SDLTouch*)touch { if (!self.isTouchEnabled) { return; // no-op } From 977f7f488b78fc1a352972913f6b56638f92463a Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 09:11:57 -0700 Subject: [PATCH 39/45] Added observation of when an application enters an invalidate state so we can end timers. --- SmartDeviceLink/SDLTouchManager.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 2e75bad43..593c16338 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -11,6 +11,7 @@ #import "dispatch_timer.h" #import "CGPoint_Util.h" +#import "SDLDebugTool.h" #import "SDLOnTouchEvent.h" #import "SDLPinchGesture.h" #import "SDLProxyListener.h" @@ -87,6 +88,16 @@ - (instancetype)init { _tapDistanceThreshold = 50.0f; _touchEnabled = YES; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(sdl_applicationDidEnterBackground:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(sdl_applicationDidResignActive:) + name:UIApplicationWillResignActiveNotification + object:nil]; + return self; } @@ -270,6 +281,20 @@ - (void)sdl_cancelSingleTapTimer { self.singleTapTimer = NULL; } +- (void)sdl_applicationDidEnterBackground:(NSNotification*)notification { + if (self.singleTapTimer != NULL) { + [SDLDebugTool logInfo:@"Application is Entering Background. Canceling Single Touch Timer."]; + [self sdl_cancelSingleTapTimer]; + } +} + +- (void)sdl_applicationDidResignActive:(NSNotification*)notification { + if (self.singleTapTimer != NULL) { + [SDLDebugTool logInfo:@"Application is Resigning Active State. Canceling Single Touch Timer."]; + [self sdl_cancelSingleTapTimer]; + } +} + @end NS_ASSUME_NONNULL_END \ No newline at end of file From 3dc4d5cedc0de662197a26c9f01e94c972628ffc Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 09:15:08 -0700 Subject: [PATCH 40/45] Updated SDLPinchGesture's touches from having copy to strong. --- SmartDeviceLink/SDLPinchGesture.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/SDLPinchGesture.h b/SmartDeviceLink/SDLPinchGesture.h index ed1533759..33617594e 100644 --- a/SmartDeviceLink/SDLPinchGesture.h +++ b/SmartDeviceLink/SDLPinchGesture.h @@ -30,13 +30,13 @@ NS_ASSUME_NONNULL_BEGIN * @abstract * First touch of a pinch gesture. */ -@property (nonatomic, copy) SDLTouch* firstTouch; +@property (nonatomic, strong) SDLTouch* firstTouch; /** * @abstract * Second touch of a pinch gesture. */ -@property (nonatomic, copy) SDLTouch* secondTouch; +@property (nonatomic, strong) SDLTouch* secondTouch; /** * @abstract From e6b44e85ff659d724e6e60280de8f10b110d8da3 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 10:27:21 -0700 Subject: [PATCH 41/45] Moved Touch Manager to be a property of the Streaming Media Manager instead of the Proxy. --- SmartDeviceLink/SDLProxy.h | 2 -- SmartDeviceLink/SDLProxy.m | 14 +------------- SmartDeviceLink/SDLStreamingMediaManager.h | 7 ++++++- SmartDeviceLink/SDLStreamingMediaManager.m | 6 +++++- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/SmartDeviceLink/SDLProxy.h b/SmartDeviceLink/SDLProxy.h index 4d4d8137a..2d86439b7 100644 --- a/SmartDeviceLink/SDLProxy.h +++ b/SmartDeviceLink/SDLProxy.h @@ -9,7 +9,6 @@ @class SDLRPCRequestFactory; @class SDLStreamingMediaManager; @class SDLTimer; -@class SDLTouchManager; #import "SDLProtocolListener.h" #import "SDLProxyListener.h" @@ -29,7 +28,6 @@ @property (copy) NSString *debugConsoleGroupName; @property (readonly, copy) NSString *proxyVersion; @property (nonatomic, strong, readonly) SDLStreamingMediaManager *streamingMediaManager; -@property (nonatomic, strong, readonly) SDLTouchManager* touchManager; - (id)initWithTransport:(SDLAbstractTransport *)transport protocol:(SDLAbstractProtocol *)protocol diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index bc5ef192f..4470381ab 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -39,7 +39,6 @@ #import "SDLSystemContext.h" #import "SDLSystemRequest.h" #import "SDLTimer.h" -#import "SDLTouchManager.h" #import "SDLURLSession.h" @@ -58,7 +57,6 @@ @interface SDLProxy () { @property (strong, nonatomic) NSMutableSet *mutableProxyListeners; @property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager; -@property (nonatomic, strong, readwrite) SDLTouchManager *touchManager; @end @@ -100,7 +98,6 @@ - (void)destructObjects { [self.protocol dispose]; [self.transport dispose]; - _touchManager = nil; _transport = nil; _protocol = nil; _mutableProxyListeners = nil; @@ -171,21 +168,12 @@ - (SDLStreamingMediaManager *)streamingMediaManager { if (_streamingMediaManager == nil) { _streamingMediaManager = [[SDLStreamingMediaManager alloc] initWithProtocol:self.protocol]; [self.protocol.protocolDelegateTable addObject:_streamingMediaManager]; + [self.mutableProxyListeners addObject:_streamingMediaManager.touchManager]; } return _streamingMediaManager; } -- (SDLTouchManager*)touchManager { - if (_touchManager == nil) { - _touchManager = [[SDLTouchManager alloc] init]; - [self.mutableProxyListeners addObject:_touchManager]; - } - - return _touchManager; -} - - #pragma mark - SDLProtocolListener Implementation - (void)onProtocolOpened { _isConnected = YES; diff --git a/SmartDeviceLink/SDLStreamingMediaManager.h b/SmartDeviceLink/SDLStreamingMediaManager.h index 05a855e13..7e0b47dac 100644 --- a/SmartDeviceLink/SDLStreamingMediaManager.h +++ b/SmartDeviceLink/SDLStreamingMediaManager.h @@ -12,7 +12,7 @@ #import "SDLProtocolListener.h" @class SDLAbstractProtocol; - +@class SDLTouchManager; NS_ASSUME_NONNULL_BEGIN @@ -85,6 +85,11 @@ typedef void (^SDLStreamingStartBlock)(BOOL success, NSError *__nullable error); @property (assign, nonatomic, readonly) BOOL videoSessionConnected; @property (assign, nonatomic, readonly) BOOL audioSessionConnected; +/** + * Touch Manager responsible for providing touch event notifications. + */ +@property (nonatomic, strong, readonly) SDLTouchManager* touchManager; + @end diff --git a/SmartDeviceLink/SDLStreamingMediaManager.m b/SmartDeviceLink/SDLStreamingMediaManager.m index 616667c5b..c1877d7b5 100644 --- a/SmartDeviceLink/SDLStreamingMediaManager.m +++ b/SmartDeviceLink/SDLStreamingMediaManager.m @@ -12,7 +12,7 @@ #import "SDLAbstractProtocol.h" #import "SDLGlobals.h" - +#import "SDLTouchManager.h" NSString *const SDLErrorDomainStreamingMediaVideo = @"com.sdl.streamingmediamanager.video"; NSString *const SDLErrorDomainStreamingMediaAudio = @"com.sdl.streamingmediamanager.audio"; @@ -34,6 +34,8 @@ @interface SDLStreamingMediaManager () @property (copy, nonatomic, nullable) SDLStreamingStartBlock videoStartBlock; @property (copy, nonatomic, nullable) SDLStreamingStartBlock audioStartBlock; +@property (nonatomic, strong, readwrite) SDLTouchManager *touchManager; + @end @@ -56,6 +58,8 @@ - (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol { _videoStartBlock = nil; _audioStartBlock = nil; + + _touchManager = [[SDLTouchManager alloc] init]; return self; } From 9f0a635a2633f00e5b07a8048da521bb6259cd22 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 10:33:47 -0700 Subject: [PATCH 42/45] Moved the observing of application state changes to Streaming Media Manager. --- SmartDeviceLink/SDLStreamingMediaManager.m | 19 ++++++++++++++ SmartDeviceLink/SDLTouchManager.h | 8 ++++++ SmartDeviceLink/SDLTouchManager.m | 29 ++++------------------ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/SmartDeviceLink/SDLStreamingMediaManager.m b/SmartDeviceLink/SDLStreamingMediaManager.m index c1877d7b5..0159c5f70 100644 --- a/SmartDeviceLink/SDLStreamingMediaManager.m +++ b/SmartDeviceLink/SDLStreamingMediaManager.m @@ -60,6 +60,16 @@ - (instancetype)initWithProtocol:(SDLAbstractProtocol *)protocol { _audioStartBlock = nil; _touchManager = [[SDLTouchManager alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(sdl_applicationDidEnterBackground:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(sdl_applicationDidResignActive:) + name:UIApplicationWillResignActiveNotification + object:nil]; return self; } @@ -358,6 +368,15 @@ + (dispatch_queue_t)sdl_streamingDataSerialQueue { return streamingDataQueue; } +#pragma mark - Private Functions +- (void)sdl_applicationDidEnterBackground:(NSNotification*)notification { + [self.touchManager cancelPendingTouches]; +} + +- (void)sdl_applicationDidResignActive:(NSNotification*)notification { + [self.touchManager cancelPendingTouches]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index c15f12cb3..b89917218 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -50,6 +50,14 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign, getter=isTouchEnabled) BOOL touchEnabled; +/** + * @abstract + * Cancels pending touch event timers that may be in progress. + * @remark + * Currently only impacts the timer used to register single taps. + */ +- (void)cancelPendingTouches; + @end NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 593c16338..f987191b7 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -88,19 +88,14 @@ - (instancetype)init { _tapDistanceThreshold = 50.0f; _touchEnabled = YES; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(sdl_applicationDidEnterBackground:) - name:UIApplicationDidEnterBackgroundNotification - object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(sdl_applicationDidResignActive:) - name:UIApplicationWillResignActiveNotification - object:nil]; - return self; } +#pragma mark - Public +- (void)cancelPendingTouches { + [self sdl_cancelSingleTapTimer]; +} + #pragma mark - SDLProxyListener Delegate - (void)onProxyOpened { } - (void)onProxyClosed { } @@ -281,20 +276,6 @@ - (void)sdl_cancelSingleTapTimer { self.singleTapTimer = NULL; } -- (void)sdl_applicationDidEnterBackground:(NSNotification*)notification { - if (self.singleTapTimer != NULL) { - [SDLDebugTool logInfo:@"Application is Entering Background. Canceling Single Touch Timer."]; - [self sdl_cancelSingleTapTimer]; - } -} - -- (void)sdl_applicationDidResignActive:(NSNotification*)notification { - if (self.singleTapTimer != NULL) { - [SDLDebugTool logInfo:@"Application is Resigning Active State. Canceling Single Touch Timer."]; - [self sdl_cancelSingleTapTimer]; - } -} - @end NS_ASSUME_NONNULL_END \ No newline at end of file From 8d4b1b85328ea46a418389d7b67620c72ab60905 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Thu, 28 Jul 2016 17:36:35 -0700 Subject: [PATCH 43/45] Added check for singleTapTimer nullability when canceling. --- SmartDeviceLink/SDLTouchManager.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index f987191b7..fc023026f 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -272,6 +272,9 @@ - (void)sdl_initializeSingleTapTimerAtPoint:(CGPoint)point { } - (void)sdl_cancelSingleTapTimer { + if (self.singleTapTimer == NULL) { + return; + } dispatch_stop_timer(self.singleTapTimer); self.singleTapTimer = NULL; } From e17cda81318d1bf6516fac4ab73b27b0d38e0cbc Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 29 Jul 2016 11:37:37 -0700 Subject: [PATCH 44/45] Fixed spec issues relating to changed protocol property name. --- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index c9ab866b8..2a3740e4c 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -27,7 +27,7 @@ context(@"initializing", ^{ it(@"should correctly have default properties", ^{ SDLTouchManager* touchManager = [[SDLTouchManager alloc] init]; - expect(touchManager.touchEventListener).to(beNil()); + expect(touchManager.touchEventDelegate).to(beNil()); expect(@(touchManager.tapDistanceThreshold)).to(equal(@50)); expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001)); expect(@(touchManager.movementTimeThreshold)).to(beCloseTo(@0.5).within(0.0001)); @@ -67,7 +67,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent beforeEach(^{ touchManager = [[SDLTouchManager alloc] init]; delegateMock = OCMProtocolMock(@protocol(SDLTouchManagerDelegate)); - touchManager.touchEventListener = delegateMock; + touchManager.touchEventDelegate = delegateMock; controlPoint = CGPointMake(100, 200); didCallSingleTap = NO; From 10b8220fad2627e25b3560cf86e8ac1f15d81ea3 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Fri, 29 Jul 2016 11:38:02 -0700 Subject: [PATCH 45/45] Fixed spec issue relating to changed default movementTimeThreshold. --- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index 2a3740e4c..21639b6b7 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -30,7 +30,7 @@ expect(touchManager.touchEventDelegate).to(beNil()); expect(@(touchManager.tapDistanceThreshold)).to(equal(@50)); expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001)); - expect(@(touchManager.movementTimeThreshold)).to(beCloseTo(@0.5).within(0.0001)); + expect(@(touchManager.movementTimeThreshold)).to(beCloseTo(@0.05).within(0.0001)); expect(@(touchManager.isTouchEnabled)).to(beTruthy()); }); @@ -336,7 +336,9 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panStartTouchCoord.x = @(panStartPoint.x); panStartTouchCoord.y = @(panStartPoint.y); - NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] + ((touchManager.movementTimeThreshold + .1) * 1000)) * 1000; + CGFloat movementTimeThresholdOffset = (touchManager.movementTimeThreshold + .01) * 1000; + + NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] * 1000) + movementTimeThresholdOffset; SDLTouchEvent* panStartTouchEvent = [[SDLTouchEvent alloc] init]; panStartTouchEvent.coord = [NSMutableArray arrayWithObject:panStartTouchCoord]; @@ -353,7 +355,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panMoveTouchCoord.x = @(panMovePoint.x); panMoveTouchCoord.y = @(panMovePoint.y); - NSUInteger panMoveTimeStamp = panStartTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); + NSUInteger panMoveTimeStamp = panStartTimeStamp + movementTimeThresholdOffset; SDLTouchEvent* panMoveTouchEvent = [[SDLTouchEvent alloc] init]; panMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panMoveTouchCoord]; @@ -370,7 +372,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panSecondMoveTouchCoord.x = @(panSecondMovePoint.x); panSecondMoveTouchCoord.y = @(panSecondMovePoint.y); - NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); + NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + movementTimeThresholdOffset; SDLTouchEvent* panSecondMoveTouchEvent = [[SDLTouchEvent alloc] init]; panSecondMoveTouchEvent.coord = [NSMutableArray arrayWithObject:panSecondMoveTouchCoord]; @@ -387,7 +389,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent panEndTouchCoord.x = @(panEndPoint.x); panEndTouchCoord.y = @(panEndPoint.y); - NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + ((touchManager.movementTimeThreshold + .1) * 1000); + NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + movementTimeThresholdOffset; SDLTouchEvent* panEndTouchEvent = [[SDLTouchEvent alloc] init]; panEndTouchEvent.coord = [NSMutableArray arrayWithObject:panEndTouchCoord];