Skip to content

Commit

Permalink
Merge branch 'develop' into feature/smartdevicelink#1272/multiple_mod…
Browse files Browse the repository at this point in the history
…ules
  • Loading branch information
SatbirTanda committed Aug 13, 2019
2 parents 525704f + 39a904c commit c41f9bd
Show file tree
Hide file tree
Showing 92 changed files with 1,716 additions and 244 deletions.
2 changes: 1 addition & 1 deletion Example Apps/Example ObjC/AlertManager.h
Expand Up @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface AlertManager : NSObject

+ (SDLAlert *)alertWithMessage:(NSString *)textField1 textField2:(nullable NSString *)textField2;
+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2;
+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName;

@end

Expand Down
18 changes: 10 additions & 8 deletions Example Apps/Example ObjC/AlertManager.m
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2018 smartdevicelink. All rights reserved.
//

#import "AppConstants.h"
#import "AlertManager.h"
#import "SmartDeviceLink.h"

Expand All @@ -21,18 +22,19 @@ @implementation AlertManager
* @return An SDLAlert object
*/
+ (SDLAlert *)alertWithMessage:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 duration:5000];
return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2];
}

/**
* Creates an alert with up to two lines of text and a close button that will dismiss the alert when tapped
*
* @param textField1 The first line of a message to display in the alert
* @param textField2 The second line of a message to display in the alert
* @return An SDLAlert object
Creates an alert with up to two lines of text and a close button that will dismiss the alert when tapped
@param textField1 The first line of a message to display in the alert
@param textField2 The second line of a message to display in the alert
@param iconName The name of the uploaded icon artwork
@return An SDLAlert object
*/
+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil duration:5000 softButtons:@[[self sdlex_okSoftButton]]];
+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName {
return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil ttsChunks:nil playTone:NO progressIndicator:NO duration:5000 softButtons:@[[self sdlex_okSoftButton]] alertIcon:[[SDLImage alloc] initWithName:iconName isTemplate:YES]];
}

+ (SDLSoftButton *)sdlex_okSoftButton {
Expand Down
4 changes: 2 additions & 2 deletions Example Apps/Example ObjC/AudioManager.m
Expand Up @@ -86,7 +86,7 @@ - (void)stopManager {
- (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]];
[self.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You must give this app permission to access Speech Recognition" textField2:nil iconName:nil]];
return;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ - (nullable SDLResponseHandler)audioPassThruEndedHandler {
// 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]];
[weakSelf.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertMessage textField2:nil iconName:nil]];
} else if ([resultCode isEqualToEnum:SDLResultAborted]) {
// The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
SDLLogD(@"Audio recording canceled");
Expand Down
8 changes: 6 additions & 2 deletions Example Apps/Example ObjC/ButtonManager.m
Expand Up @@ -73,14 +73,18 @@ - (void)setToggleEnabled:(BOOL)toggleEnabled {
}

- (SDLSoftButtonObject *)sdlex_softButtonAlertWithManager:(SDLManager *)manager {
SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:CarBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG]];
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;
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]];
[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");
}];
Expand Down
28 changes: 22 additions & 6 deletions Example Apps/Example ObjC/MenuManager.m
Expand Up @@ -23,6 +23,8 @@ @implementation MenuManager
return @[[self sdlex_menuCellSpeakNameWithManager:manager],
[self sdlex_menuCellGetAllVehicleDataWithManager:manager],
[self sdlex_menuCellShowPerformInteractionWithManager:manager performManager:performManager],
[self sdlex_sliderMenuCellWithManager:manager],
[self sdlex_scrollableMessageMenuCellWithManager:manager],
[self sdlex_menuCellRecordInCarMicrophoneAudioWithManager:manager],
[self sdlex_menuCellDialNumberWithManager:manager],
[self sdlex_menuCellChangeTemplateWithManager:manager],
Expand Down Expand Up @@ -79,7 +81,7 @@ + (SDLMenuCell *)sdlex_menuCellRecordInCarMicrophoneAudioWithManager:(SDLManager
+ (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]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to dial a number" textField2:nil iconName:nil]];
return;
}

Expand All @@ -98,7 +100,7 @@ + (SDLMenuCell *)sdlex_menuCellChangeTemplateWithManager:(SDLManager *)manager {
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutNonMedia];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (![response.resultCode isEqualToEnum:SDLResultSuccess]) {
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
}
}];
}];
Expand All @@ -109,7 +111,7 @@ + (SDLMenuCell *)sdlex_menuCellChangeTemplateWithManager:(SDLManager *)manager {
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutGraphicWithText];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (![response.resultCode isEqualToEnum:SDLResultSuccess]) {
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
}
}];
}];
Expand All @@ -122,25 +124,39 @@ + (SDLMenuCell *)sdlex_menuCellWithSubmenuWithManager:(SDLManager *)manager {
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]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"You selected %@ %i", ACSubmenuItemMenuName, i] textField2:nil iconName:nil]];
}];
[submenuItems addObject:cell];
}

return [[SDLMenuCell alloc] initWithTitle:ACSubmenuMenuName icon:[SDLArtwork artworkWithImage:[[UIImage imageNamed:MenuBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] subCells:[submenuItems copy]];
}

+ (SDLMenuCell *)sdlex_sliderMenuCellWithManager:(SDLManager *)manager {
return [[SDLMenuCell alloc] initWithTitle:ACSliderMenuName icon:nil voiceCommands:@[ACSliderMenuName] handler:^(SDLTriggerSource _Nonnull triggerSource) {
SDLSlider *sliderRPC = [[SDLSlider alloc] initWithNumTicks:3 position:1 sliderHeader:@"Select a letter" sliderFooters:@[@"A", @"B", @"C"] timeout:10000];
[manager sendRequest:sliderRPC];
}];
}

+ (SDLMenuCell *)sdlex_scrollableMessageMenuCellWithManager:(SDLManager *)manager {
return [[SDLMenuCell alloc] initWithTitle:ACScrollableMessageMenuName icon:nil voiceCommands:@[ACScrollableMessageMenuName] handler:^(SDLTriggerSource _Nonnull triggerSource) {
SDLScrollableMessage *messageRPC = [[SDLScrollableMessage alloc] initWithMessage:@"This is a scrollable message\nIt can contain many lines" timeout:10000 softButtons:nil];
[manager sendRequest:messageRPC];
}];
}

#pragma mark - Voice Commands

+ (SDLVoiceCommand *)sdlex_voiceCommandStartWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStop] handler:^{
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil iconName:nil]];
}];
}

+ (SDLVoiceCommand *)sdlex_voiceCommandStopWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStart] handler:^{
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil iconName:nil]];
}];
}

Expand Down
27 changes: 18 additions & 9 deletions Example Apps/Example ObjC/PerformInteractionManager.m
Expand Up @@ -20,6 +20,7 @@ @interface PerformInteractionManager() <SDLChoiceSetDelegate, SDLKeyboardDelegat

@property (strong, nonatomic, readonly) SDLChoiceSet *choiceSet;
@property (copy, nonatomic, readonly) NSArray<SDLChoiceCell *> *cells;
@property (copy, nonatomic, readonly) NSArray<SDLVRHelpItem *> *vrHelpList;

@end

Expand All @@ -39,17 +40,25 @@ - (void)showWithTriggerSource:(SDLTriggerSource)source {
}

- (SDLChoiceSet *)choiceSet {
return [[SDLChoiceSet alloc] initWithTitle:PICSInitialPrompt delegate:self layout:SDLChoiceSetLayoutList timeout:10 initialPromptString:PICSInitialPrompt timeoutPromptString:PICSTimeoutPrompt helpPromptString:PICSHelpPrompt vrHelpList:nil choices:self.cells];
return [[SDLChoiceSet alloc] initWithTitle:PICSInitialPrompt delegate:self layout:SDLChoiceSetLayoutList timeout:10 initialPromptString:PICSInitialPrompt timeoutPromptString:PICSTimeoutPrompt helpPromptString:PICSHelpPrompt vrHelpList:self.vrHelpList choices:self.cells];
}

- (NSArray<SDLChoiceCell *> *)cells {
SDLChoiceCell *firstChoice = [[SDLChoiceCell alloc] initWithText:PICSFirstChoice artwork:[SDLArtwork artworkWithStaticIcon:SDLStaticIconNameKey] voiceCommands:nil];
SDLChoiceCell *secondChoice = [[SDLChoiceCell alloc] initWithText:PICSSecondChoice];
SDLChoiceCell *thirdChoice = [[SDLChoiceCell alloc] initWithText:PICSThirdChoice];
SDLChoiceCell *firstChoice = [[SDLChoiceCell alloc] initWithText:PICSFirstChoice artwork:[SDLArtwork artworkWithStaticIcon:SDLStaticIconNameKey] voiceCommands:@[VCPICSFirstChoice]];
SDLChoiceCell *secondChoice = [[SDLChoiceCell alloc] initWithText:PICSSecondChoice artwork:[SDLArtwork artworkWithStaticIcon:SDLStaticIconNameMicrophone] voiceCommands:@[VCPICSecondChoice]];
SDLChoiceCell *thirdChoice = [[SDLChoiceCell alloc] initWithText:PICSThirdChoice artwork:[SDLArtwork artworkWithStaticIcon:SDLStaticIconNameKey] voiceCommands:@[VCPICSThirdChoice]];

return @[firstChoice, secondChoice, thirdChoice];
}

- (NSArray<SDLVRHelpItem *> *)vrHelpList {
SDLVRHelpItem *vrHelpListFirst = [[SDLVRHelpItem alloc] initWithText:VCPICSFirstChoice image:nil];
SDLVRHelpItem *vrHelpListSecond = [[SDLVRHelpItem alloc] initWithText:VCPICSecondChoice image:nil];
SDLVRHelpItem *vrHelpListThird = [[SDLVRHelpItem alloc] initWithText:VCPICSThirdChoice image:nil];

return @[vrHelpListFirst, vrHelpListSecond, vrHelpListThird];
}

- (SDLInteractionMode)modeForTriggerSource:(SDLTriggerSource)source {
return ([source isEqualToEnum:SDLTriggerSourceMenu] ? SDLInteractionModeManualOnly : SDLInteractionModeVoiceRecognitionOnly);
}
Expand Down Expand Up @@ -78,15 +87,15 @@ - (void)keyboardDidAbortWithReason:(SDLKeyboardEvent)event {
[self.manager sendRequest:[[SDLSpeak alloc] initWithTTS:TTSYouMissed]];
}

- (void)updateAutocompleteWithInput:(NSString *)currentInputText completionHandler:(SDLKeyboardAutocompleteCompletionHandler)completionHandler {
- (void)updateAutocompleteWithInput:(NSString *)currentInputText autoCompleteResultsHandler:(SDLKeyboardAutoCompleteResultsHandler)resultsHandler {
if ([currentInputText.lowercaseString hasPrefix:@"f"]) {
completionHandler(PICSFirstChoice);
resultsHandler(@[PICSFirstChoice]);
} else if ([currentInputText.lowercaseString hasPrefix:@"s"]) {
completionHandler(PICSSecondChoice);
resultsHandler(@[PICSSecondChoice]);
} else if ([currentInputText.lowercaseString hasPrefix:@"t"]) {
completionHandler(PICSThirdChoice);
resultsHandler(@[PICSThirdChoice]);
} else {
completionHandler(nil);
resultsHandler(nil);
}
}

Expand Down
1 change: 1 addition & 0 deletions Example Apps/Example ObjC/ProxyManager.m
Expand Up @@ -188,6 +188,7 @@ - (void)sdlex_updateScreen {

[screenManager beginUpdates];
screenManager.textAlignment = SDLTextAlignmentLeft;
screenManager.title = isTextEnabled ? @"Home" : nil;
screenManager.textField1 = isTextEnabled ? SmartDeviceLinkText : nil;
screenManager.textField2 = isTextEnabled ? [NSString stringWithFormat:@"Obj-C %@", ExampleAppText] : nil;
screenManager.textField3 = isTextEnabled ? self.vehicleDataManager.vehicleOdometerData : nil;
Expand Down
10 changes: 5 additions & 5 deletions Example Apps/Example ObjC/VehicleDataManager.m
Expand Up @@ -137,7 +137,7 @@ - (void)sdlex_resetOdometer {
+ (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTriggerSource)triggerSource vehicleDataType:(NSString *)vehicleDataType {
SDLLogD(@"Checking if app has permission to access vehicle data...");
if (![manager.permissionManager isRPCAllowed:@"GetVehicleData"]) {
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil iconName:nil]];
return;
}

Expand All @@ -150,7 +150,7 @@ + (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTri

[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]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Something went wrong while getting vehicle data" textField2:nil iconName:nil]];
return;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ + (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTri
alertMessage = [TextValidator validateText:alertMessage length:200];

if ([triggerSource isEqualToEnum:SDLTriggerSourceMenu]) {
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertTitle textField2:alertMessage]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertTitle textField2:alertMessage iconName:nil]];
} else {
NSString *spokenAlert = alertMessage ?: alertTitle;
[manager sendRequest:[[SDLSpeak alloc] initWithTTS:spokenAlert]];
Expand Down Expand Up @@ -262,15 +262,15 @@ + (void)checkPhoneCallCapabilityWithManager:(SDLManager *)manager phoneNumber:(N
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]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The head unit does not support the phone call capability" textField2:nil iconName:nil]];
return;
}

if (systemCapabilityManager.phoneCapability.dialNumberEnabled.boolValue) {
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]];
[manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The dial number feature is unavailable for this head unit" textField2:nil iconName:nil]];
}
}];
}
Expand Down

0 comments on commit c41f9bd

Please sign in to comment.