Recently I’ve been working on show notes support for SwallowCatcher. Since most podcast feeds include their show notes in the feed as embedded HTML I decided to render this HTML to display the show notes. This turned out to be ridiculously simple thanks to Android’s WebView class. The API for rendering arbitrary HTML within your app is almost Pythonic in its simplicity. However, there are a couple of gotchas which caught me out, so I decided to cover them here.

I started out by creating a new Activity class and a layout XML file for it. The layout XML was taken almost directly from the Android WebView Tutorial page:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/shownotes"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

In my Activity class the XML is loaded as normal. We also need to import the WebView class and the URLEncoder class. Additionally, the UnsupportedEncodingException class is required:

import android.webkit.WebView;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;

Next, we need to encode the text in the correct format. Weirdly, WebView requires that the text is URL escaped, but without spaces converted to ‘+’ symbols. I used URLEncoder to encode my content then replaced the ‘+’ symbols with spaces. This probably isn’t perfect, but for my purposes it works.

String text = "<html><head></head><body>Content goes here!</body></html>";
text = URLEncoder.encode(text, "utf-8");
text = text.replace('+', ' ');

Finally, we find the WebView from the XML and tell it to load the string as its content:

WebView web = (WebView)findViewById(R.id.shownotes);
web.loadData(text, "text/html", "utf-8");

All the above is encased in a try..catch statement for UnsupportedEncodingException, just in case the URLEncoder has a fit. That’s pretty much it. In SwallowCatcher the ShowNotesActivity is 56 lines, including all the verbose Java imports and bootstrapping and loading the content from the database via ORMLite.

As a wise action hero (and ex-Jedi) once said, “I love it when a plan comes together”.

Tagged with:
 
Download SwallowCatcher 0.1.2

Download SwallowCatcher 0.1.2

I’m proud to announce the release of a new version of SwallowCatcher. This version follows hot on the heals of the 0.1.1 release and fixes several bugs reported to me over the last few days. Specific fixes include:





* Fixed empty description tag problem (scratched by Linux Outlaws feed) as reported by @andyc in identi.ca.
* Fixed feed missing scheme validation problem as reported by @andyc in identi.ca.
* Fixed download permissions problem as reported by @andyc in identi.ca.
* Fixed individual feed refresh problem.

Thankfully, I have managed to hold onto my encryption key this time, so upgrading from version 0.1.1 should be smooth. Remember to check out the project page and the gitorious page where you can download the source code. Feedback and bug reports can again be submitted via identi.ca, email or via the comments on this post.

Tagged with:
 

QR Codes are a really easy way to share information between your desktop or laptop and a smartphone, which don’t have the privacy issues inherent in Google’s Chrome To Phone. The excellent FOSS Barcode Scanner app for Android makes scanning these codes and opening the scanned data a breeze. However, generating them on the desktop can be a bit of a pain. There are several websites, browser addons and APIs for generating these codes, but up until now I haven’t found anything really quick and easy.

That is until today, when I discovered the ‘qrencode’ utility. Qrencode does exactly what it says on the tin. It takes some text, encodes it as a QR Code and writes the result as a PNG file. It’s a simple command line tool, which opens up awesome scripting possibilities.

My use case is simply to send the URL of a web page that I’m viewing on my desktop to my phone, via QR Code. I found that qrencode was quite happy to write its output to stdout, which meant I could display the result directly using ImageMagick’s ‘display’ command, e.g:

$ qrencode http://blog.webworxshop.com -o - | display

You’ll notice that by default the QR Code is quite small. We can fix this by increasing the block size:

$ qrencode http://blog.webworxshop.com -s 10 -o - | display

Next, I wanted to automatically pull the text to encode from somewhere to save typing – the clipboard was an ideal candidate. Enter ‘xclip’. Xclip is a command line utility to read and write from/to the X system’s built in clipboard. I used bash’s backtick command substitution to grab text from the clipboard and encode it:

$ qrencode `xclip -o` -s 10 -o - | display

And there you have it, a simple one line command to generate and display a QR Code from the contents of the clipboard. I created a bash script containing the command and assigned it to a keyboard shortcut in Gnome (Ctrl-Shift-Q), so that sharing URLs to my phone is as simple as selecting the text in the location bar and hitting Ctrl-C followed by Ctrl-Shift-Q.

If you want to give this a try, you’ll need to install the utilities discussed, in Fedora these can be installed with:

$ sudo yum install qrencode xclip ImageMagick

Enjoy!

Tagged with:
 
Download SwallowCatcher 0.1.1

Download SwallowCatcher 0.1.1

Today sees the release of the second version of SwallowCatcher, version 0.1.1. This version contains many enhancements and bugfixes over the previous version and should so be considered as the main stable release for the 0.1.x series. Further releases in this series will contain bugfixes, with new features being added to 0.2.x.




Obligatory release notes:

Features:

* Import Podcasts from OPML;
* Add Podcasts Via Barcode or URL;
* Open podcast:// and feed:// URLs directly in SwallowCatcher;
* Download Podcast feeds;
* List newly found Episodes;
* List Subscriptions and Episodes;
* Download Podcasts;
* Share via intent (and thence via email, mustard, etc.).
* Basic playback support.

Fixed Issues from Previous Version:

* New episodes screen issue;
* Can now add podcasts directly by feed URL;
* Added basic playback support;
* Prettier downloads list;
* Podcasts list remembers scroll position;
* Fixed text on the first run dialogues;
* Fixed OPML import from Google Reader;
* More robust feed/date parsing;
* Lots of general stability fixes;
* Much improved UI with more options, etc.

Known Issues:

* Downloads still aren’t pausable/resumable;
* I need some icons!

Future Plans:

The 0.1.x series will continue to address the remaining issues above and fix bugs.
The next main release (0.2.0) will include cover art and show notes support.

SwallowCatcher is still not in the Android Market so either download above or check out the project page and the gitorious page where you can download the source code. Feedback and bug reports can again be submitted via identi.ca, email or via the comments on this post. No Spam please (only ham and eggs).

Tagged with:
 

People following me via identi.ca and via the site feed may have noticed that I’ve been a bit quiet lately. I won’t go into the details about what’s been going on (its all been good stuff though), but its safe to say I’ve been a bit busy. Anyway, I’m back (pretty much).

I’ve decided now to focus my spare time on SwallowCatcher development and poking around with cool technologies that I come across, with some write-ups here. This means that I’m ditching the Unofficial Python Module of the Week segment. This is really because I just can’t hack the schedule and don’t want to be tied down to blogging at specific times.

However, on the up side SwallowCatcher development will resume from today and I hope to have a new release soon. Of course the new release will be posted here as soon as it’s ready.

Also, apologies to anyone who came across my site in its eye-offending pink and grey glory. I’m not sure what happened there. I’m hoping that the site wasn’t hacked in my absence and I can’t find any other evidence of that, but its weird nonetheless.

Tagged with:
 
Set your Twitter account name in your settings to use the TwitterBar Section.

Bad Behavior has blocked 309 access attempts in the last 7 days.