FKInterfaceKeyboardViewController

Initial setup of the keyboard.

Interface for calling all functions regarding the KeyboardViewController.

Summary

subscribeEventBus Subscribe to any public event from the SDK.
reloadSettings Reload the settings while the keyboard is opened.
reloadTheme Reload a new theme.
reloadConfiguration Reload emoji’s configuration.
insertText Insert text in the current textfield.
replaceText Replace text in the current textfield.
replaceAllText Replace All text in context at the same time.
deleteBackward Delete one character in the context.
deleteBackwardWord Delete the last typed word until last space from the cursor position.
insertWordPrediction Automatically insert a word prediction in the text field.
updateKeyboardInsets Update keyboard insets.
addCustomActions Add custom actions in the button next to the spacebar.
addWordUserDictionary Add word to the user dictionary.
listWordUserDictionary List all words to the user dictionary.
removeWordUserDictionary Remove a word from the user dictionary.
removeAllWordUserDictionary Remove all words from the user dictionary.
deleteAutolearnDictionary Delete the current words that have been automatically learned.
updateFlaggedWordsFile Update a file with flagged words for a specific language.

SubscribeEventBus

- (void) subscribeEventBus:(NSArray*) arrayEvents;

Call this method to subscribe to all the events you want to observe. Possible subscribable events are defined in FleksyDefines.h file.

Notes:

  • arrayEvents is an array of events that you want to observe.
  • All observed notifications will notify via eventBus.

Events:

Notifications Trigger Information
NOTIFICATION_KEY_PRESSED Key is pressed < type: @Int type ; key: @string letter >
NOTIFICATION_KEY_RELEASED Key is released Time elapsed in milliseconds from pressing the key to releasing it.
<startTimestamp: @Double number; endTimestamp: @Double number >
NOTIFICATION_KEY_SWIPE_RELEASED After swipe gesture, release None
NOTIFICATION_KEY_LONGPRESS_RELEASED Long press key is released Time elapsed in milliseconds from pressing the key to releasing it.
<startTimestamp: @Double number; endTimestamp: @Double number >
NOTIFICATION_KEY_NEW_NWP New set of Next word predictions < predictions : @Array of strings , type : @Array of @Int > – (the type of word will only be provided while the user types. This indicates the category of word during typing.)

@Int type (ButtonType specified in FKEnums.h file) @string letter for NOTIFICATION_KEY_PRESSED. Here are the most used:

Int Meaning String
1 Letter a..zA..Z..0..9..()=..¿?
2 Shift off shift
3 Enter enter
5 Space None
6 Backspace backspace

type: @Array of @Int for NOTIFICATION_KEY_NEW_NWP (Specified in FKEnums.h file). Here are the values:

Int Name Meaning
0 WordPrediction_EnteredText Current text the user is typing
1 WordPrediction_Suggestion Suggested words from the Engine
2 WordPrediction_AutoCorrection Word suggested to correct and replace the current written text
3 WordPrediction_EnteredText_AutoCorrection Word suggested which will be the replacement and is the same word that the user is typing
4 WordPrediction_Emoji Emoji suggestion
5 WordPrediction_Unknown Void option

Example:

self.interface.subscribeEventBus([NOTIFICATION_KEY_NEW_NWP,
                                          NOTIFICATION_KEY_PRESSED,
                                          NOTIFICATION_KEY_RELEASED,
                                          NOTIFICATION_KEY_LONGPRESS_RELEASED])

ReloadSettings

- (void) reloadSettings;

Method to reload settings configuration. It currently reloads the “by default settings”, although it does not reload the themes. Specifically, for reloading the themes call the next function.

ReloadTheme

- (bool) reloadTheme:(NSDictionary*) theme;

Call this method with the theme passed as dict in Json format to immediately reload the current theme.

If the system was not able to reload the theme, it will return false. This can happen when swiping and reloading the theme at the same time.

Example:

let dictTheme: [String : Any] = [
            "name":"Fresh",
            "colors":[
                "letters":"#ff222222",
                "tile":"#ddebebeb",
                "tile_standby":"#ffffffff",
                "suggestion_letters":"#ff222222",
                "suggestion_selected_letters":"#ff222222",
                "swipe":"#ff1d8888",
                "swipe_caps":"#ff1d8888",
                "tile_letters":"#ffda11fb",
                "swipeLine":"#ffa8a8a8",
                "key_shadow":"#40000000",
                "button_shadow":"#40000000",
                "track_pad_cursor":"#ffa8a8a8",
            ],
            "background":["gradient":["#d1d4d9"]],
            "color":"white",
            "style":"gradient",
            "extra":"look_feel_system"]
          ]
        ]

self.interface reloadTheme:dictTheme

ReloadConfiguration

- (void) reloadConfiguration:(EmojiConfiguration*) configuration;

Function to reload emoji configuration, via EmojiConfiguration, which changes the current emoji skin tones.

InsertText

- (void) insertText:(NSString*) text;

Call this method with text as parameter to insert it after the cursor position.

ReplaceText

- (void) replaceText:(NSString*) text inRange:(NSRange) range;

Call this method for replacing text at position location and length.

Notes:

  • It replaces text in the same context of the sentence, not before and not after.
  • If NSRange doesn’t match the current sentence, the method won’t replace any part of the text.

ReplaceAllText

- (void) replaceAllTextWith:(NSString*) text;

Call this method for replacing all the current text with the new one as argument.

Notes:

  • It replaces all the text in the same context of the sentence, not before and not after.

DeleteBackward

- (void) deleteBackward;

Call this to delete one character from the current cursor position.

DeleteBackwardWord

- (void) deleteBackwardWord;

Call this to delete the last word (or half word) from the current cursor position.

InsertWordPrediction

- (void) insertWordPrediction:(NSString*) prediction withType:(WordPredictionType) type;

Call this method to insert a word prediction to the current text field. This is useful if you have customised the top bar and you receive predictions sent by the core, which displays in your custom topbar. When the end-user presses the prediction, call this method to insert the prediction in the textfield.

Arguments:

  • prediction : the prediction that we want to insert, as it is displayed.
  • type : WordPredictionType which indicates the type of the prediction. When the list of predictions to display is received, the type of prediction is also revealed. Attach the prediction to this method too (in case of no type, add unknown).

UpdateKeyboardInsets

(void) updateKeyboardInsets:(UIEdgeInsets) insets;

Call this method if you want to change the insets of the keyboard on the fly. It modifies the position of the keys accordingly to the UIEdgeInsets pass as parameter.

Example:

UIEdgeInsets insets = UIEdgeInsetsMake(0,10,0,10)
[self.fleksyInterface updateKeyboardInsets:insets];

End result would be a keyboard 10 points to the right and 10 to the left, reducing the total width in 20 points.

AddCustomActions

- (void) addCustomActions:(NSDictionary*) dict;

This function will be deprecated, the recommendation is not to use it.

AddWordUserDictionary

- (void) addWordUserDictionary:(NSString*) word;

Function to add a word to the user dictionary. The SDK automatically adds/remove words from the user dictionary depending on the learning status on the Engine side. However, this allows the client to interact with the dictionary to add specific words.

ListWordUserDictionary

- (NSArray*) listWordUserDictionary;

Function to retrieve all words in the user dictionary.

It returns a list of NSString ordered from A-Z. If there are no words in the dictionary, it returns an empty array.

RemoveWordUserDictionary

- (void) removeWordUserDictionary:(NSString*) word;

Function to delete a specific word from the user dictionary.

RemoveAllWordsUserDictionary

- (void) removeAllWordsUserDictionary;

Function to delete all user dictionary words. It deletes all words learned by the user.

DeleteAutolearnDictionary

- (void) deleteAutolearnDictionary;

Function to delete all automatically learned words. This is mostly intended to be used when we test the keyboard, or when the user wants to remove all information. As normal practice, it is good to enable the autolearn and not to remove this dictionary. (Internally we manage this properly to avoid the need for a big dictionary)

UpdateFlaggedWordsFile

- (void) updateFlaggedWordsFile:(NSString*) filePath forLanguage:(NSString*) language;

Call this method with the filepath and the language that we want to use for flagged words. After calling this method, the next time the Keyboard opens up this list of flagged words will be loaded.

Arguments:

  • filePath: Path to the file, which is a text file with a word per sentence.
  • language: String with the language code following ISO 639-1 standard (common one) followed by country code following ISO 3166-1. Examples: en-US / en-UK / de-DE / es-ES / ca-ES / …

Example:

NSURL* directoryURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:<group>];
if(!directoryURL){
  directoryURL = [[NSFileManager defaultManager] temporaryDirectory];
}
NSString* fileName = [NSString stringWithFormat:@"%@/flaggedWords.txt", directoryURL.path];
NSString* content = @"thisword\nanotherword\n";
[content writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:nil];
  
[self.interface updateFlaggedWordsFile:fileName forLanguage:@"en-US"];

If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on May 22, 2024