Skip to content

Commit

Permalink
Merge pull request #1883 from LuxoftSDL/feature/SDL0238_keyboard_enha…
Browse files Browse the repository at this point in the history
…ncements

SDL-0238 Keyboard Enhancements
  • Loading branch information
joeljfischer authored Feb 24, 2021
2 parents ac0f68a + 015b6b5 commit c9db35d
Show file tree
Hide file tree
Showing 37 changed files with 1,362 additions and 287 deletions.
302 changes: 176 additions & 126 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions SmartDeviceLink/private/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ - (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode
SDLPresentChoiceSetOperation *presentOp = nil;
if (delegate == nil) {
// Non-searchable choice set
presentOp = [[SDLPresentChoiceSetOperation alloc] initWithConnectionManager:self.connectionManager choiceSet:self.pendingPresentationSet mode:mode keyboardProperties:nil keyboardDelegate:nil cancelID:self.nextCancelId];
presentOp = [[SDLPresentChoiceSetOperation alloc] initWithConnectionManager:self.connectionManager choiceSet:self.pendingPresentationSet mode:mode keyboardProperties:nil keyboardDelegate:nil cancelID:self.nextCancelId windowCapability:self.currentWindowCapability];
} else {
// Searchable choice set
presentOp = [[SDLPresentChoiceSetOperation alloc] initWithConnectionManager:self.connectionManager choiceSet:self.pendingPresentationSet mode:mode keyboardProperties:self.keyboardConfiguration keyboardDelegate:delegate cancelID:self.nextCancelId];
presentOp = [[SDLPresentChoiceSetOperation alloc] initWithConnectionManager:self.connectionManager choiceSet:self.pendingPresentationSet mode:mode keyboardProperties:self.keyboardConfiguration keyboardDelegate:delegate cancelID:self.nextCancelId windowCapability:self.currentWindowCapability];
}
self.pendingPresentOperation = presentOp;

Expand Down Expand Up @@ -421,7 +421,7 @@ - (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode
SDLLogD(@"Presenting keyboard with initial text: %@", initialText);
// Present a keyboard with the choice set that we used to test VR's optional state
UInt16 keyboardCancelId = self.nextCancelId;
self.pendingPresentOperation = [[SDLPresentKeyboardOperation alloc] initWithConnectionManager:self.connectionManager keyboardProperties:self.keyboardConfiguration initialText:initialText keyboardDelegate:delegate cancelID:keyboardCancelId];
self.pendingPresentOperation = [[SDLPresentKeyboardOperation alloc] initWithConnectionManager:self.connectionManager keyboardProperties:self.keyboardConfiguration initialText:initialText keyboardDelegate:delegate cancelID:keyboardCancelId windowCapability:self.currentWindowCapability];
[self.transactionQueue addOperation:self.pendingPresentOperation];
return @(keyboardCancelId);
}
Expand Down Expand Up @@ -515,7 +515,7 @@ - (void)setKeyboardConfiguration:(nullable SDLKeyboardProperties *)keyboardConfi
}

- (SDLKeyboardProperties *)sdl_defaultKeyboardConfiguration {
return [[SDLKeyboardProperties alloc] initWithLanguage:SDLLanguageEnUs keyboardLayout:SDLKeyboardLayoutQWERTY keypressMode:SDLKeypressModeResendCurrentEntry limitedCharacterList:nil autoCompleteList:nil];
return [[SDLKeyboardProperties alloc] initWithLanguage:SDLLanguageEnUs keyboardLayout:SDLKeyboardLayoutQWERTY keypressMode:SDLKeypressModeResendCurrentEntry limitedCharacterList:nil autoCompleteList:nil maskInputCharacters:nil customKeys:nil];
}

#pragma mark - Getters
Expand Down
3 changes: 2 additions & 1 deletion SmartDeviceLink/private/SDLPresentChoiceSetOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@class SDLChoiceCell;
@class SDLChoiceSet;
@class SDLKeyboardProperties;
@class SDLWindowCapability;

@protocol SDLConnectionManagerType;
@protocol SDLKeyboardDelegate;
Expand Down Expand Up @@ -54,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
@param cancelID A unique ID for this specific choice set that allows cancellation through the `CancelInteraction` RPC.
@return A SDLPresentChoiceSetOperation object
*/
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager choiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode keyboardProperties:(nullable SDLKeyboardProperties *)originalKeyboardProperties keyboardDelegate:(nullable id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID;
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager choiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode keyboardProperties:(nullable SDLKeyboardProperties *)originalKeyboardProperties keyboardDelegate:(nullable id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID windowCapability:(SDLWindowCapability *)windowCapability;

@end

Expand Down
18 changes: 14 additions & 4 deletions SmartDeviceLink/private/SDLPresentChoiceSetOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "SDLRPCNotificationNotification.h"
#import "SDLSetGlobalProperties.h"
#import "SDLVersion.h"
#import "SDLWindowCapability+ScreenManagerExtensions.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -60,12 +61,13 @@ @interface SDLPresentChoiceSetOperation()
@property (strong, nonatomic, readwrite, nullable) SDLChoiceCell *selectedCell;
@property (strong, nonatomic, readwrite, nullable) SDLTriggerSource selectedTriggerSource;
@property (assign, nonatomic, readwrite) NSUInteger selectedCellRow;
@property (strong, nonatomic) SDLWindowCapability *windowCapability;

@end

@implementation SDLPresentChoiceSetOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager choiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode keyboardProperties:(nullable SDLKeyboardProperties *)originalKeyboardProperties keyboardDelegate:(nullable id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID {
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager choiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode keyboardProperties:(nullable SDLKeyboardProperties *)originalKeyboardProperties keyboardDelegate:(nullable id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID windowCapability:(SDLWindowCapability *)windowCapability {
self = [super init];
if (!self) { return self; }

Expand All @@ -86,6 +88,7 @@ - (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connecti
_cancelId = cancelID;

_selectedCellRow = NSNotFound;
_windowCapability = windowCapability;

return self;
}
Expand Down Expand Up @@ -121,15 +124,16 @@ - (void)sdl_start {
#pragma mark - Sending Requests

- (void)sdl_updateKeyboardPropertiesWithCompletionHandler:(nullable void(^)(void))completionHandler {
if (self.keyboardProperties == nil) {
// Create the keyboard configuration based on the window capability's keyboard capabilities
SDLKeyboardProperties *modifiedKeyboardConfig = [self.windowCapability createValidKeyboardConfigurationBasedOnKeyboardCapabilitiesFromConfiguration:self.keyboardProperties];
if (modifiedKeyboardConfig == nil) {
if (completionHandler != nil) {
completionHandler();
}
return;
}

SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init];
setProperties.keyboardProperties = self.keyboardProperties;
setProperties.keyboardProperties = modifiedKeyboardConfig;

__weak typeof(self) weakself = self;
[self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
Expand Down Expand Up @@ -295,6 +299,12 @@ - (void)sdl_keyboardInputNotification:(SDLRPCNotificationNotification *)notifica
} else if ([onKeyboard.event isEqualToEnum:SDLKeyboardEventAborted] || [onKeyboard.event isEqualToEnum:SDLKeyboardEventCancelled]) {
// Notify of abort / cancellation
[self.keyboardDelegate keyboardDidAbortWithReason:onKeyboard.event];
} else if ([onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskEnabled] || [onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskDisabled]) {
// Notify of key mask change
if ([self.keyboardDelegate respondsToSelector:@selector(keyboardDidUpdateInputMask:)]) {
BOOL isEnabled = [onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskEnabled];
[self.keyboardDelegate keyboardDidUpdateInputMask:isEnabled];
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion SmartDeviceLink/private/SDLPresentKeyboardOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "NSNumber+NumberType.h"

@class SDLKeyboardProperties;
@class SDLWindowCapability;


@protocol SDLConnectionManagerType;
@protocol SDLKeyboardDelegate;
Expand All @@ -33,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@param cancelID An ID for this specific keyboard to allow cancellation through the `CancelInteraction` RPC.
@return A SDLPresentKeyboardOperation object
*/
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager keyboardProperties:(SDLKeyboardProperties *)originalKeyboardProperties initialText:(NSString *)initialText keyboardDelegate:(id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID;
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager keyboardProperties:(SDLKeyboardProperties *)originalKeyboardProperties initialText:(NSString *)initialText keyboardDelegate:(id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID windowCapability:(SDLWindowCapability *)windowCapability;

/**
Cancels the keyboard-only interface if it is currently showing. If the keyboard has not yet been sent to Core, it will not be sent.
Expand Down
21 changes: 19 additions & 2 deletions SmartDeviceLink/private/SDLPresentKeyboardOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "SDLRPCNotificationNotification.h"
#import "SDLSetGlobalProperties.h"
#import "SDLVersion.h"
#import "SDLWindowCapability+ScreenManagerExtensions.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -37,12 +38,13 @@ @interface SDLPresentKeyboardOperation()
@property (strong, nonatomic, readonly) SDLPerformInteraction *performInteraction;

@property (copy, nonatomic, nullable) NSError *internalError;
@property (strong, nonatomic) SDLWindowCapability *windowCapability;

@end

@implementation SDLPresentKeyboardOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager keyboardProperties:(SDLKeyboardProperties *)originalKeyboardProperties initialText:(NSString *)initialText keyboardDelegate:(id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID {
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager keyboardProperties:(SDLKeyboardProperties *)originalKeyboardProperties initialText:(NSString *)initialText keyboardDelegate:(id<SDLKeyboardDelegate>)keyboardDelegate cancelID:(UInt16)cancelID windowCapability:(SDLWindowCapability *)windowCapability {
self = [super init];
if (!self) { return self; }

Expand All @@ -53,6 +55,7 @@ - (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connecti
_keyboardProperties = originalKeyboardProperties;
_cancelId = cancelID;
_operationId = [NSUUID UUID];
_windowCapability = windowCapability;

return self;
}
Expand Down Expand Up @@ -87,8 +90,16 @@ - (void)sdl_start {
#pragma mark - Sending Requests

- (void)sdl_updateKeyboardPropertiesWithCompletionHandler:(nullable void(^)(void))completionHandler {
// Create the keyboard configuration based on the window capability's keyboard capabilities
SDLKeyboardProperties *keyboardConfiguration = [self.windowCapability createValidKeyboardConfigurationBasedOnKeyboardCapabilitiesFromConfiguration:self.keyboardProperties];
if (keyboardConfiguration == nil) {
if (completionHandler != nil) {
completionHandler();
}
return;
}
SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init];
setProperties.keyboardProperties = self.keyboardProperties;
setProperties.keyboardProperties = keyboardConfiguration;

[self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
Expand Down Expand Up @@ -209,6 +220,12 @@ - (void)sdl_keyboardInputNotification:(SDLRPCNotificationNotification *)notifica
} else if ([onKeyboard.event isEqualToEnum:SDLKeyboardEventAborted] || [onKeyboard.event isEqualToEnum:SDLKeyboardEventCancelled]) {
// Notify of abort / cancellation
[self.keyboardDelegate keyboardDidAbortWithReason:onKeyboard.event];
} else if ([onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskEnabled] || [onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskDisabled]) {
// Notify of key mask change
if ([self.keyboardDelegate respondsToSelector:@selector(keyboardDidUpdateInputMask:)]) {
BOOL isEnabled = [onKeyboard.event isEqualToEnum:SDLKeyboardEventInputKeyMaskEnabled];
[self.keyboardDelegate keyboardDidUpdateInputMask:isEnabled];
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions SmartDeviceLink/private/SDLRPCParameterNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameCurrentForecastSupported;
extern SDLRPCParameterName const SDLRPCParameterNameCurrentTemperature;
extern SDLRPCParameterName const SDLRPCParameterNameCushion;
extern SDLRPCParameterName const SDLRPCParameterNameCustomButtonId;
extern SDLRPCParameterName const SDLRPCParameterNameCustomKeys;
extern SDLRPCParameterName const SDLRPCParameterNameCustomPresets;
extern SDLRPCParameterName const SDLRPCParameterNameOEMCustomDataType;
extern SDLRPCParameterName const SDLRPCParameterNameData;
Expand Down Expand Up @@ -354,6 +355,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameIsSubscribed;
extern SDLRPCParameterName const SDLRPCParameterNameJunctionType;
extern SDLRPCParameterName const SDLRPCParameterNameKeepContext;
extern SDLRPCParameterName const SDLRPCParameterNameKeepContextAvailable;
extern SDLRPCParameterName const SDLRPCParameterNameKeyboardCapabilities;
extern SDLRPCParameterName const SDLRPCParameterNameKeyboardLayout;
extern SDLRPCParameterName const SDLRPCParameterNameKeyboardProperties;
extern SDLRPCParameterName const SDLRPCParameterNameKeypressMode;
Expand Down Expand Up @@ -400,6 +402,8 @@ extern SDLRPCParameterName const SDLRPCParameterNameMajorVersion;
extern SDLRPCParameterName const SDLRPCParameterNameMake;
extern SDLRPCParameterName const SDLRPCParameterNameManeuverComplete;
extern SDLRPCParameterName const SDLRPCParameterNameManualTextEntry;
extern SDLRPCParameterName const SDLRPCParameterNameMaskInputCharacters;
extern SDLRPCParameterName const SDLRPCParameterNameMaskInputCharactersSupported;
extern SDLRPCParameterName const SDLRPCParameterNameMassageCushionFirmness;
extern SDLRPCParameterName const SDLRPCParameterNameMassageCushionFirmnessAvailable;
extern SDLRPCParameterName const SDLRPCParameterNameMassageEnabled;
Expand Down Expand Up @@ -485,6 +489,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameNotification;
extern SDLRPCParameterName const SDLRPCParameterNameNumber;
extern SDLRPCParameterName const SDLRPCParameterNameNumberCustomPresetsAvailable;
extern SDLRPCParameterName const SDLRPCParameterNameNumberTicks;
extern SDLRPCParameterName const SDLRPCParameterNameNumConfigurableKeys;
extern SDLRPCParameterName const SDLRPCParameterNameOdometer;
extern SDLRPCParameterName const SDLRPCParameterNameOffset;
extern SDLRPCParameterName const SDLRPCParameterNameOnLockScreenStatus;
Expand Down Expand Up @@ -675,6 +680,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameSupportedDiagnosticModes;
extern SDLRPCParameterName const SDLRPCParameterNameSupportedDynamicImageFieldNames;
extern SDLRPCParameterName const SDLRPCParameterNameSupportsDynamicSubMenus;
extern SDLRPCParameterName const SDLRPCParameterNameSupportedFormats;
extern SDLRPCParameterName const SDLRPCParameterNameSupportedKeyboards;
extern SDLRPCParameterName const SDLRPCParameterNameSupportedLights;
extern SDLRPCParameterName const SDLRPCParameterNameSyncFileName;
extern SDLRPCParameterName const SDLRPCParameterNameSyncMessageVersion;
Expand Down
6 changes: 6 additions & 0 deletions SmartDeviceLink/private/SDLRPCParameterNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
SDLRPCParameterName const SDLRPCParameterNameCurrentTemperature = @"currentTemperature";
SDLRPCParameterName const SDLRPCParameterNameCushion = @"cushion";
SDLRPCParameterName const SDLRPCParameterNameCustomButtonId = @"customButtonID";
SDLRPCParameterName const SDLRPCParameterNameCustomKeys = @"customKeys";
SDLRPCParameterName const SDLRPCParameterNameCustomPresets = @"customPresets";
SDLRPCParameterName const SDLRPCParameterNameData = @"data";
SDLRPCParameterName const SDLRPCParameterNameDataResult = @"dataResult";
Expand Down Expand Up @@ -353,6 +354,7 @@
SDLRPCParameterName const SDLRPCParameterNameJunctionType = @"junctionType";
SDLRPCParameterName const SDLRPCParameterNameKeepContext = @"keepContext";
SDLRPCParameterName const SDLRPCParameterNameKeepContextAvailable = @"keepContextAvailable";
SDLRPCParameterName const SDLRPCParameterNameKeyboardCapabilities = @"keyboardCapabilities";
SDLRPCParameterName const SDLRPCParameterNameKeyboardLayout = @"keyboardLayout";
SDLRPCParameterName const SDLRPCParameterNameKeyboardProperties = @"keyboardProperties";
SDLRPCParameterName const SDLRPCParameterNameKeypressMode = @"keypressMode";
Expand Down Expand Up @@ -395,6 +397,8 @@
SDLRPCParameterName const SDLRPCParameterNameMake = @"make";
SDLRPCParameterName const SDLRPCParameterNameManeuverComplete = @"maneuverComplete";
SDLRPCParameterName const SDLRPCParameterNameManualTextEntry = @"manualTextEntry";
SDLRPCParameterName const SDLRPCParameterNameMaskInputCharacters = @"maskInputCharacters";
SDLRPCParameterName const SDLRPCParameterNameMaskInputCharactersSupported = @"maskInputCharactersSupported";
SDLRPCParameterName const SDLRPCParameterNameMassageCushionFirmness = @"massageCushionFirmness";
SDLRPCParameterName const SDLRPCParameterNameMassageCushionFirmnessAvailable = @"massageCushionFirmnessAvailable";
SDLRPCParameterName const SDLRPCParameterNameMassageEnabled = @"massageEnabled";
Expand Down Expand Up @@ -480,6 +484,7 @@
SDLRPCParameterName const SDLRPCParameterNameNumber = @"number";
SDLRPCParameterName const SDLRPCParameterNameNumberCustomPresetsAvailable = @"numCustomPresetsAvailable";
SDLRPCParameterName const SDLRPCParameterNameNumberTicks = @"numTicks";
SDLRPCParameterName const SDLRPCParameterNameNumConfigurableKeys = @"numConfigurableKeys";
SDLRPCParameterName const SDLRPCParameterNameOdometer = @"odometer";
SDLRPCParameterName const SDLRPCParameterNameOEMCustomDataType = @"oemCustomDataType";
SDLRPCParameterName const SDLRPCParameterNameOffset = @"offset";
Expand Down Expand Up @@ -671,6 +676,7 @@
SDLRPCParameterName const SDLRPCParameterNameSupportedDynamicImageFieldNames = @"supportedDynamicImageFieldNames";
SDLRPCParameterName const SDLRPCParameterNameSupportsDynamicSubMenus = @"supportsDynamicSubMenus";
SDLRPCParameterName const SDLRPCParameterNameSupportedFormats = @"supportedFormats";
SDLRPCParameterName const SDLRPCParameterNameSupportedKeyboards = @"supportedKeyboards";
SDLRPCParameterName const SDLRPCParameterNameSupportedLights = @"supportedLights";
SDLRPCParameterName const SDLRPCParameterNameSyncFileName = @"syncFileName";
SDLRPCParameterName const SDLRPCParameterNameSyncMessageVersion = @"syncMsgVersion";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import "SDLTextFieldName.h"
#import "SDLWindowCapability.h"

@class SDLKeyboardProperties;

NS_ASSUME_NONNULL_BEGIN

@interface SDLWindowCapability (ScreenManagerExtensions)
Expand All @@ -21,6 +23,13 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)hasTextFieldOfName:(SDLTextFieldName)name;
- (BOOL)hasImageFieldOfName:(SDLImageFieldName)name;

/// Takes a keyboard configuration (SDLKeyboardProperties) and creates a valid version of it, if possible, based on this object's internal keyboardCapabilities (SDLKeyboardCapabilities).
/// If there is no internal keyboardCapabilities, it will just return the passed configuration as-is.
/// If no valid configuration can be determined based on the internal keyboard capabilities, it will return nil.
/// @param keyboardConfiguration The configuration to use to determine a valid configuration
/// @return The passed keyboardConfiguration if there are no changes needed or possible, a modified keyboardConfiguration if a valid version of the configuration could be determined, or nil if a valid configuration could not be created
- (nullable SDLKeyboardProperties *)createValidKeyboardConfigurationBasedOnKeyboardCapabilitiesFromConfiguration:(nullable SDLKeyboardProperties *)keyboardConfiguration;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit c9db35d

Please sign in to comment.