Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Appcelerator Titanium Application Development by Example Beginner's Guide
Appcelerator Titanium Application Development by Example Beginner's Guide
Appcelerator Titanium Application Development by Example Beginner's Guide
Ebook758 pages3 hours

Appcelerator Titanium Application Development by Example Beginner's Guide

Rating: 0 out of 5 stars

()

Read preview

About this ebook

In Detail

Appcelerator Titanium is the leading method for creating native cross-platform apps. This book guides you from the initial stages with the language right through to the submission of your app to the marketplace/app store. Specially crafted examples cover the most common requirements of an app programmer. This book will be your companion as you progress with the language.

"Appcelerator Titanium Application Development by Example Beginner's Guide" will guide you through the process of designing cross-platform apps using Titanium. It covers all areas of the language from installation through development to submission to the store.

This book will take a hands-on approach in teaching you how to write cross-platform apps using Titanium, as well as exploring the new features of Titanium 3. Each chapter will show you how to overcome specific challenges using Titanium. You will learn how to design your apps using MVC principles and Alloy, use the cloud to your advantage, develop apps that work on tablets and phones, use the phone gadgets like the accelerometer, integrate social media, record usage using analytics, and monetise your app. All tasks from installation to deployment to the store are covered and backed by examples. The book will be your companion from your first steps with Titanium to successful live deployment.

Approach

"Appcelerator Titanium Application Development by Example Beginner's Guide" is an example-driven tour of the language that guides you through all the stages of app design. The style is relaxed and friendly whilst remaining concise and structured.

Who this book is for

If you are new to this technology or curious about the possibilities of Appcelerator Titanium then this book is for you. If you are a web developer who is looking for a way to craft cross-platform apps, then this book and the Titanium language is the choice for you.

LanguageEnglish
Release dateApr 24, 2013
ISBN9781849695015
Appcelerator Titanium Application Development by Example Beginner's Guide
Author

Darren Cope

Darren Cope is an experienced Titanium developer having seen the light and the potential of what could be done with Titanium back in early 2011. Since 2011 he has released several cross-platform apps using the technology. He holds TCAD and TCMD certifications and along with creating apps, he has developed modules for the Appcelerator Marketplace. He attended the inaugural CODESTRONG conference in San Francisco in October 2011 and continues to preach the benefits of coding with Titanium through the Appcelerator Titans program. He is very eager to hear from other Titanium developers in the north of England and is trying to start a user group for them. He can be contacted either through his personal website at http://darren.cope.name or by e-mail on mail@darren.cope.name.

Related to Appcelerator Titanium Application Development by Example Beginner's Guide

Related ebooks

Enterprise Applications For You

View More

Related articles

Reviews for Appcelerator Titanium Application Development by Example Beginner's Guide

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Appcelerator Titanium Application Development by Example Beginner's Guide - Darren Cope

    Table of Contents

    Appcelerator Titanium Application Development by Example Beginner's Guide

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Time for action – heading

    What just happened?

    Pop quiz – heading

    Have a go hero – heading

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. How to Get Up and Running with Titanium

    System requirements and restrictions

    Installing Titanium

    Time for action – installing Titanium Studio

    What just happened?

    Setting up Titanium Studio

    Time for action – setting up Titanium Studio

    What just happened?

    Installing the Android SDK

    Time for action – configuring the Android SDK

    What just happened?

    Installing the iOS SDK

    Time for action – configuring the iOS SDK

    What just happened?

    Installation problems – did something go wrong?

    Your first cross-platform app

    Time for action – creating an app from a template

    What just happened?

    Time for action – running an app in the emulator

    What just happened?

    Did the app fail to run?

    A review of the first app

    tiapp.xml

    tiapp XML structure explained

    Other files in the base directory

    The Resources directory

    app.js

    KS_nav_ui.png and KS_nav_views.png

    The Android and iPhone directories

    Pop quiz - Titanium installation and configuration

    Summary

    2. How to Make an Interface

    What's in the toolkit?

    A recap

    Window

    Tab group and tabs

    Creating a tab group

    Creating a tab

    Labels

    Views

    Time for action – adding a view to a window

    What just happened?

    Time for action – adding a button to a view

    What just happened?

    Time for action – making something happen when the button is pressed

    What just happened?

    Adding a settings screen – a TableView masterclass

    Time for action – adding a new window

    What just happened?

    Time for action – adding a styled TableViewRow object

    What just happened?

    Platform-specific tools

    Adding an Android menu

    Time for action – adding an Android menu

    What just happened?

    Time for action – running the Android menu changes on iOS

    What just happened?

    Why did this fail?

    Isolating platform-specific code

    Time for action – add an iOS fix for the Android menu

    What just happened?

    Capturing debug messages

    Coding iOS specific elements

    Time for action – adding an info button to the navigation bar

    What just happened?

    Summary

    3. How to Design Titanium Apps

    JSON

    Extending your app over multiple files

    Titanium.include

    Time for action – creating an activity indicator

    What just happened?

    Require

    Require – loading a marketplace module

    Time for action – adding an Appcelerator marketplace module

    Have a go hero - enhancing the paint app

    Require – promoting commonJS compliant code

    MVC

    Time for action – creating a better designed app using MVC

    What just happened?

    Behind the scenes – a look at the code

    What does this mean?

    An example of require

    Alloy

    Time for action – creating an Alloy app

    What just happened?

    Pop quiz - Titanium design

    Summary

    4. Gluing Your App Together with Events, Variables, and Callbacks

    Sharing data

    Execution context

    Global variables

    What is the right way to share data?

    Time for action – sharing information between windows

    What just happened?

    Events

    Event scope

    Event properties

    Making something happen – fireEvent

    Time for action – creating a progress bar game

    What just happened?

    Global event listeners and garbage collection

    Better event code using callbacks

    Have a go hero - adding callbacks

    Pop quiz - events

    Summary

    5. It's All About Data

    External data

    Time for action – creating an HTTP request

    What just happened?

    RSS reader

    Time for action – fetching RSS

    What just happened?

    Time for action – parsing and displaying the RSS

    What just happened?

    Storing data on the device

    Which one should you use; filesystem, database, or properties?

    Storing data in files

    Storing data in the database

    Storing settings in Ti.App.Properties

    Time for action – comparing the speed of database, file, and application properties

    What just happened?

    YQL

    Time for action – creating a foreign exchange list

    What just happened?

    Have a go hero - adding offline storage

    Pop quiz - data handling

    Summary

    6. Cloud-enabling Your Apps

    Before the cloud

    Which cloud services can you use with Titanium?

    Clouds are everywhere

    Appcelerator Cloud Services

    Time for action – creating ACS custom objects

    What just happened?

    Uploading pictures

    Time for action – uploading a photo to the cloud

    What just happened?

    Fetching ACS stored content

    Time for action – creating a panel to show commentary entries

    What just happened?

    Parse

    Time for action – storing custom objects using Parse

    What just happened?

    StackMob

    Other cloud offerings

    Choosing your cloud service

    Pop quiz - cloud services

    Summary

    7. Putting the Phone Gadgets to Good Use

    The camera

    Time for action – using the camera

    What just happened?

    Time for action – selecting a photo from the photo library

    What just happened?

    Have a go hero - e-mailing a camera photo

    The accelerometer

    Time for action – showing the accelerometer on a slider

    What just happened?

    Time for action – smoothing the accelerometer response

    What just happened?

    Have a go hero - tuning the filer response

    The compass

    Time for action – displaying the compass heading

    What just happened?

    Augmented reality

    Time for action – creating a simple augmented reality app

    What just happened?

    Have a go hero - extending the AR example

    Maps

    Time for action – adding a map

    What just happened?

    Time for action – adding annotations to a map

    What just happened

    Directions

    Time for action – adding directions to a map

    What just happened?

    Geolocation

    Are we allowed to get the location?

    Accuracy and battery life

    Time for action – getting the current location

    What just happened?

    Have a go hero - getting the address of a location using reverse geocoding

    Computing the distance from a coordinate

    Time for action – getting the distance from a coordinate

    What just happened?

    Showing the user's current location on a map

    Time for action – showing the user's location on the map

    What just happened

    Pop quiz - gadgets

    Summary

    8. Creating Beautiful Interfaces

    How to position and size items on a window?

    So what is a DIP and what's so good about it?

    Time for action - making DIPs the default unit for your app

    What just happened?

    What about percentages?

    Using views to create your layout

    Orientation

    Restricting the orientation

    Time for action – restricting the orientation of your app (iPhone)

    What just happened?

    Time for action – restricting the orientation of your app [Android]

    What just happened?

    Changing the orientation manually

    Time for action – forcing an orientation change (all platforms)

    What just happened?

    Creating layouts for phones and tablets

    Time for action – creating a multiplatform interface

    What just happened?

    Time for action – creating a phone layout for your app

    What just happened?

    Pop quiz - creating a layout

    Summary

    9. Spread the Word with Social Media

    Facebook

    Time for action – registering your app with Facebook

    What just happened?

    Time for action – sending a screenshot to Facebook

    What just happened?

    Sending tweets

    Time for action – registering your app with Twitter

    What just happened?

    Time for action – sending a tweet

    What just happened?

    Sharing and social media on Android

    Time for action – sharing an update using intents

    What just happened?

    Pop quiz - integrating social media

    Summary

    10. Sending Notifications

    How push notifications work

    Why do you need to know this?

    Setting up notifications - the prerequisites

    Setting up iOS notifications

    Time for action – getting a push certificate

    What just happened?

    Push notifications using Appcelerator Cloud

    Time for action – registering for push notifications with Appcelerator Cloud

    What just happened?

    Have a go hero - sending push notifications

    Push notifications using Urban Airship

    Time for action – registering for push notifications with Urban Airship

    What just happened?

    Coding the interface to Urban Airship

    Time for action – registering a device for push notifications

    What just happened?

    Have a go hero - sending a notification from Urban Airship

    Pop quiz - push notifications

    Summary

    11. Testing and Deploying

    Registering your app with Apple

    Time for action – registering your app with Apple

    What just happened?

    Installing a development/distribution certificate

    Time for action – installing a development certificate

    What just happened?

    Running the app on devices

    Testing the app on iOS

    Time for action – running the app on an iOS device

    What just happened?

    Testing the app on Android

    Time for action – configuring your Android device

    What just happened?

    Debug your app

    Publishing your app

    iOS

    All iOS platforms

    iPhone

    iPad

    Android

    Deploying the app to the Apple App Store

    Time for action – deploying the app to the Apple App Store

    What just happened?

    Deploying the app to Google Play

    Time for action – deploying the app to Google Play

    What just happened?

    Pop quiz - deploying your app

    Summary

    12. Analytics

    Comparing the providers

    Flurry

    Time for action – setting up Flurry

    What just happened?

    Tracking page views

    Time for action – registering a page view

    What just happened?

    Tracking custom events

    Time for action – registering a custom event

    What just happened?

    Other items you can gather

    Google Analytics

    Time for action – setting up Google Analytics

    What just happened?

    Tracking page views

    Time for action – registering a page view

    What just happened?

    Tracking custom events

    Time for action – registering a custom event

    What just happened?

    Analytics using Appcelerator

    Time for action – setting up Appcelerator Analytics

    What just happened?

    Catching custom events

    Time for action – registering a custom event

    What just happened?

    Other suppliers

    Pop quiz - recording analytics

    Summary

    13. Making Money from Your App

    Displaying adverts in your app

    Time for action – configuring Google AdMob

    What just happened?

    Time for action – incorporating AdMob into your app

    What just happened?

    In-app purchases

    Time for action – adding in-app purchases for iOS

    What just happened?

    Have a go hero - recording a purchase

    In-app purchases on Android

    Time for action – adding in-app purchases for Android

    What just happened?

    Pop quiz - making money from your app

    Summary

    A. Git Integration

    Importing a project

    Time for action – importing an existing GitHub project

    What just happened?

    Time for action – uploading a project to GitHub

    What just happened?

    Alternative suppliers

    Summary

    B. Glossary

    C. Pop Quiz Answers

    Chapter 1, How to Get Up and Running with Titanium

    Pop quiz - Titanium installation and configuration

    Chapter 3, How to Design Titanium Apps

    Pop quiz - Titanium design

    Chapter 4, Gluing Your App Together with Events, Variables, and Callbacks

    Pop quiz - adding callbacks

    Chapter 5, It’s All About Data

    Pop quiz - data handling

    Chapter 6, Cloud-enabling Your Apps

    Pop quiz - cloud services

    Chapter 7, Putting the Phone Gadgets to Good Use

    Pop quiz - gadgets

    Chapter 8, Creating Beautiful Interfaces

    Pop quiz - creating a layout

    Chapter 9, Spread the Word with Social Media

    Pop quiz - integrating social media

    Chapter 10, Sending Notifications

    Pop quiz - push notifications

    Chapter 11, Testing and Deploying

    Pop quiz - deploying your app

    Chapter 12, Analytics

    Pop quiz - recording analytics

    Chapter 13, Making Money from Your App

    Pop quiz - making money from your app

    Index

    Appcelerator Titanium Application Development by Example Beginner's Guide


    Appcelerator Titanium Application Development by Example Beginner's Guide

    Copyright © 2013 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: April 2013

    Production Reference: 1120413

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-84969-500-8

    www.packtpub.com

    Cover Image by J. Blaminsky (<milak6@wp.pl>)

    Credits

    Author

    Darren Cope

    Reviewers

    Steve Dawes

    Stephen Feather

    Imraan Jhetam

    Acquisition Editor

    James Jones

    Lead Technical Editor

    Neeshma Ramakrishnan

    Technical Editors

    Chirag Jani

    Devdutt Kulkarni

    Project Coordinator

    Arshad Sopariwala

    Proofreaders

    Maria Gould

    Aaron Nash

    Paul Hindle

    Indexer

    Monica Ajmera Mehta

    Graphics

    Aditi Gajjar

    Production Coordinator

    Manu Joseph

    Cover Work

    Manu Joseph

    About the Author

    Darren Cope is an experienced Titanium developer having seen the light and the potential of what could be done with Titanium back in early 2011. Since 2011 he has released several cross-platform apps using the technology. He holds TCAD and TCMD certifications and along with creating apps, he has developed modules for the Appcelerator Marketplace. He attended the inaugural CODESTRONG conference in San Francisco in October 2011 and continues to preach the benefits of coding with Titanium through the Appcelerator Titans program. He is very eager to hear from other Titanium developers in the north of England and is trying to start a user group for them. He can be contacted either through his personal website at http://darren.cope.name or by e-mail on .

    I'd like to thank Tracey for her love, support, and encouragement during the writing of this book, and thank the writers of NCIS who have provided the background noise for most of the time I was writing this book. I would also like to thank Steve Dawes who reached out to me with an opportunity to develop an app in early 2011 and in doing so started the process that got me here.

    About the Reviewers

    Steve Dawes is a delivery-focused IT consultant with senior management experience in global corporations and director level experience in SMEs.

    Steve's experience includes end-to-end delivery of software and infrastructure projects, product development, and strategic roadmap formulation and business change in a variety of sectors including transport, retail, finance, construction, postal, and services with implementations of systems developed in e-commerce, the cloud, the Web, mobile, and SOA architectures.

    Steve is a member of the BCS and APM and specializes in interim project management and business transformation projects. Steve works through his company Rockwave Consulting Ltd, www.rockwaveconsulting.co.uk.

    Stephen Feather is an Appcelerator Titanium titan, holding TCMD and TCAD certifications. He is a frequent speaker on mobile strategies for small business and non-profit organizations. In 1994 he started his own consulting firm working directly with communications companies such as Netscape, Microsoft, and Oracle in the early days of the Internet. In 1996 he wrote JavaScript by Example, Que Publishing, one of the first publications on the then new scripting language. Over the next 17 years, his firm would grow to become a widely recognized vendor of multimedia software for language learning, providing support to colleges and universities throughout the southeastern United States.

    In 2009, he co-founded Feather Direct, recognizing a need for quality mobile app development, reputation management, and SEO services for smaller organizations. He volunteers time to assist and train a new generation of mobile app developers through online forums and local user groups.

    Imraan Jhetam is a medical doctor and entrepreneur living in England with an equal love for both medical law and technology. He earned his medical degree from the University of Natal in 1983, his MBA from the University of Witwatersrand, and a Master's degree in Law from Cardiff University.

    Imraan has been fascinated by computers since his youth and taught himself the basics of programming during his university years. He has been writing programs since the mid 1970s in various languages and for different platforms and has fond memories of his first Apple//e with its then impressive 64 KB RAM.

    When he is not busy seeing patients or writing medico-legal reports, he spends his time developing applications and developed Snappa, a social sharing game that is the better way to draw something for friends. This was written using the incredible Titanium Studio tools and Appcelerator Cloud Services and is now in the Apple and Android app stores. He was also third prize winner at the first Codestrong Hackathon with two e-payment apps, PayBill and PayPad, that also included social media, geo-location, photos, and barcodes, and which were developed in a restricted and short time using Appcelerator Titanium Studio.

    You can contact Imraan via www.snappa.mobi or via Twitter @The__i.

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    You might want to visit www.PacktPub.com for support files and downloads related to your book.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. 

    Why Subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print and bookmark content

    On demand and accessible via web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

    For Tracey and Emily.

    And for Chris, gone but not forgotten.

    Preface

    It's fair to say that while Steve Jobs didn't necessarily start a smartphone revolution with the iPhone and iPad he certainly championed it and in doing so created beautifully designed devices that rightfully became both massively popular and highly desired.

    Not long after the introduction of these seductive devices came another masterstroke, the App Store. Apple generated massive developer interest by promoting the dream of becoming a rock-star developer by creating apps for this new platform. It was a massive success; a new breed of indie developers flocked to the platform pushing new apps into the App Store hoping their app would be the one to make it big.

    The App Store opened in June 2008 with only 500 apps. By October 2011 there were over half a million apps, and it continues to grow with over 500 new apps published everyday. There will soon be 1 million apps available which has resulted in an ecosystem that has paid out over six billion dollars in royalties. Thanks to a lucrative payment strategy whereby Apple gets 30 percent of revenue from every sale, they have become one of the biggest companies in history.

    Success of that size doesn't go unnoticed or unchallenged. The monopoly didn't last long and soon after Google came along with Android and its own Android marketplace. While initial take-up was slower than Apple, it has gained ground and by late 2012 both stores had equal number of apps available.

    Now the app market has two major players. You can create an app for iOS or Android, but unfortunately there are no common compilers for the two systems, so if you want to write a native app for iOS, you have to use objective-C and Java for Android.

    Jeff Haynie and Nolan Wright (the founders of Appcelerator) were ahead of all of this; they already had a way of creating native apps for iOS using JavaScript, and it just so happened that the methodology they used in their Titanium tool would also work for Android. Titanium was launched in 2009 and since then it has attracted over 400,000 registered developers.

    Titanium allows you to create native apps that will run on both iOS and Android. A Titanium app can be run on both platforms without changing a single line of code. Over 50,000 apps have been released using the technology; this book will help you to add your app to that list.

    The book will guide you through the process of creating a cross-platform app, an app that can be released to both Android and iOS app stores.

    The book has been written in a relaxed and friendly manner with carefully selected examples that highlight the core concepts of the chapter. All examples, unless specifically stated, are written so that they may be run on both platforms.

    The chapters have been ordered to reflect the order in which I believe the tool should be learned. The initial chapters will provide guidance on how to install and configure the tool before moving on to how to create apps using Titanium. The book then looks in detail at how to design and structure apps. This is the content that will be invaluable later when your apps become larger and more complex. Being able to easily modify and extend your apps because they have been designed with a well-defined structure will be a significant advantage.

    The next few chapters then focus on some of the core components of apps with chapters on the cloud, phone gadgets, and data. After this we move on to an important area, interface design, and how to create apps that will run and look good on phones and tablets from both iOS and Android.

    Next, the book has a couple of chapters that look into a few optional extras such as social media integration and push notifications, before moving on to the final phase of testing and deploying your app to the app store.

    The final two chapters focus on areas that are often considered by developers after an app has gone live, namely analytics and making money from your app.

    What this book covers

    Chapter 1, How to Get Up and Running with Titanium, guides you through the process of

    Enjoying the preview?
    Page 1 of 1