To start working with the Predictive Text SDK, we first need to sync the required dependency, set required flags, and finally obtain an instance of the FleksyLib class.
To use the Predictive Text SDK in your app, follow the steps given below:
Add Fleksy SDK repository to the settings.gradle
file.
|
|
Set android.enableJetifier
to true
in your gradle.properties
file:
android.enableJetifier=true
Edit the app’s module build.gradle
file and add a dependency:
|
|
Ensure Java 1.8 (or higher) compatibility is enabled in the app’s module build.gradle
file:
|
|
Once done, Sync project with Gradle Files
to load the keyboard SDK dependencies.
Finally, download & copy the English language pack resourceArchive-en-US.jet to the assets or raw folder of the main app module.
assets/encrypted
directory is absent by default on new projects unless created manually.
Example:
With a terminal open at the root of the android project and with the provided language pack stored in the ~/Downloads
folder:
Create the encrypted
folder inside the assets
folder:
$ mkdir -p app/src/main/assets/encrypted
Copy the language pack to the assets/encrypted
folder:
$ cp ~/Downloads/resourceArchive-en-US.jet app/src/main/assets/encrypted
The Predictive Text SDK supports Android API 21
.
It also supports kotlin
and java
.
The FleksyLib class is the main way to interact with the Predictive Keyboard. You need to create an instance of FleksyLib to start using the autocorrection, next word prediction, and swipe functionalities.
In order to create a FleksyLib instance, you need to pass it your application’s context, a valid language file (.jet
extension) and a LibraryConfiguration object.
Example:
<your-license-key>
and <your-license-secret>
with your license.private val languageFile = LanguageFile.Asset("encrypted/resourceArchive-en-US.jet")
private val libraryConfiguration = LibraryConfiguration(
LibraryConfiguration.LicenseConfiguration(
"<your-license-key>",
"<your-license-secret>"
)
)
Now obtain an instance of FleksyLib:
val fleksyLib = FleksyLib(context.applicationContext, languageFile, libraryConfiguration)
Now you can start using the methods from the FleksyLib instance.
This includes a demo application on how to use the FleksyLib
.
There are 3 main methods offered by FleksyLib namely:
There are also additional methods available that can be explored in the class as per requirements.
The currentWordPrediction and nextWordPrediction methods can be used with in any application that wishes to take benefit of auto correction and next word predictions. Both methods requires an instance of TypingContext as a parameter.
In case you are integrating the Predictive Text SDK in your custom keyboard application, you can use additional methods offered by the FleksyLib instance. The swipePrediction and currentWordPrediction (overload method) methods requires an instance of TypingContext and a list of LayoutPoint.
An instance of LayoutPoint contains information regarding the position of the key (within the keyboard) where the user has tapped. The Fleksy Engine uses that to offer better predictions. It is important to note that a valid LayoutType must be provided as a parameter to LibraryConfiguration when instantiating FleksyLib before any methods utilizing LayoutPoint can be used.
The Predictive Text SDK supports many languages other than the default starting language. A complete list of supported languages can be found in the Languages section. To work with different languages, the SDK offers various methods in the LanguagesHelper class, among which the two main methods are:
There are also additional methods available that can be explored in the class as per requirements.