diff options
author | NicoleYarroch <nicole@livio.io> | 2020-08-10 15:46:02 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2020-08-10 15:46:02 -0400 |
commit | a003c838af18ca8a2728a94fe075503dc1cc332d (patch) | |
tree | 80cb6cf4f5f52643eab8df76623a2de21bdcd872 | |
parent | 49c4d57ea8bd6d919562ea704d080db3f29cb03c (diff) | |
download | sdl_ios-a003c838af18ca8a2728a94fe075503dc1cc332d.tar.gz |
Added subtle alert to ex. apps
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | Example Apps/Example ObjC/AlertManager.h | 21 | ||||
-rw-r--r-- | Example Apps/Example ObjC/AlertManager.m | 4 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ButtonManager.h | 2 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ButtonManager.m | 101 | ||||
-rw-r--r-- | Example Apps/Example Swift/AlertManager.swift | 14 | ||||
-rw-r--r-- | Example Apps/Example Swift/ButtonManager.swift | 75 | ||||
-rw-r--r-- | Example Apps/Example Swift/ProxyManager.swift | 2 | ||||
-rw-r--r-- | Example Apps/Shared/AppConstants.h | 16 | ||||
-rw-r--r-- | Example Apps/Shared/AppConstants.m | 16 |
9 files changed, 138 insertions, 113 deletions
diff --git a/Example Apps/Example ObjC/AlertManager.h b/Example Apps/Example ObjC/AlertManager.h index 10508261a..64474c7f3 100644 --- a/Example Apps/Example ObjC/AlertManager.h +++ b/Example Apps/Example ObjC/AlertManager.h @@ -9,21 +9,26 @@ #import <Foundation/Foundation.h> @class SDLAlert; +@class SDLSubtleAlert; NS_ASSUME_NONNULL_BEGIN @interface AlertManager : NSObject -/** - Creates an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped. - - @param textField1 The first line of the message to display in the alert - @param textField2 The second line of the message to display in the alert - @param iconName An image to show in the alert. - @return An SDLAlert object - */ +/// Creates an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped. +/// @param textField1 The first line of the message to display in the alert +/// @param textField2 The second line of the message to display in the alert +/// @param iconName An image to show in the alert +/// @return An SDLAlert object + (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName; +/// Creates as subtle alert with two lines of text, an image, and a close button that will dismiss the alert when tapped. +/// @param textField1 The first line of the message to display in the alert +/// @param textField2 The second line of the message to display in the alert +/// @param iconName An image to show in the alert +/// @return An SDLSubtleAlert object + + (SDLSubtleAlert *)subtleAlertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName; + @end NS_ASSUME_NONNULL_END diff --git a/Example Apps/Example ObjC/AlertManager.m b/Example Apps/Example ObjC/AlertManager.m index 3efbba544..072ba5ac7 100644 --- a/Example Apps/Example ObjC/AlertManager.m +++ b/Example Apps/Example ObjC/AlertManager.m @@ -22,6 +22,10 @@ NS_ASSUME_NONNULL_BEGIN return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil softButtons:@[[self.class sdlex_okSoftButton]] playTone:YES ttsChunks:nil duration:5000 progressIndicator:NO alertIcon:((iconName != nil) ? [[SDLImage alloc] initWithName:iconName isTemplate:YES] : nil) cancelID:0]; } ++ (SDLSubtleAlert *)subtleAlertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName { + return [[SDLSubtleAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertIcon:((iconName != nil) ? [[SDLImage alloc] initWithName:iconName isTemplate:YES] : nil) ttsChunks:nil duration:nil softButtons:@[[self.class sdlex_okSoftButton]] cancelID:0]; +} + @end NS_ASSUME_NONNULL_END diff --git a/Example Apps/Example ObjC/ButtonManager.h b/Example Apps/Example ObjC/ButtonManager.h index 867f50c7c..256ea8ee4 100644 --- a/Example Apps/Example ObjC/ButtonManager.h +++ b/Example Apps/Example ObjC/ButtonManager.h @@ -18,12 +18,12 @@ 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; +/// An array of all the soft buttons - (NSArray<SDLSoftButtonObject *> *)allScreenSoftButtons; @end diff --git a/Example Apps/Example ObjC/ButtonManager.m b/Example Apps/Example ObjC/ButtonManager.m index 1809249db..ea58f00f4 100644 --- a/Example Apps/Example ObjC/ButtonManager.m +++ b/Example Apps/Example ObjC/ButtonManager.m @@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN @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 @@ -37,7 +36,6 @@ NS_ASSUME_NONNULL_BEGIN _textEnabled = YES; _imagesEnabled = YES; - _toggleEnabled = YES; return self; } @@ -52,61 +50,40 @@ NS_ASSUME_NONNULL_BEGIN - (void)setImagesEnabled:(BOOL)imagesEnabled { _imagesEnabled = imagesEnabled; - - SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:AlertSoftButton]; - [object transitionToNextState]; - if (self.refreshUIHandler == nil) { return; } self.refreshUIHandler(); } -- (void)setToggleEnabled:(BOOL)toggleEnabled { - _toggleEnabled = toggleEnabled; - SDLSoftButtonObject *object = [self.sdlManager.screenManager softButtonObjectNamed:ToggleSoftButton]; - [object transitionToStateNamed:(toggleEnabled ? ToggleSoftButtonImageOnState : ToggleSoftButtonImageOffState)]; -} - #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]]; + return @[[self sdlex_softButtonAlert], [self sdlex_softButtonSubtleAlert], [self sdlex_softButtonTextVisible], [self sdlex_softButtonImagesVisible]]; } -- (SDLSoftButtonObject *)sdlex_softButtonAlertWithManager:(SDLManager *)manager { +- (SDLSoftButtonObject *)sdlex_softButtonAlert { SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:CarBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] name:CarBWIconImageName asImageFormat:SDLArtworkImageFormatPNG]]; SDLSoftButtonState *alertTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonTextState text:AlertSoftButtonText image:nil]; - __weak typeof(self) weakself = self; + __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.fileManager uploadArtwork:[SDLArtwork artworkWithImage:[UIImage imageNamed:CarBWIconImageName] asImageFormat:SDLArtworkImageFormatPNG] completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) { - [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil iconName:artworkName] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { - NSLog(@"ALERT req: %@, res: %@, err: %@", request, response, error); - }]; - }]; - - SDLLogD(@"Star icon soft button press fired"); + [weakSelf sdlex_sendAlertWithImageName:CarBWIconImageName textField1:AlertMessageText textField2:nil]; }]; return alertSoftButton; } -- (SDLSoftButtonObject *)sdlex_softButtonToggleWithManager:(SDLManager *)manager { - SDLSoftButtonState *toggleImageOnState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOnState text:nil image:[[UIImage imageNamed:ToggleOnBWIconName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; - SDLSoftButtonState *toggleImageOffState = [[SDLSoftButtonState alloc] initWithStateName:ToggleSoftButtonImageOffState text:nil image:[[UIImage imageNamed:ToggleOffBWIconName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; - - __weak typeof(self) weakself = self; - SDLSoftButtonObject *toggleButton = [[SDLSoftButtonObject alloc] initWithName:ToggleSoftButton states:@[toggleImageOnState, toggleImageOffState] initialStateName:toggleImageOnState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) { +- (SDLSoftButtonObject *)sdlex_softButtonSubtleAlert { + __weak typeof(self) weakSelf = self; + return [[SDLSoftButtonObject alloc] initWithName:SubtleAlertSoftButton text:nil artwork: [SDLArtwork artworkWithImage:[[UIImage imageNamed:BatteryFullBWIconName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] 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; + [weakSelf sdlex_sendSubtleAlertWithImageName:BatteryEmptyBWIconName textField1:SubtleAlertHeaderText textField2:SubtleAlertSubheaderText errorMessage:SubtleAlertNotSupportedText]; + }]; } -- (SDLSoftButtonObject *)sdlex_softButtonTextVisibleWithManager:(SDLManager *)manager { +- (SDLSoftButtonObject *)sdlex_softButtonTextVisible { SDLSoftButtonState *textOnState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOnState text:TextVisibleSoftButtonTextOnText image:nil]; SDLSoftButtonState *textOffState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOffState text:TextVisibleSoftButtonTextOffText image:nil]; @@ -115,39 +92,71 @@ NS_ASSUME_NONNULL_BEGIN 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); + SDLSoftButtonObject *textVisibleSoftButton = [weakself.sdlManager.screenManager softButtonObjectNamed:TextVisibleSoftButton]; + [textVisibleSoftButton transitionToNextState]; }]; return textButton; } -- (SDLSoftButtonObject *)sdlex_softButtonImagesVisibleWithManager:(SDLManager *)manager { +- (SDLSoftButtonObject *)sdlex_softButtonImagesVisible { 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; - } + if (buttonPress == nil) { return; } weakself.imagesEnabled = !weakself.imagesEnabled; - SDLSoftButtonObject *object = [weakself.sdlManager.screenManager softButtonObjectNamed:ImagesVisibleSoftButton]; - [object transitionToNextState]; + SDLSoftButtonObject *imagesVisibleSoftButton = [weakself.sdlManager.screenManager softButtonObjectNamed:ImagesVisibleSoftButton]; + [imagesVisibleSoftButton transitionToNextState]; - SDLSoftButtonObject *textButton = [weakself.sdlManager.screenManager softButtonObjectNamed:TextVisibleSoftButton]; - [textButton transitionToNextState]; - - SDLLogD(@"Image visibility soft button press fired %d", weakself.imagesEnabled); + SDLSoftButtonObject *alertSoftButton = [weakself.sdlManager.screenManager softButtonObjectNamed:AlertSoftButton]; + [alertSoftButton transitionToNextState]; }]; return imagesButton; } +#pragma mark - Helpers + +- (void)sdlex_sendImageWithName:(NSString *)imageName completionHandler:(void (^)(BOOL success, NSString *_Nullable artworkName))completionHandler { + SDLArtwork *artwork = [SDLArtwork artworkWithImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG]; + + [self.sdlManager.fileManager uploadArtwork:artwork completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) { + return completionHandler(success, artworkName); + }]; +} + +- (void)sdlex_sendAlertWithImageName:(NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 { + __weak typeof(self) weakSelf = self; + [self sdlex_sendImageWithName:imageName completionHandler:^(BOOL success, NSString * _Nullable artworkName) { + SDLAlert *alert = [AlertManager alertWithMessageAndCloseButton:textField1 textField2:textField2 iconName:(success ? artworkName : nil)]; + [weakSelf sdlex_sendAlertRequest:alert errorMessage:SubtleAlertNotSupportedText]; + }]; +} + +- (void)sdlex_sendSubtleAlertWithImageName:(NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 errorMessage:(NSString *)errorMessage { + __weak typeof(self) weakSelf = self; + [self sdlex_sendImageWithName:imageName completionHandler:^(BOOL success, NSString * _Nullable artworkName) { + SDLSubtleAlert *subtleAlert = [AlertManager subtleAlertWithMessageAndCloseButton:textField1 textField2:textField2 iconName:(success ? artworkName : nil)]; + [weakSelf sdlex_sendAlertRequest:subtleAlert errorMessage:errorMessage]; + }]; +} + +- (void)sdlex_sendAlertRequest:(SDLRPCRequest *)request errorMessage:(nullable NSString *)errorMessage { + __weak typeof(self) weakSelf = self; + [self.sdlManager sendRequest:request withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + if (response.success.boolValue == NO && errorMessage != nil) { + SDLAlert *warningAlert = [AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]; + [weakSelf.sdlManager sendRequest:warningAlert]; + } + }]; +} + + @end NS_ASSUME_NONNULL_END diff --git a/Example Apps/Example Swift/AlertManager.swift b/Example Apps/Example Swift/AlertManager.swift index 718210777..a8cd384b9 100644 --- a/Example Apps/Example Swift/AlertManager.swift +++ b/Example Apps/Example Swift/AlertManager.swift @@ -15,13 +15,23 @@ class AlertManager { } /// Creates an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped. - /// /// - Parameters: /// - textField1: The first line of a message to display in the alert /// - textField2: The second line of a message to display in the alert - /// - iconName: The name of the uploaded icon artwork + /// - iconName: An image to show in the alert /// - Returns: An SDLAlert object class func alertWithMessageAndCloseButton(_ textField1: String, textField2: String? = nil, iconName: String? = nil) -> SDLAlert { return SDLAlert(alertText1: textField1, alertText2: textField2, alertText3: nil, softButtons: [okSoftButton], playTone: true, ttsChunks: nil, duration: 5000, progressIndicator: false, alertIcon: (iconName != nil) ? SDLImage(name: iconName!, isTemplate: true) : nil, cancelID: 0) } + + + /// Creates as subtle alert with two lines of text, an image, and a close button that will dismiss the alert when tapped. + /// - Parameters: + /// - textField1: The first line of a message to display in the alert + /// - textField2: The second line of a message to display in the alert + /// - iconName: An image to show in the alert + /// - Returns: An SDLSubtleAlert object + class func subtleAlertWithMessageAndCloseButton(_ textField1: String, textField2: String? = nil, iconName: String? = nil) -> SDLSubtleAlert { + return SDLSubtleAlert(alertText1: textField1, alertText2: textField2, alertIcon: (iconName != nil) ? SDLImage(name: iconName!, isTemplate: true) : nil, ttsChunks: nil, duration: nil, softButtons: [okSoftButton], cancelID: NSNumber(0)) + } } diff --git a/Example Apps/Example Swift/ButtonManager.swift b/Example Apps/Example Swift/ButtonManager.swift index e0953accc..ac5a2f201 100644 --- a/Example Apps/Example Swift/ButtonManager.swift +++ b/Example Apps/Example Swift/ButtonManager.swift @@ -16,7 +16,7 @@ class ButtonManager: NSObject { fileprivate let sdlManager: SDLManager! fileprivate var refreshUIHandler: RefreshUIHandler? - /// SDL UI textfields are visible if true; hidden if false + /// Textfields are visible if true; hidden if false public fileprivate(set) var textEnabled: Bool { didSet { guard let refreshUIHandler = refreshUIHandler else { return } @@ -24,75 +24,75 @@ class ButtonManager: NSObject { } } - /// SDL UI images are visible if true; hidden if false + /// UI images are visible if true; hidden if false public fileprivate(set) var imagesEnabled: Bool { didSet { - guard let refreshUIHandler = refreshUIHandler, let alertSoftButton = sdlManager.screenManager.softButtonObjectNamed(AlertSoftButton) else { return } - alertSoftButton.transitionToNextState() + guard let refreshUIHandler = refreshUIHandler else { return } refreshUIHandler() } } - /// Keeps track of the toggle soft button current state. The image or text changes when the button is selected - fileprivate var toggleEnabled: Bool { - didSet { - guard let hexagonSoftButton = sdlManager.screenManager.softButtonObjectNamed(ToggleSoftButton), hexagonSoftButton.transition(toState: toggleEnabled ? ToggleSoftButtonImageOnState : ToggleSoftButtonImageOffState) else { return } - } - } - init(sdlManager: SDLManager, updateScreenHandler: RefreshUIHandler? = nil) { self.sdlManager = sdlManager self.refreshUIHandler = updateScreenHandler textEnabled = true imagesEnabled = true - toggleEnabled = true - super.init() } - /// Creates and returns an array of all soft buttons for the UI + /// An array of all the soft buttons /// /// - Parameter manager: The SDL Manager /// - Returns: An array of all soft buttons for the UI - func allScreenSoftButtons(with manager: SDLManager) -> [SDLSoftButtonObject] { - return [softButtonAlert(with: manager), softButtonToggle(), softButtonTextVisible(), softButtonImagesVisible()] + func allScreenSoftButtons() -> [SDLSoftButtonObject] { + return [softButtonAlert, softButtonSubtleAlert, softButtonTextVisible, softButtonImagesVisible] } } // MARK: - Custom Soft Buttons -private extension ButtonManager { +extension ButtonManager { /// Returns a soft button that shows an alert when tapped. /// /// - Parameter manager: The SDL Manager for showing the alert /// - Returns: A soft button - func softButtonAlert(with manager: SDLManager) -> SDLSoftButtonObject { + private var softButtonAlert: SDLSoftButtonObject { let imageSoftButtonState = SDLSoftButtonState(stateName: AlertSoftButtonImageState, text: nil, image: UIImage(named: AlertBWIconName)?.withRenderingMode(.alwaysTemplate)) let textSoftButtonState = SDLSoftButtonState(stateName: AlertSoftButtonTextState, text: AlertSoftButtonText, image: nil) - return SDLSoftButtonObject(name: AlertSoftButton, states: [imageSoftButtonState, textSoftButtonState], initialStateName: imageSoftButtonState.name) { (buttonPress, buttonEvent) in - guard buttonPress != nil else { return } - manager.fileManager.upload(artwork: SDLArtwork(image: UIImage(named: CarBWIconImageName)!, persistent: false, as: .PNG), completionHandler: { (success, artworkName, bytesAvailable, err) in - let alert = AlertManager.alertWithMessageAndCloseButton("You pressed the button!", iconName: artworkName) - manager.send(alert) + return SDLSoftButtonObject(name: AlertSoftButton, states: [imageSoftButtonState, textSoftButtonState], initialStateName: imageSoftButtonState.name) { [weak self] (buttonPress, buttonEvent) in + guard let self = self, buttonPress != nil else { return } + self.sdlManager.fileManager.upload(artwork: SDLArtwork(image: UIImage(named: CarBWIconImageName)!, persistent: false, as: .PNG), completionHandler: { [weak self] (success, artworkName, bytesAvailable, err) in + guard let self = self else { return } + let alert = AlertManager.alertWithMessageAndCloseButton(AlertMessageText, iconName: artworkName) + self.sdlManager.send(alert) }) } } - /// Returns a soft button that toggles between two states: on and off. If images are currently visible, the button image toggles; if images aren't visible, the button text toggles. + /// Returns a soft button that shows a subtle alert when tapped. /// /// - Returns: A soft button - func softButtonToggle() -> SDLSoftButtonObject { - let imageOnState = SDLSoftButtonState(stateName: ToggleSoftButtonImageOnState, text: nil, image: UIImage(named: ToggleOnBWIconName)?.withRenderingMode(.alwaysTemplate)) - let imageOffState = SDLSoftButtonState(stateName: ToggleSoftButtonImageOffState, text: nil, image: UIImage(named: ToggleOffBWIconName)?.withRenderingMode(.alwaysTemplate)) - return SDLSoftButtonObject(name: ToggleSoftButton, states: [imageOnState, imageOffState], initialStateName: imageOnState.name) { [unowned self] (buttonPress, buttonEvent) in - guard buttonPress != nil else { return } - self.toggleEnabled = !self.toggleEnabled + private var softButtonSubtleAlert: SDLSoftButtonObject { + return SDLSoftButtonObject(name: SubtleAlertSoftButton, text: nil, artwork: SDLArtwork(image: (UIImage(named: BatteryFullBWIconName)?.withRenderingMode(.alwaysTemplate))!, persistent: false, as: .PNG)) { [weak self] (buttonPress, buttonEvent) in + guard let self = self, buttonPress != nil else { return } + + let subtleAlertImage = SDLArtwork(image: (UIImage(named: BatteryEmptyBWIconName)?.withRenderingMode(.alwaysTemplate))!, persistent: false, as: .PNG) + self.sdlManager.fileManager.upload(artwork: subtleAlertImage, completionHandler: { [weak self] (success, artworkName, bytesAvailable, err) in + guard let self = self else { return } + + let subtleAlert = AlertManager.subtleAlertWithMessageAndCloseButton(SubtleAlertHeaderText, textField2: SubtleAlertSubheaderText, iconName: artworkName) + self.sdlManager.send(request: subtleAlert) { [weak self] (request, response, error) in + guard let self = self, !(response?.success.boolValue ?? false) else { return } + + self.sdlManager.send(AlertManager.alertWithMessageAndCloseButton(SubtleAlertNotSupportedText)) + } + }) } } /// Returns a soft button that toggles the textfield visibility state for the SDL UI. The button's text toggles based on the current text visibility. /// /// - Returns: A soft button - func softButtonTextVisible() -> SDLSoftButtonObject { + private var softButtonTextVisible: SDLSoftButtonObject { let textVisibleState = SDLSoftButtonState(stateName: TextVisibleSoftButtonTextOnState, text: TextVisibleSoftButtonTextOnText, artwork: nil) let textNotVisibleState = SDLSoftButtonState(stateName: TextVisibleSoftButtonTextOffState, text: TextVisibleSoftButtonTextOffText, image: nil) return SDLSoftButtonObject(name: TextVisibleSoftButton, states: [textVisibleState, textNotVisibleState], initialStateName: textVisibleState.name) { [unowned self] (buttonPress, buttonEvent) in @@ -108,16 +108,17 @@ private extension ButtonManager { /// Returns a soft button that toggles the image visibility state for the SDL UI. The button's text toggles based on the current image visibility. /// /// - Returns: A soft button - func softButtonImagesVisible() -> SDLSoftButtonObject { + private var softButtonImagesVisible: SDLSoftButtonObject { let imagesVisibleState = SDLSoftButtonState(stateName: ImagesVisibleSoftButtonImageOnState, text: ImagesVisibleSoftButtonImageOnText, image: nil) let imagesNotVisibleState = SDLSoftButtonState(stateName: ImagesVisibleSoftButtonImageOffState, text: ImagesVisibleSoftButtonImageOffText, image: nil) - return SDLSoftButtonObject(name: ImagesVisibleSoftButton, states: [imagesVisibleState, imagesNotVisibleState], initialStateName: imagesVisibleState.name) { [unowned self] (buttonPress, buttonEvent) in - guard buttonPress != nil else { return } + return SDLSoftButtonObject(name: ImagesVisibleSoftButton, states: [imagesVisibleState, imagesNotVisibleState], initialStateName: imagesVisibleState.name) { [weak self] (buttonPress, buttonEvent) in + guard let self = self, let manager = self.sdlManager, buttonPress != nil, let alertSoftButton = manager.screenManager.softButtonObjectNamed(AlertSoftButton) else { return } self.imagesEnabled = !self.imagesEnabled - // Update the button state - let softButton = self.sdlManager.screenManager.softButtonObjectNamed(ImagesVisibleSoftButton) - softButton?.transitionToNextState() + let imagesVisibleSoftButton = self.sdlManager.screenManager.softButtonObjectNamed(ImagesVisibleSoftButton) + imagesVisibleSoftButton?.transitionToNextState() + + alertSoftButton.transitionToNextState() } } } diff --git a/Example Apps/Example Swift/ProxyManager.swift b/Example Apps/Example Swift/ProxyManager.swift index fdad60360..ab6f656d9 100644 --- a/Example Apps/Example Swift/ProxyManager.swift +++ b/Example Apps/Example Swift/ProxyManager.swift @@ -255,7 +255,7 @@ private extension ProxyManager { sdlManager.send(setDisplayLayout) updateScreen() - sdlManager.screenManager.softButtonObjects = buttonManager.allScreenSoftButtons(with: sdlManager) + sdlManager.screenManager.softButtonObjects = buttonManager.allScreenSoftButtons() } /// Update the UI's textfields, images and soft buttons diff --git a/Example Apps/Shared/AppConstants.h b/Example Apps/Shared/AppConstants.h index 5fb4b25b0..bc5f3f82f 100644 --- a/Example Apps/Shared/AppConstants.h +++ b/Example Apps/Shared/AppConstants.h @@ -22,13 +22,7 @@ extern NSString * const SmartDeviceLinkText; extern NSString * const ExampleAppText; #pragma mark - SDL Soft Buttons -extern NSString * const ToggleSoftButton; -extern NSString * const ToggleSoftButtonImageOnState; -extern NSString * const ToggleSoftButtonImageOffState; -extern NSString * const ToggleSoftButtonTextOnState; -extern NSString * const ToggleSoftButtonTextOffState; -extern NSString * const ToggleSoftButtonTextTextOnText; -extern NSString * const ToggleSoftButtonTextTextOffText; +extern NSString * const SubtleAlertSoftButton; extern NSString * const AlertSoftButton; extern NSString * const AlertSoftButtonImageState; @@ -48,7 +42,11 @@ extern NSString * const ImagesVisibleSoftButtonImageOnText; extern NSString * const ImagesVisibleSoftButtonImageOffText; #pragma mark - Alert +extern NSString * const AlertMessageText; extern NSString * const AlertOKButtonText; +extern NSString * const SubtleAlertHeaderText; +extern NSString * const SubtleAlertSubheaderText; +extern NSString * const SubtleAlertNotSupportedText; #pragma mark - SDL Text-To-Speech extern NSString * const TTSGoodJob; @@ -123,8 +121,8 @@ extern NSString * const MenuBWIconImageName; extern NSString * const MicrophoneBWIconImageName; extern NSString * const PhoneBWIconImageName; extern NSString * const SpeakBWIconImageName; -extern NSString * const ToggleOffBWIconName; -extern NSString * const ToggleOnBWIconName; +extern NSString * const BatteryEmptyBWIconName; +extern NSString * const BatteryFullBWIconName; #pragma mark - SDL App Name in Different Languages extern NSString * const ExampleAppNameSpanish; diff --git a/Example Apps/Shared/AppConstants.m b/Example Apps/Shared/AppConstants.m index ffe4762d1..9c7558614 100644 --- a/Example Apps/Shared/AppConstants.m +++ b/Example Apps/Shared/AppConstants.m @@ -19,13 +19,7 @@ NSString * const SmartDeviceLinkText = @"SmartDeviceLink (SDL)"; NSString * const ExampleAppText = @"Example App"; #pragma mark - SDL Soft Buttons -NSString * const ToggleSoftButton = @"ToggleSoftButton"; -NSString * const ToggleSoftButtonImageOnState = @"ToggleSoftButtonImageOnState"; -NSString * const ToggleSoftButtonImageOffState = @"ToggleSoftButtonImageOffState"; -NSString * const ToggleSoftButtonTextOnState = @"ToggleSoftButtonTextOnState"; -NSString * const ToggleSoftButtonTextOffState = @"ToggleSoftButtonTextOffState"; -NSString * const ToggleSoftButtonTextTextOnText = @"➖"; -NSString * const ToggleSoftButtonTextTextOffText = @"➕"; +NSString * const SubtleAlertSoftButton = @"ToggleSoftButton"; NSString * const AlertSoftButton = @"AlertSoftButton"; NSString * const AlertSoftButtonImageState = @"AlertSoftButtonImageState"; @@ -45,7 +39,11 @@ NSString * const ImagesVisibleSoftButtonImageOnText = @"➖Icons"; NSString * const ImagesVisibleSoftButtonImageOffText = @"➕Icons"; #pragma mark - Alert +NSString * const AlertMessageText = @"You pressed the button!"; NSString * const AlertOKButtonText = @"OK"; +NSString * const SubtleAlertHeaderText = @"Battery Level"; +NSString * const SubtleAlertSubheaderText = @"Almost empty"; +NSString * const SubtleAlertNotSupportedText = @"Subtle alert is not supported on this module"; #pragma mark - SDL Text-To-Speech NSString * const TTSGoodJob = @"Good Job"; @@ -120,8 +118,8 @@ NSString * const MenuBWIconImageName = @"choice_set"; NSString * const MicrophoneBWIconImageName = @"microphone"; NSString * const PhoneBWIconImageName = @"phone"; NSString * const SpeakBWIconImageName = @"speak"; -NSString * const ToggleOffBWIconName = @"toggle_off"; -NSString * const ToggleOnBWIconName = @"toggle_on"; +NSString * const BatteryEmptyBWIconName = @"toggle_off"; +NSString * const BatteryFullBWIconName = @"toggle_on"; #pragma mark - SDL App Name in Different Languages NSString * const ExampleAppNameSpanish = @"SDL Aplicación de ejemplo"; |