Gmail style MultiAutoCompleteTextView for Android

Overview

Version 3.0

The 3.0.1 version is now available! This should resolve a number of text handling issues and lay the groundwork for better support of mixed text and token input. If you're still on 2.*, you can find the docs for 2.0.8 here.

Upgrading from 2.* to 3.0

For most developers, the migration should be fairly simple. Here are the likely issues you'll need to resolve:

  1. The view now inherits from AppCompatAutoCompleteTextView. You probably don't need to make any changes for this, but you will need to include the Android support library if you are not already.

  2. setTokenDeleteStyle has been removed. Something similar to the Clear style has been hardcoded in. This feature never worked reliably and caused a lot of crashes.

  3. addObject has been renamed addObjectAsync. removeObject has been renamed removeObjectAsync. There are also addObjectSync/removeObjectSync versions that can be called from the UI thread and guarantee that getObjects will include these changes on the next call.

  4. setAllowDuplicates(false) has been made more flexible to deal with issues around different kinds of equality. If you need the 2.* version of the behavior, add this to your TokenCompleteTextView subclass:

@Override
public boolean shouldIgnoreToken(T token) {
    return getObjects().contains(token);
}
  1. TokenListener has a new method you will need to add:
public interface TokenListener<T> {
    void onTokenAdded(T token);
    void onTokenRemoved(T token);
    void onTokenIgnored(T token);
}
  1. convertSerializableArrayToObjectArray has been renamed convertSerializableObjectsToTypedObjects.

You may also find that the vertical alignment of your tokens has changed. It appears that the app compat text view layout is slightly different than the normal one. You will likely find that you need to adjust the baseline values for your token views.

There have been a number of under the hood changes to the text handling, so if you've been directly accessing the text or using your own tokenizer, you may need to make more changes than this.

Upgrading from 1.* to 2.0

There is one breaking change from 1.* to 2.0. You need to extend TokenCompleteTextView<Object> instead of TokenCompleteTextView.

TokenAutoComplete

TokenAutoComplete is an Android Gmail style token auto-complete text field and filter. It's designed to have an extremely simple API to make it easy for anyone to implement this functionality while still exposing enough customization to let you make it awesome.

Support for Android 4.0.3 (API 14) and up. If you need support for earlier versions of Android, version 1.2.1 is the most recent version that supports Android 2.2 (API 8) and up.

Focused TokenAutoCompleteTextView example

Unfocused TokenAutoCompleteTextView example

Setup

Gradle

dependencies {
    compile "com.splitwise:tokenautocomplete:3.0.1@aar"
}

Maven

<dependency>
  <groupId>com.splitwise</groupId>
  <artifactId>tokenautocomplete</artifactId>
  <version>3.0.1</version>
  <type>aar</type>
</dependency>

No build tools

Download the jar file and add it to your project

If you would like to get the most recent code in a jar, clone the project and run ./gradlew jar from the root folder. This will build a tokenautocomplete.jar in library/build/libs/.

You may also add the library as an Android Library to your project. All the library files live in library.

Creating your auto complete view

If you'd rather just start with a working example, clone the project and take a look.

For a basic token auto complete view, you'll need to

  1. Subclass TokenCompleteTextView
  2. Create a layout and activity for your completion view

Subclass TokenCompleteTextView

You'll need to provide your own implementations for getViewForObject and defaultObject. You should return a view that displays the token from getViewForObject. In defaultObject, you need to guess what the user meant with their completion. This is usually from the user typing something and hitting "," - see the way gmail for Android handles this for example. Here's a simple example:

public class ContactsCompletionView extends TokenCompleteTextView<Person> {
    public ContactsCompletionView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected View getViewForObject(Person person) {

        LayoutInflater l = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        TextView view = (TextView) l.inflate(R.layout.contact_token, (ViewGroup) getParent(), false);
        view.setText(person.getEmail());

        return view;
    }

    @Override
    protected Person defaultObject(String completionText) {
        //Oversimplified example of guessing if we have an email or not
        int index = completionText.indexOf('@');
        if (index == -1) {
            return new Person(completionText, completionText.replace(" ", "") + "@example.com");
        } else {
            return new Person(completionText.substring(0, index), completionText);
        }
    }
}

Layout code for contact_token

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/token_background"
    android:padding="5dp"
    android:textColor="@android:color/white"
    android:textSize="18sp" />

Token background drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ffafafaf" />
    <corners android:radius="5dp" />
</shape>

Person object code

public class Person implements Serializable {
    private String name;
    private String email;

    public Person(String n, String e) { name = n; email = e; }

    public String getName() { return name; }
    public String getEmail() { return email; }

    @Override
    public String toString() { return name; }
}

Note that the class implements Serializable. In order to restore the view state properly, the TokenCompleteTextView needs to be able to save and restore your objects from disk. If your objects cannot be made Serializable, please look at restoring the view state.

Create a layout and activity for your completion view

I'm adding some very stupid "contacts" to the app so you can see it work, but you should read data from the contacts data provider in a real app.

Activity code

public class TokenActivity extends Activity {
    ContactsCompletionView completionView;
    Person[] people;
    ArrayAdapter<Person> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        people = new Person[]{
                new Person("Marshall Weir", "[email protected]"),
                new Person("Margaret Smith", "[email protected]"),
                new Person("Max Jordan", "[email protected]"),
                new Person("Meg Peterson", "[email protected]"),
                new Person("Amanda Johnson", "[email protected]"),
                new Person("Terry Anderson", "[email protected]")
        };

        adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people);

        completionView = (ContactsCompletionView)findViewById(R.id.searchView);
        completionView.setAdapter(adapter);
    }
}

Layout code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.yourpackagename.ContactsCompletionView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

That's it! You can grab the objects the user tokenized with getObjects() on the TokenCompleteTextView when you need to get the data out.

Setting a prefix prompt

If you have a short prompt like "To: ", you can probably get away with setting a drawable on the left side of the TokenCompleteTextView. If you have something longer, you will probably not want your prefix to take up the whole height of the view. If you would like to have a prefix that only indents the first line, you should use setPrefix. This code is a little quirky when restoring the activity, so you want to make sure it only gets called on a fresh start in onCreate:

if (savedInstanceState == null) {
    completionView.setPrefix("Your bestest friends: ");
}

Custom filtering

If you've used the gmail auto complete, you know that it doesn't use the default "toString" filtering you get with an ArrayAdapter.

I've added my own FilteredArrayAdapter to the jar file that is a subclass of ArrayAdapter but has some good hooks for custom filtering. You'll want to be fairly efficient in this as it gets called a lot, but it's a simple process to add a custom filter. If you are using the TokenActivity above, you simply replace the line

adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people);

with

adapter = new FilteredArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people) {
    @Override
    protected boolean keepObject(Person obj, String mask) {
        mask = mask.toLowerCase();
        return obj.getName().toLowerCase().startsWith(mask) || obj.getEmail().toLowerCase().startsWith(mask);
    }
};

Duplicate objects

In addition to custom filtering, you may want to make sure you don't get duplicate tokens. In your TokenCompleteTextView subclass, override shouldIgnoreToken:

@Override
public boolean shouldIgnoreToken(T token) {
    return getObjects().contains(token);
}

Any text the user entered for the duplicate token will be cleared. You can implement whatever matching behavior you need. This implementation assumes the equals method on your token objects is a reasonable comparison.

Responding to user selections

If you're solving a similar problem to Splitwise, you need to handle users adding and removing tokens. I've provided a simple interface to get these events and allow you to respond to them in the TokenCompleteTextView:

public static interface TokenListener<T> {
    public void onTokenAdded(T token);
    public void onTokenRemoved(T token);
    public void onTokenIgnored(T token)
}

We can modify the TokenActivity to see how these callbacks work:

public class TokenActivity extends Activity implements TokenCompleteTextView.TokenListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        /* code from the initial example */

        completionView.setTokenListener(this);
    }

    @Override
    public void onTokenAdded(Person token) {
        System.out.println("Added: " + token);
    }

    @Override
    public void onTokenRemoved(Person token) {
        System.out.println("Removed: " + token);
    }

    @Override
    public void onTokenIgnored(Person token) {
        System.out.println("Ignored: " + token);
    }
}

In Splitwise we use these callbacks to handle users selecting a group when adding an expense. When a user adds a group to an expense, we remove all the users in the group and the other groups from the array adapter. A user should only be able to select one group and it would be redundant to add users in the group to the expense again.

Programatically add and remove objects

You may want to prefill the list with objects. For example when replying to an email, you would want the To: and CC: fields to have the correct emails in them. You can use addObjectSync to put these tokens in. You can also remove objects programatically with removeObjectSync though this will remove all objects that return true when calling equals on them. If you have copies in the array, you may need to take special care with this.

The Sync versions of these methods must be called from the UI thread. There are also addObjectAsync and removeObjectAsync that can be called from any thread, but will not update the view or data immediately. Finally, there is a clearAsync function to empty the EditText and remove all the objects.

Letting users click to select and delete tokens

There are four different styles of click handling build into the project. Call setTokenClickStyle to change the behavior. If you need more control over how click behavior works, please see issue #350.

TokenCompleteTextView.TokenClickStyle.None

This is the default, even though it doesn't match the Gmail behavior. When the user clicks on a token, the view will move the cursor in front of or after the token. Users should not be able to get the cursor in the token as this causes confusing behavior.

TokenCompleteTextView.TokenClickStyle.Delete

When the user clicks on a token, the token will be removed from the field. If you need some kind of confirmation, handle it with the onTokenRemoved callback and re-add the token if the user changes their mind.

TokenCompleteTextView.TokenClickStyle.Select

This behavior most closely matches the Gmail token field behavior, but I did not make it the default to simplify the initial tutorial. The first click on a token will unselect any currently selected token views, then it will call setSelected(true) on the selected token.

TokenCompleteTextView.TokenClickStyle.SelectDeselect

This works the same as Select except that a second click on the token will deselect it and call setSelected(false).

Showing token selected state

If you want to change the colors of the token when it is selected, you will need to add appropriate drawables to your project. In the test project, we have the following:

token_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/token_default" android:state_selected="false" />
    <item android:drawable="@drawable/token_selected" android:state_selected="true" />
</selector>

token_default.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
        android:width="1dp"
        android:color="#ffd4d4d4" />
    <solid android:color="#ffafafaf" />

    <corners android:radius="3dp"/>
</shape>

token_selected.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
        android:width="1dp"
        android:color="#ffa4a4a4" />
    <solid android:color="#ff7a7a7a" />

    <corners android:radius="3dp"/>
</shape>

If you need more detailed view customization like changing a picture in the token or resizing the token, you will need to provide a custom view to use in the layout you inflate in getViewForObject and override setSelected in that view. You can then make appropriate changes to the view.

Example custom view

In a view implementation (see com.tokenautocomplete.TokenTextView):

public class TokenTextView extends TextView {

    ...

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        setCompoundDrawablesWithIntrinsicBounds(0, 0, selected ? R.drawable.close_x : 0, 0);
    }
}

contact_token.xml

<com.tokenautocomplete.TokenTextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/token_background"
    android:textColor="@android:color/white"
    android:textSize="14sp"
    android:maxLines="1"
    android:ellipsize="end"
    android:padding="4dp"
    tools:text="Glenda Jönsson" />

Inflate your custom view:

public class ContactsCompletionView extends TokenCompleteTextView<Person> {

    ...

    @Override
    protected View getViewForObject(Person person) {
        LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        TokenTextView token = (TokenTextView) l.inflate(R.layout.contact_token, (ViewGroup) getParent(), false);
        token.setText(person.getEmail());
        return token;
    }
}

Restoring the view state

If your token objects implement Serializable or Parcelable, the TokenCompleteTextView will automatically handle onSaveInstanceState and onRestoreInstanceState. If you cannot make your objects Serializable or Parcelable, you should override getSerializableObjects and convertSerializableObjectsToTypedObjects. getSerializableObjects should return an array of Serializable objects that can be used to rebuild your original objects when restoring the view state. convertSerializableObjectsToTypedObjects should take an array of Serializable objects and use them to rebuild your token objects.

We use something similar to this at splitwise to avoid saving complicated object graphs:

@Override
protected ArrayList<Object> convertSerializableObjectsToTypedObjects(ArrayList<Serializable> sers) {
    ArrayList<Object> objs = new ArrayList<Object>();
    for (Serializable s: sers) {
        if (s instanceof Long) {
            Contact c = Contact.loadFromDatabase((Long)s);
            objs.add(c);
        } else {
            objs.add(s);
        }
    }

    return objs;
}

@Override
protected ArrayList<Serializable> getSerializableObjects() {
    ArrayList<Serializable> s = new ArrayList<Serializable>();
    for (Object obj: getObjects()) {
        if (obj instanceof Serializable) {
            s.add((Serializable)obj);
        } else {
            //obj is a Contact
            s.add(((Contact)obj).getId());
        }
    }
    return s;
}

Other options

  • Turn off making a best guess when converting text into a token
performBestGuess(false);
  • Prevent the TokenCompleteTextView collapsing to a single line when it loses focus
allowCollapse(false);
  • Change the set of characters that complete a token
setTokenizer(new CharacterTokenizer(Arrays.asList('.', ','), ","));
  • Detect tokens based on their first character
//Detect @usernames and #hashtags
setTokenizer(new TagTokenizer(Arrays.asList('@', '#')));
  • Change the number of characters required to start showing suggestions
setThreshold(1);
  • Limit the total number of tokens in the field
setTokenLimit(10);
  • Prevent specific tokens from being deleted by overriding isTokenRemovable on your completion view

Experimental mixed freeform text and token input support

These options should allow you to build something similar to a Tweet composing view, but is likely to still have some edge cases with unusual behavior.

  • Allow mixed text and token input
preventFreeFormText(false);
  • Get the string value of the text content of the view, including reasonable string representations of the tokens. If getContextText is not using an acceptable string representation of the token, you can override tokenToString to change how the token is represented.
getContentText();

License

Copyright (c) 2013, 2014 splitwise, Wouter Dullaert

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Planning next version

    Planning next version

    Hi everyone!

    It's been a while since I've done significant work on this project and there are a number of bugs that have cropped up (#253, #242, #241, #238, #237, #228, #226, #220, #193, #184, #183, #172, #132, #95) that will require a lot of reworking. There are also some use cases I hadn't considered during my initial design that don't work well with the current structure. I'd also like to simplify and automate the testing process.

    Part of this is that I'll be removing a lot of features and reducing the public interface of the class as much as possible. To help me figure out what I should keep and do better planning out improvements, please comment and let me know how you're using it. Here's the template I'd like to see. Please copy and paste this into a comment and complete it. See my example below.

    ### My use case (a few sentences describing it)
    
    ### Settings (choose the correct one in each [], first option is the default)
    
     - setDeletionStyle([Clear, PartialCompletion, ToString])
     - setTokenClickStyle([None, Delete, Select, SelectDeselect])
     - allowDuplicates([true, false])
     - performBestGuess([true, false])
     - allowCollapse([true, false])
    
    ### API (delete all functions you do not use directly)
    
     - setPrefix()
     - setSplitChar()
     - setTokenLimit()
     - setTokenizer()
     - setTokenListener()
     - getObjects()
     - addListeners()
     - removeListeners()
     - clearCompletionText()
     - currentCompletionText()
     - performCompletion()
     - performCollapse()
     - addObject()
     - removeObject()
     - clear()
    
    ### Behavior overrides (delete all functions you do not override)
    
     - performFiltering()
     - isTokenRemovable()
     - maxTextWidth()
     - enoughToFilter()
     - buildSpanForObject()
     - replaceText()
     - getSerializableObjects()
     - convertSerializableArrayToObjectArray()
     - canDeleteSelection()
    
    ### Workarounds (any customization that is likely to break if I stop subclassing MultiAutoCompleteTextView)
    
    
    ### Feature requests (anything you currently do that the library could do for you)
    
    need feedback 
    opened by mgod 16
  • Crash when cast to spanned, v3.0, android 9.0

    Crash when cast to spanned, v3.0, android 9.0

    E/MessageQueue-JNI: java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spanned at com.tokenautocomplete.SpanUtils.ellipsizeWithSpans(SpanUtils.java:36) at com.tokenautocomplete.TokenCompleteTextView.performCollapse(TokenCompleteTextView.java:793) at com.tokenautocomplete.TokenCompleteTextView.onFocusChanged(TokenCompleteTextView.java:844) at android.view.View.clearFocusInternal(View.java:7164) at android.view.View.unFocus(View.java:7197) at android.view.ViewGroup.requestChildFocus(ViewGroup.java:813) at android.view.View.handleFocusGainInternal(View.java:6989) at android.view.View.requestFocusNoSearch(View.java:11642) at android.view.View.requestFocus(View.java:11616) at android.view.View.requestFocus(View.java:11583) at android.view.View.requestFocus(View.java:11525) at android.view.View.onTouchEvent(View.java:13909) at android.widget.TextView.onTouchEvent(TextView.java:10421) at com.tokenautocomplete.TokenCompleteTextView.onTouchEvent(TokenCompleteTextView.java:701) at android.view.View.dispatchTouchEvent(View.java:12615) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:541) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1893) at android.app.Dialog.dispatchTouchEvent(Dialog.java:1001) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:490) at android.view.View.dispatchPointerEvent(View.java:12860) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5767) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5533) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5160) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5217) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7794) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7759) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7717) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7986) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:202) at android.os.MessageQueue.nativePollOnce(Native D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: mobile.socialboards.com, PID: 27289 java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spanned at com.tokenautocomplete.SpanUtils.ellipsizeWithSpans(SpanUtils.java:36) at com.tokenautocomplete.TokenCompleteTextView.performCollapse(TokenCompleteTextView.java:793) at com.tokenautocomplete.TokenCompleteTextView.onFocusChanged(TokenCompleteTextView.java:844) at android.view.View.clearFocusInternal(View.java:7164) at android.view.View.unFocus(View.java:7197) at android.view.ViewGroup.requestChildFocus(ViewGroup.java:813) at android.view.View.handleFocusGainInternal(View.java:6989) at android.view.View.requestFocusNoSearch(View.java:11642) at android.view.View.requestFocus(View.java:11616) at android.view.View.requestFocus(View.java:11583) at android.view.View.requestFocus(View.java:11525) at android.view.View.onTouchEvent(View.java:13909) at android.widget.TextView.onTouchEvent(TextView.java:10421) at com.tokenautocomplete.TokenCompleteTextView.onTouchEvent(TokenCompleteTextView.java:701) at android.view.View.dispatchTouchEvent(View.java:12615) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:541) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1893) at android.app.Dialog.dispatchTouchEvent(Dialog.java:1001) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:490) at android.view.View.dispatchPointerEvent(View.java:12860) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5767) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5533) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5160) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5217) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7794) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7759) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7717) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7986) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:202) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:386) at android.os.Looper.loop(Looper.java:169) at android.app.ActivityThread.main(ActivityThread.java:7470) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958) E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spanned at com.tokenautocomplete.SpanUtils.ellipsizeWithSpans(SpanUtils.java:36) at com.tokenautocomplete.TokenCompleteTextView.performCollapse(TokenCompleteTextView.java:793) at com.tokenautocomplete.TokenCompleteTextView.onFocusChanged(TokenCompleteTextView.java:844) at android.view.View.clearFocusInternal(View.java:7164) at android.view.View.unFocus(View.java:7197) at android.view.ViewGroup.requestChildFocus(ViewGroup.java:813) at android.view.View.handleFocusGainInternal(View.java:6989) at android.view.View.requestFocusNoSearch(View.java:11642) at android.view.View.requestFocus(View.java:11616) at android.view.View.requestFocus(View.java:11583) at android.view.View.requestFocus(View.java:11525) at android.view.View.onTouchEvent(View.java:13909) at android.widget.TextView.onTouchEvent(TextView.java:10421) at com.tokenautocomplete.TokenCompleteTextView.onTouchEvent(TokenCompleteTextView.java:701) at android.view.View.dispatchTouchEvent(View.java:12615) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3041) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2728) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:541) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1893) at android.app.Dialog.dispatchTouchEvent(Dialog.java:1001) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:490) at android.view.View.dispatchPointerEvent(View.java:12860) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5767) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5533) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5160) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5217) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5040) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5006) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5014) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4987) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7794) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7759) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7717) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7986) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:202) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:386) at android.os.Looper.loop(Looper.java:169) at android.app.ActivityThread.main(ActivityThread.java:7470) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

    need feedback 
    opened by Pirokar 14
  • Search text not cleared on Samsung S9 (Android 8.0)

    Search text not cleared on Samsung S9 (Android 8.0)

    We have an issue that occurs only on the S9 (tested two devices, both on 8.0), not on Pixel, S5 and other test devices or simulators.

    When we enter text and complete it to a token the text re-appears when typing another character. Example: Enter "gui", complete it to a token, enter "m", the field displays the token and "guim".

    I have added logging in the textchangelistener that shows this behavior: beforeTextChanged: gui //now the token is created onTextChanged: ,, afterTextChanged: ,, //now enter "m" beforeTextChanged: ,, onTextChanged: ,, guim afterTextChanged: ,, guim

    When using a standard MultiAutoCompleteTextView on the device the issue does not come up. I am a bit clueless about where the text comes from as it is not there in beforeTextChanged.

    opened by slowcar 14
  • Append characters in prefix (exactly 3 char)

    Append characters in prefix (exactly 3 char)

    I'm using your code in my application(multiple tag like gmail to address), working fine. But while i type exactly 3 character for searching and values are shown in dropdown, select one value then I start to type another email search in same filed means the before searching characters are append with newly searching character.

    Eg:- I have search email "moh" select "[email protected]" then start type to another mail search start with "e" means it's showing with previous searching character like "mohe"... how can i solve this. I have download this latest code and check it. This also having same issue. Please update your feedback about this issue. Thanks.
    
    opened by Vijay-Yosi 14
  • Limit the number of character in Token (or add

    Limit the number of character in Token (or add "...")

    Hi,

    great work on the library, Thanks !

    here is a bug_report / request,

    when the token's width is longer than the MultiAutoCompleteTextView's width, somehow the token gets cropped (Which is not a bad thing!) and then it gets duplicated in two lines. so either let me know how I can prevent the duplication, or how we can replace the string in the token with string.substring(0,LIMIT) + "..." or any other enhancement

    in the first screenshot you can see both TAC s showing the tokens OK! screenshot_2015-11-09-15-30-10

    here the right one increased in size, hence the left one gets smaller than the token (ONLY ONE TOKEN, IT HAS) and you can see how it gets duplicated screenshot_2015-11-09-15-30-17

    same goes with the left one here

    screenshot_2015-11-09-15-30-25

    bug 
    opened by muhammad-naderi 14
  • Tokens in one line are displayed too close to the tokens in the line above.

    Tokens in one line are displayed too close to the tokens in the line above.

    As you insert tokens so they go over more than 2 lines of tokens, the additional tokens have no vertical space from the tokens above them.

    The xml for the textview:

    <?xml version="1.0" encoding="utf-8"?>
    <TextView android:id="@+id/name"
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/background_token"
              android:ellipsize="end"
              android:maxLines="1"
              android:padding="4dp"
              android:textColor="@android:color/white"
              android:textSize="14sp"
              tools:text="#francislata" />
    

    And for the background drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <corners
            android:bottomLeftRadius="4dp"
            android:bottomRightRadius="4dp"
            android:topLeftRadius="4dp"
            android:topRightRadius="4dp" />
    
        <solid android:color="@color/orange" />
    </shape>
    

    device-2016-08-11-122351

    opened by raylee4204 13
  • Use generics instead of unchecked casts for more type-safety

    Use generics instead of unchecked casts for more type-safety

    I've changed the library (and the example app) to use generics to enforce type-safety at compile time. This keeps you from having to cast every Object that comes back from the view. The app code becomes much cleaner at the expense of generic use and some object casting in the library.

    Closes #46

    enhancement 
    opened by austynmahoney 13
  • remove token but listener onRemovedToken not work

    remove token but listener onRemovedToken not work

    I have implement token listener on my tokenautocomplete. when I am delete token with delete button on softkeyboard, but the tokenListener never call, even when I add a token with click the suggestion on auto complete too.

                val secretaryListSize = getDataList()[adapterPosition].secretaryList.size
                itemView.auto_complete_add_approval_item.setTokenListener(null)
                if (secretaryListSize > 0) {
                    itemView.auto_complete_add_approval_item.clear()
                    itemView.auto_complete_add_approval_item.text = SpannableStringBuilder("")
                    for (secretary in getDataList()[adapterPosition].secretaryList) {
                        itemView.auto_complete_add_approval_item.addObject(secretary)
                    }
                }else {
                    itemView.auto_complete_add_approval_item.clear()
                }
                itemView.auto_complete_add_approval_item.setTokenListener(object : TokenCompleteTextView.TokenListener<Secretary> {
                    override fun onTokenAdded(secretary: Secretary) {
    
                    }
    
                    override fun onTokenRemoved(secretary: Secretary) {
                        getDataList()[adapterPosition].secretaryList.remove(secretary)
                    }
                })```
    
    
    opened by ahmaadyunus 12
  • ANR  when Collapse

    ANR when Collapse

    Exception: application is no response, the stacktrace like this:

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.386 android.graphics.Paint.getFontMetricsInt(Native Method)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.386 android.text.MeasuredText.addStyleRun(MeasuredText.java:191)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.387 android.text.MeasuredText.addStyleRun(MeasuredText.java:281)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.387 android.text.StaticLayout.generate(StaticLayout.java:745)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.387 android.text.DynamicLayout.reflow(DynamicLayout.java:300)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.387 android.text.DynamicLayout.access$000(DynamicLayout.java:36)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.388 android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:662)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.388 android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:691)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.388 android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1077)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.388 android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:637)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.389 android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:567)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.389 android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:225)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.389 android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:34)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.389 com.tokenautocomplete.TokenCompleteTextView.removeSpan(TokenCompleteTextView.java:1020)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.390 com.tokenautocomplete.TokenCompleteTextView.performCollapse(TokenCompleteTextView.java:776)

    02-22 15:00:26.397 27569 27705 I AnrError: 02-22 15:00:26.390 com.tokenautocomplete.TokenCompleteTextView.onFocusChanged(TokenCompleteTextView.java:830)

    opened by lpflpy 12
  • Remove typed text programatically

    Remove typed text programatically

    Hi, is there any way to remove typed text when object is added programatically through addObject()? I simply want to replace (or delete) all text when new object is added. I've tried updating editable, but this haven't lead to success. Thanks.

    opened by skywall 11
  • Added method to set the character that triggers token creation

    Added method to set the character that triggers token creation

    I wanted the EditTextView to create tokens when the user inputs a space, so I removed the hardcoded comparison with ',' and added some convenience methods to set the character that triggers token creation. It is possible to set multiple characters.

    The code can be shorter by using a List instead of an array of chars, but given that char is a primitive I think the current approach is less resource intensive.

    I hope I did this pull request thing right, I'm quite new to GitHub

    enhancement 
    opened by wdullaer 11
  • Add `prefixEnabled` property to allow the prefix to be disabled

    Add `prefixEnabled` property to allow the prefix to be disabled

    I ran in a weird bug with TokenCompleteTextView.onRestoreInstanceState() and so ended up not wanting to use the restored objects in onRestoreInstanceState (we have the state in our viewmodel. However the even though I'm not using the prefix the setPrefix() in onRestoreInstanceState() the would clear the tokens I had already set in the TokenCompleteTextView in my activities onCreate(). Specifically when it called setText().

    To resolve I've added the prefixEnabled property. This allows callers to disable the prefix behaviour and solve the issue I was seeing. However, there maybe an alternate way to solve this that doesn't involve and extra property. Open to suggestions.

    Also, apologies for the additional formatting changes it seems my code formatter got carried away. I can correct this if there's approval for this PR to the merged.

    opened by scottyab 0
  • tokenLimit is not publically readable

    tokenLimit is not publically readable

    setTokenLimit(tokenLimit) is pretty handy when I need to have a token field limited however it would be useful to query what the current tokenLimit however currently there's no way to get at that. Super minor issue but I'd find it useful.

    Thank for the library BTW and the maintenance 👏

    opened by scottyab 0
  • Dropdown list is not reset when setThredshold(0)

    Dropdown list is not reset when setThredshold(0)

    This can be reproduce by ExampleActivity:

    1. Set Thredshold(0) in completionView
    2. In email completeView, type "ma". Dropdown list will appear, then select the first item. The dropdown will be dismissed
    3. Click on the completionView again. The dropdown is appeared as if filtered by "ma", although user didn't type anything. The only way to reset full dropdown list is type some random character, then delete it.

    If you know any way to walk around this. Please advise :) Thank you

    opened by jasontruong 3
  • Improve token selection logic while editing text in the view

    Improve token selection logic while editing text in the view

    See https://github.com/splitwise/TokenAutoComplete/pull/243 for initial improvements.

    This should also address https://github.com/splitwise/TokenAutoComplete/issues/401

    opened by mgod 0
  • onTokenAdded not called with cursoradapter

    onTokenAdded not called with cursoradapter

    We use TokenCompleteTextView with a cusoradapter to provide a lookup. When an item from the adapter is selected tokenAdded is not called after we updated from 2.0.8 to 3.0.1 This worked before.

    opened by slowcar 3
Releases(4.0.0-beta03)
Owner
Splitwise
Split expenses with friends and family.
Splitwise
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 752 Dec 29, 2022
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 753 Jun 7, 2022
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android. Looking for iOS? Check out cjwirth/RichEditorView Supported Functions Bold

Daichi Furiya 6k Jan 2, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022
[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

icarus-android Maybe the best rich text editor on android platform. Base on Simditor Features Alignment (left/center/right) Bold Blockquote Code Horiz

Dyson Woo 739 Sep 5, 2022
Android Bubble View

BubbleTextView Custom arrow position Custom fillet radius Custom background color Can be placed anywhere Two default style Two default theme Snapshot

null 669 Nov 11, 2022
A Material Android password view that toggles password visibility via an eye icon.

8/17/2016: As of about an hour ago, this library is deprecated! Support for password visibility is now included in the Design Support Library in TextI

Lisa Wray 715 Dec 29, 2022
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

Pavlos-Petros Tournaris 651 Dec 30, 2022
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven <dependency

Evgeny Safronov 600 Nov 29, 2022
Circular timer on Android platform.

CircleTimerView [No Longer Support] Circle timer on Android platform. System Requirement Android v2.2+ TODO Developed by AndroidStudio Usage <com.gith

Abbott 515 Nov 19, 2022
An address-autocompleting text field for Android

android-PlacesAutocompleteTextView An AutocompleteTextView that interacts with the Google Maps Places API to provide location results and caches selec

SeatGeek 283 Dec 28, 2022
library to implement and render emojis For Android

Release Notes SuperNova-Emoji SuperNova-Emoji is a library to implement and render emojis. Minimum SDK Level: 9 (2.3) Contact Java Usage To use defaul

Hani Al-momani 360 Jan 3, 2023
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

kpbird 381 Nov 20, 2022