summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2018-05-14 13:24:11 -0400
committerNicoleYarroch <nicole@livio.io>2018-05-14 13:24:11 -0400
commitc7d1402617831610a15f4d1b21f45218ecc66e29 (patch)
tree43064d71c7375c7981bbbb1f2c41d9c7052552b6
parent3ca9f29ad294dfe97608c16d444ca7cc8571379a (diff)
downloadsdl_ios-c7d1402617831610a15f4d1b21f45218ecc66e29.tar.gz
Added a button manager to the Obj-C app
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj6
-rw-r--r--SmartDeviceLink_Example/AppDelegate.m1
-rw-r--r--SmartDeviceLink_Example/AppDelegate.swift1
-rw-r--r--SmartDeviceLink_Example/ButtonManager.h32
-rw-r--r--SmartDeviceLink_Example/ButtonManager.m163
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.m116
6 files changed, 218 insertions, 101 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index 7e4b1bbe6..ae97d8c7e 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -1062,6 +1062,7 @@
5DF40B26208FA7DE00DD6FDA /* SDLMenuManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF40B25208FA7DE00DD6FDA /* SDLMenuManagerSpec.m */; };
5DF40B28208FDA9700DD6FDA /* SDLVoiceCommandManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF40B27208FDA9700DD6FDA /* SDLVoiceCommandManagerSpec.m */; };
5DFFB9151BD7C89700DB3F04 /* SDLConnectionManagerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */; };
+ 8800871E20A6356D008E1EA0 /* ButtonManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8800871B20A6338C008E1EA0 /* ButtonManager.m */; };
8803A0AA208E281E009FDC02 /* Enum+SDLAudioRecordingState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8803A0A7208E27E6009FDC02 /* Enum+SDLAudioRecordingState.swift */; };
8803A0AF208E2A3A009FDC02 /* AudioManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8803A0AC208E2907009FDC02 /* AudioManager.m */; };
8803A0B2208E7CA4009FDC02 /* VehicleDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8803A0B1208E7CA4009FDC02 /* VehicleDataManager.m */; };
@@ -2404,6 +2405,8 @@
5DF40B25208FA7DE00DD6FDA /* SDLMenuManagerSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLMenuManagerSpec.m; path = DevAPISpecs/SDLMenuManagerSpec.m; sourceTree = "<group>"; };
5DF40B27208FDA9700DD6FDA /* SDLVoiceCommandManagerSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLVoiceCommandManagerSpec.m; path = DevAPISpecs/SDLVoiceCommandManagerSpec.m; sourceTree = "<group>"; };
5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLConnectionManagerType.h; sourceTree = "<group>"; };
+ 8800871A20A6338C008E1EA0 /* ButtonManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ButtonManager.h; sourceTree = "<group>"; };
+ 8800871B20A6338C008E1EA0 /* ButtonManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ButtonManager.m; sourceTree = "<group>"; };
8803A0A7208E27E6009FDC02 /* Enum+SDLAudioRecordingState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Enum+SDLAudioRecordingState.swift"; sourceTree = "<group>"; };
8803A0AB208E2907009FDC02 /* AudioManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioManager.h; sourceTree = "<group>"; };
8803A0AC208E2907009FDC02 /* AudioManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AudioManager.m; sourceTree = "<group>"; };
@@ -3351,6 +3354,8 @@
88DA6D0F209794A400AD8297 /* AlertManager.m */,
88DE80B520A5C8DD00BA9CF0 /* RPCPermissionsManager.h */,
88DE80B620A5C8DD00BA9CF0 /* RPCPermissionsManager.m */,
+ 8800871A20A6338C008E1EA0 /* ButtonManager.h */,
+ 8800871B20A6338C008E1EA0 /* ButtonManager.m */,
);
name = SDL;
sourceTree = "<group>";
@@ -5731,6 +5736,7 @@
buildActionMask = 2147483647;
files = (
5D4832A51A94F90D00252386 /* ConnectionTransitionContext.m in Sources */,
+ 8800871E20A6356D008E1EA0 /* ButtonManager.m in Sources */,
5D0218FC1A8E7E1700D1BF62 /* ConnectionContainerViewController.m in Sources */,
88DA6D10209794A400AD8297 /* AlertManager.m in Sources */,
8803A0AF208E2A3A009FDC02 /* AudioManager.m in Sources */,
diff --git a/SmartDeviceLink_Example/AppDelegate.m b/SmartDeviceLink_Example/AppDelegate.m
index 96d9759f8..1ceb6f765 100644
--- a/SmartDeviceLink_Example/AppDelegate.m
+++ b/SmartDeviceLink_Example/AppDelegate.m
@@ -18,7 +18,6 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // [ProxyManager.sharedManager startIAP];
return YES;
}
diff --git a/SmartDeviceLink_Example/AppDelegate.swift b/SmartDeviceLink_Example/AppDelegate.swift
index 1a9b6007d..fd42468d3 100644
--- a/SmartDeviceLink_Example/AppDelegate.swift
+++ b/SmartDeviceLink_Example/AppDelegate.swift
@@ -15,7 +15,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
-// ProxyManager.sharedManager.start(with: .iAP)
AppUserDefaults.setDefaults()
return true
diff --git a/SmartDeviceLink_Example/ButtonManager.h b/SmartDeviceLink_Example/ButtonManager.h
new file mode 100644
index 000000000..71ab38f87
--- /dev/null
+++ b/SmartDeviceLink_Example/ButtonManager.h
@@ -0,0 +1,32 @@
+//
+// ButtonManager.h
+// SmartDeviceLink
+//
+// Created by Nicole on 5/11/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class SDLManager;
+@class SDLSoftButtonObject;
+
+NS_ASSUME_NONNULL_BEGIN
+
+typedef void(^RefreshUIHandler)(void);
+
+@interface ButtonManager : NSObject
+
+@property (assign, nonatomic, getter=isTextEnabled, readonly) BOOL textEnabled;
+@property (assign, nonatomic, getter=isHexagonEnabled, readonly) BOOL toggleEnabled;
+@property (assign, nonatomic, getter=areImagesEnabled, readonly) BOOL imagesEnabled;
+
+- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithManager:(SDLManager *)manager refreshUIHandler:(RefreshUIHandler)refreshUIHandler;
+- (void)stopManager;
+
+- (NSArray<SDLSoftButtonObject *> *)allScreenSoftButtons;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink_Example/ButtonManager.m b/SmartDeviceLink_Example/ButtonManager.m
new file mode 100644
index 000000000..1e163db56
--- /dev/null
+++ b/SmartDeviceLink_Example/ButtonManager.m
@@ -0,0 +1,163 @@
+//
+// ButtonManager.m
+// SmartDeviceLink
+//
+// Created by Nicole on 5/11/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import "ButtonManager.h"
+#import "AlertManager.h"
+#import "AppConstants.h"
+#import "SmartDeviceLink.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ButtonManager ()
+
+@property (copy, nonatomic, nullable) RefreshUIHandler refreshUIHandler;
+@property (strong, nonatomic) SDLManager *sdlManager;
+
+@property (assign, nonatomic, getter=isTextEnabled, readwrite) BOOL textEnabled;
+@property (assign, nonatomic, getter=isHexagonEnabled, readwrite) BOOL toggleEnabled;
+@property (assign, nonatomic, getter=areImagesEnabled, readwrite) BOOL imagesEnabled;
+
+@end
+
+@implementation ButtonManager
+
+- (instancetype)initWithManager:(SDLManager *)manager refreshUIHandler:(RefreshUIHandler)refreshUIHandler {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+
+ _sdlManager = manager;
+ _refreshUIHandler = refreshUIHandler;
+
+ _textEnabled = YES;
+ _imagesEnabled = YES;
+ _toggleEnabled = YES;
+
+ return self;
+}
+
+- (void)stopManager {
+ _textEnabled = YES;
+ _imagesEnabled = YES;
+ _toggleEnabled = YES;
+}
+
+#pragma mark - Setters
+
+- (void)setTextEnabled:(BOOL)textEnabled {
+ _textEnabled = textEnabled;
+ if (self.refreshUIHandler == nil) { return; }
+ self.refreshUIHandler();
+}
+
+- (void)setImagesEnabled:(BOOL)imagesEnabled {
+ _imagesEnabled = imagesEnabled;
+ [self sdlex_setToggleSoftButtonIcon:self.isHexagonEnabled imagesEnabled:imagesEnabled];
+ [self sdlex_setAlertSoftButtonIcon];
+ if (self.refreshUIHandler == nil) { return; }
+ self.refreshUIHandler();
+}
+
+- (void)setToggleEnabled:(BOOL)hexagonEnabled {
+ _toggleEnabled = hexagonEnabled;
+ [self sdlex_setToggleSoftButtonIcon:hexagonEnabled imagesEnabled:self.areImagesEnabled];
+}
+
+#pragma mark - Custom Soft Buttons
+
+- (NSArray<SDLSoftButtonObject *> *)allScreenSoftButtons {
+ return @[[self sdlex_softButtonAlertWithManager:self.sdlManager], [self sdlex_softButtonToggleWithManager:self.sdlManager], [self sdlex_softButtonTextVisibleWithManager:self.sdlManager], [self sdlex_softButtonImagesVisibleWithManager:self.sdlManager]];
+}
+
+- (SDLSoftButtonObject *)sdlex_softButtonAlertWithManager:(SDLManager *)manager {
+ SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText image:[UIImage imageNamed:CarIconImageName]];
+ SDLSoftButtonState *alertTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonTextState text:AlertSoftButtonText image:nil];
+
+ __weak typeof(self) weakself = self;
+ SDLSoftButtonObject *alertSoftButton = [[SDLSoftButtonObject alloc] initWithName:AlertSoftButton states:@[alertImageAndTextState, alertTextState] initialStateName:alertImageAndTextState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
+ if (buttonPress == nil) { return; }
+
+ [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil]];
+
+ SDLLogD(@"Star icon soft button press fired");
+ }];
+
+ return alertSoftButton;
+}
+
+- (SDLSoftButtonObject *)sdlex_softButtonToggleWithManager:(SDLManager *)manager {
+ SDLSoftButtonState *toggleImageOnState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOnState text:nil image:[UIImage imageNamed:WheelIconImageName]];
+ SDLSoftButtonState *toggleImageOffState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOffState text:nil image:[UIImage imageNamed:LaptopIconImageName]];
+ SDLSoftButtonState *toggleTextOnState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonTextOnState text:ToggleSoftButtonTextTextOnText image:nil];
+ SDLSoftButtonState *toggleTextOffState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonTextOffState text:ToggleSoftButtonTextTextOffText image:nil];
+
+ __weak typeof(self) weakself = self;
+ SDLSoftButtonObject *toggleButton = [[SDLSoftButtonObject alloc] initWithName:ToggleSoftButton states:@[toggleImageOnState, toggleImageOffState, toggleTextOnState, toggleTextOffState] initialStateName:toggleImageOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
+ if (buttonPress == nil) { return; }
+ weakself.toggleEnabled = !weakself.toggleEnabled;
+ SDLLogD(@"Toggle icon button press fired %d", self.toggleEnabled);
+ }];
+
+ return toggleButton;
+}
+
+- (SDLSoftButtonObject *)sdlex_softButtonTextVisibleWithManager:(SDLManager *)manager {
+ SDLSoftButtonState *textOnState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOnState text:TextVisibleSoftButtonTextOnText image:nil];
+ SDLSoftButtonState *textOffState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOffState text:TextVisibleSoftButtonTextOffText image:nil];
+
+ __weak typeof(self) weakself = self;
+ SDLSoftButtonObject *textButton = [[SDLSoftButtonObject alloc] initWithName:TextVisibleSoftButton states:@[textOnState, textOffState] initialStateName:textOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
+ if (buttonPress == nil) { return; }
+
+ weakself.textEnabled = !weakself.textEnabled;
+ SDLSoftButtonObject *object = [weakself.sdlManager.screenManager softButtonObjectNamed:TextVisibleSoftButton];
+ [object transitionToNextState];
+
+ SDLLogD(@"Text visibility soft button press fired %d", weakself.textEnabled);
+ }];
+
+ return textButton;
+}
+
+- (SDLSoftButtonObject *)sdlex_softButtonImagesVisibleWithManager:(SDLManager *)manager {
+ SDLSoftButtonState *imagesOnState = [[SDLSoftButtonState alloc] initWithStateName:ImagesVisibleSoftButtonImageOnState text:ImagesVisibleSoftButtonImageOnText image:nil];
+ SDLSoftButtonState *imagesOffState = [[SDLSoftButtonState alloc] initWithStateName:ImagesVisibleSoftButtonImageOffState text:ImagesVisibleSoftButtonImageOffText image:nil];
+
+ __weak typeof(self) weakself = self;
+ SDLSoftButtonObject *imagesButton = [[SDLSoftButtonObject alloc] initWithName:ImagesVisibleSoftButton states:@[imagesOnState, imagesOffState] initialStateName:imagesOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
+ if (buttonPress == nil) {
+ return;
+ }
+
+ weakself.imagesEnabled = !weakself.imagesEnabled;
+
+ SDLSoftButtonObject *object = [weakself.sdlManager.screenManager softButtonObjectNamed:ImagesVisibleSoftButton];
+ [object transitionToNextState];
+
+ SDLLogD(@"Image visibility soft button press fired %d", weakself.imagesEnabled);
+ }];
+
+ return imagesButton;
+}
+
+#pragma mark - Button State Helpers
+
+- (void)sdlex_setToggleSoftButtonIcon:(BOOL)toggleEnabled imagesEnabled:(BOOL)imagesEnabled {
+ SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:ToggleSoftButton];
+ imagesEnabled ? [object transitionToStateNamed:(toggleEnabled ? ToggleSoftButtonImageOnState : ToggleSoftButtonImageOffState)] : [object transitionToStateNamed:(toggleEnabled ? ToggleSoftButtonTextOnState : ToggleSoftButtonTextOffState)];
+}
+
+- (void)sdlex_setAlertSoftButtonIcon {
+ SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:AlertSoftButton];
+ [object transitionToNextState];
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m
index 7790376c6..b8c76baaa 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.m
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.m
@@ -5,6 +5,7 @@
#import "AppConstants.h"
#import "AlertManager.h"
#import "AudioManager.h"
+#import "ButtonManager.h"
#import "Preferences.h"
#import "ProxyManager.h"
#import "RPCPermissionsManager.h"
@@ -26,11 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
// Describes the first time the HMI state goes non-none and full.
@property (assign, nonatomic) SDLHMILevel firstHMILevel;
-@property (assign, nonatomic, getter=isTextEnabled) BOOL textEnabled;
-@property (assign, nonatomic, getter=isHexagonEnabled) BOOL toggleEnabled;
-@property (assign, nonatomic, getter=areImagesEnabled) BOOL imagesEnabled;
-
@property (strong, nonatomic) VehicleDataManager *vehicleDataManager;
+@property (strong, nonatomic) ButtonManager *buttonManager;
@property (strong, nonatomic) AudioManager *audioManager;
@property (nonatomic, copy, nullable) RefreshUIHandler refreshUIHandler;
@end
@@ -59,10 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
_state = ProxyStateStopped;
_firstHMILevel = SDLHMILevelNone;
- _textEnabled = YES;
- _toggleEnabled = YES;
- _imagesEnabled = YES;
-
return self;
}
@@ -76,6 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
}
self.vehicleDataManager = [[VehicleDataManager alloc] initWithManager:self.sdlManager refreshUIHandler:self.refreshUIHandler];
+ self.buttonManager = [[ButtonManager alloc] initWithManager:self.sdlManager refreshUIHandler:self.refreshUIHandler];
self.audioManager = [[AudioManager alloc] initWithManager:self.sdlManager];
[weakSelf sdlex_updateProxyState:ProxyStateConnected];
@@ -164,34 +159,7 @@ NS_ASSUME_NONNULL_BEGIN
}
[self sdlex_updateScreen];
- self.sdlManager.screenManager.softButtonObjects = [self sdlex_softButtons];
-}
-
-- (void)setTextEnabled:(BOOL)textEnabled {
- _textEnabled = textEnabled;
- [self sdlex_updateScreen];
-}
-
-- (void)setImagesEnabled:(BOOL)imagesEnabled {
- _imagesEnabled = imagesEnabled;
- [self sdlex_updateScreen];
- [self setToggleSoftButtonIcon:self.isHexagonEnabled imagesEnabled:imagesEnabled];
- [self setAlertSoftButtonIcon];
-}
-
-- (void)setToggleEnabled:(BOOL)hexagonEnabled {
- _toggleEnabled = hexagonEnabled;
- [self setToggleSoftButtonIcon:hexagonEnabled imagesEnabled:self.areImagesEnabled];
-}
-
-- (void)setToggleSoftButtonIcon:(BOOL)toggleEnabled imagesEnabled:(BOOL)imagesEnabled {
- SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:ToggleSoftButton];
- imagesEnabled ? [object transitionToStateNamed:(toggleEnabled ? ToggleSoftButtonImageOnState : ToggleSoftButtonImageOffState)] : [object transitionToStateNamed:(toggleEnabled ? ToggleSoftButtonTextOnState : ToggleSoftButtonTextOffState)];
-}
-
-- (void)setAlertSoftButtonIcon {
- SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:AlertSoftButton];
- [object transitionToNextState];
+ self.sdlManager.screenManager.softButtonObjects = [self.buttonManager allScreenSoftButtons];
}
- (nullable RefreshUIHandler)refreshUIHandler {
@@ -206,16 +174,20 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdlex_updateScreen {
+ if (![self.sdlManager.hmiLevel isEqualToEnum:SDLHMILevelFull]) { return; }
+
SDLScreenManager *screenManager = self.sdlManager.screenManager;
+ BOOL isTextEnabled = self.buttonManager.isTextEnabled;
+ BOOL areImagesVisible = self.buttonManager.areImagesEnabled;
[screenManager beginUpdates];
screenManager.textAlignment = SDLTextAlignmentLeft;
- screenManager.textField1 = self.isTextEnabled ? SmartDeviceLinkText : nil;
- screenManager.textField2 = self.isTextEnabled ? [NSString stringWithFormat:@"Obj-C %@", ExampleAppText] : nil;
- screenManager.textField3 = self.isTextEnabled ? self.vehicleDataManager.vehicleOdometerData : nil;
+ screenManager.textField1 = isTextEnabled ? SmartDeviceLinkText : nil;
+ screenManager.textField2 = isTextEnabled ? [NSString stringWithFormat:@"Obj-C %@", ExampleAppText] : nil;
+ screenManager.textField3 = isTextEnabled ? self.vehicleDataManager.vehicleOdometerData : nil;
if (self.sdlManager.systemCapabilityManager.displayCapabilities.graphicSupported) {
- screenManager.primaryGraphic = self.areImagesEnabled ? [SDLArtwork persistentArtworkWithImage:[UIImage imageNamed:@"sdl_logo_green"] asImageFormat:SDLArtworkImageFormatPNG] : nil;
+ screenManager.primaryGraphic = areImagesVisible ? [SDLArtwork persistentArtworkWithImage:[UIImage imageNamed:@"sdl_logo_green"] asImageFormat:SDLArtworkImageFormatPNG] : nil;
}
[screenManager endUpdatesWithCompletionHandler:^(NSError * _Nullable error) {
@@ -325,70 +297,16 @@ static UInt32 choiceSetId = 100;
}];
}
-# pragma mark Soft buttons
-
-- (NSArray<SDLSoftButtonObject *> *)sdlex_softButtons {
- SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText image:[UIImage imageNamed:CarIconImageName]];
- SDLSoftButtonState *alertTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonTextState text:AlertSoftButtonText image:nil];
-
- __weak typeof(self) weakself = self;
- SDLSoftButtonObject *alertSoftButton = [[SDLSoftButtonObject alloc] initWithName:AlertSoftButton states:@[alertImageAndTextState, alertTextState] initialStateName:alertImageAndTextState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
- if (buttonPress == nil) { return; }
-
- [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil]];
-
- SDLLogD(@"Star icon soft button press fired");
- }];
-
- SDLSoftButtonState *toggleImageOnState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOnState text:nil image:[UIImage imageNamed:WheelIconImageName]];
- SDLSoftButtonState *toggleImageOffState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOffState text:nil image:[UIImage imageNamed:LaptopIconImageName]];
- SDLSoftButtonState *toggleTextOnState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonTextOnState text:ToggleSoftButtonTextTextOnText image:nil];
- SDLSoftButtonState *toggleTextOffState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonTextOffState text:ToggleSoftButtonTextTextOffText image:nil];
- SDLSoftButtonObject *toggleButton = [[SDLSoftButtonObject alloc] initWithName:ToggleSoftButton states:@[toggleImageOnState, toggleImageOffState, toggleTextOnState, toggleTextOffState] initialStateName:toggleImageOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
- if (buttonPress == nil) { return; }
-
- weakself.toggleEnabled = !weakself.toggleEnabled;
- SDLLogD(@"Toggle icon button press fired %d", self.toggleEnabled);
- }];
-
- SDLSoftButtonState *textOnState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOnState text:TextVisibleSoftButtonTextOnText image:nil];
- SDLSoftButtonState *textOffState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOffState text:TextVisibleSoftButtonTextOffText image:nil];
- SDLSoftButtonObject *textButton = [[SDLSoftButtonObject alloc] initWithName:TextVisibleSoftButton states:@[textOnState, textOffState] initialStateName:textOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
- if (buttonPress == nil) { return; }
-
- weakself.textEnabled = !weakself.textEnabled;
- SDLSoftButtonObject *object = [weakself.sdlManager.screenManager softButtonObjectNamed:TextVisibleSoftButton];
- [object transitionToNextState];
-
- SDLLogD(@"Text visibility soft button press fired %d", weakself.textEnabled);
- }];
-
- SDLSoftButtonState *imagesOnState = [[SDLSoftButtonState alloc] initWithStateName:ImagesVisibleSoftButtonImageOnState text:ImagesVisibleSoftButtonImageOnText image:nil];
- SDLSoftButtonState *imagesOffState = [[SDLSoftButtonState alloc] initWithStateName:ImagesVisibleSoftButtonImageOffState text:ImagesVisibleSoftButtonImageOffText image:nil];
- SDLSoftButtonObject *imagesButton = [[SDLSoftButtonObject alloc] initWithName:ImagesVisibleSoftButton states:@[imagesOnState, imagesOffState] initialStateName:imagesOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
- if (buttonPress == nil) {
- return;
- }
-
- weakself.imagesEnabled = !weakself.imagesEnabled;
-
- SDLSoftButtonObject *object = [weakself.sdlManager.screenManager softButtonObjectNamed:ImagesVisibleSoftButton];
- [object transitionToNextState];
-
- SDLLogD(@"Image visibility soft button press fired %d", weakself.imagesEnabled);
- }];
-
- return @[alertSoftButton, toggleButton, textButton, imagesButton];
-}
-
#pragma mark - SDLManagerDelegate
- (void)managerDidDisconnect {
[self sdlex_updateProxyState:ProxyStateStopped];
-
- // Reset our state
self.firstHMILevel = SDLHMILevelNone;
- [self.vehicleDataManager stopManager];
+
+ if (self.vehicleDataManager != nil && self.buttonManager != nil) {
+ [self.vehicleDataManager stopManager];
+ [self.buttonManager stopManager];
+ }
// If desired, automatically start searching for a new connection to Core
if (ExampleAppShouldRestartSDLManagerOnDisconnect) {