package com.sachachua.infoextractor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class InfoReceiver extends Activity {
	 @Override 
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 // Get intent, action and MIME type
		 Intent intent = getIntent();
		 String action = intent.getAction();
		 String type = intent.getType();
		 if (Intent.ACTION_SEND.equals(action) && type != null) {
			 handleSendText(intent); // Handle text being sent
		 }	
		 finish();
	 }

	 private void handleSendText(Intent intent) {
		 String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
		 // Find the matching URL
		 Pattern pattern = Pattern.compile(
				 "\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" + 
						 "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" + 
						 "|mil|biz|info|mobi|name|aero|jobs|museum" + 
						 "|travel|[a-z]{2}))(:[\\d]{1,5})?" + 
						 "(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" + 
						 "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + 
						 "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" + 
						 "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + 
						 "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" + 
				 "(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
		 Matcher matcher = pattern.matcher(sharedText);
		 if (matcher.find()) {
			 Intent newIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(matcher.group()));
			 startActivity(newIntent);
		 }
	 }
}

@@ -205,16 +205,46 @@
 .Bundle;
+%0Aimport android.util.Patterns;
 %0A%0Apublic
@@ -841,533 +841,17 @@
 tern
-.compile(%0A%09%09%09%09 %22%5C%5Cb(((ht%7Cf)tp(s?)%5C%5C:%5C%5C/%5C%5C/%7C~%5C%5C/%7C%5C%5C/)%7Cwww.)%22 + %0A%09%09%09%09%09%09 %22(%5C%5Cw+:%5C%5Cw+@)?((%5B-%5C%5Cw%5D+%5C%5C.)+(com%7Corg%7Cnet%7Cgov%22 + %0A%09%09%09%09%09%09 %22%7Cmil%7Cbiz%7Cinfo%7Cmobi%7Cname%7Caero%7Cjobs%7Cmuseum%22 + %0A%09%09%09%09%09%09 %22%7Ctravel%7C%5Ba-z%5D%7B2%7D))(:%5B%5C%5Cd%5D%7B1,5%7D)?%22 + %0A%09%09%09%09%09%09 %22(((%5C%5C/(%5B-%5C%5Cw~!$+%7C.,=%5D%7C%25%5Ba-f%5C%5Cd%5D%7B2%7D)+)+%7C%5C%5C/)+%7C%5C%5C?%7C#)?%22 + %0A%09%09%09%09%09%09 %22((%5C%5C?(%5B-%5C%5Cw~!$+%7C.,*:%5D%7C%25%5Ba-f%5C%5Cd%7B2%7D%5D)+=?%22 + %0A%09%09%09%09%09%09 %22(%5B-%5C%5Cw~!$+%7C.,*:=%5D%7C%25%5Ba-f%5C%5Cd%5D%7B2%7D)*)%22 + %0A%09%09%09%09%09%09 %22(&(?:%5B-%5C%5Cw~!$+%7C.,*:%5D%7C%25%5Ba-f%5C%5Cd%7B2%7D%5D)+=?%22 + %0A%09%09%09%09%09%09 %22(%5B-%5C%5Cw~!$+%7C.,*:=%5D%7C%25%5Ba-f%5C%5Cd%5D%7B2%7D)*)*)*%22 + %0A%09%09%09%09 %22(#(%5B-%5C%5Cw~!$+%7C.,*:=%5D%7C%25%5Ba-f%5C%5Cd%5D%7B2%7D)*)?%5C%5Cb%22)
+s.WEB_URL
 ;%0A%09%09

Use built-in pattern for Web URL