Sunday, March 28, 2010

Match.com

At the end of last year I changed jobs. One of the complications with doing this is obtaining a new Visa so I can legally live and work in the United States. After a holiday back home in Australia while waiting for USCIS to process the paperwork I was finally able to return to the United States at the beginning of February.

Since my return I have been working on the new Android application at Match.com. On Thursday 25th after roughly 2 months of development we launched the beta version to market.


This has been a complete 180 from my previous employment working at Hands-On Mobile. While I worked on some applications my primary focus was on game development. After working on licensed titles such as Guitar Hero, World Poker Tour, Call of Duty, Hulk it is welcome change to work on something "you own".

If we want to add a new feature, we can. If we want to trial something, we can. The turn around is much faster than having to ask a 3rd party for permission before doing something. This allows development ("me") to spend more time working on real features instead of replacing minor elements to keep someone else happy.

Don't get me wrong I loved working on games but after 5 years it is a welcome change to try something new.


The official release of Match.com for Android is coming soon!

Don't worry, we are not releasing this to market and forgetting about it. We will continue to improve the application and add new features. If you have any feedback about the application please get in contact and I will see that your voice is heard.

Tuesday, March 23, 2010

Android TextView and HTML

Recently I wanted to display a TextView with a clickable link.




Let's setup a simple TextView and add a link.

mTextSample = (TextView) findViewById(R.id.textSample);
String text = "Visit my blog jtomlinson.blogspot.com";
mTextSample.setText(text);


The result is pure text displayed on screen. Android has no idea we want to display a clickable link.

This wasn't acceptable. I wanted people to be able to launch the url directly by clicking on the link. The next step was to use Linkify, a great feature for adding clickable links to text.

mTextSample = (TextView) findViewById(R.id.textSample);
String text = "Visit my blog jtomlinson.blogspot.com";
mTextSample.setText(text);
//jmt: pattern we want to match and turn into a clickable link
Pattern pattern = Pattern.compile("jtomlinson.blogspot.com");
//jmt: prefix our pattern with http://
Linkify.addLinks(mTextSample, pattern, "http://");



Now we are getting somewhere. Our link is clickable and the user is taken directly to the url using the browser. This is the most basic example of Linkify. WikiNotes is an example from Google that discusses more detailed use of Linkify.

Our next step is to tidy up the view by removing the url and allow the user to click on "blog" to launch the browser.

mTextSample = (TextView) findViewById(R.id.textSample);
String text ="Visit my blog"
mTextSample.setText(text);


Note: blogspot has marked up my text string, you can see the actual string in the screen shot below.



Again this doesn't quite work straight away. We need to tweak our text slightly so Android understands we want to display HTML.

All we need to do is update our setText method to include Html.fromHtml. This method will style our text based on the HTML tags. Not all tags are included so make sure you test first.

//jmt: style our text based on html tags
mTextSample.setText(Html.fromHtml(text));




Perfect, now we have our TextView looking exactly how we want it. There is only one problem, if we try to click the link nothing happens.

We have one last line of code to write. This informs Android we have a link that we would like to open when selected.

mTextSample.setMovementMethod(LinkMovementMethod.getInstance());


When clicked, the browser is launched and the user is taken to the specified url.






Here are the 4 lines of code required to display a clickable link
mTextSample = (TextView) findViewById(R.id.textSample);
mTextSample.setMovementMethod(LinkMovementMethod.getInstance());
String text = "Visit my blog";
mTextSample.setText(Html.fromHtml(text));

Blog is back

After some blogging absence due to unforeseen circumstances I'm back. I am once again free to blog about my Android exploits.

I even found time to re-release Amazed 2 with some scaling tweaks to account for the larger screen resolutions we are starting to see on devices. Amazed 2 should have really done this from the beginning but I was lazy due to only having 320x480 devices available.

I know I've said it before but I plan to post more frequently from now on.