Hello,
I started a Swift Maniaplanet style formatter. Inputs a string, returns a Spanned for style usage on labels and more. It can also be used to strip styles, colors and links.
I will use the framework myself in the Maniaplanet Toolkit in later versions for faster parsing of styles. Currently it's using the Html.fromHtml functions, but that's slow and not efficient.
(Requires Android API 9 and later)
Installation
You can use gradle to compile it, it's in the Maven Central repository.
Code: Select all
dependencies {
compile 'net.tvalk.mpformatter:mpformatter:1.3.6'
}
Usage
To use the formatter you have to init the MPFormatter class with the input string. After it you have to parse all the dollar codes first, also if you want to strip it you have to parse it first. On the return of the parse() function you can strip url, color or fontstyle's seperatly, and not by default. Then you can get the Spanned or String also on the return of parse().
Sample, parse all the style codes on the nickname:
Code: Select all
String nickname = "$F80Test$06fSmurf$z $l[http://goo.gl/y4M9VK][App]$l";
Spanned styledNickname = new MPFormatter(nickname).parse().getSpannable();
Sample 2, parse only links on the nickname:
Code: Select all
String nickname = "$F80Test$06fSmurf$z $l[http://goo.gl/y4M9VK][App]$l";
Spanned styledNickname = new MPFormatter(nickname).parse().stripColors().stripStyles().getSpannable();
Sample 3, remove all the styles and get a String:
Code: Select all
String nickname = "$F80Test$06fSmurf$z $l[http://goo.gl/y4M9VK][App]$l";
String plainNickname = new MPFormatter(nickname).parse().getString();
Github
Github: https://github.com/tomvlk/MPFormatter_android
Toffe