Friday, April 29, 2011

PhoneGap Lifecycle Events

With the release of PhoneGap version 0.9.5 all of the major platforms (Android, BlackBerry and iOS) now support lifecycle events. Documentation for the events will be available in the Events section of docs.phonegap.com but I thought I'd put together a small post explaining it in more details.

Whenever talking about events a finite state diagram is usually the best place to start.


When you start an application the load event is fired when all of the content has finished loading.  You can register an event listener for the load event in the body tag.
<script type="text/javascript" charset="utf-8">

function onLoad() {
  // handle on load event
}
</script>

<body onload="onLoad()">

However, this is not the most important event from a PhoneGap perspective. The PhoneGap API is not ready until you receive the deviceready event.  You should register for the deviceready event in your load event handler.  Wait until you get this event before you start calling PhoneGap API commands.
<script type="text/javascript" charset="utf-8">

function onLoad() {
  document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
  // PhoneGap is ready to be used
}
</script>

<body onload="onLoad()">

Once your application is up and running you can register for a couple of other lifecycle events in pause and resume.  The pause event is called when your application leaves the foreground and is suspended by the operating system.  The application is not closed it is just in the Paused state.  When the application is returned from the background and placed into the foreground the resume event is fired and your app is back in the Running state.
<script type="text/javascript" charset="utf-8">

function onLoad() {
  document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
  // Register the event listener
  document.addEventListener("pause", onPause, false);
  document.addEventListener("resume", onResume, false);
}

function onPause() {
  console.log("I've been paused");
}

function onResume() {
  console.log("I've been resumed");
}

</script>

<body onload="onLoad()">

When you application exits the unload event is called.  This is a useful event if your application needs to save some state data. You would register your unload listener the same as you would for the load event by adding it to the body tag.
<body onload="onLoad()" onunload="onUnLoaded()">

It is worth noting that if your application is in the Running state when it told by the OS to unload it will first be paused so the pause event will fire before the unload event.

If you want the full HTML listing you can find it here.

Thursday, March 24, 2011

Worlds Colliding: Comics at Starbucks

It looks like I will be spending more time at Starbucks as Marvel Comics will be offering free access to Marvel Digital Comics Unlimited on the Starbucks Digital Network.  Digital Comics Unlimited is a way for folks to read Marvel comics from their computer. The SDC is a network only accessible from Starbucks free wifi giving users access to speciality content.

Friday, January 28, 2011

Starbucks Ticked at Kraft

Apparently Starbucks is very ticked off at Kraft foods right now.  Starbucks entered into a 13 year agreement with Kraft to push their coffee out into grocery stores and other venues.  To say the partnership hasn't been a success is a bit of an understatement.  Sales of their instant coffee, Via, in grocery stores seems to be tanking.  See the picture left for an example of how my local grocery store is slashing the price (over 50%) of Via to move the product off it's shelves.

In addition to that Starbuck's is missing out on the single serve coffee bonanza that is currently going on.  Since Starbucks is only available on the Tassimo (3% market share) coffee maker it is unavailable to the majority of single serve coffee makers as the Keurig brand controls about 70% of the market.

As much as I enjoy Starbucks coffee the availability of many different k-cups for the Keurig was the tipping point when we were deciding what single server coffee maker we would get at Christmas.

Thursday, January 20, 2011

Where to Buy K-Cups in Ottawa

Thanks to Meegs I was directed to the Tweed and Hickory as a good place to pick up K-Cups. They had an in-store deal that allowed you to create a sample pack of 24 k-cups for $16.49 taxes included. The offer similar deals on line for 5, 10, 50 and 100 sample packs.

So far my favourite brew of the k-cups we picked up was Coffee People's Tree Hugger which is currently sold out on the on-line Tweed and Hickory store so I'm guessing other people like it as well.

Monday, January 17, 2011

Help me de-clutter my office

While this isn't a picture of my office it is indicative of the amount of books and videos I have hanging around.  I'm looking at doing some winter cleaning to make room for a number of items I received for Christmas.

To that end I'm putting a number of books and DVD's on sale for rock bottom prices.  Take a look at the following list and let me know if you'd be interested in any of them.  If you are leave a comment on the blog or @ me on twitter.

Books

$5 Paperbacks
Deathgate 1: Dragon Wing by Weis and Hickman
Deathgate 2: Elven Star by Weis and Hickman
Deathgate 3: Fire Sea by Weis and Hickman
Deathgate 4: Serpent Mage by Weis and Hickman
Deathgate 5: The Hand of Chaos by Weis and Hickman
Deathgate 6: Into the Labyrinth by Weis and Hickman
Deathgate 7: The Seventh Gate by Weis and Hickman

DVD's

$10 Collections
Family Guy Volume 1
Family Guy Volume 2
The Simpson's Season 1
The Simpson's Season 2
The Simpson's Season 3
The Simpson's Season 4

Graphic Novels

$5 Trades
Incredible Hercules: Against the World
JLA: Tower of Babel
Starman Vol 1: Sins of the Father
Starman Vol 2: Night and Day
Starman Vol 5: Infernal Devices
Starman Vol 6: To Reach the Stars
Starman Vol 7: A Starry Knight
Starman Vol 8: Stars My Destination
Starman Vol 9: Grand Guignol
Starman Vol 10: Sons of the Father

$10 Hardcover
X-Men Noir

$15 Collections
Cerebus by Dave Sim
High Society by Dave Sim
Church and State I by Dave Sim
Church and State II by Dave Sim
Jaka's Story by Dave Sim
Melmoth by Dave Sim
Flight by Dave Sim
Women by Dave Sim
Reads by Dave Sim
Minds by Dave Sim
Guys by Dave Sim
Rick's Story by Dave Sim
Going Home by Dave Sim
Form and Void by Dave Sim
Latter Days by Dave Sim

$20 Hardcover
Avengers/Invaders