Thursday, June 13, 2013

My PhoneGap Presentation to Ottawa JS

So on Wednesday night I did my Introduction to PhoneGap/Apache Cordova (GitHub repo) presentation for Ottawa JS at the beautiful Shopify lounge. I've given this presentation a ton of times so I decided to give it a twist this time around.

The first thing I did was convert my old slide deck into a reveal.js presentation. Then I popped all the assets into a PhoneGap iPad project to see how it looked. Well, reveal.js looks and works great on an iPad.

At this point I started to get fancy. When I got to the part of the presentation where I would usually switch from the presentation software to Eclipse/Xcode to show the code and emulator I decided to call out to PhoneGap to take a picture instead. All I needed to do was include cordova.js in the app and make a call to Camera.getPicture and the results were:


this is my view from the stage


the view from the audience

And Darren took a picture of me taking the picture, while the picture I was taking was being put up on the big screen which is also in this picture. So I was able to do a presentation on PhoneGap in a PhoneGap app calling the PhoneGap API. It got meta pretty damn quick!





Tuesday, June 11, 2013

A Couple of Good Google Apps Scripts

Here are a couple of good Google Apps Scripts I've run into last week. The first script I saw on Lifehacker. It converts a Google Doc to markdown. It is a great way to create a README.md for GitHub. The second is from Pamela Fox which converts a Google Speadsheet to JSON data. Great way to create sample JSON data for your app.

Sunday, June 2, 2013

Why Don't My Plugins Work in PhoneGap Android 2.7?

Well it's pretty simple, the Plugin class which has been deprecated for awhile has been removed from the package and should be replaced with CordovaPlugin.

I'm going to go through the steps needed to upgrade your old style plugins to the new style. For this example I'm going to use the Google Analytics plugin.

The first thing you will notice in 2.7.0+ is that the GoogleAnalyticsTracker class now has 4 errors in Eclipse. To get rid of them you would change:


import org.apache.cordova.api.Plugin;

into:

import org.apache.cordova.api.CordovaPlugin;

and:

public class GoogleAnalyticsTracker extends Plugin {

to:

public class GoogleAnalyticsTracker extends CordovaPlugin {

and now you'll notice you only have one error left in the file and that has to do with the execute method. You'll need to change the method signature from:

public PluginResult execute(String action, JSONArray data, String callbackId) {

to:

public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

then you need to add a new import line at the top of the Java file:


import org.apache.cordova.api.CallbackContext;

and we still have one error which is now the line in which we are returning the PluginResult. That's because the method now expect a boolean to be the return value. To fix this issue you would replace:

return result;

with:

callbackContext.sendPluginResult(result);
return true;

Finally our Java code is free of error messages. Whew, were done but what's with the change to the execute method? Well let's just say there have been improvements in the way the Plugins are handled internally. What you need to know is that when you want to send a result back to the JavaScript side you now have a choice of three methods:

1) callbackContext.sendPluginResult(...)

Use this if you have constructed your own PluginResult and you want to send it to the JavaScript side.

2) callbackContext.error(int | String | JSONObject) 

Skip creating a PluginResult and just invoke the error callback on the JavaScript side sending back an int, a String or a JSONObject as the method payload.

3) callbackContext.success(empty | int | String | JSONObject | JSONArray)

Again, just skip creating the PluginResult and invoke the success callback on the JavaScript side sending back an int, a String, JSONObject or JSONArray as the method payload. If you don't provide any payload the method on the JS side will be executed with no payload.

So that should get you unstuck if you have a Plugin that no longer works for you as of PhoneGap 2.7.0. You should also check out my posts on the GalleryPlugin as shows how to write a Plugin using the new API for JS and Java.

IMPORTANT UPDATE!!!

We've heard your screams of pain and we are putting the Plugin class back for PhoneGap 2.8.1. Go read Joe Bowser's post. The class is back in 2.8.1 and will be in 2.9.0 then gone for good in the 3.0.0 stream!





Friday, May 31, 2013

Books I've Read This Week

The Demon by Jack Kirby collects the entire 16 issue run of the series. Kirby's art is brilliant and his story telling is frantic. This book defies convention as it isn't a pure super hero story but it isn't a pure horror story either. You can see how these stories went on to inspire so many other authors in their use of the Demon and maybe even Mike Mignola and his Hellboy character.
Inferno by Dan Brown. Yeah, I wasn't going to read it but the book is available so cheaply and it such a quick read. Plus, I already reviewed it before it even came out so I figured I should read it to see how right or wrong I was.

Whelp, I was way off base in plotting as Brown uses flashbacks to re-jigger his timeline. However on character's I was spot on and you can check them off one by one as they appear in the story. There is supposed to be a huge swerve in the book but it is utterly predictable when you realize that two of Brown's usual character archetypes are combined into one person.

If you usually like the Robert Langdon series you'll probably like this one as well. It's like comfort food at this point as you know what to expect.  

Saturday, May 18, 2013

Books I've Read This Week

Marvel Comics: The Untold Story by Sean Howe. Ug, sometimes it's not a good idea to learn how the sausage is made. As a long time comic book fan and a lover of Marvel comics for untold years I though it would be interesting to learn the story behind how some of my favourite comic books were produced. That was kinda a bad idea that left me feeling depressed. These weren't super happy people bouncing around the bullpen fronted by the always jovial Stan Lee, these were real people with real problems. After reading this book I wonder how the entire comics industry didn't implode, multiple times. Anyway, it was a good read but one I'm wishing I didn't read regardless.

Tuesday, May 14, 2013

My Review of Dan Brown's Inferno Before I've Even Read It

Oh my god! I just heard that Dan Brown is releasing a new book today starring Robert Langdon called Inferno. If you are not a Dan Brown fan you might not know that this is the 4th book with Robert Langdon as the main character with Angels & Demons, The DaVinci Code and The Lost Symbol being the prequels. I have read all the previous novels and even reviewed The Lost Symbol so you wouldn't have to read it yourself.

This time around I figured I'd review the novel before I even have read the book. Please note I haven't read the book and I don't have an advanced copy of the book. Instead I'm basing my review completely on what I've read in the previous books. I figure I can get about 85% correct so if this spoils the novel for you then I'm sorry.

The book opens in Florence Italy where an old man is being chased. He's able to avoid his pursuers long enough to hide some crucial piece of information that will become important later even though it seems silly now. The old man is now murdered and we immediately cut to...
Robert Langdon being awoken. The author is just trying to show how clever he is as he understands time zones. Langdon soon learns that an important figure in the symbolism sect has been killed and only Robert Langdon can help solve the problem. He then gets off to Florence Italy. 
Where he's taken to the crime scene where he meets the Misguided Policeman who immediately starts off on a bunch of exposition to catch up all us readers on why this person is important. Then the love interested walks in and we soon discover that she is the daughter/grand-daughter/adopted daughter of the dead man. The Misguided Policeman gets a phone call/interrupted by underling and leaves the two alone to talk where Langdon realizes that this is all a big puzzle related to Dante's Inferno. 
At that point Misguided Policeman realizes that Langdon must be in on it somehow even though he was an ocean away when the murder was committed. The chase is on!  Langdon uses his knowledge of medieval Florence to give the police a slip. Not realizing that they are being chased by a crazed assassin who has a some sort of glaring physical trait like a unicorn horn that should make him easily spottable from space. 
Langdon and love interest run around Florence solving clues only to get to a point where they need help. Langdon now realizes he knows someone near Florence that can help so they go to them for help. Super Spoiler Alert! This person they go to for help is the villain who is pulling all the strings from behind the scenes. 
Now the three of them are running around Florence solving clues and heading towards a final conflict where Langdon realizes that the help is the villain and tricks him into thinking that he can't solve the final puzzle. The Misguided Policeman finally realizes who the true villain is and arrests the help and guns down the crazed assassin. 
Langdon and the love interest go off and solve the final puzzle and for some reason even though beautiful women keep throwing themselves at him Langdon once again fails to seal the deal.
The End

Well that's my best guess. Feel free to leave a comment to let me know how right or wrong I am.





Monday, May 13, 2013

The Ottawa City Councillor PhoneGap app

So a couple of friends of mine wanted to learn more about programming mobile applications so we decided to get together and create an application for the Apps4Ottawa competition.

We settled on creating an application that would enable folks from Ottawa to learn more about and connect with their city councillors. Sadly, I didn't even know who my city councillor was until I started working on this app.

It uses the open data Ottawa to get the city councillor information and it the Open North API to do reverse geocoding to turn your GPS co-ordinates into the correct ward.

Currently the app is available on the Google Play store and we are going through the process of getting approval for the app on the Apple store.

PhoneGap was definitely the way to go with this project. We developed pretty much in Android then when we were ready to release a version of the app we just compiled it in Xcode and it just worked. The only thing we changed were the break points for the CSS media queries to deal with the different iPhone screen sizes. Support for Windows 8 and BlackBerry 10 are also coming as we have time.

I'm going to write up a post later in the week to talk about some of the micro libraries we used in order to accelerate development.

Please give the app a try and let me know what you think of it and what can be done better. If you are so inclined we wouldn't mind a vote or two in the app in the Apps4Ottawa competition.