Thursday, February 28, 2013

What's New in PhoneGap Android 2.5.0

Well PhoneGap Android 2.5.0 is out! There isn't much to get excited about on Android in this release as it is mostly bug fixes. Check out the full list of commits in the CHANGELOG. Fixes include:

  • Fixing a null pointer exception when the user clicks the back button while the app is starting.
  • Enabling the application cache.
  • New configuration parameter "disallowOverscroll" to remove that blue glow when you try to scroll past the top/bottom of the screen.
  • Enabled geolocation in the InAppBrowser.

However, something I can get excited about is that in the past month we've seen 8 new committers to the Android project. Yup, 8 new coders contributed their time to cordova-android which I think is a great sign of the health of the project.

Friday, February 22, 2013

Books I've Read This Week

The Fifth Assassin by Brad Meltzer is a follow up to his The Inner Circle novel in which librarians take on the president. Well technically they are archivists from the US National Archives but it is just as exciting as you would think. Look, my Dad really likes Brad Meltzer's novels and I borrowed this from him and read it in an afternoon between hockey games on TV. Now you can either think it is a gripping mystery novel or I'm a really fast reader. It's up to you to decide.
The Lost Stars: Tarnished Knight by Jack Campbell is a bait and switch! I thought we were getting another Black Jack Geary novel but this one is set on the recently freed Syndicate start system of Midway. Even though it isn't what I was expecting it is still a pretty good novel that follows a couple of CEO's as they try to gain control of the Midway system and free it from the communist Syndicate rule.

Soon enough there will be a new Black Jack Geary novel on the way in The Lost Fleet: Beyond the Frontier: Guardian.

Hmmm...a bit negative today maybe I'll be more positive next week.

Monday, February 18, 2013

PhoneGap Android XhrFileReader

The FileReader API works great as long as the file you want to read is on the device's file system. However if you want to read a file you've packed in the Android assets folder you would need to use XHR to read the file. I'm providing an interface that follows the same API as the regular FileReader. Of course the XhrFileReader is not limited to only reading files from the assets folder, it can also read files from the file system and over HTTP.

Adding the plugin to your project 

To install the plugin, move XhrFileReader.js to your project's www folder and include a reference to it in your html files.

Using the plugin 

To instantiate a new reader use the folling code:
var reader = cordova.require("cordova/plugin/xhrfilereader"); 
Setup your event handlers:
// called once the reader begins
reader.onloadstart = function() {
    console.log("load start");
};
// called when the file has been completely read
reader.onloadend = function(evt) {
    console.log("File read");
    console.log(evt.target.result);
}; 
Unfortunately, you will only get an error on files read over HTTP. When you specify a file:// path the request status is always 0. There is no way to tell between a successful read or an error. So if you specify a file that does not exist like "file:///does.not.exist.txt" you will get an empty evt.target.result in your onloadend handler.
// called if the reader encounters an error
reader.onerror = function(error) {
    console.log("Error: " + error.code);
}; 
Progress events are fired but are not very useful as they don't contain partial results.
// called while the file is being read
reader.onprogress = function(evt) {
    console.log("progress");
}; 
Finally call your read method, for instance:
reader.readAsText("http://www.google.com"); reader.readAsText("file:///android_asset/www/config.json"); reader.readAsText("file:///sdcard/error.log");
and that's about it. Obviously, this plugin is most useful when you need to read a text file from the assets folder.

Friday, February 15, 2013

Books I've Read This Week

Mind the Gap Volume 1: Intimate Strangers by Jim McCann and art by Rodin Esquejo is a book I love. When it was originally announced with Esquejo on interior art duties I was excited as I love his covers on Morning Glories and having Eisner award winning McCann providing scripting duties it seemed like it couldn't miss. It doesn't miss, it delivers in spades.

Mind the Gap is a bit hard to explain as it is structured not unlike a murder mystery but in this case the investigator is also the victim, Elle Peterssen. You see Elle is in a coma but can her spirt can still interact with the mortal plain. I know it sounds a bit crazy but it really works.

McCann has said all the information you need to solve the mystery is contained in the story which has me reading and re-reading the book. Just recently I picked up on something I'd never seen before which caused me to re-evaluate all of my theories.

Highly recommended for lovers of graphic novels.
The Signal and the Noise by Nate Silver is a really interesting book about what a lot of people find to be a boring topic, statistics (not me I'm a stats nerd). Specifically how one can make better predictions by learning to separate good information, the signal, from extraneous information, the noise. There are some really great chapters in here on weather, baseball and political predictions. I particularly enjoyed reading that we've gotten much better at weather predictions in the past 15 years. When I used to work at the Department of Meteorology a 4 day forecast was the best you could do with even a 30% accuracy. Now we've gotten out to fairly accurate 7 day forecasts. As an aside days 8 to 14 of a 2 week forecast are crap, don't plan anything around them. Plus there is a name check to the company I work for when he talks about Kasparov and Deep Blue. 

Thursday, February 14, 2013

What's New in PhoneGap Android 2.4.0

Well PhoneGap 2.4.0 has been released. So here are couple of the new things you can look forward to:

1. Support Reading Slices of Text Files.

The File object now has a slice method. Suppose the file we're reading contains the text:

"All that is gold does not glitter, not all those who wander are lost." 

Then...

  • f.slice(4, 8) would result in "that" 
  • f.slice(9) would be "is gold does not glitter, not all those who wander are lost." 
  • f.slice(-5, -1) would be "lost"


2. Added input type=file support

Now if you specify an input field of type file you will get a "Choose File" button:


Then when you click the button you will launch an intent that can handle file picking:


Now the value of your input tag will be the file you selected.

3. Additional preferences in config.xml

I completely missed this one so Joe Bowser wrote it up.

Tumblr Account

I've created a new Tumblr account where I will post links to things that I find funny and or interesting. If you enjoy comics, quirky comedies and Star Wars you'll probably enjoy it.