GithubHelp home page GithubHelp logo

polok / taggerstring Goto Github PK

View Code? Open in Web Editor NEW
240.0 10.0 16.0 383 KB

TaggerString is very light library which allows to build dynamic string resource in much more readable way.

Java 100.00%

taggerstring's Introduction

TaggerString

TaggerString is very light library which allows to build dynamic string resource in much more readable way.

License Android Arsenal

I guess that every Android developer has seen or added similar piece of code in string.xml file:

<string name="user_description_string">I am %s and I am %d years old</string>`

Some probably discovered that above code is a little bit not readable and extended such declarations to something like this:

<string name="user_description_string">I am $1%s and I am $2%d years old</string>

And in source code:

String userDesc = String.format(resources.getString(R.string.user_description_string), "John Kowalski", 27);

So far so good but maybe this could be a little bit more readable ? Yes, it can be (at least in my opinion) - TaggerString.

In source code above example will look like :

  TaggerString taggerString = TaggerString.from(getString(R.string.user_description_string));
  taggerString.with("user_name", "John Kowalski");
  taggerString.with("user_age", 27);
  tvExampleOne.setText(taggerString.format());

And our string resource looks

<string name="example_one">My name is {user_name} and I am a {developer_role}</string>

If you want to use bold (TaggerStyleType.BOLD), italic (TaggerStyleType.ITALIC) or underscore (TaggerStyleType.UNDERLINE), please go ahead:

TaggerString taggerString = TaggerString.from(getString(R.string.user_description_string));
taggerString.with("user_name", "John Kowalski", TaggerStyleType.BOLD);
taggerString.with("user_age", 27, TaggerStyleType.UNDERLINE);
tvExampleOne.setText(taggerString.formatCustom());

Please note that in this case method formatCustom() returns Spanned object.

Multiple formatting (since version 1.1.0)

If you want to apply few tags for one string go ahead and do it:

taggerString.with("developer_role", "Android Software Developer", TaggerStyleType.UNDERLINE, TaggerStyleType.BOLD, TaggerStyleType.ITALIC);

Usage

If you are using gradle please add below:

dependencies {
    compile 'com.github.polok.taggerstring:library:1.0.0'
}

Since version 1.1.0 the artefactId was changed from library to taggerstring:

dependencies {
    compile 'com.github.polok.taggerstring:taggerstring:1.1.0'
}

Developed By

Marcin Polak - mpolak87(at).gmail.com

License

Copyright 2015 Marcin Polak

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

taggerstring's People

Contributors

polok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taggerstring's Issues

Missing bit in README

In the README you introduce this example:

  TaggerString taggerString = TaggerString.from(getString(R.string.user_description_string));
  taggerString.with("user_name", "John Kowalski");
  taggerString.with("user_age", 27);

but you don't show how the string resource would look like in order to make this work. I assume it would be something like

<string name="user_description_string">I am {user_name} and I am {user_age} years old</string>

but you should probably be a bit more explicit.

Use CharSequence instead of String

It would be great if TaggerString.from(String) took a CharSequence instead of a String and thus could be used with Resources.getText(int).

Gradle link broken

could you confirm this please?
I've tried:

compile 'com.github.polok.taggerstring:taggerstring:1.1.0'
compile 'com.github.polok.taggerstring:taggerstring:1.0.0'
compile 'com.github.polok.taggerstring:1.0.0'
compile 'com.github.polok.taggerstring:library:1.1.0'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.