• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    Java
  • Created about 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

PinCodePicker

PinCodePicker was created for Android platform as a view which allows to take passwords/codes or some other sensitive data from end user in easy way, so developers can focus on the core functionalities of their application
Java
130
star
2

ClickNumberPicker

Custom view to pick up a value from a given range using click button or swiping.
Java
99
star
3

RouteDrawer

RouteDrawer is an Android utils library which
Java
97
star
4

UICheckbox.Swift

UICheckbox is simple as hell and lightweight class to add 'checkbox' UI component in iOS application
Swift
69
star
5

localify

Localify is a small Andorid library which allows to load a content from files which are stored under assets and/or raw directory. It can be useful when you have to load some init data or during tests to load mock data.
Java
68
star
6

FlipView

Android FlipView UI library
Java
26
star
7

android-architecture

Repository demonstrates three different approaches to the implementation of the Android applications.
Java
6
star
8

MediaPlayerAndroidDemo

Simple custom MediaPlayer
Java
3
star
9

polok.github.com

My blog
HTML
2
star
10

design-patterns-with-swift

📖 Design Patterns implemented in Swift 5.+
Swift
2
star
11

Android-Gson-JsonDeserializer

Custom Json Deserializer for Gson
Shell
1
star
12

docker-jenkins-ios

Sample project to play with Docker, Jenkins and iOS ;)
Swift
1
star
13

FirebaseGradleChat

Simple integration with Firebase service. App is managed by Gradle. As IDE - Android Studio
Java
1
star
14

oversnackbar

OverSnackBar allows to show a popup from top of the screen with some message. It was based on Google's Snackbar implementation. Project is under development!
Java
1
star
15

XcodePolakTheme

Custom Xcode theme based on AppCode's Darcula theme
1
star