summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-05-07 14:31:08 -0400
committerGitHub <noreply@github.com>2020-05-07 14:31:08 -0400
commit67d00d0caa0296a3a9ec839bf7bd93141110b6d7 (patch)
tree4d100da13f8ff3dadb5259908eeb8b95b4d5c1ee
parent546c6b93e21237562a897163c05e9ed355407ced (diff)
parenta756ccf1dbf9b96d7ba83eba771994f1886181e0 (diff)
downloadsdl_ios-67d00d0caa0296a3a9ec839bf7bd93141110b6d7.tar.gz
Merge pull request #1650 from smartdevicelink/bugfix/issue-1631-focusableitemlocator-stop
Stop / Start FocusableItemLocator when VideoStreamingLifecycleManager starts / stops
-rw-r--r--SmartDeviceLink/SDLFocusableItemLocator.m23
-rw-r--r--SmartDeviceLink/SDLFocusableItemLocatorType.h6
-rw-r--r--SmartDeviceLink/SDLStreamingVideoLifecycleManager.m3
-rw-r--r--SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m65
4 files changed, 81 insertions, 16 deletions
diff --git a/SmartDeviceLink/SDLFocusableItemLocator.m b/SmartDeviceLink/SDLFocusableItemLocator.m
index b4fc294b5..e416c2a3a 100644
--- a/SmartDeviceLink/SDLFocusableItemLocator.m
+++ b/SmartDeviceLink/SDLFocusableItemLocator.m
@@ -47,11 +47,21 @@ NS_ASSUME_NONNULL_BEGIN
_focusableViews = [NSMutableArray array];
_enableHapticDataRequests = NO;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_projectionViewUpdated:) name:SDLDidUpdateProjectionView object:nil];
return self;
}
+- (void)start {
+ SDLLogD(@"Starting");
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_projectionViewUpdated:) name:SDLDidUpdateProjectionView object:nil];
+}
+
+- (void)stop {
+ SDLLogD(@"Stopping");
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [self.focusableViews removeAllObjects];
+}
+
- (void)updateInterfaceLayout {
if (@available(iOS 9.0, *)) {
[self.focusableViews removeAllObjects];
@@ -63,7 +73,11 @@ NS_ASSUME_NONNULL_BEGIN
[self.focusableViews exchangeObjectAtIndex:preferredViewIndex withObjectAtIndex:0];
}
+ SDLLogD(@"Updated VC layout, sending new haptic rects");
+ SDLLogV(@"For focusable views: %@", self.focusableViews);
[self sdl_sendHapticRPC];
+ } else {
+ SDLLogE(@"Attempted to update user interface layout, but it only works on iOS 9.0+");
}
}
@@ -78,10 +92,14 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
+ SDLLogD(@"Parsing UIView heirarchy");
+ SDLLogV(@"UIView: %@", currentView);
if (@available(iOS 9.0, *)) {
+ // Finding focusable subviews
NSArray *focusableSubviews = [currentView.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIView * _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
return (evaluatedObject.canBecomeFocused || [evaluatedObject isKindOfClass:[UIButton class]]);
}]];
+ SDLLogV(@"Found focusable subviews: %@", focusableSubviews);
BOOL isButton = [currentView isKindOfClass:[UIButton class]];
if ((currentView.canBecomeFocused || isButton) && focusableSubviews.count == 0) {
@@ -129,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
}
SDLLogV(@"Sending haptic data: %@", hapticRects);
- SDLSendHapticData* hapticRPC = [[SDLSendHapticData alloc] initWithHapticRectData:hapticRects];
+ SDLSendHapticData *hapticRPC = [[SDLSendHapticData alloc] initWithHapticRectData:hapticRects];
[self.connectionManager sendConnectionManagerRequest:hapticRPC withResponseHandler:nil];
}
@@ -151,6 +169,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+ SDLLogD(@"Found a focusable view: %@, for point: %@", selectedView, NSStringFromCGPoint(point));
return selectedView;
}
diff --git a/SmartDeviceLink/SDLFocusableItemLocatorType.h b/SmartDeviceLink/SDLFocusableItemLocatorType.h
index 400d9460d..cc43ad207 100644
--- a/SmartDeviceLink/SDLFocusableItemLocatorType.h
+++ b/SmartDeviceLink/SDLFocusableItemLocatorType.h
@@ -36,6 +36,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithViewController:(UIViewController *)viewController connectionManager:(id<SDLConnectionManagerType>)connectionManager videoScaleManager:(SDLStreamingVideoScaleManager *)videoScaleManager;
+/// Start observing updates
+- (void)start;
+
+/// Stop observing updates and clear data
+- (void)stop;
+
/**
updateInterfaceLayout crawls through the view hierarchy, updates and keep tracks of views to be reported through Haptic RPC. This function is automatically called when SDLDidUpdateProjectionView notification is sent by the application.
*/
diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
index be9135cb8..ddee38a90 100644
--- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
+++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
@@ -189,6 +189,8 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
}
}
+ [self.focusableItemManager start];
+
// attempt to start streaming since we may already have necessary conditions met
[self sdl_startVideoSession];
}
@@ -204,6 +206,7 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
_videoStreamingState = SDLVideoStreamingStateNotStreamable;
_protocol = nil;
[self.videoScaleManager stop];
+ [self.focusableItemManager stop];
_connectedVehicleMake = nil;
[self.videoStreamStateMachine transitionToState:SDLVideoStreamManagerStateStopped];
diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m
index 77a658a86..c5e50301f 100644
--- a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m
+++ b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m
@@ -367,27 +367,64 @@ describe(@"the haptic manager", ^{
[hapticManager updateInterfaceLayout];
viewRect2 = CGRectMake(201, 201, 50, 50);
- UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2];
+ UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2];
[uiViewController.view addSubview:textField2];
+ });
+
+ context(@"when not started", ^{
+ beforeEach(^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidUpdateProjectionView object:nil];
+ });
+
+ it(@"should have one view", ^{
+ int expectedCount = 1;
+ expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount));
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidUpdateProjectionView object:nil];
+ if(sentHapticRequest.hapticRectData.count == expectedCount) {
+ NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData;
+ SDLHapticRect *sdlhapticRect1 = hapticRectData[0];
+ SDLRectangle *sdlRect1 = sdlhapticRect1.rect;
+
+ compareRectangle(sdlRect1, viewRect1);
+ }
+ });
});
- it(@"should have two views", ^{
- int expectedCount = 2;
- expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount));
+ context(@"when started", ^{
+ beforeEach(^{
+ [hapticManager start];
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidUpdateProjectionView object:nil];
+ });
- if(sentHapticRequest.hapticRectData.count == expectedCount) {
- NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData;
- SDLHapticRect *sdlhapticRect1 = hapticRectData[0];
- SDLRectangle *sdlRect1 = sdlhapticRect1.rect;
+ it(@"should have two views", ^{
+ int expectedCount = 2;
+ expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount));
- SDLHapticRect *sdlhapticRect2 = hapticRectData[1];
- SDLRectangle *sdlRect2 = sdlhapticRect2.rect;
+ if(sentHapticRequest.hapticRectData.count == expectedCount) {
+ NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData;
+ SDLHapticRect *sdlhapticRect1 = hapticRectData[0];
+ SDLRectangle *sdlRect1 = sdlhapticRect1.rect;
- compareRectangle(sdlRect1, viewRect2);
- compareRectangle(sdlRect2, viewRect1);
- }
+ SDLHapticRect *sdlhapticRect2 = hapticRectData[1];
+ SDLRectangle *sdlRect2 = sdlhapticRect2.rect;
+
+ compareRectangle(sdlRect1, viewRect2);
+ compareRectangle(sdlRect2, viewRect1);
+ }
+ });
+
+ context(@"when stopped", ^{
+ beforeEach(^{
+ [hapticManager stop];
+ for (UIView *subview in uiViewController.view.subviews) { [subview removeFromSuperview]; }
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidUpdateProjectionView object:nil];
+ });
+
+ it(@"should have two views", ^{
+ int expectedCount = 2;
+ expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount));
+ });
+ });
});
});