├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── res
├── drawable-hdpi
│ ├── android.png
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values-sw600dp
│ └── dimens.xml
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── menu
│ └── main.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── layout
│ ├── hashtag_listview.xml
│ ├── activity_main.xml
│ ├── activity_example.xml
│ └── tagviewrow.xml
├── Screenshot_2014-07-23-20-41-05.png
├── Screenshot_2014-07-23-20-41-13.png
├── Screenshot_2014-07-23-20-41-27.png
├── Screenshot_2014-07-23-22-32-27.png
├── Screenshot_2014-07-23-23-06-04.png
├── .settings
└── org.eclipse.jdt.core.prefs
├── src
└── com
│ └── hashtagandroid
│ ├── interfaces
│ └── TagClick.java
│ ├── ListViewHashTag.java
│ ├── MainActivity.java
│ ├── adaptors
│ └── HashTagAdaptor.java
│ ├── TagSelectingTextview.java
│ └── HashTagActivity.java
├── .gitignore
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
├── LICENSE
├── AndroidManifest.xml
└── README.md
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/res/drawable-hdpi/android.png
--------------------------------------------------------------------------------
/Screenshot_2014-07-23-20-41-05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/Screenshot_2014-07-23-20-41-05.png
--------------------------------------------------------------------------------
/Screenshot_2014-07-23-20-41-13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/Screenshot_2014-07-23-20-41-13.png
--------------------------------------------------------------------------------
/Screenshot_2014-07-23-20-41-27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/Screenshot_2014-07-23-20-41-27.png
--------------------------------------------------------------------------------
/Screenshot_2014-07-23-22-32-27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/Screenshot_2014-07-23-22-32-27.png
--------------------------------------------------------------------------------
/Screenshot_2014-07-23-23-06-04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/Screenshot_2014-07-23-23-06-04.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameshvoltella/Hash-Tags-Android/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/src/com/hashtagandroid/interfaces/TagClick.java:
--------------------------------------------------------------------------------
1 | /*
2 | * interface class which passes the hash tag click to the main page
3 | *
4 | * @auther Ramesh M Nair
5 | * */
6 | package com.hashtagandroid.interfaces;
7 |
8 | public interface TagClick {
9 |
10 | public void clickedTag(CharSequence tag);
11 | }
12 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/hashtag_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/src/com/hashtagandroid/ListViewHashTag.java:
--------------------------------------------------------------------------------
1 | package com.hashtagandroid;
2 |
3 | import com.hashtagandroid.adaptors.HashTagAdaptor;
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 | import android.widget.ListView;
8 |
9 | public class ListViewHashTag extends Activity {
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | // TODO Auto-generated method stub
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.hashtag_listview);
15 |
16 | ListView lv = (ListView) findViewById(R.id.list);
17 | lv.setAdapter(new HashTagAdaptor(ListViewHashTag.this));
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HashTagAndroid
5 | Settings
6 | Hello world!
7 | A hashtag is simply a way for people to search for tweets that have a common topic. For example, if you search on #Gravity (or #gravity or #GraVItY, because it\'s not case-sensitive), youll get a list of tweets related to the movie. What you wont get are tweets that say "Who discovered gravity?" because "gravity" isnt preceded by the hashtag.\n Some Examples #android #google #stackoverflow #fifa #me #world these are all examples of hash tag
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainActivity
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Ramesh M Nair
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/com/hashtagandroid/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Main Page showing hash tag text.
3 | *
4 | * @auther Ramesh M Nair
5 | *
6 | * */
7 |
8 | package com.hashtagandroid;
9 |
10 | import android.app.Activity;
11 | import android.content.Intent;
12 | import android.os.Bundle;
13 | import android.text.method.LinkMovementMethod;
14 | import android.view.Menu;
15 | import android.view.View;
16 | import android.view.View.OnClickListener;
17 | import android.widget.CheckBox;
18 | import android.widget.TextView;
19 | import android.widget.TextView.BufferType;
20 | import android.widget.Toast;
21 |
22 | import com.hashtagandroid.interfaces.TagClick;
23 |
24 | public class MainActivity extends Activity {
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | }
32 |
33 | public void exampleActivity(View v) {
34 | startActivity(new Intent(getApplicationContext(), HashTagActivity.class));
35 | }
36 |
37 | public void exampleListview(View v) {
38 | startActivity(new Intent(getApplicationContext(), ListViewHashTag.class));
39 |
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Hash-Tags-Android
2 | =================
3 |
4 | This is a sample of handling hash tags that contain in a text,the tags are clickable and user can do specifc actions for the corresponding hash tags.In this example we can change color and also can give underline to hash tags according to the usecase.
5 |
6 | Hash-Tags: how to use
7 | ------------------------
8 |
9 |
10 | 1. Set Hash Tag Handler
11 |
12 | ```java
13 |
14 | TagSelectingTextview mTagSelectingTextview=new TagSelectingTextview();
15 |
16 |
17 | ```
18 |
19 |
20 |
21 | 2. For setting data form html content
22 |
23 | ```java
24 |
25 | mHashTagTextView = (TextView) findViewById(R.id.hashtag_textview);
26 | mHashTagTextView.setMovementMethod(LinkMovementMethod.getInstance());
27 | mHashTagTextView.setText(mTagSelectingTextview.addClickablePart(
28 | testText, this, mHyperlinkStatus, hashTagColor),
29 | BufferType.SPANNABLE)
30 |
31 | ```
32 |
33 |
34 | 3. For setting data form html content
35 |
36 | ```java
37 |
38 | mHashTagTextView.setText(mTagSelectingTextview.addClickablePart(
39 | Html.fromHtml(testText).toString(), this, mhyperlickStatus, hashtagColor),
40 | BufferType.SPANNABLE);
41 |
42 | ```
43 |
44 |
45 |
46 | ## VIDEO ([SAMPLE](https://www.youtube.com/watch?v=Bp7aiqxKhv0&feature=youtu.be))
47 |
48 |
49 |
50 |
51 |
52 |
53 | ## License
54 |
55 | The MIT License (MIT)
56 |
57 | Copyright (c) 2014 Ramesh M Nair
58 |
59 | Permission is hereby granted, free of charge, to any person obtaining a copy
60 | of this software and associated documentation files (the "Software"), to deal
61 | in the Software without restriction, including without limitation the rights
62 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
63 | copies of the Software, and to permit persons to whom the Software is
64 | furnished to do so, subject to the following conditions:
65 |
66 | The above copyright notice and this permission notice shall be included in all
67 | copies or substantial portions of the Software.
68 |
69 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
70 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
71 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
72 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
73 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
74 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
75 | SOFTWARE.
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/res/layout/activity_example.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
26 |
27 |
33 |
34 |
39 |
40 |
47 |
48 |
55 |
56 |
63 |
64 |
71 |
72 | /
73 |
74 |
--------------------------------------------------------------------------------
/src/com/hashtagandroid/adaptors/HashTagAdaptor.java:
--------------------------------------------------------------------------------
1 | /***
2 | * Tile : Adaptor class Shows Category view
3 | * @author Ramesh M Nair
4 | *
5 | * **/
6 |
7 | package com.hashtagandroid.adaptors;
8 |
9 | import java.util.ArrayList;
10 | import java.util.HashMap;
11 |
12 | import android.app.Activity;
13 | import android.content.Context;
14 | import android.text.method.LinkMovementMethod;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.widget.BaseAdapter;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 | import android.widget.TextView.BufferType;
22 |
23 | import com.hashtagandroid.R;
24 | import com.hashtagandroid.TagSelectingTextview;
25 | import com.hashtagandroid.interfaces.TagClick;
26 |
27 | public class HashTagAdaptor extends BaseAdapter implements TagClick {
28 |
29 | // Declaring Variables
30 |
31 | private Activity activity;
32 |
33 | private static LayoutInflater inflater = null;
34 |
35 | TagSelectingTextview mTagSelectingTextview;
36 |
37 | String[] hashtags = { "#testing #github", "#dwts #glee #idol #xfactor",
38 | "#teachers", "", "#jobs #business #sales #economy",
39 | "#testing #github", "#dwts #glee #idol #xfactor", "#teachers", "",
40 | "#jobs #business #sales #economy", "#climate, #solar" };
41 |
42 | public static int hashTagHyperLinkEnabled = 1;
43 | public static int hashTagHyperLinkDisabled = 0;
44 |
45 | String hastTagColorBlue = "#5BCFF2";
46 |
47 | public HashTagAdaptor(Activity mActivity) {
48 |
49 | activity = mActivity;
50 |
51 | inflater = (LayoutInflater) activity
52 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
53 |
54 | mTagSelectingTextview = new TagSelectingTextview();
55 |
56 | }
57 |
58 | public int getCount() {
59 |
60 | return hashtags.length;
61 |
62 | }
63 |
64 | public Object getItem(int position) {
65 |
66 | return position;
67 |
68 | }
69 |
70 | public long getItemId(int position) {
71 |
72 | return position;
73 |
74 | }
75 |
76 | public View getView(int position, View convertView, ViewGroup parent) {
77 | View vi = convertView;
78 | if (convertView == null)
79 |
80 | // Get the view from mainpage_row.xml
81 |
82 | vi = inflater.inflate(R.layout.tagviewrow, null);
83 |
84 | TextView tags = (TextView) vi.findViewById(R.id.tag_row);
85 |
86 | tags.setMovementMethod(LinkMovementMethod.getInstance());
87 |
88 | tags.setText(mTagSelectingTextview.addClickablePart(hashtags[position],
89 | this, hashTagHyperLinkDisabled, hastTagColorBlue),
90 | BufferType.SPANNABLE);
91 |
92 |
93 |
94 | return vi;
95 | }
96 |
97 | @Override
98 | public void clickedTag(CharSequence tag) {
99 | // TODO Auto-generated method stub
100 | Toast.makeText(activity, "Clicked on " + tag, 1).show();
101 | }
102 |
103 | }
--------------------------------------------------------------------------------
/src/com/hashtagandroid/TagSelectingTextview.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Class handling the hash tags in a string.
3 | * @auther Ramesh M Nair
4 | *
5 | * */
6 |
7 | package com.hashtagandroid;
8 |
9 | import android.graphics.Color;
10 | import android.text.Spannable;
11 | import android.text.SpannableString;
12 | import android.text.SpannableStringBuilder;
13 | import android.text.TextPaint;
14 | import android.text.method.LinkMovementMethod;
15 | import android.text.style.ClickableSpan;
16 | import android.util.Log;
17 | import android.view.View;
18 | import android.widget.TextView;
19 |
20 | import com.hashtagandroid.interfaces.TagClick;
21 |
22 | import java.util.regex.Matcher;
23 | import java.util.regex.Pattern;
24 |
25 | public class TagSelectingTextview {
26 |
27 | String mhastTagColor;
28 | TagClick mTagClick;
29 | int mHypeLinkEnabled;
30 |
31 | public SpannableStringBuilder addClickablePart(String nTagString,
32 | TagClick TagClick, int hypeLinkEnabled, String hastTagColor) {
33 |
34 | this.mhastTagColor = hastTagColor;
35 |
36 | this.mHypeLinkEnabled = hypeLinkEnabled;
37 |
38 | this.mTagClick = TagClick;
39 |
40 | // Pattern for getting the hash tags from a string
41 |
42 |
43 | Pattern hashTagsPattern = Pattern.compile("(#[a-zA-Z0-9_-]+)");
44 |
45 | SpannableStringBuilder string = new SpannableStringBuilder(nTagString);
46 |
47 | CharSequence spanText;
48 | int start;
49 | int end;
50 |
51 | // Matching the pattern with the existing string
52 |
53 | Matcher m = hashTagsPattern.matcher(nTagString);
54 |
55 | while (m.find()) {
56 |
57 | start = m.start();
58 | end = m.end();
59 |
60 | spanText = nTagString.subSequence(start, end);
61 |
62 |
63 | final CharSequence mLastTextSpan = spanText;
64 |
65 | string.setSpan(new ClickableSpan() {
66 |
67 | @Override
68 | public void onClick(View widget) {
69 |
70 | // Click on each tag will get here
71 |
72 | Log.d("TAg--HAsh", String.format("Clicked", mLastTextSpan));
73 | mTagClick.clickedTag(mLastTextSpan);
74 | }
75 |
76 | @Override
77 | public void updateDrawState(TextPaint ds) {
78 |
79 | // color for the hash tag
80 | ds.setColor(Color.parseColor(mhastTagColor));
81 |
82 | if (mHypeLinkEnabled == 0) {
83 | ds.setUnderlineText(false);// Disable the
84 | // underline for
85 | // hash Tags.
86 | } else {
87 | ds.setUnderlineText(true);// Enables the
88 | // underline for
89 | // hash Tags.
90 |
91 | }
92 | }
93 | }, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
94 |
95 |
96 | }
97 |
98 |
99 |
100 | return string;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/res/layout/tagviewrow.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
27 |
28 |
34 |
35 |
44 |
45 |
46 |
53 |
54 |
62 |
63 |
64 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/com/hashtagandroid/HashTagActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Main Page showing hash tag text.
3 | *
4 | * @auther Ramesh M Nair
5 | *
6 | * */
7 |
8 | package com.hashtagandroid;
9 |
10 | import android.app.Activity;
11 | import android.os.Bundle;
12 | import android.text.Html;
13 | import android.text.method.LinkMovementMethod;
14 | import android.view.Menu;
15 | import android.view.View;
16 | import android.view.View.OnClickListener;
17 | import android.widget.CheckBox;
18 | import android.widget.TextView;
19 | import android.widget.TextView.BufferType;
20 | import android.widget.Toast;
21 |
22 | import com.hashtagandroid.interfaces.TagClick;
23 |
24 | public class HashTagActivity extends Activity implements TagClick {
25 |
26 | TextView mHashTagTextView, mHashTagTextViewTwo;
27 |
28 | TagSelectingTextview mTagSelectingTextview;
29 |
30 | String hastTagColorBlue = "#5BCFF2", hastTagColorRed = "#FF0000",
31 | hastTagColorYellow = "#FFFF00", hastTagColorGreen = "#014a01",
32 | testText, currentHashTagColor;
33 |
34 | public static int hashTagHyperLinkEnabled = 1;
35 | public static int hashTagHyperLinkDisabled = 0;
36 | int tempHyperlinkStatus;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_example);
42 |
43 | mTagSelectingTextview = new TagSelectingTextview();// TagSelectingTextview
44 | // for
45 | // showing tag
46 | // without underline
47 |
48 | mHashTagTextView = (TextView) findViewById(R.id.hashtag_textview);
49 | CheckBox chkIos = (CheckBox) findViewById(R.id.checkBox1);
50 |
51 | testText = getResources().getString(R.string.test_word);
52 |
53 | // testText="What Is #Agile?
The Agile movement proposes alternatives to traditional project management. #Agile approaches are typically used in software development to help businesses respond to unpredictability.";
54 |
55 |
56 | mHashTagTextView.setMovementMethod(LinkMovementMethod.getInstance());
57 |
58 | // Initially we are setting hash tag color as blue and without
59 | // underlines to the hash tags
60 | setHashTag(hastTagColorBlue, hashTagHyperLinkDisabled);
61 |
62 | // Enable or Disable unbeline to a hash Tags
63 |
64 | chkIos.setOnClickListener(new OnClickListener() {
65 |
66 | @Override
67 | public void onClick(View v) {
68 | // is chkIos checked?
69 | if (((CheckBox) v).isChecked()) {
70 | setHashTag(currentHashTagColor, hashTagHyperLinkEnabled);
71 | } else {
72 | setHashTag(currentHashTagColor, hashTagHyperLinkDisabled);
73 |
74 | }
75 |
76 | }
77 | });
78 |
79 | }
80 |
81 | @Override
82 | public boolean onCreateOptionsMenu(Menu menu) {
83 | // Inflate the menu; this adds items to the action bar if it is present.
84 | getMenuInflater().inflate(R.menu.main, menu);
85 | return true;
86 | }
87 |
88 | public void red(View v) {
89 | // TODO Auto-generated method stub
90 | setHashTag(hastTagColorRed, tempHyperlinkStatus);
91 | }
92 |
93 | public void blue(View v) {
94 | // TODO Auto-generated method stub
95 | setHashTag(hastTagColorBlue, tempHyperlinkStatus);
96 | }
97 |
98 | public void green(View v) {
99 | // TODO Auto-generated method stub
100 | setHashTag(hastTagColorGreen, tempHyperlinkStatus);
101 | }
102 |
103 | public void yellow(View v) {
104 | // TODO Auto-generated method stub
105 | setHashTag(hastTagColorYellow, tempHyperlinkStatus);
106 | }
107 |
108 | @Override
109 | public void clickedTag(CharSequence tag) {
110 | // TODO Auto-generated method stub
111 |
112 | Toast.makeText(getApplicationContext(),
113 | "You have clicked on hash tag " + tag, 1).show();
114 |
115 | }
116 |
117 | public void setHashTag(String hashtagColor, int mhyperlickStatus) {
118 | /*
119 | * Temp color code and undelinestatus used for showing Example
120 | */
121 | currentHashTagColor = hashtagColor;
122 | tempHyperlinkStatus = mhyperlickStatus;
123 |
124 | /*
125 | * Main Section where we set the hash tag for the textview
126 | */
127 | mHashTagTextView.setText(mTagSelectingTextview.addClickablePart(
128 | Html.fromHtml(testText).toString(), this, mhyperlickStatus, hashtagColor),
129 | BufferType.SPANNABLE);
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------