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 all 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, strong) SDLTouch* firstTouch;

/**
* @abstract
* Second touch of a pinch gesture.
*/
@property (nonatomic, strong) 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: 1 addition & 1 deletion SmartDeviceLink/SDLProxy.m
Expand Up @@ -174,12 +174,12 @@ - (SDLStreamingMediaManager *)streamingMediaManager {
}
_streamingMediaManager = [[SDLStreamingMediaManager alloc] initWithProtocol:self.protocol displayCapabilities:self.displayCapabilities];
[self.protocol.protocolDelegateTable addObject:_streamingMediaManager];
[self.mutableProxyListeners addObject:_streamingMediaManager.touchManager];
}

return _streamingMediaManager;
}


#pragma mark - SDLProtocolListener Implementation
- (void)onProtocolOpened {
_isConnected = YES;
Expand Down
6 changes: 6 additions & 0 deletions SmartDeviceLink/SDLStreamingMediaManager.h
Expand Up @@ -13,6 +13,7 @@

@class SDLAbstractProtocol;
@class SDLDisplayCapabilities;
@class SDLTouchManager;


NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -89,6 +90,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;

/**
* The settings used in a VTCompressionSessionRef encoder. These will be verified when the video stream is started. Acceptable properties for this are located in VTCompressionProperties. If set to nil, the defaultVideoEncoderSettings will be used.
*
Expand Down
37 changes: 30 additions & 7 deletions SmartDeviceLink/SDLStreamingMediaManager.m
Expand Up @@ -15,6 +15,8 @@
#import "SDLGlobals.h"
#import "SDLImageResolution.h"
#import "SDLScreenParams.h"
#import "SDLTouchManager.h"


NSString *const SDLErrorDomainStreamingMediaVideo = @"com.sdl.streamingmediamanager.video";
NSString *const SDLErrorDomainStreamingMediaAudio = @"com.sdl.streamingmediamanager.audio";
Expand All @@ -36,6 +38,8 @@ @interface SDLStreamingMediaManager ()
@property (copy, nonatomic, nullable) SDLStreamingStartBlock videoStartBlock;
@property (copy, nonatomic, nullable) SDLStreamingStartBlock audioStartBlock;

@property (nonatomic, strong, readwrite) SDLTouchManager *touchManager;

@end


Expand Down Expand Up @@ -90,10 +94,20 @@ - (instancetype)init {

_videoStartBlock = nil;
_audioStartBlock = nil;

_screenSize = CGSizeMake(640, 480);
_videoEncoderSettings = self.defaultVideoEncoderSettings;
_touchManager = [[SDLTouchManager alloc] init];

_screenSize = CGSizeMake(640, 480);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sdl_applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];

_videoEncoderSettings = self.defaultVideoEncoderSettings;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sdl_applicationDidResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];

return self;
}
Expand All @@ -104,7 +118,7 @@ - (instancetype)init {
- (void)startVideoSessionWithStartBlock:(SDLStreamingStartBlock)startBlock {
if (SDL_SYSTEM_VERSION_LESS_THAN(@"8.0")) {
NSAssert(NO, @"SDL Video Sessions can only be run on iOS 8+ devices");
startBlock(NO, [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLSTreamingVideoErrorInvalidOperatingSystemVersion userInfo:nil]);
startBlock(NO, [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorInvalidOperatingSystemVersion userInfo:nil]);

return;
}
Expand Down Expand Up @@ -291,7 +305,7 @@ - (BOOL)sdl_configureVideoEncoderWithError:(NSError *__autoreleasing *)error {

if (status != noErr) {
// TODO: Log the error
if (*error == nil) {
if (*error != nil) {
*error = [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorConfigurationCompressionSessionCreationFailure userInfo:@{ @"OSStatus" : @(status) }];
}

Expand All @@ -302,7 +316,7 @@ - (BOOL)sdl_configureVideoEncoderWithError:(NSError *__autoreleasing *)error {
CFDictionaryRef supportedProperties;
status = VTSessionCopySupportedPropertyDictionary(self.compressionSession, &supportedProperties);
if (status != noErr) {
if (*error == nil) {
if (*error != nil) {
*error = [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorConfigurationCompressionSessionSetPropertyFailure userInfo:@{ @"OSStatus" : @(status) }];
}

Expand All @@ -311,7 +325,7 @@ - (BOOL)sdl_configureVideoEncoderWithError:(NSError *__autoreleasing *)error {

for (NSString* key in self.videoEncoderSettings.allKeys) {
if (CFDictionaryContainsKey(supportedProperties, (__bridge CFStringRef)key) == false) {
if (*error == nil) {
if (*error != nil) {
NSString* description = [NSString stringWithFormat:@"\"%@\" is not a supported key.", key];
*error = [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorConfigurationCompressionSessionSetPropertyFailure userInfo:@{NSLocalizedDescriptionKey : description}];
}
Expand All @@ -327,7 +341,7 @@ - (BOOL)sdl_configureVideoEncoderWithError:(NSError *__autoreleasing *)error {

status = VTSessionSetProperty(self.compressionSession, (__bridge CFStringRef)key, (__bridge CFTypeRef)value);
if (status != noErr) {
if (*error == nil) {
if (*error != nil) {
*error = [NSError errorWithDomain:SDLErrorDomainStreamingMediaVideo code:SDLStreamingVideoErrorConfigurationCompressionSessionSetPropertyFailure userInfo:@{ @"OSStatus" : @(status) }];
}

Expand Down Expand Up @@ -433,6 +447,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