Homework 3 – Seven Seas of Rhyme
Ok, first and foremost, the title is a pun a Queen song. Now that the most important piece of information is out of the way lets get to the app.
For this assignment I hooked a simple GUI onto RhymeBrain.com‘s rhyming dictionary API. In addition to rhyming words, the API has two other functions: it can create portmanteaus (blog + augmentation = blogmentation), or look up some simple word information, like a pronunciation.
Say we type in ‘hello’ and do a search. The app does a really simple http get and comes back with some results, up to a maximum number that’s customizable in preferences, as an array of JSON. When the search is all done, we’re brought to a list of rhyming words, and if we click on one we see some extra information about the rhyming word.
When a rhyme search is performed, we get back a flag saying if the pronunciation of the rhyming word is known, but not the pronunciation itself. Originally I didn’t care and just left it at that, figuring that if the user wanted a pronunciation they could just do a word info search. But since it was basically a matter of copy and paste, I decided to have this viewing activity call the service and request a word info search. So when this activity is brought up the pronunciation field say “retrieving…” until a result is receiver and the actual pronunciation can be inserted. If for some reason the user lost network access between the initial rhyme search and the starting of this activity, the pronunciation fields, including the link at the bottom, won’t be included in the layout.
On the API page is says that website should include a link to Rhyme Brain, and that other apps should just mention them in their about page. So I made a little ‘about’ alert dialog, but it seemed silly not to put in a link as well.
Turns out that sticking a link into an alert dialog is more work than putting one anywhere else that I’ve tried.
// wrestle a link into a dialog // make a view that will contain the linked text TextView message = new TextView(this); // throw on some padding message.setPadding(6, 3, 3, 3); // make a string for linking SpannableString text = new SpannableString("Seven Seas of Rhyme by Eric Hutter\n" + "data provided by RhymeBrain.com"); // link the string Linkify.addLinks(text, Linkify.WEB_URLS); // set the views text to the linked string message.setText(text); // make the link clickable message.setMovementMethod(LinkMovementMethod.getInstance()); // build the dialog new AlertDialog.Builder(this).setTitle("about").setView(message).show();
In this case, linkify-ing the text wasn’t enough, we also needed to tell the view that it’s text should act like a link when clicked, which seems unnecessary, but oh well.