summaryrefslogtreecommitdiff
path: root/Example Apps
diff options
context:
space:
mode:
authorleonid lokhmatov, Luxoft <zaqqqqqqqq@gmail.com>2020-08-27 18:36:40 +0300
committerleonid lokhmatov, Luxoft <zaqqqqqqqq@gmail.com>2020-08-27 18:36:40 +0300
commite9e1d6143af4fea1725b66636439017c79bcccaa (patch)
tree39c926dda18a24fb6bc9992e28a789b372c05527 /Example Apps
parent4d936bd0496538994a403143a0c20731bd7ee18b (diff)
parente5975a4c8f0b9109b42e3192cd5ac3d576ae0f6c (diff)
downloadsdl_ios-e9e1d6143af4fea1725b66636439017c79bcccaa.tar.gz
0261 'New vehicle data WindowStatus': Merge branch 'develop' into this [0261], conflicts resolved
# Conflicts: # SmartDeviceLink/SDLGetVehicleDataResponse.h # SmartDeviceLink/SDLVehicleDataType.m # SmartDeviceLinkTests/RPCSpecs/NotificationSpecs/SDLOnVehicleDataSpec.m # SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLGetVehicleDataSpec.m # SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLSubscribeVehicleDataSpec.m # SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLUnsubscribeVehicleDataSpec.m # SmartDeviceLinkTests/RPCSpecs/ResponseSpecs/SDLGetVehicleDataResponseSpec.m # SmartDeviceLinkTests/RPCSpecs/ResponseSpecs/SDLSubscribeVehicleDataResponseSpec.m # SmartDeviceLinkTests/RPCSpecs/ResponseSpecs/SDLUnsubscribeVehicleDataResponseSpec.m
Diffstat (limited to 'Example Apps')
-rw-r--r--Example Apps/Example ObjC/AlertManager.h24
-rw-r--r--Example Apps/Example ObjC/AlertManager.m43
-rw-r--r--Example Apps/Example ObjC/AudioManager.m5
-rw-r--r--Example Apps/Example ObjC/ButtonManager.h2
-rw-r--r--Example Apps/Example ObjC/ButtonManager.m94
-rw-r--r--Example Apps/Example ObjC/MenuManager.m24
-rw-r--r--Example Apps/Example ObjC/VehicleDataManager.m10
-rw-r--r--Example Apps/Example Swift/AlertManager.swift60
-rw-r--r--Example Apps/Example Swift/AudioManager.swift9
-rw-r--r--Example Apps/Example Swift/ButtonManager.swift107
-rw-r--r--Example Apps/Example Swift/MenuManager.swift26
-rw-r--r--Example Apps/Example Swift/ProxyManager.swift2
-rw-r--r--Example Apps/Example Swift/VehicleDataManager.swift14
-rw-r--r--Example Apps/Shared/AppConstants.h31
-rw-r--r--Example Apps/Shared/AppConstants.m33
15 files changed, 301 insertions, 183 deletions
diff --git a/Example Apps/Example ObjC/AlertManager.h b/Example Apps/Example ObjC/AlertManager.h
index 10508261a..d7b42b655 100644
--- a/Example Apps/Example ObjC/AlertManager.h
+++ b/Example Apps/Example ObjC/AlertManager.h
@@ -9,20 +9,26 @@
#import <Foundation/Foundation.h>
@class SDLAlert;
+@class SDLManager;
+@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
- */
-+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName;
+/// Sends an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped.
+/// @param imageName The name of the image to upload
+/// @param textField1 The first line of text in the alert
+/// @param textField2 The second line of text in the alert
+/// @param sdlManager The SDLManager
++ (void)sendAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2;
+
+/// Sends a subtle alert with up to two lines of text, and an image.
+/// @param imageName The name of the image to upload
+/// @param textField1 The first line of text in the alert
+/// @param textField2 The second line of text in the alert
+/// @param sdlManager The SDLManager
++ (void)sendSubtleAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2;
@end
diff --git a/Example Apps/Example ObjC/AlertManager.m b/Example Apps/Example ObjC/AlertManager.m
index 3efbba544..9ee13fcdd 100644
--- a/Example Apps/Example ObjC/AlertManager.m
+++ b/Example Apps/Example ObjC/AlertManager.m
@@ -14,12 +14,47 @@ NS_ASSUME_NONNULL_BEGIN
@implementation AlertManager
-+ (SDLSoftButton *)sdlex_okSoftButton {
- return [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:AlertOKButtonText image:nil highlighted:YES buttonId:1 systemAction:nil handler:nil];
++ (void)sendAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
+ SDLSoftButton *okSoftButton = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:AlertOKButtonText image:nil highlighted:YES buttonId:1 systemAction:nil handler:nil];
+ SDLAlert *alert = [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil softButtons:@[okSoftButton] playTone:YES ttsChunks:nil duration:5000 progressIndicator:NO alertIcon:nil cancelID:0];
+
+ if (imageName == nil) {
+ [sdlManager sendRequest:alert];
+ } else {
+ [self sdlex_sendImageWithName:imageName sdlManager:sdlManager completionHandler:^(BOOL success, NSString * _Nullable artworkName) {
+ if (success) {
+ alert.alertIcon = [[SDLImage alloc] initWithName:artworkName isTemplate:YES];
+ }
+ [sdlManager sendRequest:alert];
+ }];
+ }
}
-+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName {
- 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];
++ (void)sendSubtleAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
+ SDLSubtleAlert *subtleAlert = [[SDLSubtleAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertIcon:nil ttsChunks:nil duration:nil softButtons:nil cancelID:0];
+
+ if (imageName == nil) {
+ [sdlManager sendRequest:subtleAlert];
+ } else {
+ [self sdlex_sendImageWithName:imageName sdlManager:sdlManager completionHandler:^(BOOL success, NSString * _Nullable artworkName) {
+ if (success) {
+ subtleAlert.alertIcon = [[SDLImage alloc] initWithName:artworkName isTemplate:YES];
+ }
+ [sdlManager sendRequest:subtleAlert];
+ }];
+ }
+}
+
+/// Helper method for uploading an image before it is shown in an alert
+/// @param imageName The name of the image to upload
+/// @param sdlManager The SDLManager
+/// @param completionHandler Handler called when the artwork has finished uploading with the success of the upload and the name of the uploaded image.
++ (void)sdlex_sendImageWithName:(NSString *)imageName sdlManager:(SDLManager *)sdlManager completionHandler:(void (^)(BOOL success, NSString * _Nonnull artworkName))completionHandler {
+ SDLArtwork *artwork = [SDLArtwork artworkWithImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG];
+
+ [sdlManager.fileManager uploadArtwork:artwork completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) {
+ return completionHandler(success, artworkName);
+ }];
}
@end
diff --git a/Example Apps/Example ObjC/AudioManager.m b/Example Apps/Example ObjC/AudioManager.m
index cd6ec4ecf..dc1c77e41 100644
--- a/Example Apps/Example ObjC/AudioManager.m
+++ b/Example Apps/Example ObjC/AudioManager.m
@@ -7,6 +7,7 @@
//
#import "AlertManager.h"
+#import "AppConstants.h"
#import "AudioManager.h"
#import <AVFoundation/AVFoundation.h>
#import "SDLLogMacros.h"
@@ -86,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startRecording {
if (self.speechRecognitionAuthState != SpeechRecognitionAuthStateAuthorized) {
SDLLogW(@"This app does not have permission to access the Speech Recognition API");
- [self.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You must give this app permission to access Speech Recognition" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:self.sdlManager image:nil textField1:AlertSpeechPermissionsWarningText textField2:nil];
return;
}
@@ -155,7 +156,7 @@ NS_ASSUME_NONNULL_BEGIN
// The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
SDLLogD(@"Audio Pass Thru ended successfully");
NSString *alertMessage = [NSString stringWithFormat:@"You said: %@", weakSelf.speechTranscription.length == 0 ? @"No speech detected" : weakSelf.speechTranscription];
- [weakSelf.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertMessage textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:weakSelf.sdlManager image:nil textField1:alertMessage textField2:nil];
} else if ([resultCode isEqualToEnum:SDLResultAborted]) {
// The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
SDLLogD(@"Audio recording canceled");
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..4ca86be0a 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,73 @@ 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 - Getters
+
+- (BOOL)sdlex_isSubtleAlertAllowed {
+ return [self.sdlManager.permissionManager isRPCNameAllowed:SDLRPCFunctionNameSubtleAlert];
+}
+
+- (BOOL)sdlex_isAlertAllowed {
+ return [self.sdlManager.permissionManager isRPCNameAllowed:SDLRPCFunctionNameAlert];
}
#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 {
- 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];
+/// Returns a soft button that shows an alert when tapped.
+/// @returns A SDLSoftButtonObject object
+- (SDLSoftButtonObject *)sdlex_softButtonAlert {
+ SDLSoftButtonState *imageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageAndTextState text:AlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:AlertBWIconName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG]];
+ SDLSoftButtonState *textState = [[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) {
+ SDLSoftButtonObject *alertSoftButton = [[SDLSoftButtonObject alloc] initWithName:AlertSoftButton states:@[imageAndTextState, textState] initialStateName:imageAndTextState.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");
+ if (self.sdlex_isAlertAllowed) {
+ [AlertManager sendAlertWithManager:weakself.sdlManager image:CarBWIconImageName textField1:AlertMessageText textField2:nil];
+ } else if (self.sdlex_isSubtleAlertAllowed) {
+ [AlertManager sendSubtleAlertWithManager:weakself.sdlManager image:CarBWIconImageName textField1:AlertMessageText textField2:nil];
+ } else {
+ SDLLogW(@"The module does not support the Alert request or the Subtle Alert request");
+ }
}];
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]];
+/// Returns a soft button that shows a subtle alert when tapped. If the subtle alert is not supported, then a regular alert is shown.
+/// @returns A SDLSoftButtonObject object
+- (SDLSoftButtonObject *)sdlex_softButtonSubtleAlert {
+ SDLSoftButtonState *imageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:SubtleAlertSoftButtonImageAndTextState text:SubtleAlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:BatteryFullBWIconName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG]];
+ SDLSoftButtonState *textState = [[SDLSoftButtonState alloc] initWithStateName:SubtleAlertSoftButtonTextState text:SubtleAlertSoftButtonText image:nil];
__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 *subtleAlertSoftButton = [[SDLSoftButtonObject alloc] initWithName:SubtleAlertSoftButton states:@[imageAndTextState, textState] initialStateName:imageAndTextState.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);
+
+ if (self.sdlex_isSubtleAlertAllowed) {
+ [AlertManager sendSubtleAlertWithManager:weakself.sdlManager image:BatteryEmptyBWIconName textField1:SubtleAlertHeaderText textField2:SubtleAlertSubheaderText];
+ } else if (self.sdlex_isAlertAllowed) {
+ [AlertManager sendAlertWithManager:weakself.sdlManager image:BatteryEmptyBWIconName textField1:SubtleAlertHeaderText textField2:SubtleAlertSubheaderText];
+ } else {
+ SDLLogW(@"The module does not support the Alert request or the Subtle Alert request");
+ }
}];
- return toggleButton;
+ return subtleAlertSoftButton;
}
-- (SDLSoftButtonObject *)sdlex_softButtonTextVisibleWithManager:(SDLManager *)manager {
+/// Returns a soft button that toggles the textfield visibility state.
+/// @returns A SDLSoftButtonObject object
+- (SDLSoftButtonObject *)sdlex_softButtonTextVisible {
SDLSoftButtonState *textOnState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOnState text:TextVisibleSoftButtonTextOnText image:nil];
SDLSoftButtonState *textOffState = [[SDLSoftButtonState alloc] initWithStateName:TextVisibleSoftButtonTextOffState text:TextVisibleSoftButtonTextOffText image:nil];
@@ -115,34 +125,34 @@ 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 {
+/// Returns a soft button that toggles the image visibility state.
+/// @returns A SDLSoftButtonObject object
+- (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];
+ SDLSoftButtonObject *alertSoftButton = [weakself.sdlManager.screenManager softButtonObjectNamed:AlertSoftButton];
+ [alertSoftButton transitionToNextState];
- SDLLogD(@"Image visibility soft button press fired %d", weakself.imagesEnabled);
+ SDLSoftButtonObject *subtleAlertSoftButton = [weakself.sdlManager.screenManager softButtonObjectNamed:SubtleAlertSoftButton];
+ [subtleAlertSoftButton transitionToNextState];
}];
return imagesButton;
diff --git a/Example Apps/Example ObjC/MenuManager.m b/Example Apps/Example ObjC/MenuManager.m
index 6ed1f1f2c..7d572a658 100644
--- a/Example Apps/Example ObjC/MenuManager.m
+++ b/Example Apps/Example ObjC/MenuManager.m
@@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (SDLMenuCell *)sdlex_menuCellDialNumberWithManager:(SDLManager *)manager {
return [[SDLMenuCell alloc] initWithTitle:ACDialPhoneNumberMenuName icon:[SDLArtwork artworkWithImage:[[UIImage imageNamed:PhoneBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] voiceCommands:@[ACDialPhoneNumberMenuName] handler:^(SDLTriggerSource _Nonnull triggerSource) {
if (![RPCPermissionsManager isDialNumberRPCAllowedWithManager:manager]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to dial a number" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertDialNumberPermissionsWarningText textField2:nil];
return;
}
@@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutNonMedia];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (!response.success) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:errorMessage textField2:nil];
}
}];
}];
@@ -111,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutGraphicWithText];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (!response.success) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:errorMessage textField2:nil];
}
}];
}];
@@ -124,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray *submenuItems = [NSMutableArray array];
for (int i = 0; i < 75; i++) {
SDLMenuCell *cell = [[SDLMenuCell alloc] initWithTitle:[NSString stringWithFormat:@"%@ %i", ACSubmenuItemMenuName, i] icon:[SDLArtwork artworkWithImage:[[UIImage imageNamed:MenuBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"You selected %@ %i", ACSubmenuItemMenuName, i] textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:[NSString stringWithFormat:@"You selected %@ %i", ACSubmenuItemMenuName, i] textField2:nil];
}];
[submenuItems addObject:cell];
}
@@ -138,11 +138,11 @@ NS_ASSUME_NONNULL_BEGIN
[manager sendRequest:sliderRPC withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if(![response.resultCode isEqualToEnum:SDLResultSuccess]) {
if ([response.resultCode isEqualToEnum:SDLResultTimedOut]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Slider timed out" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertSliderTimedOutWarningText textField2:nil];
} else if ([response.resultCode isEqualToEnum:SDLResultAborted]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Slider cancelled" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertSliderCancelledWarningText textField2:nil];
} else {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Slider could not be displayed" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertSliderGeneralWarningText textField2:nil];
}
}
}];
@@ -155,11 +155,11 @@ NS_ASSUME_NONNULL_BEGIN
[manager sendRequest:messageRPC withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if(![response.resultCode isEqualToEnum:SDLResultSuccess]) {
if ([response.resultCode isEqualToEnum:SDLResultTimedOut]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Scrollable Message timed out" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertScrollableMessageTimedOutWarningText textField2:nil];
} else if ([response.resultCode isEqualToEnum:SDLResultAborted]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Scrollable Message cancelled" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertScrollableMessageCancelledWarningText textField2:nil];
} else {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Scrollable Message could not be displayed" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertScrollableMessageGeneralWarningText textField2:nil];
}
}
}];
@@ -170,13 +170,13 @@ NS_ASSUME_NONNULL_BEGIN
+ (SDLVoiceCommand *)sdlex_voiceCommandStartWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStop] handler:^{
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil];
}];
}
+ (SDLVoiceCommand *)sdlex_voiceCommandStopWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStart] handler:^{
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil];
}];
}
diff --git a/Example Apps/Example ObjC/VehicleDataManager.m b/Example Apps/Example ObjC/VehicleDataManager.m
index 51a83f145..e7a8b0079 100644
--- a/Example Apps/Example ObjC/VehicleDataManager.m
+++ b/Example Apps/Example ObjC/VehicleDataManager.m
@@ -138,7 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTriggerSource)triggerSource vehicleDataType:(NSString *)vehicleDataType {
SDLLogD(@"Checking if app has permission to access vehicle data...");
if (![manager.permissionManager isRPCNameAllowed:SDLRPCFunctionNameGetVehicleData]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertVehicleDataPermissionsWarningText textField2:nil];
return;
}
@@ -154,7 +154,7 @@ NS_ASSUME_NONNULL_BEGIN
[manager sendRequest:getAllVehicleData withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error || ![response isKindOfClass:SDLGetVehicleDataResponse.class]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Something went wrong while getting vehicle data" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertVehicleDataGeneralWarningText textField2:nil];
return;
}
@@ -184,7 +184,7 @@ NS_ASSUME_NONNULL_BEGIN
alertMessage = [TextValidator validateText:alertMessage length:200];
if ([triggerSource isEqualToEnum:SDLTriggerSourceMenu]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertTitle textField2:alertMessage iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:alertTitle textField2:alertMessage];
} else {
NSString *spokenAlert = alertMessage ?: alertTitle;
[manager sendRequest:[[SDLSpeak alloc] initWithTTS:spokenAlert]];
@@ -277,7 +277,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLLogD(@"Checking phone call capability");
[manager.systemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
if (!systemCapabilityManager.phoneCapability) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The head unit does not support the phone call capability" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertDialNumberPermissionsWarningText textField2:nil];
return;
}
@@ -285,7 +285,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLLogD(@"Dialing phone number %@", phoneNumber);
[self sdlex_dialPhoneNumber:phoneNumber manager:manager];
} else {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The dial number feature is unavailable for this head unit" textField2:nil iconName:nil]];
+ [AlertManager sendAlertWithManager:manager image:nil textField1:AlertDialNumberUnavailableWarningText textField2:nil];
}
}];
}
diff --git a/Example Apps/Example Swift/AlertManager.swift b/Example Apps/Example Swift/AlertManager.swift
index 718210777..9e37dd1c5 100644
--- a/Example Apps/Example Swift/AlertManager.swift
+++ b/Example Apps/Example Swift/AlertManager.swift
@@ -10,18 +10,58 @@ import Foundation
import SmartDeviceLink
class AlertManager {
- private class var okSoftButton: SDLSoftButton {
- return SDLSoftButton(type: .text, text: AlertOKButtonText, image: nil, highlighted: true, buttonId: 1, systemAction: nil, handler: nil)
+ /// Sends an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped.
+ /// - Parameters:
+ /// - imageName: The name of the image to upload
+ /// - textField1: The first line of text in the alert
+ /// - textField2: The second line of text in the alert
+ /// - sdlManager: The SDLManager
+ class func sendAlert(imageName: String? = nil, textField1: String, textField2: String? = nil, sdlManager: SDLManager) {
+ let okSoftButton = SDLSoftButton(type: .text, text: AlertOKButtonText, image: nil, highlighted: true, buttonId: 1, systemAction: nil, handler: nil)
+ let alert = SDLAlert(alertText1: textField1, alertText2: textField2, alertText3: nil, softButtons: [okSoftButton], playTone: true, ttsChunks: nil, duration: 5000, progressIndicator: false, alertIcon: nil, cancelID: 0)
+
+ if let imageName = imageName {
+ sendImage(imageName, sdlManager: sdlManager) { (success, artworkName) in
+ if success {
+ alert.alertIcon = SDLImage(name: artworkName, isTemplate: true)
+ }
+ sdlManager.send(alert)
+ }
+ } else {
+ sdlManager.send(alert)
+ }
+ }
+
+ /// Sends a subtle alert with up to two lines of text, and an image.
+ /// - Parameters:
+ /// - imageName: The name of the image to upload
+ /// - textField1: The first line of text in the alert
+ /// - textField2: The second line of text in the alert
+ /// - sdlManager: The SDLManager
+ class func sendSubtleAlert(imageName: String? = nil, textField1: String, textField2: String? = nil, sdlManager: SDLManager) {
+ let subtleAlert = SDLSubtleAlert(alertText1: textField1, alertText2: textField2, alertIcon: nil, ttsChunks: nil, duration: nil, softButtons: nil, cancelID: NSNumber(0))
+
+ if let imageName = imageName {
+ sendImage(imageName, sdlManager: sdlManager) { (success, artworkName) in
+ if success {
+ subtleAlert.alertIcon = SDLImage(name: artworkName, isTemplate: true)
+ }
+ sdlManager.send(subtleAlert)
+ }
+ } else {
+ sdlManager.send(subtleAlert)
+ }
}
- /// Creates an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped.
- ///
+ /// Helper method for uploading an image before it is shown in an alert
/// - 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
- /// - 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)
+ /// - imageName: The name of the image to upload
+ /// - sdlManager: The SDLManager
+ /// - completionHandler: Handler called when the artwork has finished uploading with the success of the upload and the name of the uploaded image.
+ private class func sendImage(_ imageName: String, sdlManager: SDLManager, completionHandler: @escaping ((_ success: Bool, _ artwork: String) -> ())) {
+ let artwork = SDLArtwork(image: UIImage(named: imageName)!.withRenderingMode(.alwaysTemplate), persistent: false, as: .PNG)
+ sdlManager.fileManager.upload(artwork: artwork) { (success, artworkName, bytesAvailable, error) in
+ return completionHandler(success, artworkName)
+ }
}
}
diff --git a/Example Apps/Example Swift/AudioManager.swift b/Example Apps/Example Swift/AudioManager.swift
index 6ea7e8813..cfbc4538f 100644
--- a/Example Apps/Example Swift/AudioManager.swift
+++ b/Example Apps/Example Swift/AudioManager.swift
@@ -60,7 +60,7 @@ class AudioManager: NSObject {
func startRecording() {
guard speechRecognitionAuthState == .authorized else {
SDLLog.w("This app does not have permission to access the Speech Recognition API")
- sdlManager.send(AlertManager.alertWithMessageAndCloseButton("You must give this app permission to access Speech Recognition"))
+ AlertManager.sendAlert(textField1: AlertSpeechPermissionsWarningText, sdlManager: sdlManager)
return
}
@@ -106,20 +106,19 @@ private extension AudioManager {
/// Called when `PerformAudioPassThru` request times out or when a `EndAudioPassThru` request is sent
var audioPassThruEndedHandler: SDLResponseHandler? {
return { [weak self] (request, response, error) in
- guard let response = response else { return }
+ guard let self = self, let response = response else { return }
switch response.resultCode {
case .success: // The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
SDLLog.d("Audio Pass Thru ended successfully")
- guard let speechTranscription = self?.speechTranscription else { return }
- self?.sdlManager.send(AlertManager.alertWithMessageAndCloseButton("You said: \(speechTranscription.isEmpty ? "No speech detected" : speechTranscription)"))
+ AlertManager.sendAlert(textField1: "You said: \(self.speechTranscription.isEmpty ? "No speech detected" : self.speechTranscription)", sdlManager: self.sdlManager)
case .aborted: // The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
SDLLog.d("Audio recording canceled")
default:
SDLLog.d("Audio recording not successful: \(response.resultCode)")
}
- self?.stopSpeechRecognitionTask()
+ self.stopSpeechRecognitionTask()
}
}
diff --git a/Example Apps/Example Swift/ButtonManager.swift b/Example Apps/Example Swift/ButtonManager.swift
index e0953accc..02d3f7962 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,20 +24,20 @@ 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 }
- }
+ private var isSubtleAlertAllowed: Bool {
+ return sdlManager.permissionManager.isRPCNameAllowed(.subtleAlert)
+ }
+
+ private var isAlertAllowed: Bool {
+ return sdlManager.permissionManager.isRPCNameAllowed(.alert)
}
init(sdlManager: SDLManager, updateScreenHandler: RefreshUIHandler? = nil) {
@@ -45,54 +45,56 @@ class ButtonManager: NSObject {
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 {
- 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)
- })
+ private var softButtonAlert: SDLSoftButtonObject {
+ let imageAndTextState = SDLSoftButtonState(stateName: AlertSoftButtonImageAndTextState, text: AlertSoftButtonText, image: UIImage(named: AlertBWIconName)?.withRenderingMode(.alwaysTemplate))
+ let textState = SDLSoftButtonState(stateName: AlertSoftButtonTextState, text: AlertSoftButtonText, image: nil)
+ return SDLSoftButtonObject(name: AlertSoftButton, states: [imageAndTextState, textState], initialStateName: imageAndTextState.name) { [weak self] (buttonPress, buttonEvent) in
+ guard let self = self, buttonPress != nil else { return }
+
+ if (self.isAlertAllowed) {
+ AlertManager.sendAlert(imageName: CarBWIconImageName, textField1: AlertMessageText, sdlManager: self.sdlManager)
+ } else if (self.isSubtleAlertAllowed) {
+ AlertManager.sendSubtleAlert(imageName: CarBWIconImageName, textField1: AlertMessageText, sdlManager: self.sdlManager)
+ } else {
+ SDLLog.w("The module does not support the Alert request or the Subtle Alert request")
+ }
}
}
- /// 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
- 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
+ /// Returns a soft button that shows a subtle alert when tapped. If the subtle alert is not supported, then a regular alert is shown.
+ private var softButtonSubtleAlert: SDLSoftButtonObject {
+ let imageAndTextState = SDLSoftButtonState(stateName: SubtleAlertSoftButtonImageAndTextState, text: SubtleAlertSoftButtonText, image: UIImage(named: BatteryFullBWIconName)?.withRenderingMode(.alwaysTemplate))
+ let textState = SDLSoftButtonState(stateName: SubtleAlertSoftButtonTextState, text: SubtleAlertSoftButtonText, image: nil)
+ return SDLSoftButtonObject(name: SubtleAlertSoftButton, states: [imageAndTextState, textState], initialStateName: imageAndTextState.name) { [weak self] (buttonPress, buttonEvent) in
+ guard let self = self, buttonPress != nil else { return }
+
+ if (self.isSubtleAlertAllowed) {
+ AlertManager.sendSubtleAlert(imageName: BatteryEmptyBWIconName, textField1: SubtleAlertHeaderText, textField2: SubtleAlertSubheaderText, sdlManager: self.sdlManager)
+ } else if (self.isAlertAllowed) {
+ AlertManager.sendAlert(imageName: BatteryEmptyBWIconName, textField1: SubtleAlertHeaderText, textField2: SubtleAlertSubheaderText, sdlManager: self.sdlManager)
+ } else {
+ SDLLog.w("The module does not support the Alert request or the Subtle Alert request")
+ }
}
}
- /// 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 {
+ /// Returns a soft button that toggles the textfield visibility state.
+ 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
@@ -105,19 +107,26 @@ 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 {
+ /// Returns a soft button that toggles the image visibility state.
+ 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 sdlManager = self.sdlManager, buttonPress != nil else { return }
+
self.imagesEnabled = !self.imagesEnabled
- // Update the button state
- let softButton = self.sdlManager.screenManager.softButtonObjectNamed(ImagesVisibleSoftButton)
- softButton?.transitionToNextState()
+ if let imagesVisibleSoftButton = sdlManager.screenManager.softButtonObjectNamed(ImagesVisibleSoftButton) {
+ imagesVisibleSoftButton.transitionToNextState()
+ }
+
+ if let alertSoftButton = sdlManager.screenManager.softButtonObjectNamed(AlertSoftButton) {
+ alertSoftButton.transitionToNextState()
+ }
+
+ if let subtleAlertSoftButton = sdlManager.screenManager.softButtonObjectNamed(SubtleAlertSoftButton) {
+ subtleAlertSoftButton.transitionToNextState()
+ }
}
}
}
diff --git a/Example Apps/Example Swift/MenuManager.swift b/Example Apps/Example Swift/MenuManager.swift
index 397fa38b2..3981bc7fa 100644
--- a/Example Apps/Example Swift/MenuManager.swift
+++ b/Example Apps/Example Swift/MenuManager.swift
@@ -98,7 +98,7 @@ private extension MenuManager {
}
return SDLMenuCell(title: ACRecordInCarMicrophoneAudioMenuName, icon: SDLArtwork(image: UIImage(named: SpeakBWIconImageName)!.withRenderingMode(.alwaysTemplate), persistent: true, as: .PNG), voiceCommands: [ACRecordInCarMicrophoneAudioMenuName], handler: { _ in
- manager.send(AlertManager.alertWithMessageAndCloseButton("Speech recognition feature only available on iOS 10+"))
+ AlertManager.sendAlert(textField1: "Speech recognition feature only available on iOS 10+", sdlManager: manager)
})
}
@@ -109,7 +109,7 @@ private extension MenuManager {
class func menuCellDialNumber(with manager: SDLManager) -> SDLMenuCell {
return SDLMenuCell(title: ACDialPhoneNumberMenuName, icon: SDLArtwork(image: UIImage(named: PhoneBWIconImageName)!.withRenderingMode(.alwaysTemplate), persistent: true, as: .PNG), voiceCommands: [ACDialPhoneNumberMenuName], handler: { _ in
guard RPCPermissionsManager.isDialNumberRPCAllowed(with: manager) else {
- manager.send(AlertManager.alertWithMessageAndCloseButton("This app does not have the required permissions to dial a number"))
+ AlertManager.sendAlert(textField1: AlertDialNumberPermissionsWarningText, sdlManager: manager)
return
}
@@ -133,7 +133,7 @@ private extension MenuManager {
let display = SDLSetDisplayLayout(predefinedLayout: .nonMedia)
manager.send(request: display) { (request, response, error) in
guard response?.success.boolValue == .some(true) else {
- manager.send(AlertManager.alertWithMessageAndCloseButton(errorMessage))
+ AlertManager.sendAlert(textField1: errorMessage, sdlManager: manager)
return
}
}
@@ -145,7 +145,7 @@ private extension MenuManager {
let display = SDLSetDisplayLayout(predefinedLayout: .graphicWithText)
manager.send(request: display) { (request, response, error) in
guard response?.success.boolValue == .some(true) else {
- manager.send(AlertManager.alertWithMessageAndCloseButton(errorMessage))
+ AlertManager.sendAlert(textField1: errorMessage, sdlManager: manager)
return
}
}
@@ -166,7 +166,7 @@ private extension MenuManager {
let message = "\(submenuTitle) selected!"
switch triggerSource {
case .menu:
- manager.send(AlertManager.alertWithMessageAndCloseButton(message))
+ AlertManager.sendAlert(textField1: message, sdlManager: manager)
case .voiceRecognition:
manager.send(SDLSpeak(tts: message))
default: break
@@ -184,11 +184,11 @@ private extension MenuManager {
guard let response = response else { return }
guard response.resultCode == .success else {
if response.resultCode == .timedOut {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Slider timed out"))
+ AlertManager.sendAlert(textField1: AlertSliderTimedOutWarningText, sdlManager: manager)
} else if response.resultCode == .aborted {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Slider cancelled"))
+ AlertManager.sendAlert(textField1: AlertSliderCancelledWarningText, sdlManager: manager)
} else {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Slider could not be displayed"))
+ AlertManager.sendAlert(textField1: AlertSliderGeneralWarningText, sdlManager: manager)
}
return
}
@@ -203,11 +203,11 @@ private extension MenuManager {
guard let response = response else { return }
guard response.resultCode == .success else {
if response.resultCode == .timedOut {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Scrollable Message timed out"))
+ AlertManager.sendAlert(textField1: AlertScrollableMessageTimedOutWarningText, sdlManager: manager)
} else if response.resultCode == .aborted {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Scrollable Message cancelled"))
+ AlertManager.sendAlert(textField1: AlertScrollableMessageCancelledWarningText, sdlManager: manager)
} else {
- manager.send(AlertManager.alertWithMessageAndCloseButton("Scrollable Message could not be displayed"))
+ AlertManager.sendAlert(textField1: AlertScrollableMessageGeneralWarningText, sdlManager: manager)
}
return
}
@@ -225,7 +225,7 @@ private extension MenuManager {
/// - Returns: A SDLVoiceCommand object
class func voiceCommandStart(with manager: SDLManager) -> SDLVoiceCommand {
return SDLVoiceCommand(voiceCommands: [VCStart], handler: {
- manager.send(AlertManager.alertWithMessageAndCloseButton("\(VCStart) voice command selected!"))
+ AlertManager.sendAlert(textField1: "\(VCStart) voice command selected!", sdlManager: manager)
})
}
@@ -235,7 +235,7 @@ private extension MenuManager {
/// - Returns: A SDLVoiceCommand object
class func voiceCommandStop(with manager: SDLManager) -> SDLVoiceCommand {
return SDLVoiceCommand(voiceCommands: [VCStop], handler: {
- manager.send(AlertManager.alertWithMessageAndCloseButton("\(VCStop) voice command selected!"))
+ AlertManager.sendAlert(textField1: "\(VCStop) voice command selected!", sdlManager: manager)
})
}
}
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/Example Swift/VehicleDataManager.swift b/Example Apps/Example Swift/VehicleDataManager.swift
index c0f6e59dc..3c83f2ff9 100644
--- a/Example Apps/Example Swift/VehicleDataManager.swift
+++ b/Example Apps/Example Swift/VehicleDataManager.swift
@@ -144,9 +144,7 @@ extension VehicleDataManager {
if triggerSource == .menu {
let title = !alertTitle.isEmpty ? alertTitle : "No Vehicle Data Available"
let detailMessage = !alertMessage.isEmpty ? alertMessage : nil
- let alert = AlertManager.alertWithMessageAndCloseButton(title,
- textField2: detailMessage)
- manager.send(alert)
+ AlertManager.sendAlert(textField1: title, textField2: detailMessage, sdlManager: manager)
} else {
let spokenAlert = !alertMessage.isEmpty ? alertMessage : alertTitle
manager.send(SDLSpeak(tts: spokenAlert))
@@ -233,8 +231,7 @@ extension VehicleDataManager {
SDLLog.d("Checking if app has permission to access vehicle data...")
guard manager.permissionManager.isRPCNameAllowed(SDLRPCFunctionName.getVehicleData) else {
- let alert = AlertManager.alertWithMessageAndCloseButton("This app does not have the required permissions to access vehicle data")
- manager.send(request: alert)
+ AlertManager.sendAlert(textField1: AlertVehicleDataPermissionsWarningText, sdlManager: manager)
return false
}
@@ -252,8 +249,7 @@ extension VehicleDataManager {
SDLLog.d("Checking if Core returned vehicle data")
guard response != nil, error == nil else {
- let alert = AlertManager.alertWithMessageAndCloseButton("Something went wrong while getting vehicle data")
- manager.send(request: alert)
+ AlertManager.sendAlert(textField1: AlertVehicleDataGeneralWarningText, sdlManager: manager)
return false
}
@@ -272,14 +268,14 @@ extension VehicleDataManager {
SDLLog.d("Checking phone call capability")
manager.systemCapabilityManager.updateCapabilityType(.phoneCall, completionHandler: { (error, systemCapabilityManager) in
guard let phoneCapability = systemCapabilityManager.phoneCapability else {
- manager.send(AlertManager.alertWithMessageAndCloseButton("The head unit does not support the phone call capability"))
+ AlertManager.sendAlert(textField1: AlertDialNumberPermissionsWarningText, sdlManager: manager)
return
}
if phoneCapability.dialNumberEnabled?.boolValue ?? false {
SDLLog.d("Dialing phone number \(phoneNumber)...")
dialPhoneNumber(phoneNumber, manager: manager)
} else {
- manager.send(AlertManager.alertWithMessageAndCloseButton("A phone call can not be made"))
+ AlertManager.sendAlert(textField1: AlertDialNumberUnavailableWarningText, sdlManager: manager)
}
})
}
diff --git a/Example Apps/Shared/AppConstants.h b/Example Apps/Shared/AppConstants.h
index 8f2e27fb6..b06009fa7 100644
--- a/Example Apps/Shared/AppConstants.h
+++ b/Example Apps/Shared/AppConstants.h
@@ -22,16 +22,13 @@ 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 SubtleAlertSoftButtonImageAndTextState;
+extern NSString * const SubtleAlertSoftButtonTextState;
+extern NSString * const SubtleAlertSoftButtonText;
extern NSString * const AlertSoftButton;
-extern NSString * const AlertSoftButtonImageState;
+extern NSString * const AlertSoftButtonImageAndTextState;
extern NSString * const AlertSoftButtonTextState;
extern NSString * const AlertSoftButtonText;
@@ -48,7 +45,21 @@ 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 AlertDialNumberPermissionsWarningText;
+extern NSString * const AlertDialNumberUnavailableWarningText;
+extern NSString * const AlertSliderTimedOutWarningText;
+extern NSString * const AlertSliderCancelledWarningText;
+extern NSString * const AlertSliderGeneralWarningText;
+extern NSString * const AlertScrollableMessageTimedOutWarningText;
+extern NSString * const AlertScrollableMessageCancelledWarningText;
+extern NSString * const AlertScrollableMessageGeneralWarningText;
+extern NSString * const AlertVehicleDataPermissionsWarningText;
+extern NSString * const AlertVehicleDataGeneralWarningText;
+extern NSString * const AlertSpeechPermissionsWarningText;
#pragma mark - SDL Text-To-Speech
extern NSString * const TTSGoodJob;
@@ -124,8 +135,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 9ef0c0e8b..69447b16d 100644
--- a/Example Apps/Shared/AppConstants.m
+++ b/Example Apps/Shared/AppConstants.m
@@ -19,18 +19,15 @@ 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 = @"SubtleAlertSoftButton";
+NSString * const SubtleAlertSoftButtonImageAndTextState = @"SubtleAlertSoftButtonImageAndTextState";
+NSString * const SubtleAlertSoftButtonTextState = @"SubtleAlertSoftButtonTextState";
+NSString * const SubtleAlertSoftButtonText = @"Check Battery";
NSString * const AlertSoftButton = @"AlertSoftButton";
-NSString * const AlertSoftButtonImageState = @"AlertSoftButtonImageState";
+NSString * const AlertSoftButtonImageAndTextState = @"AlertSoftButtonImageAndTextState";
NSString * const AlertSoftButtonTextState = @"AlertSoftButtonTextState";
-NSString * const AlertSoftButtonText = @"Tap Me";
+NSString * const AlertSoftButtonText = @"Show Alert";
NSString * const TextVisibleSoftButton = @"TextVisibleSoftButton";
NSString * const TextVisibleSoftButtonTextOnState = @"TextVisibleSoftButtonTextOnState";
@@ -45,7 +42,21 @@ 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 AlertDialNumberPermissionsWarningText = @"This app does not have the required permissions to dial a number";
+NSString * const AlertDialNumberUnavailableWarningText = @"The dial number feature is unavailable for this head unit";
+NSString * const AlertSliderTimedOutWarningText = @"Slider timed out";
+NSString * const AlertSliderCancelledWarningText = @"Slider cancelled";
+NSString * const AlertSliderGeneralWarningText = @"Slider could not be displayed";
+NSString * const AlertScrollableMessageTimedOutWarningText = @"Scrollable Message timed out";
+NSString * const AlertScrollableMessageCancelledWarningText = @"Scrollable Message cancelled";
+NSString * const AlertScrollableMessageGeneralWarningText = @"Scrollable Message could not be displayed";
+NSString * const AlertVehicleDataPermissionsWarningText = @"This app does not have the required permissions to access vehicle data";
+NSString * const AlertVehicleDataGeneralWarningText = @"Something went wrong while getting vehicle data";
+NSString * const AlertSpeechPermissionsWarningText = @"You must give this app permission to access Speech Recognition";
#pragma mark - SDL Text-To-Speech
NSString * const TTSGoodJob = @"Good Job";
@@ -121,8 +132,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";