Code Monkey home page Code Monkey logo

social-text-view's Introduction

Social Text View

A custom Android TextView that highlights social media lingo (#hashtags, @mentions, phone, emails, and urls).

Core features of this library:

  • Highlight social media lingo in text
  • Clickable social media lingo in text

How to use it...

In your project level build.gradle :

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
} 

In your app level build.gradle:

dependencies {
    compile 'com.github.tylersuehr7:social-text-view:1.0.0'
}  

Using the Social Text View

The basic usage of this library is to highlight, and make clickable, whenever social media lingo appears in text. To achieve this functionality, you'll need to use the SocialTextView.

This library also includes an object, AccurateMovementMethod, which improves the touch on the Android LinkMovementMethod, so that clicking links are much more accurate.

Using in an XML layout

SocialTextView can be used in any ViewGroup and supports all available width and height attributes that TextView does. Simple usage is shown here:

<com.tylersuehr.socialtextview.SocialTextView
        android:id="@+id/social_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@tylersuehr7, Android is awesome! #android"
        app:hashtagColor="#757575"
        app:mentionColor="#757575"
        app:linkModes="hashtag|mention"/>

Here is a table of all the XML attributes available for this view:

Attribute Type Summary
app:hashtagColor color Sets the text color of a hashtag link in the text.
app:mentionColor color Sets the text color of a mention link in the text.
app:phoneColor color Sets the text color of a phone number link in the text.
app:emailColor color Sets the text color of an email link in the text.
app:urlColor color Sets the text color of a web url link in the text.
app:selectedColor color Sets the text color of a selected link in the text.
app:linkModes int Sets flags for which types of links the text should show. i.e: "hashtag

Using in Java code

SocialTextView can be programmatically added into any ViewGroup. Simple usage in an Activity is shown here:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // Text to display in the view
    String example = "Really neat stuff @tylersuehr7! #Android #GitHub";
    
    // Create an instance of the view and set the text above
    SocialTextView textView = new SocialTextView(this);
    textView.setLinkText(example);
    // set any other properties you want social text view
    
    setContentView(textView);
}

Here is a table of all the accessible attributes available for this view:

Method Summary
setLinkText(String) Checks the given text for any available links and displays it.
appendLinkText(String) Checks the given text for any available links and appends it.
setOnLinkClickListener(OnLinkClickListener) Sets a listener for when available links are clicked.

social-text-view's People

Contributors

tylersuehr7 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

Watchers

 avatar  avatar  avatar  avatar  avatar

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.