Page 1 of 1

ManiaPlanet style Java (Android) parser

Posted: 04 Mar 2015, 18:34
by toffe
Image

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'
    }
If you want to stay updated, replace the '1.3.6' with '1.+'. But can break things when there is a new version.

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();
Results in: "TestSmurf [App]"

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();
Results in: "TestSmurf [App]"

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();
Results in: "TestSmurf [App]"

Github
Github: https://github.com/tomvlk/MPFormatter_android


Toffe

Re: ManiaPlanet style Java (Android) parser

Posted: 04 Mar 2015, 19:02
by adamkooo2
And where is the apk file for instlation?

Re: ManiaPlanet style Java (Android) parser

Posted: 04 Mar 2015, 19:04
by toffe
adamkooo2 wrote:And where is the apk file for instlation?
It's not an app, it's an library that developers can use to make an app.

Toffe

Re: ManiaPlanet style Java (Android) parser

Posted: 05 Mar 2015, 12:49
by toffe
Updated topic,
Now usable with Gradle and jCentral repository:

Code: Select all

    dependencies {
        compile 'net.tvalk.mpformatter:mpformatter:1.0'
    }
:thumbsup:

EDIT: We are on Maven Central! version 1.3.3

Toffe

Re: ManiaPlanet style Java (Android) parser

Posted: 23 Mar 2015, 12:40
by toffe
New version (1.1) is released on JCentral.
It includes a fix for $h links. And will now not parse telephone numbers as a link (Linkify).

EDIT: Use 1.3.3 on maven central!

Toffe

Re: ManiaPlanet style Java (Android) parser

Posted: 25 Feb 2017, 15:55
by toffe
Update released: 1.3.6:
- Fixing a bug which causes a Nullpointer in specific malformed inputs.
Live on Maven Central.