All Projects → natario1 → Autocomplete

natario1 / Autocomplete

Licence: apache-2.0
Simple yet powerful autocomplete behavior for EditTexts, to avoid working with MultiAutoCompleteTextView APIs.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Autocomplete

QuestionnaireView
A simple view to be able to display question and various field (Radio, EditText, checkbox ) for answers
Stars: ✭ 34 (-88.93%)
Mutual labels:  android-ui, edittext
Codeeditor
Code Editor Native Way
Stars: ✭ 155 (-49.51%)
Mutual labels:  edittext, autocomplete
Aestheticdialogs
📱 An Android Library for 💫fluid, 😍beautiful, 🎨custom Dialogs.
Stars: ✭ 352 (+14.66%)
Mutual labels:  android-ui, popup
BalloonPopup
Forget Android Toast! BalloonPopup displays a round or squared popup and attaches it to a View, like a callout. Uses the Builder pattern for maximum ease. The popup can automatically hide and can persist when the value is updated.
Stars: ✭ 32 (-89.58%)
Mutual labels:  popup, android-ui
Selectmenu
Simple, easily and diversity menu solution
Stars: ✭ 284 (-7.49%)
Mutual labels:  autocomplete, popup
MaterialDesign-Toast
Custom android Toast with Material Design
Stars: ✭ 70 (-77.2%)
Mutual labels:  popup, android-ui
Balloon
🎈 Modernized and sophisticated tooltips, fully customizable with an arrow and animations on Android.
Stars: ✭ 2,242 (+630.29%)
Mutual labels:  android-ui, popup
CodeView
Android Library to make it easy to create an Code editor or IDE that support any languages and themes, with auto complete, auto indenting, snippets and more features
Stars: ✭ 254 (-17.26%)
Mutual labels:  autocomplete, android-ui
CustomFontView
Custom View classes for TextView, EditText & Buttons - to set custom fonts
Stars: ✭ 26 (-91.53%)
Mutual labels:  android-ui, edittext
Spedittool
An efficient and scalable library for inputing and displaying gif or @mention on graph-text mixed TextView/EditText
Stars: ✭ 292 (-4.89%)
Mutual labels:  edittext, android-ui
React Native Mentions
Mentions textbox for React Native. Works on both ios and android. 🐳
Stars: ✭ 277 (-9.77%)
Mutual labels:  autocomplete
Autocomplete
Accessible autocomplete component for vanilla JavaScript and Vue.
Stars: ✭ 277 (-9.77%)
Mutual labels:  autocomplete
Bottomdrawer
BottomSheet with animations
Stars: ✭ 291 (-5.21%)
Mutual labels:  android-ui
Basiclightbox
The lightest lightbox ever made.
Stars: ✭ 299 (-2.61%)
Mutual labels:  popup
Cornersheet
Behavior to expand view from corner
Stars: ✭ 274 (-10.75%)
Mutual labels:  android-ui
Fuzzy
Spell checking and fuzzy search suggestion written in Go
Stars: ✭ 290 (-5.54%)
Mutual labels:  autocomplete
Bankcardformat
💳 自动格式化银行卡号的EditText,卡号格式化、归属银行及卡别判断
Stars: ✭ 273 (-11.07%)
Mutual labels:  edittext
Touchdemo
Custom touch handling in Android
Stars: ✭ 273 (-11.07%)
Mutual labels:  android-ui
Wpopup
一个简单使用并且高度定制的Popupwindow。超简单实现朋友圈点赞效果,并且只用一个WPopup!完全不用担心复用问题!点击切换动画效果等!
Stars: ✭ 269 (-12.38%)
Mutual labels:  popup
Sqls
SQL language server written in Go.
Stars: ✭ 301 (-1.95%)
Mutual labels:  autocomplete

Build Status Release Issues

Need support, consulting, or have any other business-related question? Feel free to get in touch.

Like the project, make profit from it, or simply want to thank back? Please consider sponsoring me!

Autocomplete

Simple yet powerful autocomplete behavior for EditTexts, to avoid working with MultiAutoCompleteTextView APIs.

implementation("com.otaliastudios:autocomplete:1.1.0")

To see it in action, take a look at the sample app in the sample module.

Usage

Autocomplete let's you add autocomplete behavior to any EditText of your choice. The workflow is as follows:

  • User types stuff into the edit text
  • AutocompletePolicy detects if typed text should trigger the autocomplete popup
  • If yes, the popup is shown
  • AutocompletePolicy extracts the query string from text. For instance, if text is Look at this @john, you might want to look for john users in your database
  • The query string is passed to AutocompletePresenter, that shows a list of items for that query
  • When some item is clicked, AutocompleteCallback is notified and tells whether the popup should be dismissed or not.

These are the base components of the library. You will build an Autocomplete instance passing each component you need, and that's it.

Autocomplete.on(editText)
  .with(autocompletePolicy)
  .with(autocompleteCallback)
  .with(autocompletePresenter)
  .with(popupBackground)
  .with(popupElevation)
  .build();

AutocompletePolicy

This is an interface that controls when to show/hide the popup. For simple cases (single autocompletion, with just one result, similar to AutocompleteTextView) you can leave this unspecified. The library will fallback to Autocomplete.SimplePolicy:

public class SimplePolicy implements AutocompletePolicy {
    @Override
    public boolean shouldShowPopup(Spannable text, int cursorPos) {
        return text.length() > 0;
    }

    @Override
    public boolean shouldDismissPopup(Spannable text, int cursorPos) {
        return text.length() == 0;
    }

    @Override
    public CharSequence getQuery(Spannable text) {
        return text;
    }

    @Override
    public void onDismiss(Spannable text) {}
}

For more complex situations, you can go implementing the methods:

  • shouldShowPopup(Spannable, int): called to understand whether the popup should be shown. For instance, you might want to trigger the popup only when the hashtag character '#' is typed.
  • shouldDismissPopup(Spannable, int): whether the popup should be hidden. The typical implementation would simply be to return !shouldShowPopup(), but that is up to you.
  • getQuery(Spannable): called to understand which part of the text should be passed to presenters. For instance, user might have typed @john but you want to query for john of course.
  • onDismiss(Spannable): this is the moment you should clear any span you have added to the text.

For the typical case of #hashtags, @usernames or whatever is triggered by a certain character, the library provides the CharPolicy class. It works as multi-autocomplete as well (e.g. for texts like you should see this @john @pete).

Autocomplete.on(editText)
  .with(new CharPolicy('#'))
  .with(autocompletePresenter)
  .build();

AutocompletePresenter

The presenter controls the display of items and their filtering when a query is selected. It is recommended to extend RecyclerViewPresenter, which shows a RecyclerView list. For more complex needs, look at the base AutocompletePresenter class and its comments.

Note: starting from 1.1.0, if the view returned by AutocompletePresenter has 0 height, this is read as a no-data signal and the popup will be dismissed. Not doing so would cause drawing artifacts, by leaving the popup in a weird state.

If you are performing asynchronous loading, make sure to give some height to your view, for example by returning a 'loading' item from your adapter, or adding vertical padding.

RecyclerViewPresenter

This automatically inflates a RecyclerView into the popup. Some relevant callbacks to be overriden:

  • instantiateAdapter(): you should provide an adapter for the recycler here.
  • instantiateLayoutManager(): same for the layout manager. Defaults to vertical LinearLayoutManager. Complex managers might lead to UI inconsistencies.
  • getPopupDimensions(): return dimensions for the popup (width, height, maxWidth, maxHeight).
  • onViewShown(): you can perform further initialization on the recycler. The list now is about to be requested.
  • onQuery(CharSequence): we have a query from the edit text, as returned by AutocompletePolicy. This is the time to display a list of results corresponding to this filter.
  • onViewHidden(): release resources here if needed.

When a list item is clicked, please ensure you are calling dispatchClick(item) to dispatch the click event to the AutocompleteCallback, if present.

AutocompleteCallback

public interface AutocompleteCallback<T> {
    boolean onPopupItemClicked(Editable editable, T item);
    void onPopupVisibilityChanged(boolean shown);
}

AutocompleteCallback controls what happens when either the popup visibility changes, or when an item is selected. Typically at this point you might want to insert a String related to that item into the EditText.

This should be done by acting on the Editable interface that you should already know, using methods like editable.insert() or editable.replace().

Contributing

You are welcome to contribute with issues, PRs or suggestions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].