0

Have an app with few dragable custom font TextView's.

Have created a class TextAnimator which initiates single ValueAnimator and allows to add wanted TextViews which are set as setText(textValue, BufferType.SPANNABLE);.

By adding a new TextView to this TextAnimator, it stores a TextView, arrays of initial/end random colors and Spannable variables for each letter in ArrayLists of simple arrays.

On UpdateListener of ValueAnimator I iterate through all added TextViews, calculate color transition values and change color of each letter like this (according to suggestion here: Change text color of one word in a TextView):

listOfSpannables.get(indexLocation).setSpan(new ForegroundColorSpan(Color.HSVToColor(listOfHSVs.get(indexLocation)[i])), i, i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

This animation makes my app work (dragging, other animations) very sluggish and Im not sure what is causing it. My guess is that maybe using of spannables is inappropriate (maybe I should somehow clear all added spannables before re-adding them on each iteration - how to clear them all at once?).

I could also use HTML to set color of each letter, if that would be faster. Or maybe whole approach is wrong.

Any suggestions, tips on how to improve performance?

Community
  • 1
  • 1
wilkas
  • 1,161
  • 1
  • 12
  • 34
  • calling `new ForegroundColorSpan` inside `AnimatorUpdateListener` which is called multiple times per second makes it sluggish, try creating a custom span similar to `FCS` where you can change the color – pskink Nov 05 '16 at 10:48
  • Not sure what does FCS stands for. Would it be better if I had single global instance of ForeGroundColorSpan and update / use it on each iteration? Or what do you mean by creating a custom span? – wilkas Nov 05 '16 at 11:58
  • FCS = ForegroundColorSpan, see its sources and create your own custom wersion of FCS where you can change the color – pskink Nov 05 '16 at 12:02
  • Now I see that you cant just assign new color to the instance of FCS and need to create it anew anyway. I tried to CTRL click the name of this class, but the code shown is only half a screen and nothing to look at. How do I get the full code? And also would `setSpan()` accept a custom span object? – wilkas Nov 05 '16 at 14:09
  • see http://androidxref.com/ select "android source" from the left and type `ForegroundColorSpan` in "Definition" field – pskink Nov 05 '16 at 14:10
  • Code in this website is the same as shown when CTRL clicking the name of the class and I am to big of a noob to craft something useful from what I see. I guess I'll have to try HTML formatting way to see if it gets any faster. – wilkas Nov 05 '16 at 17:16

0 Answers0