├── .gitignore
├── AndroidManifest.xml
├── README.md
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ ├── activity_main.xml
│ └── activity_tag_details.xml
├── menu
│ └── main.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── sourabhsoni
└── hashtags
├── MainActivity.java
├── TagDetailsActivity.java
└── TagProvider.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HashTagsAndroid
2 | ===============
3 |
4 | This is a sample project that implements hashtags in android.
5 |
6 | Jump to http://goo.gl/Ojfzkx for complete tutorial.
7 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/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.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-17
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/HashTagsAndroid/7268f73831d533a539834d9e1a422412102f618f/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
19 |
20 |
21 |
22 |
31 |
32 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/res/layout/activity_tag_details.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/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/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HashTags
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/sourabhsoni/hashtags/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sourabhsoni.hashtags;
2 |
3 | import java.util.ArrayList;
4 | import java.util.regex.Pattern;
5 |
6 | import android.app.Activity;
7 | import android.os.Bundle;
8 | import android.text.util.Linkify;
9 | import android.view.Menu;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.View.OnClickListener;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.ListView;
17 | import android.widget.TextView;
18 |
19 | public class MainActivity extends Activity {
20 |
21 | //public static variable for demo purpose
22 | //we'll use this ArrayList in other activity
23 | public static ArrayList messagesList=new ArrayList();
24 | private ArrayAdapter adapter;
25 | private ListView messagesListView;
26 | private EditText messageEditText;
27 | private Button addButton;
28 |
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 | //initialize variables
36 | messagesListView = (ListView)findViewById(R.id.messagesListView);
37 | messageEditText = (EditText)findViewById(R.id.messageEditText);
38 | addButton = (Button)findViewById(R.id.addButton);
39 |
40 | //Extend an ArrayAdapter so that we can make
41 | //our TextView HashTag compatible
42 | adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,
43 | messagesList){
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | TextView hashView;
47 | if (convertView == null) {
48 | hashView = new TextView(MainActivity.this);
49 | } else
50 | hashView = (TextView) convertView;
51 |
52 | //Get the message from list and set as text
53 | String message = messagesList.get(position);
54 | hashView.setText(message);
55 |
56 | //Pattern to find if there's a hash tag in the message
57 | //i.e. any word starting with a # and containing letter or numbers or _
58 | Pattern tagMatcher = Pattern.compile("[#]+[A-Za-z0-9-_]+\\b");
59 |
60 | //Scheme for Linkify, when a word matched tagMatcher pattern,
61 | //that word is appended to this URL and used as content URI
62 | String newActivityURL = "content://com.sourabhsoni.hashtags.tagdetailsactivity/";
63 |
64 | //Attach Linkify to TextView
65 | Linkify.addLinks(hashView, tagMatcher, newActivityURL);
66 |
67 | return hashView;
68 | }
69 | };
70 |
71 | //assign custom adapter to messages listview
72 | messagesListView.setAdapter(adapter);
73 |
74 | //Add text from EditText to our messages list on button click
75 | addButton.setOnClickListener(new OnClickListener() {
76 | @Override
77 | public void onClick(View arg0) {
78 | String message = messageEditText.getText().toString();
79 | if(message.trim()!="")
80 | {
81 | messagesList.add(0,message);
82 | adapter.notifyDataSetChanged();
83 | messageEditText.setText("");
84 | }
85 | }
86 | });
87 | }
88 |
89 | @Override
90 | public boolean onCreateOptionsMenu(Menu menu) {
91 | // Inflate the menu; this adds items to the action bar if it is present.
92 | getMenuInflater().inflate(R.menu.main, menu);
93 | return true;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/com/sourabhsoni/hashtags/TagDetailsActivity.java:
--------------------------------------------------------------------------------
1 | package com.sourabhsoni.hashtags;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.app.Activity;
6 | import android.net.Uri;
7 | import android.os.Bundle;
8 | import android.widget.ArrayAdapter;
9 | import android.widget.ListView;
10 |
11 | public class TagDetailsActivity extends Activity {
12 |
13 | //List to store messages that contain clicked Tag.
14 | private ArrayList messagesWithTag;
15 |
16 | @Override
17 | public void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_tag_details);
20 |
21 | messagesWithTag=new ArrayList();
22 | ListView messagesListView=(ListView)findViewById(R.id.messagesWithTag);
23 |
24 | //Get the content URI
25 | Uri uri = getIntent().getData();
26 | //strip off hashtag from the URI
27 | String tag=uri.toString().split("/")[3];
28 |
29 | //Iterate through all the messages and find the ones
30 | //which contain this hashtag.
31 | for(String message:MainActivity.messagesList)
32 | {
33 | if(message.contains(tag))
34 | {
35 | messagesWithTag.add(message);
36 | }
37 | }
38 |
39 | //Show the list of messages which has the hashtag
40 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, messagesWithTag);
41 | messagesListView.setAdapter(adapter);
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/sourabhsoni/hashtags/TagProvider.java:
--------------------------------------------------------------------------------
1 | package com.sourabhsoni.hashtags;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentValues;
5 | import android.database.Cursor;
6 | import android.net.Uri;
7 |
8 | public class TagProvider extends ContentProvider {
9 |
10 | @Override
11 | public int delete(Uri arg0, String arg1, String[] arg2) {
12 | // TODO Auto-generated method stub
13 | return 0;
14 | }
15 |
16 | @Override
17 | public String getType(Uri arg0) {
18 | return "vnd.android.cursor.item/vnd.cc.tag";
19 | }
20 |
21 | @Override
22 | public Uri insert(Uri arg0, ContentValues arg1) {
23 | // TODO Auto-generated method stub
24 | return null;
25 | }
26 |
27 | @Override
28 | public boolean onCreate() {
29 | // TODO Auto-generated method stub
30 | return false;
31 | }
32 |
33 | @Override
34 | public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
35 | String arg4) {
36 | // TODO Auto-generated method stub
37 | return null;
38 | }
39 |
40 | @Override
41 | public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
42 | // TODO Auto-generated method stub
43 | return 0;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------