robinhood / ticker

An Android text view with scrolling text change animation
https://medium.com/robinhood-engineering/hello-ticker-20eaf6e51689
Apache License 2.0
4.38k stars 462 forks source link

Provide convenience methods for extending character lists #91

Closed Steppschuh closed 6 years ago

Steppschuh commented 6 years ago

Just getting started with this library, I don't understand why it animates chars that are not part of the currently set character list. IMHO, these chars should not be animated at all.

For my use case, I'm displaying a percentage value (e.g. 81.03%). However, the % char is not included in the default lists provided by the TickerUtils, thus the ticker animates it on every value change.

The straight forward fix for that was adding the % char to a new character list and using it for the ticker:

protected void initializeLayout(View contentView) {
    valueTickerView = contentView.findViewById(R.id.valueTickerView);
    valueTickerView.setCharacterList(createTickerCharacterList());
}

private static char[] createTickerCharacterList() {
    char[] newCharacters = new char[]{'%', '€'};
    return extendCharacterList(TickerUtils.getDefaultNumberList(), newCharacters);
}

private static char[] extendCharacterList(char[] existingCharacters, char[] newCharacters) {
    char[] extendedCharacters = new char[existingCharacters.length + newCharacters.length];
    System.arraycopy(existingCharacters, 0, extendedCharacters, 0, existingCharacters.length);
    System.arraycopy(newCharacters, 0, extendedCharacters, existingCharacters.length, newCharacters.length);
    return extendedCharacters;
}

I think something like extendCharacterList would be nice to have as part of the TickerUtils. Note that the implementation above doesn't check for duplicate characters.

jinatonic commented 6 years ago

sorry for the late reply. this is a great point, and it's a pain point for many people (including us at Robinhood where sometimes the . or $ animates unexpectedly). Ticker 2.0 release will be happening in the next week or two, and it will have substantial changes on how characters animate that will fix the issues you are seeing.