Book Image

Creating Mobile Apps with Appcelerator Titanium

By : Christian Brousseau
Book Image

Creating Mobile Apps with Appcelerator Titanium

By: Christian Brousseau

Overview of this book

Smartphones and tablets have really changed the technological landscape over the last 3-4 years. Much like the web did in the last decade, these powerful tools have changed the way people communicate and access information. Such a wide market creates opportunities for developers who have the skills to develop mobile applications. "Creating Mobile Apps with Appcelerator Titanium" is a practical, step-by-step guide to building iPhone, iPad, and Android applications using JavaScript. This book will give you a solid grounding of the dos and don'ts of mobile development and also covers a lot of the functionalities offered by the Titanium platform. This book begins with a look at what the Titanium platform has to offer. By taking you through clear tutorials on developing each application step-by-step, it helps you to apply your newly acquired knowledge afterwards. The difficulty level gradually increases along the course of the book. Each application from this book covers different aspects of mobile development. Every chapter starts by defining the application's features as well as the user interface structure. Every single code section is then explained and put into context allowing you to gain a clear understanding of their purpose and functionality. The book takes a “small milestone” approach, allowing you to actually run the application and see the progression. Every step is accompanied by many screenshots so you can see the expected result on screen. You will learn everything you need to know to develop your very own mobile applications. The book takes a laid-back approach to Titanium development and provides information in a way designed to never overwhelm the reader with information and also uses clear diagrams, screenshots, and tips throughout.
Table of Contents (18 chapters)
Creating Mobile Apps with Appcelerator Titanium
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Most people are familiar with Titanium Mobile SDK, which allows developers to develop native mobile applications using JavaScript. But Titanium SDK is part of a much larger ecosystem.

Titanium core

What many consider as the main component of Titanium, comprises three major components discussed in the following sections.

Titanium Mobile SDK

Any developer who wants to develop mobile applications using Titanium must use the SDK. It comprises more than 5000 APIs.

The SDK is developed by a company named Appcelerator, but it is an open source project and is released under the Apache License. This means that you can look at the source code and even modify it if you wish.

Titanium studio

Studio is an Integrated Development Environment (IDE) based on Aptana Studio (which itself is based on the Eclipse platform). It offers all of the basic features you would expect from an IDE, such as project management, code editor, and some pretty powerful features such as debugging.

While Appcelerator distributes it for free, it is not an open source product. They do, however, provide an SDK if you ever wish to expand some of its features.

Appcelerator analytics

This is an analytics module for developers who want to track the deployment of their app.

The service is free up to a certain point. This means that if you generate a lot of traffic, you will probably have to move over to a paid service plan.

Appcelerator Cloud Services

Appcelerator Cloud Services (ACS) is a cloud service that offers over 20 prebuilt common services you would expect from a cloud service provider. It becomes interesting when it is in very tight integration with the native SDK.

Simply create a new project in Titanium Studio, and boom, you have a cloud-enabled application! This saves enormous efforts in terms of integration. Like analytics, the service is free up to a certain threshold. If you go over that, you will have to move to a paid plan.

Also, ACS is not limited to Titanium applications. In fact, they offer SDK for other platforms and languages as well.

What if this is not enough for my needs?

The day will come where all the APIs offered by Titanium won't be able to fulfill one specific need. Specific as it may be, it might prove vital for your business. Titanium allows more experienced developers to develop extension modules. The name says it all; extension modules extend the capabilities of Titanium while keeping the compatibility with the existing JavaScript code.

This is interesting because some platforms would require you to rewrite the entire application in their respective language (objective C or Java), just to have access to one specific feature of the platform.

Module developers can also hope to recoup their investment by distributing their modules on the Appcelerator marketplace, where other developers can download existing modules (for free or for a fee).

What are the goals of this book?

Each chapter covers the development of a complete mobile application. At the end of each chapter, you will have a working mobile application whether it's for iOS, Android, Blackberry 10, Tizen, or even Mobile web. There is no better way to learn how to do something than building it yourself. Developers can start from any application that has similarities to the one they wish to produce and extend it from there.

Another goal of this book is to introduce some aspects of Titanium that are probably less known by mobile developers.

What this book covers

Chapter 1, Stopwatch (with Lap Counter), guides the reader in creating a standalone Stopwatch application. This first application is pretty straightforward; it covers interactions between user interface elements and data structures.

Chapter 2, Sili, the assistant that just listens, guides the reader in creating a voice recorder application. While Siri interprets what the user is saying, this application simply listens by storing the recordings on the device for later use. It covers media management as well as file system access on the device.

Chapter 3, The To-do List, guides the reader in creating a To-do items management application. It allows the creation and deletion of items, as well as the possibility to mark them as done. All items are persisted in an SQLite database. It covers the integration with an embedded database.

Chapter 4, Interactive E-book for iPad, guides the reader in creating an interactive electronic book (e-book) application with realistic page flipping (like a real book). This is an iPad-specific application in order to benefit from the large screen resolution. It covers the integration and utilization of a native module as well a rich media presentation.

Chapter 5, You've Got to Know When to Hold 'em, guides the reader in creating a standalone Stock Portfolio application. It allows users to organize stocks (price and quantity). From there, the user selects an amount of money he/she wants to gain through his/her investments. The application will periodically retrieve stock prices from the web and calculate the sum of money earned. It will then indicate how far (or close) he/she is from his/her objective. It covers HTTP API calls, property persistence, and custom UI controls.

Chapter 6, JRPG – Second to Last Fantasy, guides the reader in creating a native mobile game. The game shows how players roam around a map from a top view perspective, much similar to a classic Japanese RPG. It covers graphics manipulation and touch control.

Chapter 7, JRPG – Second to Last Fantasy Online, guides the reader in adding online multiplayer functionality to a game. This chapter re-uses the code from the game created in Chapter 6, JRPG – Second to Last Fantasy. It covers network interaction, intervals, and testing.

Chapter 8, Social Networks, guides the reader in creating a social application that allows them to update their status on Facebook and Twitter with a single click. It covers application preferences, social network authentication, and integration.

Chapter 9, Marvels of the World Around Us, guides the reader in creating an application that shows online pictures that were taken near the device's current location. It covers location services, web API calls, and photo gallery integration.

Chapter 10, Worldwide Marco Polo, guides the reader in creating a social application that allows users to check in at a location based on the device's location and then share this check in with the world using Appcelerator Cloud Services. It covers location services, cloud integration, and map view.

Appendix, References, contains detailed information about the JavaScript frameworks, libraries, and native extension modules used throughout the book, as well as download locations, and where to find the source code (when applicable).

What you need for this book

You will need a computer with at least 2 GB of memory and a recent version of Windows, Mac OS X, or Ubuntu in order to use Titanium SDK properly. You will also require the Oracle Java Development Kit as well as an install of Node.js to use the Titanium Command Line Interface (CLI) tools.

If you are developing an iOS application, you will also need to install the Xcode Integrated Development Environment (IDE). For Android development, you will need the Android SDK provided by Google for free (Titanium Studio provides wizards that can automate the installation).

To develop iOS (iPhone, iPad) applications, you absolutely need a Mac. This limitation is enforced by Apple requiring the use of its own tools. This is not related to Titanium.

Who this book is for

This book is geared towards developers who already have experience with more modern languages and development environments. It is for those who are also familiar with concepts such as Object Oriented Programming (OOP), reusable components, AJAX closures, and so on. This book is also geared for those who are not yet familiar with mobile development, but have a keen interest in this topic.

The book is geared towards existing Titanium developers, who have some (or more) experience with the SDK and the toolset; it is also for those who wish to know more about Titanium and its broad range of capabilities (many of them are not yet very well known). This book can help developers identify how they can extend Titanium's basic set of features by using the extension modules.

This book begins with the basics in the first chapters and it increases throughout the course of the book. The first few chapters will give very detailed step-by-step procedures.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: " We create the window using the Ti.Ui.createWindow function."

A block of code is set as follows:

var win = Ti.UI.createWindow({
  backgroundColor: '#ffffff',
  layout: 'vertical'
});

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

var buttonStartLap = Ti.UI.createButton({
  title: 'GO!',
  color: '#C0BFBF',
  width: '50%',
  height: Ti.UI.FILL,
  backgroundColor: '#727F7F',
  font: {
    fontSize: '25sp',
    fontWeight: 'bold'
  }
});

Any command-line input or output is written as follows:

[INFO] 00:01:17:37
[INFO] 00:02:53:19
[INFO] 00:04:06:93
[INFO] 00:06:11:52

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "In the Classic section, select the Default Project template, and then click on Next >."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: http://www.packtpub.com/sites/default/files/downloads/9267OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.