This is a library designed for highlighting hashtags ("#example") and catching click on them.

Overview

HashTagHelper

This is a library designed for highlighting hashtags ("#example") and catching click on them.

Android_weekly Android Arsenal

#Usage Add this snippet to your project build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
}

Add this snippet to your module build.gradle file:

dependencies {
    compile 'com.github.danylovolokh:hashtag-helper:1.1.0'
}

Getting click events and highligthing hashtags.

private HashTagHelper mTextHashTagHelper;

private TextView mHashTagText;

@Override
protected void onCreate(Bundle savedInstanceState) {

  mHashTagText = (TextView) findViewById(R.id.text);
  mTextHashTagHelper = HashTagHelper.Creator.create(getResources().getColor(R.color.colorPrimary), new HashTagHelper.OnHashTagClickListener() {
    @Override
    public void onHashTagClicked(String hashTag) {
        
    }
  });
        
  // pass a TextView or any descendant of it (incliding EditText) here.
  // Hash tags that are in the text will be hightlighed with a color passed to HasTagHelper
  mTextHashTagHelper.handle(mHashTagText);
}

Highlighting without click events. Just set "null" instead of HashTagHelper.OnHashTagClickListener;

mTextHashTagHelper = HashTagHelper.Creator.create(getResources().getColor(R.color.colorPrimary), null);
mTextHashTagHelper.handle(mHashTagText);

By default only digits and letters are valid symbols for hashtag To add support of custom symbols like '_' or '-' you need to specify another parameter when creating HashTagHelper

char[] additionalSymbols = new char[]{
                '_',
                '$'
        };
// If you set additional symbols not only letters and digits will be a valid symbols for hashtag
// Example: "hash_tag_with_underscore_and$dolar$sign$is$also$valid_hashtag"
mTextHashTagHelper = HashTagHelper.Creator.create(getResources().getColor(R.color.colorPrimary), null, additionalSymbols);
mTextHashTagHelper.handle(mHashTagText);

To get all hashtags from text.

// get all hashtags with "#", example: "#blueeyes"
List<String> allHashTags = mTextHashTagHelper.getAllHashTags(true);

// get all hashtags without "#", example: "blueeyes"
List<String> allHashTags = mTextHashTagHelper.getAllHashTags(false);

#Demo alt tag alt tag

License

Copyright 2015 Danylo Volokh

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.

Comments
  • #first_second is not working

    #first_second is not working

    Hello Danylo, Thank you for great effort. I face an issue that if I wrote hashtag of 2 words like this" #first_second, first word only is highlighted . please advise.

    Thank you, Hisham

    opened by hishambakr 5
  • App crashing in the RecyclerView Adapter

    App crashing in the RecyclerView Adapter

    Hi Danylo!

    I am showing hash tags in the RecyclerView items and onBindViewHolder method is simple and looks like this:

    @Override
        public void onBindViewHolder(TaskViewHolder holder, int position) {
    
            holder.mTaskTitleTv.setText(mList.get(position).getTitle());
    
            // pass a TextView or any descendant of it (incliding EditText) here.
            // Hash tags that are in the text will be hightlighed with a color passed to HasTagHelper
            mTextHashTagHelper.handle(holder.mTaskTitleTv);
        }
    

    The app crashes when i reach the bottom of the List and scroll up again.

    Complete crash report is:

    java.lang.IndexOutOfBoundsException: setSpan (0 ... 9) ends beyond length 5
                                                                                         at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016)
                                                                                         at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592)
                                                                                         at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
                                                                                         at com.volokh.danylo.hashtaghelper.HashTagHelper.setColorForHashTagToTheEnd(HashTagHelper.java:155)
                                                                                         at com.volokh.danylo.hashtaghelper.HashTagHelper.setColorsToAllHashTags(HashTagHelper.java:115)
                                                                                         at com.volokh.danylo.hashtaghelper.HashTagHelper.eraseAndColorizeAllText(HashTagHelper.java:99)
                                                                                         at com.volokh.danylo.hashtaghelper.HashTagHelper.access$100(HashTagHelper.java:27)
                                                                                         at com.volokh.danylo.hashtaghelper.HashTagHelper$1.onTextChanged(HashTagHelper.java:56)
                                                                                         at android.widget.TextView.sendOnTextChanged(TextView.java:7408)
                                                                                         at android.widget.TextView.setText(TextView.java:3816)
                                                                                         at android.widget.TextView.setText(TextView.java:3671)
                                                                                         at android.widget.TextView.setText(TextView.java:3646)
                                                                                         at com.shajeelafzal.quicktasks_app.adapter.TasksAdapter.onBindViewHolder(TasksAdapter.java:72)
                                                                                         at com.shajeelafzal.quicktasks_app.adapter.TasksAdapter.onBindViewHolder(TasksAdapter.java:25)
                                                                                         at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
                                                                                         at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
                                                                                         at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
                                                                                         at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
                                                                                         at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
                                                                                         at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
                                                                                         at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
                                                                                         at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1161)
                                                                                         at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1018)
                                                                                         at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3807)
                                                                                         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
                                                                                         at android.view.Choreographer.doCallbacks(Choreographer.java:574)
                                                                                         at android.view.Choreographer.doFrame(Choreographer.java:543)
                                                                                         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
                                                                                         at android.os.Handler.handleCallback(Handler.java:733)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:136)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                                         at dalvik.system.NativeStart.main(Native Method)
    01-05 01:31:44.324 14479-14550/com.shajeelafzal.quicktasks_app I/Fabric: Crashlytics report upload complete: 568AD6AD00EE-0001-388F-1CE3EAB0099E.cls
    
    
    opened by Shajeel-Afzal 3
  • How to have the same functionality with @ mentions

    How to have the same functionality with @ mentions

    I am thinking about using this library in my app. But I also require the library to work with @ mentions . Please tell me where to make changes to achieve functionalities with the @ mentions. Please reply.

    opened by mik-dass 2
  • onHashTagClicked not working correctly

    onHashTagClicked not working correctly

    I am showing Hash Tags in a TextView in the RecyclerAdaper.

    Problem is that the Click Listener on the adapter Item is not working properly when i am using HashTagHelper library. If the user clicks on TextView's text that is not a Hash Tag then the onClick of the Item is not being called.

    Inside onBindView method i am showing the Hash Tag on the TextView:

    @Override
        public void onBindViewHolder(TaskViewHolder holder, int position) {
            ...
            holder.mTaskTitleTv.setText(mTasksList.get(position).getTitle());
            holder.mTextHashTagHelper.handle(holder.mTaskTitleTv);
        }
    

    And ViewHolder looks like this:

    class TaskViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
    
            ...
            public TaskViewHolder(View itemView) {
                super(itemView);
                findViews(itemView);
                itemView.setOnClickListener(this);
                mTextHashTagHelper = HashTagHelper.Creator.create(mContext.getResources().getColor(R.color.primary), new HashTagHelper.OnHashTagClickListener() {
                    @Override
                    public void onHashTagClicked(String hashTag) {
                        mContext.startActivity(HashTagTaskActivity.createLauncherIntent(mContext, hashTag));
                    }
                });
            }
    
           @Override
            public void onClick(View v) {
                mListner.onItemClick(v, getLayoutPosition());
            }
    }
    
    opened by Shajeel-Afzal 2
  • Failed to resolve: com.github.danylo2006:hashtag-helper:1.1.0

    Failed to resolve: com.github.danylo2006:hashtag-helper:1.1.0

    Hi

    I am trying to update the version of the library and i am getting the error: Failed to resolve: com.github.danylo2006:hashtag-helper:1.1.0, can you please recheck and correct?

    Thanks.

    opened by Shajeel-Afzal 2
  • Application crashing on onlong press

    Application crashing on onlong press

    hello @danylovolokh, whenever I long press on any hashtag, my application is getting crashed, with the error Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference

    opened by akshay2211 1
  • Problem when clicking outside hashtags

    Problem when clicking outside hashtags

    I think you should take a look at https://stackoverflow.com/questions/16792963/android-clickablespan-intercepts-the-click-event

    When I touch outside a link on a EditText, LinkMovementMethod fires the onHashtagClicked.

    opened by ciceromsjr 0
  • Different ClickListener for plain text and HashTagText

    Different ClickListener for plain text and HashTagText

    I have a RecyclerView and I need handle different click listener in row: one for row view and one for HashTag text.

    I noticed that if I put an Hashtag click listener, row click listener is not consumed (if clicked on plain text).

    So, the first fix is set row click listener to TextView: now, if I click on HashTag both listener are consumed (hashtag click listener before than view On click listener).

    In order to avoid this behavior I implemented this listener:

    
    public class FooClickListener implements View.OnClickListener,HashTagHelper.OnHashTagClickListener {
        FooAdapter.FooListener listener;
        FooModel model;
        private boolean consumedHashTagClick = false;
    
        public FooClickListener(FooAdapter.FooListener listener, FooModel model) {
            this.listener = listener;
            this.model = model;
        }
    
        @Override
        public void onClick(View view) {
            if(!consumedHashTagClick) listener.onRowClick(model.text);
    
            consumedHashTagClick = false;
        }
    
        @Override
        public void onHashTagClicked(String hashTag) {
            consumedHashTagClick = true;
            listener.onHashtagClick(hashTag);
        }
    }
    
    

    Now I can be sure of what listener will be consumed.

    opened by chemickypes 0
Owner
Danylo Volokh
Hi, Welcome to my github :)
Danylo Volokh
An Android TagView Widget. You can edit the tag's style, and set listener of selecting or deleting tag.

Android-Cloud-TagView-Plus ###Introduction An Android Cloud Tag Widget. You can edit the tag's style, and set listener of selecting or deleting tag. U

Kaede Akatsuki 663 Nov 19, 2022
An Android TagView Widget. You can edit the tag's style, and set listener of selecting or deleting tag.

Android-Cloud-TagView-Plus ###Introduction An Android Cloud Tag Widget. You can edit the tag's style, and set listener of selecting or deleting tag. U

Kaede Akatsuki 663 Nov 19, 2022
AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URLs (http://), Phone and Email automatically detecting and ability to handle clicks.

AutoLinkTextView Deprecated Please use the new version of AutoLinkTextView AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URL

Arman 1.1k Nov 23, 2022
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

null 2 Jan 9, 2022
H4SGTAG MANAGER - CRUD that saves hashtags for social media

H4SGTAG_MANAGER CRUD that saves hashtags for social media made using android stu

Aldo Malacara 0 Jan 13, 2022
Lightweight android library for highlighting sections of a textview, with optional callbacks.

Linker Lightweight android library for highlighting Strings inside of a textview (ignoring case), with optional callbacks. Language: Java MinSDK: 17 J

Josh Gainey 35 Apr 30, 2022
Library for testing highlighting in plugins for IDEA in KPHP format.

intellij-kphp-highlighting-test-adapter Library for testing highlighting in plugins for IDEA in KPHP format. Installation Kotlin DSL plugins { id(

Makhnev Petr 2 Jul 23, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
KodeEditor - A simple code editor with syntax highlighting and pinch to zoom

KodeEditor - A simple code editor with syntax highlighting and pinch to zoom

Markus Ressel 65 Oct 28, 2022
Theme for VSCode and JetBrains IDEs, based on morhetz/gruvbox but with a plainer color palette for syntax highlighting.

gruvbox-plain Theme for VSCode and JetBrains IDEs, based on morhetz/gruvbox but with a plainer color palette for syntax highlighting. Syntax Colors gr

null 2 Dec 28, 2022
Display code with syntax highlighting :sparkles: in native way.

CodeView (Android) CodeView helps to show code content with syntax highlighting in native way. Description CodeView contains 3 core parts to implement

Kirill Biakov 827 Dec 22, 2022
Display code with syntax highlighting :sparkles: in native way.

CodeView (Android) CodeView helps to show code content with syntax highlighting in native way. Description CodeView contains 3 core parts to implement

Kirill Biakov 827 Dec 22, 2022
Awesome Kid's Drawing App. It has a click and draws feature.

CanvaKids Overview It's a kid's drawing app which is build for android users. It is built in Kotlin with some very good practices involved.

null 9 Oct 30, 2021
NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect.

NTabLayout Brief NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect. This tab bar's effe

XellossRyan 1 Oct 22, 2021
A random meme generator and can be shared , each click will show yo a different meme.

AlphaMemes(random meme sharing app) A android app which display new meme on each click. used API which is dynamic/ Glide library used / Recycler view

SUMIT KUMAR 4 Jan 18, 2022
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

Muthuramakrishnan Viswanathan 1.2k Dec 30, 2022
learn to click in a good rhythm

pvp instruktarz Build plugin jar ./gradlew jar Running To run this plugin you must include Kotlin 1.4.32+ to the server classpath somehow. Example two

makin 8 Aug 31, 2022
Explode compose elements on click! Just add explodeOnClick() modifier!

compose-explode Explode compose elements on click! Just add explodeOnClick() modifier! Inspired from ExplosionField Getting started Go to library/expl

Nikhil Chaudhari 33 Jan 8, 2023
ClickMachine Fabric - Click Machine for minecraft

Minecraft mod for Fabric Adds one block to the game: Auto Clicker. This autoclic

null 0 Jan 10, 2022