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
Touch Manager #423
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 80ba013
Updated SDLTouchManager's header to public
asm09fsu 17337c4
Added touch manager to SmartDeviceLink.h
asm09fsu 3ca1d55
Fixed issue relating to using C files in cocoapods.
asm09fsu e704ce7
Using ULONG_MAX instead of 0 for our unsigned longs in const struct v…
asm09fsu 4e3c613
Updated the tapTimeThreshold to be seconds instead of milliseconds to…
asm09fsu 0debf95
Fixed function mistype.
asm09fsu ca030ed
Added missing header for ULONG_MAX.
asm09fsu e39aeaa
Added spec tests for CGPoint_Util.
asm09fsu 5338b68
Updated SDLTouch to use a signed long for identifier, so we may use -…
asm09fsu d26d4f9
Added SDLTouch spec tests.
asm09fsu 23281cb
Removed public exposure of SDLTouchEqualToTouch
asm09fsu de8db6e
Added SDLPinchGesture spec tests.
asm09fsu 4564749
Fixed SDLPinchGesture tests.
asm09fsu ef754ee
Added dispatch_timer spec tests.
asm09fsu 116008b
removed unecessary @class
asm09fsu 8199fcf
Reduced pan time threshold to a lower value to improve panning delay.
asm09fsu ef7d601
Adding check in the event we receive an invalid timestamp object from…
asm09fsu 301f21f
Made performingTouchType internal because necessity of it for develop…
asm09fsu 565d10f
Added multiple structs/notifications to be visible to testing target.
asm09fsu b11680b
Added tests for all touch events.
asm09fsu c8d0846
Moved all helper class tests to separate files.
asm09fsu ac2dcf5
Using NSSelectorFromString instead of @selector to silence warning.
asm09fsu 1ff49f6
Rewrote SDLTouchManager tests to extract variables out of the tests a…
asm09fsu 0baeebb
Replaced structs for SDLTouch & SDLPinchGesture in favor of classes.
asm09fsu bb4adcb
Merge remote-tracking branch 'origin/develop' into feature/touch_manager
asm09fsu 83d93f6
Removed "k" from internal constant.
asm09fsu a4dc92e
Updated panTimeThreshold to seconds instead of milliseconds. Also ren…
asm09fsu e7b9481
Updated inits to avoid right shift.
asm09fsu c3dfc98
Fixed issue causing Panning tests to sometimes fail.
asm09fsu 1ed1b8e
Added missing non-null audited regions. Updated all properties to con…
asm09fsu 4c7fc67
Removed duplicate function.
asm09fsu 4696481
Removed unneeded function.
asm09fsu f822b52
Added documentation
asm09fsu 34e4441
Renamed SDLTouchManagerListener to SDLTouchManagerDelegate
asm09fsu 37c3351
Updated variable from "Listener" to "Delegate.
asm09fsu adaa29e
Renamed touchEventListener to touchEventDelegate.
asm09fsu 7dd3744
Fixed issue with default movementTimeThreshold being off by a tenth r…
asm09fsu 32506bc
Merge branch 'develop' into feature/touch_manager
joeljfischer a353f96
Renamed internal methods to make them more readable.
asm09fsu 977f7f4
Added observation of when an application enters an invalidate state s…
asm09fsu 3dc4d5c
Updated SDLPinchGesture's touches from having copy to strong.
asm09fsu e6b44e8
Moved Touch Manager to be a property of the Streaming Media Manager i…
asm09fsu 9f0a635
Moved the observing of application state changes to Streaming Media M…
asm09fsu 8d4b1b8
Added check for singleTapTimer nullability when canceling.
asm09fsu e17cda8
Fixed spec issues relating to changed protocol property name.
asm09fsu 10b8220
Fixed spec issue relating to changed default movementTimeThreshold.
asm09fsu ca91918
Merge branch 'develop' into feature/touch_manager
joeljfischer File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/** | ||
* @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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.