summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleonid lokhmatov, Luxoft <zaqqqqqqqq@gmail.com>2021-02-17 18:14:02 +0200
committerleonid lokhmatov, Luxoft <zaqqqqqqqq@gmail.com>2021-02-17 18:14:02 +0200
commita49e4b7c6dc727b47d64d4069a25bb0ace55bd24 (patch)
tree625f8843e32cc35c37c102f96822166c37a47524
parent27f2b8b6e0c62440c54db864eee6c37cb46a50c6 (diff)
downloadsdl_ios-a49e4b7c6dc727b47d64d4069a25bb0ace55bd24.tar.gz
SDL0238 'Keyboard Enhancements/r3': implement filter supported keyboard capability method and proper logic
-rw-r--r--SmartDeviceLink/private/SDLChoiceSetManager.m6
-rw-r--r--SmartDeviceLink/private/SDLPresentChoiceSetOperation.h3
-rw-r--r--SmartDeviceLink/private/SDLPresentChoiceSetOperation.m11
-rw-r--r--SmartDeviceLink/private/SDLPresentKeyboardOperation.h4
-rw-r--r--SmartDeviceLink/private/SDLPresentKeyboardOperation.m14
-rw-r--r--SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.h4
-rw-r--r--SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.m41
7 files changed, 72 insertions, 11 deletions
diff --git a/SmartDeviceLink/private/SDLChoiceSetManager.m b/SmartDeviceLink/private/SDLChoiceSetManager.m
index 9ab56ea87..0f2cb67ad 100644
--- a/SmartDeviceLink/private/SDLChoiceSetManager.m
+++ b/SmartDeviceLink/private/SDLChoiceSetManager.m
@@ -379,10 +379,10 @@ UInt16 const ChoiceCellCancelIdMin = 1;
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;
@@ -421,7 +421,7 @@ UInt16 const ChoiceCellCancelIdMin = 1;
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);
}
diff --git a/SmartDeviceLink/private/SDLPresentChoiceSetOperation.h b/SmartDeviceLink/private/SDLPresentChoiceSetOperation.h
index df82bfa22..b2589a280 100644
--- a/SmartDeviceLink/private/SDLPresentChoiceSetOperation.h
+++ b/SmartDeviceLink/private/SDLPresentChoiceSetOperation.h
@@ -15,6 +15,7 @@
@class SDLChoiceCell;
@class SDLChoiceSet;
@class SDLKeyboardProperties;
+@class SDLWindowCapability;
@protocol SDLConnectionManagerType;
@protocol SDLKeyboardDelegate;
@@ -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
diff --git a/SmartDeviceLink/private/SDLPresentChoiceSetOperation.m b/SmartDeviceLink/private/SDLPresentChoiceSetOperation.m
index f0fbbf28a..a4e2b5c9f 100644
--- a/SmartDeviceLink/private/SDLPresentChoiceSetOperation.m
+++ b/SmartDeviceLink/private/SDLPresentChoiceSetOperation.m
@@ -24,6 +24,7 @@
#import "SDLRPCNotificationNotification.h"
#import "SDLSetGlobalProperties.h"
#import "SDLVersion.h"
+#import "SDLWindowCapability+ScreenManagerExtensions.h"
NS_ASSUME_NONNULL_BEGIN
@@ -60,12 +61,13 @@ NS_ASSUME_NONNULL_BEGIN
@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; }
@@ -86,6 +88,7 @@ NS_ASSUME_NONNULL_BEGIN
_cancelId = cancelID;
_selectedCellRow = NSNotFound;
+ _windowCapability = windowCapability;
return self;
}
@@ -121,15 +124,15 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Sending Requests
- (void)sdl_updateKeyboardPropertiesWithCompletionHandler:(nullable void(^)(void))completionHandler {
- if (self.keyboardProperties == nil) {
+ SDLKeyboardProperties *outProperties = [self.windowCapability filterValidKeyboardProperties:self.keyboardProperties];
+ if (!outProperties) {
if (completionHandler != nil) {
completionHandler();
}
return;
}
-
SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init];
- setProperties.keyboardProperties = self.keyboardProperties;
+ setProperties.keyboardProperties = outProperties;
__weak typeof(self) weakself = self;
[self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
diff --git a/SmartDeviceLink/private/SDLPresentKeyboardOperation.h b/SmartDeviceLink/private/SDLPresentKeyboardOperation.h
index 9a5a6cfb5..508c948b4 100644
--- a/SmartDeviceLink/private/SDLPresentKeyboardOperation.h
+++ b/SmartDeviceLink/private/SDLPresentKeyboardOperation.h
@@ -10,6 +10,8 @@
#import "NSNumber+NumberType.h"
@class SDLKeyboardProperties;
+@class SDLWindowCapability;
+
@protocol SDLConnectionManagerType;
@protocol SDLKeyboardDelegate;
@@ -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.
diff --git a/SmartDeviceLink/private/SDLPresentKeyboardOperation.m b/SmartDeviceLink/private/SDLPresentKeyboardOperation.m
index d4c47b780..58499ff5f 100644
--- a/SmartDeviceLink/private/SDLPresentKeyboardOperation.m
+++ b/SmartDeviceLink/private/SDLPresentKeyboardOperation.m
@@ -21,6 +21,7 @@
#import "SDLRPCNotificationNotification.h"
#import "SDLSetGlobalProperties.h"
#import "SDLVersion.h"
+#import "SDLWindowCapability+ScreenManagerExtensions.h"
NS_ASSUME_NONNULL_BEGIN
@@ -37,12 +38,13 @@ NS_ASSUME_NONNULL_BEGIN
@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; }
@@ -53,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
_keyboardProperties = originalKeyboardProperties;
_cancelId = cancelID;
_operationId = [NSUUID UUID];
+ _windowCapability = windowCapability;
return self;
}
@@ -87,8 +90,15 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Sending Requests
- (void)sdl_updateKeyboardPropertiesWithCompletionHandler:(nullable void(^)(void))completionHandler {
+ SDLKeyboardProperties *outProperties = [self.windowCapability filterValidKeyboardProperties:self.keyboardProperties];
+ if (!outProperties) {
+ if (completionHandler) {
+ completionHandler();
+ }
+ return;
+ }
SDLSetGlobalProperties *setProperties = [[SDLSetGlobalProperties alloc] init];
- setProperties.keyboardProperties = self.keyboardProperties;
+ setProperties.keyboardProperties = outProperties;
[self.connectionManager sendConnectionRequest:setProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
diff --git a/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.h b/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.h
index 9321c98cd..689c4cf05 100644
--- a/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.h
+++ b/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.h
@@ -12,6 +12,8 @@
#import "SDLTextFieldName.h"
#import "SDLWindowCapability.h"
+@class SDLKeyboardProperties;
+
NS_ASSUME_NONNULL_BEGIN
@interface SDLWindowCapability (ScreenManagerExtensions)
@@ -21,6 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)hasTextFieldOfName:(SDLTextFieldName)name;
- (BOOL)hasImageFieldOfName:(SDLImageFieldName)name;
+- (SDLKeyboardProperties *__nullable)filterValidKeyboardProperties:(SDLKeyboardProperties *__nullable)keyboardProperties;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.m b/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.m
index 441356a83..a09e70da5 100644
--- a/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.m
+++ b/SmartDeviceLink/private/SDLWindowCapability+ScreenManagerExtensions.m
@@ -10,6 +10,10 @@
#import "SDLWindowCapability+ScreenManagerExtensions.h"
#import "SDLImageField.h"
+#import "SDLKeyboardCapabilities.h"
+#import "SDLKeyboardLayoutCapability.h"
+#import "SDLKeyboardProperties.h"
+#import "SDLLogMacros.h"
#import "SDLTextField.h"
@implementation SDLWindowCapability (ScreenManagerExtensions)
@@ -52,4 +56,41 @@
return NO;
}
+- (SDLKeyboardProperties *__nullable)filterValidKeyboardProperties:(SDLKeyboardProperties *__nullable)inKeyboardProperties {
+ if (!self.keyboardCapabilities || !inKeyboardProperties || !inKeyboardProperties.keyboardLayout) {
+ return inKeyboardProperties;
+ }
+ SDLKeyboardLayoutCapability *selectedLayoutCapability = nil;
+ if (inKeyboardProperties.keyboardLayout) {
+ for (SDLKeyboardLayoutCapability *layoutCapability in self.keyboardCapabilities.supportedKeyboards) {
+ if ([layoutCapability.keyboardLayout isEqualToEnum:inKeyboardProperties.keyboardLayout]) {
+ selectedLayoutCapability = layoutCapability;
+ break;
+ }
+ }
+ }
+ if (!selectedLayoutCapability) {
+ SDLLogD(@"Keyboard layout is not supported: %@", inKeyboardProperties.keyboardLayout);
+ return nil;
+ }
+
+ SDLKeyboardProperties *outKeyboardProperties = [inKeyboardProperties copy];
+
+ if (!inKeyboardProperties.customKeys.count) {
+ outKeyboardProperties.customKeys = nil;
+ } else {
+ const NSUInteger numConfigurableKeys = (NSUInteger)selectedLayoutCapability.numConfigurableKeys.integerValue;
+ if (inKeyboardProperties.customKeys.count > numConfigurableKeys) {
+ outKeyboardProperties.customKeys = [inKeyboardProperties.customKeys subarrayWithRange:NSMakeRange(0, numConfigurableKeys)];
+ SDLLogD(@"Too many custom keys %d, only the first %d will be used and the rest will get dropped.", (int)inKeyboardProperties.customKeys.count, (int)numConfigurableKeys);
+ }
+ }
+
+ if (!self.keyboardCapabilities.maskInputCharactersSupported.boolValue) {
+ outKeyboardProperties.maskInputCharacters = nil;
+ }
+
+ return outKeyboardProperties;
+}
+
@end