Friday, November 30, 2012

Books I've Read This Week

Saga Volume 1 by Brian K Vaughn and with art by Fiona Staples is pretty damn amazing. It is a science fiction epic where we follow Alana and Marko who are fleeing a war. The crux of the matter is that Alana and Marko are from opposite sides of a war between two different alien races. The powers that be from both sides want them apprehended before it is discovered that the two races can inter-breed. Oh yeah, the story opens up shortly before the birth of their first child.

The pair are chased by a collection of odd characters including elements from the military of Alana's race as well as a number of bounty hunters which include the Stalk (a human spider hybrid) and The Will. Just image the original cantina scene from Star Wars: A New Hope writ large. Fiona Staples really gets a chance to play with character designs and sweeping alien vistas. The book would be well worth it from the art alone but you also get some great writing as well. I'm looking forward to picking up this series for years to come.

Finally the six issue collection only has a $9.99 price which is an absolute steal. I really love that introductory price on Image Comics first trade paper backs.
The $100 Startup: Reinvent the Way You Make a Living, Do What You Love, and Create a New Future by Chris Guillebeau. I admit I'm intrigued by entrepeneurs. I'm super impressed by the guts one must have in order to strike out on their own. The thing this book tries to address is taking away the fear of taking that risk. Guillebeau dives into fifty case studies of small entrepreneurs who've started their business with as little as $100 and now make a full time living off of that business.

The key piece that I take away from this book is that anyone can do it and you don't need to risk your financial security in order to do it. However, the book also tells you that the way to succeed is to do something that you are not only good at but passionate about. That's where I count myself lucky as my day job is working with open source software and playing with mobile phones. It doesn't get much better than that for me.

Wednesday, November 28, 2012

Building a HTML Options Menu for PhoneGap Android

Alright, sorry it took me so long to get back to this but I was busy getting things done for the 2.3.0 release. This is a continuation of my series of posts on menus the previous ones were on Context and Option menus. Also, the code is not perfect there are some things I want to do that will support multiple image sizes and organize the menu in multiple rows but I figured I'd release what I was able to re-create. My original code is somewhere on another laptop. So the new code is now available in this github repo.

Okay, so if you want to use this component you will need to download OptionsMenu.js from the above link, place it in your assets/www folder then add the script tag after cordova.js in your HTML file.

Next you will want to create you menu. For my purposes I've used the settings/help example like the previous two posts on menus. To do it you add some code into your to the method that is listening for the "deviceready" event. Something like this:
and that will produce a menu that looks like this:


But let's dig in a bit of that call to create a new OptionsMenu. The magic is in the JSON object passed to the construction. Obviously the "id" is used to set the ID of the div that will hold the menu items. Then the items array will contain all of the menu items you want to display. Each menu item has three properties, image is a url the icon you want to display in the item, label which is the text which is shown under the image and finally action which is a JavaScript function that is called when the item is tapped.

So that's it, you have a fully functioning HTML/CSS/JS only options menu just by including an additional JavaScript file. Like I said the code is up on github and it is not perfect. Feel free to submit issues as I'm going to pick away at making it more robust after I take a mini vacation.

Update: So I realized the menu really should support multiple rows just like a real Android options menu so I just pushed an update to my code on Github to support it. Instead of an array being sent to the constructor of the OptionsMenu you send a multi-dimensional array like so:

and then it looks like this:


You will also notice the icons are a bit smaller. I'm checking for the size of the screen and adjusting the icon width and height accordingly.

Friday, November 23, 2012

Books I've Read This Week

Wheat Belly by William Davis is another book in a series of books that are blaming the obesity epidemic on carbohydrates, in this case specifically wheat. I'm not a Doctor myself but the author William Davis is and he has the science and real world experience to back up his claims. Personally what I have noticed is that by limiting the amount of processed carbs I eat that my weight is way down, over 10 lbs this year. That may not seem like a lot but I'm not carrying around a lot of extra weight to begin with so maybe Dr. Davis is on to something here.

Other books that are similar in natured include The G.I. Diet, The Paleo Solution and even The 4-Hour Body.
Invincible Iron Man - Volume 7: My Monsters by Matt Fraction is where this series goes off the rails for me. I really enjoyed the first 6 volumes but this is where I suggest folks stop. At the end of volume 6 we could see that the Mandarin was going to be the big baddie going forward. So in volume 7 it opens up with a Mandarin story written by Kelly Sue Deconnick which is the main reason to pick up this book. The Mandarin has kidnapped a famous director so that he can make a movie based on his life story. Of course  the Mandarin wants to paint himself in the most flattering light but the director is looking for more "authenticity".

After that we are treated to a re-hash of the origin of Iron Man and some alternative future story which I'd rather just forget I'd even read. 

Friday, November 16, 2012

Getting the create Command to Work on PhoneGap 2.2.0 Android

Okay as of PhoneGap 2.2.0 the Getting Started guide has been "simplified" to make creating your first Phonegap Android project easier. Boy, that's not the  impression I get after helping people on the PhoneGap Google Group for the past week and a half.

From what I understand most of us Cordova core developers use a Mac as our main machine. Now I don't want to and won't start an OS holy war since there is a very good reason why we do that, you can't do iOS without a Mac and the tools for Android and BlackBerry development will run on a Mac so it makes sense for those of us who have to jump back and forth to be using a Mac. However, we've really dropped the ball in explaining what the proper setup needs to be when you are on a PC. So that's why I'm writing this blog post from my old Windows laptop that I dusted off so I can feel your pain.

Required Software
  1. Java Development Kit
  2. Apache Ant
  3. Android Development Kit
Go ahead and download and install those packages if you haven't already. I'll wait. I'm not up to anything else right now. But please pay attention to where you install these packages as you'll need those paths later.

Oh good, you're back.

First problem

Once you navigate to the phongeap\lib\android\bin directory the getting started guide tells you to run the following command:
./create <project_folder_path> <package_name> <project_name>
but that is not accurate on a Windows system as it won't be able to find the create command. The line should be:
create <project_folder_path> <package_name> <project_name>
Second problem

Once you do that you probably will see this error:


So basically and unhelpful error telling you that you are missing a package. We'll need to make sure the following commands can be run from the command prompt. Let's start by testing if the command line can find java.exe first. So type:
java
into the command line. If you see something like this:


then you will need to modify your PATH environment variable so that the script can find Java. First you'll need to discover where your JDK is installed. I can't tell you where that is so I hope you took my advice and noted where the installer placed those files. Armed with the path to your Java Development Kit do the following:

  • From the Desktop, right-click My Computer and click Properties. 
  • Click Advanced System Settings link in the left column. 
  • In the System Properties window click the Environment Variables button. 
  • Select the PATH variable from the System variables section. 
  • Select the Edit button.
which means you should have a dialog something like this:


This is where you will add the JDK\bin directory to your PATH. Notice you need to point to the bin directory where commands line java and javac are kept. For example "c:\jdk\bin". Also make sure to separate different path entries using a ";". Now you need to click OK then OK once more. After that close your command prompt and start a new one so the updated PATH variable will be used. In the new command prompt run:
java
once again and you should see something like this:


Now the create script will be able to find java. Unfortunately you'll need to repeat the process for the following commands:
  • javac
  • ant
  • adb
  • android
If you get the "blah" is not a recognized internal or external command error message for any of the above you'll need to add it to the PATH.

Third problem

The environment variable JAVA_HOME may be set incorrectly. Make sure that this variable is set and it refers to the root directory of your JDK and not JRE. The create.js script looks for %JAVA_HOME%\bin\javac.exe and if it can't find it there will be an error.

Fourth problem

Don't use '-' in your package name. The '-' is not a valid character in a Java package name.

Bad:    ./create ./name com.my-company.name name
Good:  ./create ./name com.mycompany.name name

Okay, I hope that helps everyone. I'm going to make the error messages more descriptive while I'm on my PC for the upcoming 2.3.0 release.


Books I've Read This Week

Doomsday Book by Connie Willis is a book I've been meaning to read ever since I finished her Blackout/All Clear duology. I was surprised but pleased to find out that this book takes place in the same universe as Blackout/All Clear. Unfortunately that also means that I had a very good idea how the time travel plot would play out. It won the Hugo and Nebula awards back in 1993 so I came into it with high expectations considering the other Hugo/Nebula winners I can think off the top of my head are Dune, Ender's Game, Neuromancer, American Gods, The Windup Girl and the afore mentioned Blackout/All Clear. Sadly it didn't live up to my high expectations even though it is a pretty darn good book.

In 2048 we are able to send people back into the past to observe things. Our historian Kivrin is about to travel back to the 14th century to observe contemporary life. Unfortunately, the technician who is to send her back to the past falls prey to a 21st century disease and she ends up smack dab in the middle of the black plague. We are left with parallel stories of how the people of the 14th and 21st centuries deal with epidemics.
The Best of Down Goes Brown by Sean McIndeo is hilarious. By the time I was on page 6 I had already laughed out loud on 4 separate occasions. Honestly this book is worth the purchase price if you only ever read "A Look Back at Game Seven of the 2011 Stanley Cup Final (which, due to a scheduling error, had to be published twelve hours early)" which is one of the best piece of satirical writing I've ever read. Seems like a great gift for that hockey lover in your life and I thoroughly enjoyed every chapter.

I'm now a follower of the blog and twitter feed.

Monday, November 12, 2012

Building a Native Context Menu for PhoneGap Android

So I know I promised that I'd write about a HTML only menu but I thought folks might be interested in native context menus as well. It's not much different than my last blog post on menu's so it should be easy to follow.

So when I talk about a native context menu I mean the menu that clicks when you do a long press on an Android device. Again this is well covered on the Android Developer page. Here is an example of an context menu from the Contacts app:


The first step in creating the menu is to define it in XML. My recommendation is to create a menu folder under the res folder in your Android Eclipse project. Then you create a new File with an XML extension. For this post I'll call mine example.xml. When you're done your res folder should look something like this:


Don't worry about the red X's as we haven't edited the XML file yet so it is going to complain about a premature end of file. For a real good description of what goes into a menu XML file read this. For our purposes I'm just going to give you the XML to paste into the file:

But when you view the file in Eclipse you'll still see errors:


and that is to be expected as we haven't added the two images to the drawables folder nor have we added our two new strings to strings.xml. To fix these issues first download these two images:


and copy them to your projects res/drawable-hdpi folder. When you want to put out a professional application you'll need to provide icons of various sizes but the above is enough for our needs.

To fix the rest of the red X's you'll need to open the res/values/strings.xml and add two new Strings. The first should have the name "settings" and a value of "Settings. The second should have the name"help" and, predictably, the value of "Help". At this point all the red X's from example.xml and from the res folder hierarchy should have disappeared. 


If they haven't, well then you've done something wrong and should probably go back over all the steps to make sure you haven't missed anything.

Okay, so now we've got all the resources in place. Let's go write some actual Java code. Don't worry much of it will be cut and paste. In Eclipse open up your main Java class, you know the one that extends DroidGap.

First you'll need to register the context menu in the onCreate method. Basically, you'll need to add the call to registerForContextMenu to your onCreate method:


Secondly we'll need to tell your application what to do when it detects a long press. You'll need to paste the following code into you main Java class:

You shouldn't need to change anything unless you've called your menu XML file something different than example.xml. If you have you'll need to change R.menu.example into R.menu. where you replace with the name of your file minus the .xml extension.

The last bit of code you need to add is a method that will tell your application what to do when the individual menu items are clicked. Here's some example code:


When you click on the Setting button we'll use an Android intent to load the devices Settings panel. If you click on the Help button then we'll execute some JavaScript code. That's it! You don't need to add anything to your HTML/JS code to get a native Android context menu working with your PhoneGap application. Here is what it would look like:



Please note, I'm just providing a quick example and you are not limited to how you handle the menu button clicks in the least. You may want to handle it in Java and do something that you can't do in JavaScript or you may want to call a JavaScript function on your page to have your UI react in some interesting way.

So, there you go. The process is nearly identical to creating an options menu that I described in my previous post. I promise that in my next post I'll show you how to handle everything in HTML and JavaScript!

Friday, November 9, 2012

Books I've Read This Week

The Happiness Project by Gretchen Rubin  is not the usual type of book I read. Honestly, I have a lot of things to be thankful for. I've got my health, I'm married to an amazing woman, we have a great child, I'm gainfully employed in a job that I actually enjoy but I'm not sure you could call me a happy person. Ernest Hemmingway once said "Happiness in intelligent people is the rarest thing I know." and I identify with that statement. My mind is always running thinking of ways to make things better or thinking of what else needs to be done.

So, that's why I was attracted to the Happiness Project. I enjoyed reading the book and what I've really taken from it is just to let go of things. I lead an incredibly blessed life and I should not let the little things bother me quite so much. The book is quite well written in a light tone. It's organized in months where each month focuses on a particular way to improve one's happiness. This makes a lot of sense as it is hard to make new positive habits if you are trying to focus on too many things.



Thursday, November 8, 2012

My PhoneGap Plugins Have Moved

If you are looking for any of the plugins that I have contributed to the PhoneGap Plugins repo they have moved into my own repo. Why do you ask? Well you should go read Shaz's blog post as to the why's and wherefore's.

So you can now find my plugins at:

Tuesday, November 6, 2012

Building a Native Menu with PhoneGap Android

So this question has been posed to me quite a few times over the past couple of weeks so I figure this is probably a good idea for a series of blog posts. In this instalment I'll talk about creating a native menu and next time we'll use only HTML.

So when I talk about a native menu I mean an Android options menu and a lot of the information I'm going to give you is covered very well on this Android Developer page but what I'm going to do is help show you where to add the hooks into your PhoneGap application. Here is an example of an options menu from the Contacts app:


The first step in creating the menu is to define it in XML. My recommendation is to create a menu folder under the res folder in your Android Eclipse project. Then you create a new File with an XML extension. For this post I'll call mine example.xml. When your're done your res folder should look something like this:


Don't worry about the red X's as we haven't edited the XML file yet so it is going to complain about a premature end of file. For a real good description of what goes into a menu XML file read this. For our purposes I'm just going to give you the XML to paste into the file:

But when you view the file in Eclipse you'll still see errors:


and that is to be expected as we haven't added the two images to the drawables folder nor have we added our two new strings to strings.xml. To fix these issues first download these two images:


and copy them to your projects res/drawable-hdpi folder. When you want to put out a professional application you'll need to provide icons of various sizes but the above is enough for our needs.

To fix the rest of the red X's you'll need to open the res/values/strings.xml and add two new Strings. The first should have the name "settings" and a value of "Settings. The second should have the name"help" and, predictably, the value of "Help". At this point all the red X's from example.xml and from the res folder hierarchy should have disappeared. 


If they haven't, well then you've done something wrong and should probably go back over all the steps to make sure you haven't missed anything.

Okay, so now we've got all the resources in place. Let's go write some actual Java code. Don't worry much of it will be cut and paste. In Eclipse open up your main Java class, you know the one that extends DroidGap.

First we'll need to tell your application what to do when it detects that the menu button has been pressed. You'll need to paste the following code into you main Java class:

You shouldn't need to change anything unless you've called your menu XML file something different than example.xml. If you have you'll need to change R.menu.example into R.menu. where you replace with the name of your file minus the .xml extension.

The second bit of code you need to add is a method that will tell your application what to do when the individual menu items are clicked. Here's some example code:


When you click on the Setting button we'll use an Android intent to load the devices Settings panel. If you click on the Help button then we'll execute some JavaScript code. That's it! You don't need to add anything to your HTML/JS code to get a native Android options menu working with your PhoneGap application. Here is what it would look like:



Please note, I'm just providing a quick example and you are not limited to how you handle the menu button clicks in the least. You may want to handle it in Java and do something that you can't do in JavaScript or you may want to call a JavaScript function on your page to have your UI react in some interesting way.

In my next post I'll show you the reverse. How to handle everything in HTML and JavaScript!

Monday, November 5, 2012

My WD MyBook Live Crashed

Well, we had a bit of a power hiccup last week and when I got home my WD MyBook Live could no longer be recognized on my home network. Nothing I could do would get the drive working again so I had to assume the power outage fried the ethernet chip on the board of the enclosure. Googling around the internet showed other folks encountered the same problem that I have.

This is the second time a WD enclosure has failed on me. Why, oh why, do I do this to myself. I guess it is because I'm cheap and the WD products offer a good price/functionality ratio. However, what they do not offer is reliability. This is a good lesson for us all not to skimp on quality when you have an important piece of your home setup.

I guess I should explain that I use the MyBook Live to host my iTunes library. As a result it is just packed with shows for my daughter and I really need to get this fixed before she wants to watch Beverly Hills Chihuahua again. As well this drive is setup to be the receptacle of the Time Machine backup on the Mac. I get antsy if my backup isn't running daily even though I also run Carbonite to backup to the cloud.

Anyway, the drive in the enclosure is just fine. I pulled it out and popped it into SATA to USB which works great except for the fact the drive is formatted as XFS. It's a typical Linux file system which predictably isn't recognized by Mac OS or Windows. Luckily there is a great free program called Linux Reader from Disk Internals that you can run on Windows which will allow you read only access to the partitions. I've got it setup on an old Windows laptop now and it is busily copying away.

Friday, November 2, 2012

Support Canadian Comic Book Creators

Extremely talented Canadian comic book creators have put together an IndiGoGo campaign to self publish a 100 page hard cover anthology of comic stories. They are looking to raise $20,000 by November the 5th and are currently just shy of $13,000. If you love comics then this will be a great anthology to pick up. There are perks levels from $5 to $300 so they are making it so easy for you to find a contribution level you are comfortable with.

Who are they? Well there is...

Adrian Alphona


Andy Belanger



J. Bone


Jack Briglio


Scott Chantler

Tom Fowler

Agnes Garbowska she drew one of my childhood favourites Spider-Ham but I can't get the image to load.

Faith Erin Hicks I recently read all her books.
Tim Levins
Ramon Perez
Ron Salas
Jay Stephens
J. Torres
Howard Wong

I will add images for the rest of these folks as I have time but really you shouldn't need anymore convincing. Go contribute!

Books I've Read This Week

This weeks entry is a bit of an amuse-bouche as I needed to read something light between some of the weightier books I've got on the go.

Invincible Iron Man - Volume 2: World's Most Wanted - Book 1 by Matt Fraction was a bit of a mistake. I meant to get volume 1 of this run by Fraction but accidentally got volume 2 so there is no going back now! Even though I had not read the first volume which collects the first 7 issues of this comic series I was not lost upon starting to read this volume.

We pick up at a point where Iron Man/Tony Stark has been fired from his job of Director of S.H.E.I.L.D. Basically, the top cop in the world. Additionally, his multi-billion dollar company, Stark Industries, is failing and Tony has to go on the run to protect the secrets in his head from the worlds new top cop and former/current super villain Norman Osborn.

His audacious plan to protect his secrets includes erasing his memory. Dun-dun-dah!
Invincible Iron Man - Volume 3: World's Most Wanted - Book 2 by Matt Fraction picks up immediately where the last volume left off. There is a pretty interesting plot point that is continued on in this volume. As Tony continues to lose bits of his memory he has to move down the technology ladder to earlier Iron Man suits as he does not have the mental faculties to operate the more advanced armours anymore. Which is a real problem as the threats he face get exponentially more difficult to over come.

Anyway, at the end of this volume Tony is left at, arguably, the lowest point of his career. Volume 4 should be an interesting read to see how they put Tony Stark back together again.

Oh, and Salvador Larroca is the artist on both volumes. I think he is a great artist but I would be remiss if I didn't mention that some of the photo-realistic techniques he used in the book took me out of the story. It was a bit of an uncanny valley situation where the characters looked too real but not real enough. I really don't mind if my comic books look like comic books or even cartoony.