Android

To start working with Fleksy Core 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.
The below steps assume that you already have an existing project to add Fleksy Core SDK support. If you lack a current project, follow the steps from official Android documentation to create a new project.

Setup

To use Fleksy Core 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 Core SDK dependency
  implementation 'co.thingthing.fleksy.lib:fleksycore-release:1.0.0'
}
...

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.

For 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
    

Instantiating FleksyLib

The FleksyLib class is the main way to interact with the Fleksy Core SDK. 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.

For 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(
    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.

Overview of FleksyLib’s 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 Fleksy Core 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.

Working with Languages

The Fleksy Core 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


Last updated on September 9, 2022