Skip to content

HashGirl is a simple library to make a linkable string for Android.

License

Notifications You must be signed in to change notification settings

skyfe79/HashGirl

Repository files navigation

#HashGirl

Platform API License

HashGirl is a simple library to make a linkable string for Android. HashGirl can make hash a string which contains spaces. You can set the regular expression to grab a link and also you can set the character to indicate the end of the link.

HashGirl uses method chain to make linkable string like below:

String text = "Hello, I'm #Super Hash Girl^ in the World. You can hash #every^thing what you want. #I will hash you^";

TextView afterTextView = (TextView)findViewById(R.id.afterTextView);
HashGirl
        .with(text)
        .grab("(#((\\w+ *)*)\\^)", "^", "#")
        .underline()
        .color(Color.BLUE)
        .bgcolor(Color.WHITE)
        .click(new OnClickHashListener() {
            @Override
            public void onClickHash(String hash) {
                Toast.makeText(MainActivity.this, hash, Toast.LENGTH_SHORT).show();
            }
        })
        .into(afterTextView);

Setup Gradle

dependencies {
    ...
    compile 'kr.pe.burt.android.lib:hashgirl:1.0.3'
}

HashGirl's methods

  • with(String text)
    • is static method to set the text data.
    • You should start HashGirl from this 'with' method.
  • grab(String regExp)
  • grab(String regExp, String postfixToRemove = "", String prefixToRemove = "")
    • set regular expression to grab linkable string
    • set postfixToRemove or prefixToRemove to remove indicator of the start or end of the linked string.
  • underline()
    • to underline linked string
  • strike()
    • to strike line through the string
  • color(int color)
    • set foreground color of the linked string
  • bgcolor(int color)
    • set background color of the linked string
  • alpha(int alpha)
    • set alpha of the linked string
  • click(OnClickHashListener onClickHashListener)
    • set a handler to process the click action of the linked string
  • into(TextView textVieW)
    • set a TextView to set the result.

Examples

String text = "Hello, I'm #Super Hash Girl^ in the World. You can hash #every^thing what you want. #I will hash you^";

TextView before = (TextView)findViewById(R.id.before);
before.setText(text);

TextView after1 = (TextView)findViewById(R.id.after1);
HashGirl
    .with(text)
    .grab("(#((\\w+ *)*)\\^)", "^")
    .click(new OnClickHashListener() {
        @Override
        public void onClickHash(String hash) {
            Toast.makeText(MainActivity.this, hash, Toast.LENGTH_SHORT).show();
        }
    })
    .into(after1);

TextView after2 = (TextView)findViewById(R.id.after2);
HashGirl
        .with(text)
        .grab("(#((\\w+ *)*)\\^)", "^", "#")
        .underline()
        .color(Color.BLUE)
        .bgcolor(Color.WHITE)
        .click(new OnClickHashListener() {
            @Override
            public void onClickHash(String hash) {
                Toast.makeText(MainActivity.this, hash, Toast.LENGTH_SHORT).show();
            }
        })
        .into(after2);

MIT License

The MIT License (MIT)

Copyright (c) 2016 Sungcheol Kim, https://github.com/skyfe79/HashGirl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

HashGirl is a simple library to make a linkable string for Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages