{"id":18465139,"url":"https://github.com/natario1/autocomplete","last_synced_at":"2025-04-05T04:11:46.477Z","repository":{"id":41454799,"uuid":"88896032","full_name":"natario1/Autocomplete","owner":"natario1","description":"Simple yet powerful autocomplete behavior for EditTexts, to avoid working with MultiAutoCompleteTextView APIs.","archived":false,"fork":false,"pushed_at":"2020-03-20T14:54:28.000Z","size":8037,"stargazers_count":359,"open_issues_count":6,"forks_count":73,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-29T03:07:57.022Z","etag":null,"topics":["android","android-ui","autocomplete","autocompletetextview","edittext","popup"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natario1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["natario1"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-04-20T18:08:14.000Z","updated_at":"2025-02-22T03:33:24.000Z","dependencies_parsed_at":"2022-08-25T06:51:38.144Z","dependency_job_id":null,"html_url":"https://github.com/natario1/Autocomplete","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natario1%2FAutocomplete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natario1%2FAutocomplete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natario1%2FAutocomplete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natario1%2FAutocomplete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natario1","download_url":"https://codeload.github.com/natario1/Autocomplete/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284951,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-ui","autocomplete","autocompletetextview","edittext","popup"],"created_at":"2024-11-06T09:12:05.818Z","updated_at":"2025-04-05T04:11:46.453Z","avatar_url":"https://github.com/natario1.png","language":"Java","funding_links":["https://github.com/sponsors/natario1","https://github.com/sponsors/natario1)!"],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/natario1/Autocomplete/workflows/Build/badge.svg?event=push)](https://github.com/natario1/Autocomplete/actions)\n[![Release](https://img.shields.io/github/release/natario1/Autocomplete.svg)](https://github.com/natario1/Autocomplete/releases)\n[![Issues](https://img.shields.io/github/issues-raw/natario1/Autocomplete.svg)](https://github.com/natario1/Autocomplete/issues)\n\n*Need support, consulting, or have any other business-related question? Feel free to \u003ca href=\"mailto:mat.iavarone@gmail.com\"\u003eget in touch\u003c/a\u003e.*\n\n*Like the project, make profit from it, or simply want to thank back? Please consider [sponsoring me](https://github.com/sponsors/natario1)!*\n\n# Autocomplete\n\nSimple yet powerful autocomplete behavior for `EditText`s, to avoid working with\n`MultiAutoCompleteTextView` APIs.\n\n```kotlin\nimplementation(\"com.otaliastudios:autocomplete:1.1.0\")\n```\n\nTo see it in action, take a look at the sample app in the `sample` module.\n\n- [Usage](#usage)\n  - [AutocompletePolicy](#autocompletepolicy)\n  - [AutocompletePresenter](#autocompletepresenter)\n    - [RecyclerViewPresenter](#recyclerviewpresenter)\n  - [AutocompleteCallback](#autocompletecallback)\n- [Contributing](#contributing)\n\n\u0026#10240;  \u003c!-- Hack to add whitespace --\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/static/auto1.gif\" width=\"250\" hspace=\"5\"\u003e\u003cimg src=\"docs/static/auto2.gif\" width=\"250\" hspace=\"5\"\u003e\u003cimg src=\"docs/static/auto3.gif\" width=\"250\" hspace=\"5\"\u003e\n\u003c/p\u003e\n\n\u0026#10240;  \u003c!-- Hack to add whitespace --\u003e\n\n## Usage\n\n`Autocomplete` let's you add autocomplete behavior to any `EditText` of your choice. The workflow is\nas follows:\n\n- User types stuff into the edit text\n- `AutocompletePolicy` detects if typed text should trigger the autocomplete popup\n- If yes, the popup is shown\n- `AutocompletePolicy` extracts the **query** string from text. For instance, if text is *Look at \nthis @john*, you might want to look for *john* users in your database\n- The query string is passed to `AutocompletePresenter`, that shows a list of items for that query\n- When some item is clicked, `AutocompleteCallback` is notified and tells whether the popup should be\ndismissed or not.\n\nThese are the base components of the library. You will build an `Autocomplete` instance passing\neach component you need, and that's it.\n\n```java\nAutocomplete.on(editText)\n  .with(autocompletePolicy)\n  .with(autocompleteCallback)\n  .with(autocompletePresenter)\n  .with(popupBackground)\n  .with(popupElevation)\n  .build();\n```\n\n### AutocompletePolicy\n\nThis is an interface that controls when to show/hide the popup. For simple cases (single autocompletion,\nwith just one result, similar to `AutocompleteTextView`) you can leave this unspecified. The library will\nfallback to `Autocomplete.SimplePolicy`:\n\n```java\npublic class SimplePolicy implements AutocompletePolicy {\n    @Override\n    public boolean shouldShowPopup(Spannable text, int cursorPos) {\n        return text.length() \u003e 0;\n    }\n\n    @Override\n    public boolean shouldDismissPopup(Spannable text, int cursorPos) {\n        return text.length() == 0;\n    }\n\n    @Override\n    public CharSequence getQuery(Spannable text) {\n        return text;\n    }\n\n    @Override\n    public void onDismiss(Spannable text) {}\n}\n```\n\nFor more complex situations, you can go implementing the methods:\n\n- `shouldShowPopup(Spannable, int)`: called to understand whether the popup should be shown. For\ninstance, you might want to trigger the popup only when the hashtag character '#' is typed.\n- `shouldDismissPopup(Spannable, int)`: whether the popup should be hidden. The typical implementation\nwould simply be to return `!shouldShowPopup()`, but that is up to you.\n- `getQuery(Spannable)`: called to understand which part of the text should be passed to presenters.\nFor instance, user might have typed *@john* but you want to query for *john* of course.\n- `onDismiss(Spannable)`: this is the moment you should clear any span you have added to the text.\n\nFor the typical case of `#hashtags`, `@usernames` or whatever is triggered by a certain character,\nthe library provides the `CharPolicy` class. It works as multi-autocomplete as well (e.g. for texts\nlike *you should see this @john @pete*).\n\n```java\nAutocomplete.on(editText)\n  .with(new CharPolicy('#'))\n  .with(autocompletePresenter)\n  .build();\n```\n\n### AutocompletePresenter\n\nThe presenter controls the display of items and their filtering when a query is selected.\nIt is recommended to extend `RecyclerViewPresenter`, which shows a `RecyclerView` list.\nFor more complex needs, look at the base `AutocompletePresenter` class and its comments.\n\n**Note**: starting from **1.1.0**, if the view returned by `AutocompletePresenter` has 0 height, this is read as a\nno-data signal and the popup will be dismissed. Not doing so would cause drawing artifacts, by\nleaving the popup in a weird state.\n\nIf you are performing asynchronous loading, make sure to give some height to your view,\nfor example by returning a 'loading' item from your adapter, or adding vertical padding.\n\n#### RecyclerViewPresenter\n\nThis automatically inflates a `RecyclerView` into the popup. Some relevant callbacks to be overriden:\n\n- `instantiateAdapter()`: you should provide an adapter for the recycler here.\n- `instantiateLayoutManager()`: same for the layout manager. Defaults to vertical `LinearLayoutManager`.\nComplex managers might lead to UI inconsistencies.\n- `getPopupDimensions()`: return dimensions for the popup (width, height, maxWidth, maxHeight).\n- `onViewShown()`: you can perform further initialization on the recycler. The list now is about to be requested.\n- `onQuery(CharSequence)`: we have a query from the edit text, as returned by `AutocompletePolicy`.\nThis is the time to display a list of results corresponding to this filter.\n- `onViewHidden()`: release resources here if needed.\n\nWhen a list item is clicked, please ensure you are calling `dispatchClick(item)` to dispatch the\nclick event to the `AutocompleteCallback`, if present.\n\n### AutocompleteCallback\n\n```java\npublic interface AutocompleteCallback\u003cT\u003e {\n    boolean onPopupItemClicked(Editable editable, T item);\n    void onPopupVisibilityChanged(boolean shown);\n}\n```\n\n`AutocompleteCallback` controls what happens when either the popup visibility changes, or when an\nitem is selected. Typically at this point you might want to insert a `String` related to that item\ninto the `EditText`.\n\nThis should be done by acting on the `Editable` interface that you should already know, using \nmethods like `editable.insert()` or `editable.replace()`.\n\n## Contributing\n\nYou are welcome to contribute with issues, PRs or suggestions.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatario1%2Fautocomplete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatario1%2Fautocomplete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatario1%2Fautocomplete/lists"}