Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Touch Manager #423

Merged
merged 48 commits into from Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ef3fe39
Initial support for a touch manager for interpreting onTouchEvent not…
asm09fsu Jun 15, 2016
80ba013
Updated SDLTouchManager's header to public
asm09fsu Jun 15, 2016
17337c4
Added touch manager to SmartDeviceLink.h
asm09fsu Jun 15, 2016
3ca1d55
Fixed issue relating to using C files in cocoapods.
asm09fsu Jun 15, 2016
e704ce7
Using ULONG_MAX instead of 0 for our unsigned longs in const struct v…
asm09fsu Jun 15, 2016
4e3c613
Updated the tapTimeThreshold to be seconds instead of milliseconds to…
asm09fsu Jun 15, 2016
0debf95
Fixed function mistype.
asm09fsu Jun 15, 2016
ca030ed
Added missing header for ULONG_MAX.
asm09fsu Jun 16, 2016
e39aeaa
Added spec tests for CGPoint_Util.
asm09fsu Jun 17, 2016
5338b68
Updated SDLTouch to use a signed long for identifier, so we may use -…
asm09fsu Jun 17, 2016
d26d4f9
Added SDLTouch spec tests.
asm09fsu Jun 17, 2016
23281cb
Removed public exposure of SDLTouchEqualToTouch
asm09fsu Jun 17, 2016
de8db6e
Added SDLPinchGesture spec tests.
asm09fsu Jun 17, 2016
4564749
Fixed SDLPinchGesture tests.
asm09fsu Jun 17, 2016
ef754ee
Added dispatch_timer spec tests.
asm09fsu Jun 17, 2016
116008b
removed unecessary @class
asm09fsu Jun 18, 2016
8199fcf
Reduced pan time threshold to a lower value to improve panning delay.
asm09fsu Jun 24, 2016
ef7d601
Adding check in the event we receive an invalid timestamp object from…
asm09fsu Jun 24, 2016
301f21f
Made performingTouchType internal because necessity of it for develop…
asm09fsu Jun 28, 2016
565d10f
Added multiple structs/notifications to be visible to testing target.
asm09fsu Jun 28, 2016
b11680b
Added tests for all touch events.
asm09fsu Jun 28, 2016
c8d0846
Moved all helper class tests to separate files.
asm09fsu Jul 1, 2016
ac2dcf5
Using NSSelectorFromString instead of @selector to silence warning.
asm09fsu Jul 1, 2016
1ff49f6
Rewrote SDLTouchManager tests to extract variables out of the tests a…
asm09fsu Jul 2, 2016
0baeebb
Replaced structs for SDLTouch & SDLPinchGesture in favor of classes.
asm09fsu Jul 17, 2016
bb4adcb
Merge remote-tracking branch 'origin/develop' into feature/touch_manager
asm09fsu Jul 17, 2016
83d93f6
Removed "k" from internal constant.
asm09fsu Jul 17, 2016
a4dc92e
Updated panTimeThreshold to seconds instead of milliseconds. Also ren…
asm09fsu Jul 17, 2016
e7b9481
Updated inits to avoid right shift.
asm09fsu Jul 17, 2016
c3dfc98
Fixed issue causing Panning tests to sometimes fail.
asm09fsu Jul 17, 2016
1ed1b8e
Added missing non-null audited regions. Updated all properties to con…
asm09fsu Jul 17, 2016
4c7fc67
Removed duplicate function.
asm09fsu Jul 17, 2016
4696481
Removed unneeded function.
asm09fsu Jul 17, 2016
f822b52
Added documentation
asm09fsu Jul 17, 2016
34e4441
Renamed SDLTouchManagerListener to SDLTouchManagerDelegate
asm09fsu Jul 17, 2016
37c3351
Updated variable from "Listener" to "Delegate.
asm09fsu Jul 19, 2016
adaa29e
Renamed touchEventListener to touchEventDelegate.
asm09fsu Jul 19, 2016
7dd3744
Fixed issue with default movementTimeThreshold being off by a tenth r…
asm09fsu Jul 25, 2016
32506bc
Merge branch 'develop' into feature/touch_manager
joeljfischer Jul 28, 2016
a353f96
Renamed internal methods to make them more readable.
asm09fsu Jul 28, 2016
977f7f4
Added observation of when an application enters an invalidate state s…
asm09fsu Jul 28, 2016
3dc4d5c
Updated SDLPinchGesture's touches from having copy to strong.
asm09fsu Jul 28, 2016
e6b44e8
Moved Touch Manager to be a property of the Streaming Media Manager i…
asm09fsu Jul 28, 2016
9f0a635
Moved the observing of application state changes to Streaming Media M…
asm09fsu Jul 28, 2016
8d4b1b8
Added check for singleTapTimer nullability when canceling.
asm09fsu Jul 29, 2016
e17cda8
Fixed spec issues relating to changed protocol property name.
asm09fsu Jul 29, 2016
10b8220
Fixed spec issue relating to changed default movementTimeThreshold.
asm09fsu Jul 29, 2016
ca91918
Merge branch 'develop' into feature/touch_manager
joeljfischer Jul 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 88 additions & 0 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions SmartDeviceLink/CGPoint_Util.h
@@ -0,0 +1,39 @@
//
// 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 <stdio.h>
#include <CoreGraphics/CGGeometry.h>

/**
* @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 */
20 changes: 20 additions & 0 deletions SmartDeviceLink/CGPoint_Util.m
@@ -0,0 +1,20 @@
//
// 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 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);
}

CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2) {
return hypotf(point1.x - point2.x, point1.y - point2.y);
}
62 changes: 62 additions & 0 deletions SmartDeviceLink/SDLPinchGesture.h
@@ -0,0 +1,62 @@
//
// SDLPinchGesture.h
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "SDLTouch.h"

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't copyable, I don't think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! This was when we were using c-structs instead of objects.


/**
* @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

NS_ASSUME_NONNULL_END
79 changes: 79 additions & 0 deletions SmartDeviceLink/SDLPinchGesture.m
@@ -0,0 +1,79 @@
//
// SDLPinchGesture.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//

#import "SDLPinchGesture.h"

#import "SDLTouch.h"
#import "CGPoint_Util.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLPinchGesture

@synthesize distance = _distance;
@synthesize center = _center;

- (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch {
self = [super init];
if (!self) {
return nil;
}

_firstTouch = firstTouch;
_secondTouch = secondTouch;
_distance = -1;
_center = CGPointZero;

return self;
}

#pragma mark - Setters
- (void)setFirstTouch:(SDLTouch *)firstTouch {
if (firstTouch.identifier == SDLTouchIdentifierFirstFinger) {
_firstTouch = firstTouch;
[self sdl_invalidate];
}
}

- (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

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions SmartDeviceLink/SDLProxy.h
Expand Up @@ -9,6 +9,7 @@
@class SDLRPCRequestFactory;
@class SDLStreamingMediaManager;
@class SDLTimer;
@class SDLTouchManager;

#import "SDLProtocolListener.h"
#import "SDLProxyListener.h"
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions SmartDeviceLink/SDLProxy.m
Expand Up @@ -39,6 +39,7 @@
#import "SDLSystemContext.h"
#import "SDLSystemRequest.h"
#import "SDLTimer.h"
#import "SDLTouchManager.h"
#import "SDLURLSession.h"


Expand All @@ -57,6 +58,7 @@ @interface SDLProxy () {

@property (strong, nonatomic) NSMutableSet *mutableProxyListeners;
@property (nonatomic, strong, readwrite) SDLStreamingMediaManager *streamingMediaManager;
@property (nonatomic, strong, readwrite) SDLTouchManager *touchManager;

@end

Expand Down Expand Up @@ -98,6 +100,7 @@ - (void)destructObjects {
[self.protocol dispose];
[self.transport dispose];

_touchManager = nil;
_transport = nil;
_protocol = nil;
_mutableProxyListeners = nil;
Expand Down Expand Up @@ -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 {
Expand Down
65 changes: 65 additions & 0 deletions SmartDeviceLink/SDLTouch.h
@@ -0,0 +1,65 @@
//
// SDLTouch.h
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//

#import <UIKit/UIKit.h>

@class SDLTouchEvent;

typedef enum {
SDLTouchIdentifierFirstFinger = 0,
SDLTouchIdentifierSecondFinger = 1
} SDLTouchIdentifier;

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

NS_ASSUME_NONNULL_END
64 changes: 64 additions & 0 deletions SmartDeviceLink/SDLTouch.m
@@ -0,0 +1,64 @@
//
// SDLTouch.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//

#import "SDLTouch.h"

#import "SDLTouchEvent.h"
#import "SDLTouchCoord.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLTouch

- (instancetype)init {
self = [super init];
if (!self) {
return nil;
}

_identifier = -1;
_location = CGPointZero;
_timeStamp = 0;

return self;
}

- (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;
}

#pragma mark - Getters
- (BOOL)isFirstFinger {
return self.identifier == SDLTouchIdentifierFirstFinger;
}

- (BOOL)isSecondFinger {
return self.identifier == SDLTouchIdentifierSecondFinger;
}

@end

NS_ASSUME_NONNULL_END