Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

shubham0204/text-predictor-android

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text Prediction in Android - With Rust 🚀

Perform next-word prediction with text-autocompletion, all in Android. The library uses Rust internally, to bring text-suggestions within a few-milliseconds. See the rust branch for more details.

Installation

  1. Download text-predictor.aar from the latest release. (See Releases)
  2. Move the AAR to app/libs.
  3. In module-level build.gradle, add the dependency,
dependencies {
    ...
    implementation files('libs/text-predictor.aar')
    ...
}

Usage

To generate suggestions while text is being entered in a text-widget (could be a EditText or TextField), we use the stream method available in the TextPredictor class. The stream method must be called inside on a onTextChanged or a similar callback that provides a string entered by the user.

For a Compose TextField,

val textPredictor = TextPredictor( this , results )

var inputString by remember{ mutableStateOf("") }
TextField(
    modifier = modifier,
    value = inputString,,
    onValueChange = {
        textPredictor.stream(it)
        inputString = it
    },
    singleLine = true,
)

private val results: ((List<String>) -> Unit) = { suggestions ->
    // Handle UI changes that display `suggestions`
}

For a View-based EditText,

val textPredictor = TextPredictor( this , results )

editText.addTextChangedListener { it ->
    textPredictor.stream( it.toString() )
}

private val results: ((List<String>) -> Unit) = { suggestions ->
    // Handle UI changes that display `suggestions`
} 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.