Category Archives: Android

Halloween Fun with PhoneGap

About two weeks ago I had a random thought… “Wouldn’t it be fun to build a free Halloween sound effects app using PhoneGap?” (I tend to get excited for any holiday). I had already done a lot of work using sounds in PhoneGap apps with my LowLatencyAudio native plugin, so the groundwork had already been laid.  Next thing you know, I’m searching for sound files (freesound.org is a fantastic resource for creative commons sound effects). Write some JS code here, add some CSS styles code there, and next thing you know I had a complete app. The best part – this app went from idea to App Store submission in under 48 hours (yes, I did sleep during this 48 hour period). Add one more day, and it’s ready for Android.  That is the power of PhoneGap.

Now, I’d like to introduce you to “Instant Halloween”. Instant Halloween is a Halloween-themed sound effects app built with PhoneGap. My app store description is:

Instant Halloween is a fun holiday application to help you scare the pants off of your friends! Use it to create a creepy ambiance, or play scary Halloween sound effects to liven up any situation. This app is best experienced turned up really loud!

Check it out in the video below, and make sure you have your sound turned on!  

It is definitely best when turned up really loud. There’s nothing like an ear-splitting shriek combined with the thumping bass of the heartbeat and thunder in the background. I connected it to a home theater with a decent subwoofer, and it was awesome. Setup some speakers in the bushes next to your front door, and you could use this to really scare some children on Halloween. (I take no responsibility for your actions.)

You can download it for free today for both iOS and Android devices:

 

It supports both phone and tablet form factors, which you can see in action here:

I started out using CSS media queries and Twitter Bootstrap for a responsive layout.  However, I ran into a few issues with column layout and content wrapping, so I ended up going with a totally custom solution.

Of course, just releasing a new PhoneGap app in the ecosytems isn’t enough.  As usual, I’m releasing the full source of this application for anyone to explore and learn from.  All HTML/JS/CSS source code between the iOS and Android versions is exactly the same (note: I’ve submitted an updated build pending approval for iOS to bring it in parity with the Android build).

You can download the full application source code at https://github.com/triceam/Instant-Halloween.  Be sure to also read the README file for complete set up instructions and references to the sound files.   This project uses my LowLatencyAudio PhoneGap native plugin for layered sounds in PhoneGap applications.

Sounds

The audio assets are not redistributed in GitHub due to copyright law. However, all of these assets are available under Creative Commons licenses from freesound.org. Be sure to review the individual licenses for each file before any attempt to use them in any commercial or non-commercial work. You can access specific download links in the readme.

All sound files were converted to 16bit 22050 Hz MP3 files. You can use a higher quality/bitrate if you want. I chose the lower quality due to skipping and memory issues on older/low-end Android devices.

Attribution

The font used within this application is “Creepsville”, available for free. An embedded font was chosen over a hosted web font so that the font will still work in offline scenarios. The TTF font was converted for in-browser use with Font Squirrel Generator.

The “Skull” icon used by this application is by Tim Piper, from The Noun Project

Code Libraries

The following libraries were used within this application:

  • Zepto - for quick and easy DOM manipulation
  • iScroll - for cross-platform touch-based scrolling of visual elements
  • MustacheJS - for HTML templating

Quick Links

Enjoy!

Introducing “Walkable” – A New Sample App for PhoneGap

I’d like to take a moment and introduce “Walkable Restaurants” (or just “Walkable” as I like to call it), a new application that I built to demonstrate how to create PhoneGap applications using Backbone.js.

Walkable Restaurants provides you with an easy way to find a bite to eat or refreshing drink anywhere in the US. Either select a type of cuisine, or enter a search phrase, and the Walkable Restaurants app will find destinations that are nearby.  Only destinations near your current location will be returned in your search result. If we are able to calculate travel times based upon walking and train schedules, then we will only return destinations within a 20-minute walk. If we are not able to calculate walk time, only destinations within 2.5 miles of your current location will be displayed.

Walkable Restaurants is available today for FREE in both Apple’s App Store and on Google Play, so go download it now!

        Get it on Google Play

Code Organization

The code for this application uses Backbone.js for client-side JavaScript Model-View-Controller patterns. Backbone.js provides separation of concerns (discrete, reusable classes, with separation of view logic from application logic). However, in this example I am not using Backbone’s data binding features – these enable your views to auto-update when your data changes.

Backbone is built on top of Underscore.js, and leverages Underscore’s templating engine to separate HTML string concatenation from application logic.

Open Source

The Walkable Restaurants application source code is freely available and open source on GitHub at: https://github.com/triceam/Walkable-App

Application source code is intended to be used as a learning tool for building PhoneGap applications using backbone.js, but there are no limitations on its use following the MIT license.

Open source libraries used in this app include:

Data Services

All walking/travel time distance calculations are obtained through Travel Time, by Igeolise. This service calculates travel time between geographic locations based upon walking, driving, and mass transit systems.

All point-of-interest (POI) information is obtained through services provided by factual.com. This application uses the U.S. Restaurants data set, which provides information for over 800,000 restaurants across the United States, including location, price ratings, cuisine, and more.

The server-side portion of this application simply aggregates data from Factual and Travel Time, and is developed with node.js, using the expressjs framework.

Also, I almost forgot – Many thanks to Tony Weeg of Revolution Web Design, who I used as a sounding board for UI design & layout ideas for this app!

Enterprise Android Apps W/ PhoneGap

Here are my presentation slides and extra content from last night’s DC Droids meetup. I gave the presentation “Enterprise Android Applications With PhoneGap“.  There were excellent questions and conversations at last night’s event – Thank you everyone for attending, and making it a great meetup.

You can view the presentation here:

Or access the presentation content at: https://github.com/triceam/Presentations.

Here are two of the apps I presented, with source code and additional details:

I discussed strategies for data visualization in PhoneGap apps, which you can read more about here: Data Visualization With Web Standards.

I also discussed code organization and client-side MVC in PhoneGap apps.   I personally have used backbone.js on several projects (although neither of the ones mentioned above).   Other popular frameworks are Angular.js, Ember.js, and Knockout.js. You can read more about various and comparisons of JavaScript client-side MVC frameworks all over the web, but Smashing Magazine has a pretty detailed summary.

Presentations: Intro To PhoneGap, Web Data Viz & PhoneGap Native Plugins

As promised, here are my presentation slides and extra content from last week’s RIACon conference. I gave three presentations: “Intro to PhoneGap”, “Data Visualization With Web Standards”, and “PhoneGap Native Plugins”. All of the presentations are freely available at: https://github.com/triceam/Presentations.


Intro To PhoneGap

Click to view presentation

PhoneGap is an application container that allows you to build natively installed mobile applications using HTML, CSS, & JavaScript.

  • Build your applications using HTML, CSS, & JavaScript
  • Use the PhoneGap API to communicate with the native OS
  • PhoneGap packages your app into a distributable binary

For more detail, check out these posts:

PhoneGap related services:

Sample apps with source code:


Data Visualization With Web Standards

Click to view presentation

Data visualization is the art & science of creating a visual representation of data and information.  Really, it can be anything: a bar chart, scatter plot, pie chart, complex flow diagram, 3d model, etc…  If your visualization conveys information without having to read a table of data, then it’s doing what it should. Recently, the emergence of HTML5′s dynamic graphics and SVG support have made rich, dynamic, and interactive graphics possible on the web without having to leverage Flash, which was previously the only real option. Be sure to check out this presentation, and read this blog post for more info: Data Visualization With Web Standards


PhoneGap Native Plugins

Click to view presentation

PhoneGap provides you with the ability to create natively-installed mobile applications using web technologies.  As a part of this, PhoneGap provides an API to access native operating system functionality from JavaScript. Luckily for everyone, the JavaScript-to-native bridge is extensible and you can very easily create and expose your own custom native functionality with a JavaScript API.  Basically, all PhoneGap native plugins are made up of two parts: a native implementation, and a JavaScript interface.  Your PhoneGap application calls the JavaScript interface, which leverages cordovoa.exec to communicate with the native layer.  The native layer then performs a native operation and communicates back to the JS layer.

Read more about PhoneGap native plugins from:

…and of course, the sample apps:

iOS Multi-Screen

This sample app demonstrates how to create multi-screen experiences using the UIScreen API on iOS.  You can use AirPlay mirroring on an AppleTV as a second screen, the content of which is entirely controlled by the JavaScript in the “main” PhoneGap experience on the device. Check out the links and video below to learn more.

LowLatencyAudio

The PhoneGap LowLatencyAudio native plugin for Android and iOS allows you to preload audio, and playback that audio quickly, with a very simple to use API.  It overcomes the current limitations of the HTML5 Audio API on many mobile devices. Check out the links and video below to learn more.

MegaList jQuery Plugin

I’ve been working on lots of different projects lately.  On several of them, I’ve had the need for a reusable list component.  In some cases, it needed to handle a large data set, in others it just needed to be self-contained and easy to use.   Out of these projects came MegaList: a reusable list component for jQuery, which I’ve released as open source on Github.

MegaList is a jQuery plugin that creates a touch-enabled list component, capable of very large datasets, complete with data virtualization. It was originally intended for touch-enabled devices, however it also works in many desktop browsers.

For performance optimizations, the list component uses data virtualization techniques, so there are never more list elements in the HTML DOM than what is currently visible on the screen. As the user scrolls through content, the list updates the DOM elements accordingly. This makes scrolling lists of thousands of items extremely fluid.  This works in a very similar way to ItemRenderer classes in Flex list and grid components.

You can employ the list component using one of two approaches.  One option is to declare the list structure in HTML markup, another option is to specify a dataProvider array, from which the list will create DOM elements.


Why?

Sometimes you need a pre-built list that you can reuse. Sometimes you need to scroll through big data sets, and other times you just need component logic kept away from your app logic. It doesn’t fit every scenario, but it certainly fits a few.

Data virtualization techniques allow you to quickly scroll through massive lists, without performance degradation. However, if your app really has 100K list items to scroll through, you should fire your UX designer.


Samples

View the “samples” directory to see the scrollable list component in action. All samples are interactive, and scrollable via touch or mouse events, with function event handlers.

Each of these examples can be scrolled using either the mouse or finger, and just tap/click on a row to select it, invoking the selection handler (alert message). On the desktop, you can also scroll with the scrollbar. Note: I originally intended this for mobile – on the desktop, I’ve only tested in Chrome and Safari.

Simple List Created With Inline LI Elements
This is a basic example with a list of 50 LI elements.

Simple List Created With A DataProvider of 100,000 items:
This is a more complex example using a massive data provider (100,000 elements!) with a label function.

Styled Dynamic List Created With Remote Data:
This is a dynamic example pulling data from twitter for a dataprovider, with a label function that returns HTML, instead of plain text strings.

Note: These inline/embedded examples are contained inside of iframes – if you mouse-up outside of the iframe, the iframe contents won’t receive the event. If MegaList is used in a page, without a wrapping iframe, you don’t run into this issue. Follow the “View Sample” links above to see them without the iframe issue.


Observations

  • Contrary to my expectations, using CSS3 translate3d is actually slower than using CSS top/left when placing the virtualized content. If you enable CSS3 translate3d and set backface visibility, there is an extremely noticeable performance degradation on both desktop and mobile devices.
  • I’ve experimented with lots of permutations to get the best performance possible. I’m not finished yet, but I’ve found that you can achieve significantly faster performance of DOM manipulation by removing elements from the DOM, manipulating them, then re-adding them. This is what is done within the updateLayout() method. The <ul> is removed from the DOM, <li> elements are added or removed, and then the <ul> is added back to the DOM. You may see a flicker on rare occasions, but I didn’t find this overly intrusive.
  • For small data sets, this may not be much advantage – you can get better performance by just using something like iScroll in a <div> containing a <ul>. With large data sets, this is definitely faster.
  • The more complex the HTML inside of your label function, the slower the animation will be.

Download

The full source code for this component is available on Github. Check out the landing page for API documentation and samples.