ManiaPlanet style Java (Android) parser

Moderators: Xymph, NADEO

Post Reply
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

ManiaPlanet style Java (Android) parser

Post 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
Last edited by toffe on 25 Feb 2017, 15:54, edited 6 times in total.
User avatar
adamkooo2
Posts: 1371
Joined: 13 Jun 2014, 08:43
Location: Slovakia
Contact:

Re: ManiaPlanet style Java (Android) parser

Post by adamkooo2 »

And where is the apk file for instlation?
/\rkady
Image
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Java (Android) parser

Post 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
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Java (Android) parser

Post 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
Last edited by toffe on 12 May 2015, 09:13, edited 1 time in total.
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Java (Android) parser

Post 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
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Java (Android) parser

Post by toffe »

Update released: 1.3.6:
- Fixing a bug which causes a Nullpointer in specific malformed inputs.
Live on Maven Central.
Post Reply

Return to “General Tools”

Who is online

Users browsing this forum: No registered users and 1 guest