Android

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 SDK, please note that you first need a license key which can be requested in the developer’s dashboard.

Installation

To use the Predictive Text SDK in your app, follow the steps given below:

Step 1

Add Fleksy SDK repository to the settings.gradle file.

17
18
19
20
21
22
23
24
25
26
27
...
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = "https://maven.fleksy.com/maven"
        }
    }
}...

Step 2

Set android.enableJetifier to true in your gradle.properties file:

android.enableJetifier=true

Step 3

Edit the app’s module build.gradle file and add a dependency:

17
18
19
20
21
22
23
...
dependencies {
...       
  // Fleksy Predictive Text SDK dependency
  implementation("co.thingthing.fleksylib:fleksylib-release:1.0.6")
}
...

Step 4

Ensure Java 1.8 (or higher) compatibility is enabled in the app’s module build.gradle file:

17
18
19
20
21
22
23
24
25
26
27
android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toString()
  }
}

Once done, Sync project with Gradle Files to load the keyboard SDK dependencies.

Step 5

Finally, download & copy the English language pack resourceArchive-en-US.jet to the assets or raw folder of the main app module.

The 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:

  1. Create the encrypted folder inside the assets folder:

    $ mkdir -p app/src/main/assets/encrypted
    

  2. Copy the language pack to the assets/encrypted folder:

    $ cp ~/Downloads/resourceArchive-en-US.jet app/src/main/assets/encrypted
    

Supported Platforms

The Predictive Text SDK supports Android API 21.

It also supports kotlin and java.

Initialization

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:

  1. Create an instance of LanguageFile to specify a path to your default language file.
  2. Create an instance of LibraryConfiguration to return LicenseConfiguration as shown below.
  3. Replace <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.

Example

This includes a demo application on how to use the FleksyLib.

Methods

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.

Languages

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:

  • availableLanguages that allows you to obtain a list of all supported languages from Fleksy’s remote server, and
  • downloadLanguageFile that can download a given language from the Fleksy’s remote server at a given path and invoke a callback function to trigger a custom action.

There are also additional methods available that can be explored in the class as per requirements.

Additional Resources


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