blob: d9fa83c7ab9ac78dccc7e8a2a416815f82acbbc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
//
// SDLTouch.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//
#import "SDLTouch.h"
#import "SDLTouchCoord.h"
#import "SDLTouchEvent.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.integerValue;
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 = (NSUInteger)([[NSDate date] timeIntervalSince1970] * 1000);
} 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;
}
- (NSString *)description {
return [NSString stringWithFormat:@"SDLTouch: ID: %ld, Location: %@, Timestamp: %lu, firstFinger? %@, secondFinger? %@", (long)_identifier, NSStringFromCGPoint(_location), (unsigned long)_timeStamp, (self.isFirstFinger ? @"YES" : @"NO"), (self.isSecondFinger ? @"YES" : @"NO")];
}
@end
NS_ASSUME_NONNULL_END
|