Closed muhammad-naderi closed 5 years ago
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?
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,
what I think would be great is for the token to get re-sized on-demand (while it's bigger than the available space.
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.
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.
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.
I take everything back, this might be very simple.
can you take a look at https://github.com/splitwise/TokenAutoComplete/tree/width-experiment and let me know if it works for you?
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
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;
}
}
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 :)
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.
No problem, and again thanks for your nice work.
back to the duplication bug, can I have an ETA on it, please?
Unfortunately, It's not something I can see a simple fix to, so I'm not sure when I'll get it done.
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?
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!
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
same goes with the left one here