Giter Site home page Giter Site logo

hasankucuk / socialtextview Goto Github PK

View Code? Open in Web Editor NEW
206.0 1.0 29.0 1.13 MB

A simple custom Android TextView that highlights content such as Mention, Hashtag, Phone, Email and Url.

License: Apache License 2.0

Kotlin 100.00%
android-textview android-socialtextview custom-android-textview hashtags phone mention linked

socialtextview's Introduction

SocialTextView

API Android Arsenal Android Weekly

A simple custom Android TextView that highlights content such as Mention, Hashtag, Phone, Email and Url.

Setup

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

dependencies {
   implementation 'com.github.hasankucuk:SocialTextView:1.0.0'
}

Usage

    <com.hasankucuk.socialtextview.SocialTextView
        android:id="@+id/socialTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:text="This project was #developed by @hasankucuk as #opensource. \n
        [email protected] \n
        https://medium.com/@hasann.kucuk \n
        [email protected] \n
        +1 123456789"
        app:emailColor="#FF9E80"
        app:hashtagColor="#82B1FF"
        app:linkType="mention|hashtag|phone|email|url"
        app:mentionColor="#BCBCCF"
        app:normalTextColor="#18181F"
        app:phoneColor="#03A9F4"
        app:urlColor="#8BC34A" />

only for linking of the mention you specify

      val mentions: MutableList<String> = arrayListOf()
        mentions.add("@hasankucuk")
        socialTextView.setLinkedMention(mentions)

only for linking of the hashtag you specify

     val hashtags: MutableList<String> = arrayListOf()
        hashtags.add("#developed")
        socialTextView.setLinkedHashtag(hashtags)

To capture click events

        socialTextView.setLinkClickListener(object : SocialTextView.LinkClickListener {
            override fun onLinkClicked(linkType: LinkedType, matchedText: String) {

                when (linkType) {
                    TEXT -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> TEXT and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                    HASHTAG -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> HASHTAG and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                    MENTION -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> MENTION and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                    URL -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> URL and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                    EMAIL -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> EMAIL and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                    PHONE -> {
                        Toast.makeText(this@MainActivity, "You are clicked type -> PHONE and value ->$matchedText", Toast.LENGTH_SHORT).show()
                    }
                }
            }
        })

Attributes

Attribute Type Summary
app:linkType int hashtag-mention-url-phone-email
app:underLine int true or false
app:normalTextColor int Sets the text color of a normal text color.
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.

License

Copyright 2019 Hasan Küçük

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.

socialtextview's People

Contributors

halilozel1903 avatar hasankucuk 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

socialtextview's Issues

username with dot and hyphen not recognized.

Everything is working until i entered a username with dot and hyphen.

@user.pretty - not working
@user-pretty - not working
@user_pretty - working (but only @user turned to green in ui)

here is my regex. "(@[a-zA-Z0-9._-]{2,50}\b)"

i tried debugging the list here is the result:
[@user.pretty, @user-pretty, @user_pretty]

in ui here is result:
image

every mentions should be in color green..

Can you help me with this?

Error In Java Implementation

AAPT: warn: removing resource grand.memdubai:string/com_facebook_loginview_logged_in_using_facebook_f1gender without required default value.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8672: error: resource attr/normalTextColor (aka grand.memdubai:attr/normalTextColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8673: error: resource attr/underLine (aka grand.memdubai:attr/underLine) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8674: error: resource attr/hashtagColor (aka grand.memdubai:attr/hashtagColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8675: error: resource attr/mentionColor (aka grand.memdubai:attr/mentionColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8676: error: resource attr/phoneColor (aka grand.memdubai:attr/phoneColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8677: error: resource attr/urlColor (aka grand.memdubai:attr/urlColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8678: error: resource attr/emailColor (aka grand.memdubai:attr/emailColor) not found.
/Users/macmini/Desktop/android/MemDubai/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:8679: error: resource attr/selectedColor (aka grand.memdubai:attr/selectedColor) not found.
error: failed linking references.

Supported Languages

I tried this lib in others languages ( in my case Arabic ) but doesn't work

Need help

Can possible to make different text color and Underline color. Please ref image
underline_color

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.