Building the Derby App in Titanium –  Page 297.  see Chapter 10 
Page 297.  see Chapter 10 – Alternative Formats
For the submission describe/explain/answer the following:
1. Describe in short standard ways to represent data, make selections, navigation patterns, and display quick alerts to the user.
2. Explain the use of offline storage.
3. What is GPS device Accelerometer used for?
Building the Derby App in Titanium ! 297
Once this is set you are ready to begin building your application.
The same patterns explained in the native application chapters are used to develop the Derby Names
application, only this time in Titanium. You create the UI, using some of the device features (GPS,
Accelerometer), and communicating with the web service you created in Chapter 3.
Common UI Patterns
This section discusses the basic patterns in mobile applications: standard ways to represent data,
make selections, navigation patterns, and display quick alerts to the user.
The Table UI element is the standard way to display data.
You can bind JSON objects directly to tables (as long as they have a title element):
var data = [{title:”Row 1”},{title:”Row 2”}];
var table = Titanium.UI.createTableView({data:data});
Or you can bind arrays of TableViewRow objects. When you create a TableViewRow object you can
assign other UI elements to the row as well:
function BindTeamsToTable(dataFromService)
var dataToBind = [];;
for (var i=0; i 0)
cityToQueryBy = places[0].city;
derbyService.getTeamsByCity(cityToQueryBy, bindDataCallback);
function bindDataCallback(data)
if (data.length > 0)
//There were teams based on your search criteria bind them to a UI element.
//This would live in derbyservice.js
this.getAllNames = function (queryVal, successFunction)
//OData Filter to look for Teams by City By Name
var serviceString = baseServiceUrl +
“DerbyNames?$filter=League like ‘%” + queryVal + “%’”;
odata.getData(serviceString, successFunction);
You can use a headingfilter as opposed to a distancefilter to track only where the user is
going, versus information about where the user is. Difference in use cases would be a location-based
application (foursquare), versus a heading-based app (compass).
Now that you understand location-based events, the next section discusses interactions with your
Both the iPhone and Android devices have a built-in accelerometer and Titanium has an API for
accessing it. The Titanium.Accelerometer namespace provides access for adding an event listener
to read the coordinates of the accelerometer data, but the Appcelerator documentation recommends
that you remove the event listener when not in use.
Common uses for accelerometer data include triggering aspect changes (portrait
to landscape), triggering media (turn the ringer off when the phone headset is set
down), and randomizing navigation (spin the wheel, or shake to refresh).
c10.indd 306c10.indd 306 28/07/12 6:07 PM28/07/12 6:07 PM
Building the Derby App in Titanium ! 307
Here is a basic example of checking your accelerometer data on the x-axis:
var shakeCount = 5;
var xShakes = [];
if (shakeCount > 0)
Ti.API.debug(“accelerometer – x:”+e.x+”,y:”+e.y+”,z:”+e.z);
WhipItGood(xShakes[0], xShakes[3]);
var shakeThreshold = 1.5;
function WhipItGood(int x1, int x2)
if((x1 – x2) >= Math.abs(shakeThreshold))
{“It can be said that on the x axis this device has been Whipped
function GetRandomDerbyPlayer()
//Get a random Number (at last count our record count was around 25k
var randomNumber=Math.floor(Math.random()*25001)
derbyService.getDerbyPlayerById(randomNumber, randomDerbyCallback);
function randomDerbyCallback(data)
if (data.length > 0)
//You received a random derby player.
//This would live in derbyservice.js
this.getDerbyPlayerById = function (queryVal, successFunction)
//OData Filter to look for Teams BY City BY Name
var serviceString = baseServiceUrl +
“DerbyNames?$filter=DerbyNameId eq ‘” + queryVal + “’”;
odata.getData(serviceString, successFunction);
c10.indd 307c10.indd 307 28/07/12 6:07 PM28/07/12 6:07 PM
Titanium is not a magic bullet. It is a solid framework for developing a single codebase to deploy to
multiple platforms. In addition, it allows developers to use a language they are more familiar with
to create apps in a domain outside of their knowledge. Titanium is not an exact match to native
languages. Not all features of the mobile platforms are exposed (or can necessarily be exposed) in
its API. With the addition of Titanium Studio, developing in the framework has grown by leaps and
bounds. The team at Appcelerator works to pack as much functionality into their framework as
possible. Titanium is an excellent tool to learn mobile device programming, and for many projects
can provide the necessary functionality to deliver a fi nished product.
c10.indd 308c10.indd 308 28/07/12 6:07 PM28/07/12 6:07 PM

Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.