Skip to content

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

Description

@muhammad-naderi

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

Activity

  1. mgod commented on Nov 9, 2015

    @mgod
    Contributor

    The duplication is definitely a bug. To avoid the extra long token, you just need to return a view from getViewForObject that isn't wider than the available space. Maybe add a maxWidth an appropriate details in your layout?

  2. muhammad-naderi commented on Nov 10, 2015

    @muhammad-naderi
    Author

    Actually right now I am doing such a thing, but this results in the tokens gets small all the time, frankly it's not that beautiful,
    screenshot_2015-11-10-11-30-47

    what I think would be great is for the token to get re-sized on-demand (while it's bigger than the available space.

  3. mgod commented on Nov 10, 2015

    @mgod
    Contributor

    I don't think doing a lot of work on the layout is going to do a much better job than just picking a reasonable token size maximum. If we ware going to do fully justified tokens, we'd also need to be able to expand them as well. If we're not, I'm not sure the result would be much better than if you set you max width to about 1/3 of the available space of the field.

  4. mgod commented on Nov 10, 2015

    @mgod
    Contributor

    More helpful note is that you can probably do this yourself if you want. In your subclass of TokenCompleteTextView you can use Layout.getDesiredWidth on getText and mod that by maxTextWidth. This will give you the amount of space left in the current line. If you subtract that from maxTextWidth, that's how much space your token can take and fit on the last line. You may need to account for the space characters between tokens and the prefix if you have one.

  5. mgod commented on Nov 10, 2015

    @mgod
    Contributor

    I could see adding a call that would give the amount of space left for tokens on the current line, which would make custom token sizing relatively straightforward. I just don't think adding a bunch of custom layout finagling code to an already tricky library is going to give good results.

  6. mgod commented on Nov 10, 2015

    @mgod
    Contributor

    I take everything back, this might be very simple.

  7. mgod commented on Nov 10, 2015

    @mgod
    Contributor

    can you take a look at https://github.com/splitwise/TokenAutoComplete/tree/width-experiment and let me know if it works for you?

  8. muhammad-naderi commented on Nov 14, 2015

    @muhammad-naderi
    Author

    The only file that has been changed is link to File
    right?
    if yes, then No, the problem still exists and the tokens get duplicated

  9. mgod commented on Nov 14, 2015

    @mgod
    Contributor

    I'm terribly sorry, I failed to actually push the changes. You should see more changed now. This doesn't fix the duplicate issue, but does let you do custom handling for the width of tokens by overriding maxTokenWidth in your TokenCompleteTextView. Something like:

    protected float maxTokenWidth() {
        float left = getTextLineWidthLeft();
        if (left < maxTextWidth() / 4) {
            return maxTextWidth();
        } else {
            return left;
        }
    }
  10. muhammad-naderi commented on Nov 14, 2015

    @muhammad-naderi
    Author

    to be completely honest I do not get how this can help me !
    my problem is that I generate the TAC in run time, and also change the width while user focuses on the TAC, (in pictures you may see that first, two TACs have weight of 0.5, each, then when user focuses on each one, it gains weight from the other one and the weight distribution becomes 0.8 and 0.2 , and vice versa.

    so if you help me out a little more, I can check what ever you want :)

  11. mgod commented on Nov 16, 2015

    @mgod
    Contributor

    Ah, I see. Sorry to misunderstand. I think live resizing and auto layout of the tokens on field resize is possible, and the code I've added in that branch is the start of it. I don't think this is something I'll be able to get in a comfortable place to add to the main library.

  12. muhammad-naderi commented on Nov 17, 2015

    @muhammad-naderi
    Author

    No problem, and again thanks for your nice work.

    back to the duplication bug, can I have an ETA on it, please?

  13. mgod commented on Nov 17, 2015

    @mgod
    Contributor

    Unfortunately, It's not something I can see a simple fix to, so I'm not sure when I'll get it done.

  14. mgod commented on Mar 9, 2019

    @mgod
    Contributor

    Version 3.0.0 cleaned up a lot of the token handling code. Can you try it and let me know if you're still seeing the duplication issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions