Creating Mobile Apps with Appcelerator Titanium Develop fully-featured mobile applications using a hands-on approach, and get inspired to develop more Christian Brousseau BIRMINGHAM - MUMBAI Creating Mobile Apps with Appcelerator Titanium 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: October 2013 Production Reference: 1211013 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-926-7 www.packtpub.com Cover Image by Prashant Timappa Shetty ([email protected]) Credits Author Project Coordinator Christian Brousseau Anugya Khurana Proofreader Reviewers Simran Bhogal Stephen Feather Amisha Green Jude Osborn Acquisition Editor Indexer Usha Iyer Rekha Nair Sam Wood Tejal Soni Lead Technical Editor Graphics Balaji Naidu Abhinash Sahu Yuvraj Mannari Technical Editors Krishnaveni Haridas Production Coordinator Manal Pednekar Pooja Chiplunkar Shali Sasidharan Cover Work Pooja Chiplunkar Copy Editors Gladson Monteiro Sayanee Mukherjee Alfida Paiva Kirti Pai About the Author Christian Brousseau is a proud Canadian who has been developing software for over twenty years. He made his debut in Windows development and then moved on to Java when the Web came along. About thirteen years ago, he had the opportunity to move to France where he worked on major Java Enterprise projects for one of the largest software companies in the world, in different sectors such as banking, insurance, retail, government, and defense. Over the last few years, he became very enthusiastic about mobile platforms in general and has developed quite a few applications for iOS and Android devices using the Appcelerator Titanium platform. He is very active within the community; being a Titanium-certified application developer and a member of the Titans Evangelist group, he is one of the top 10 contributors on the Appcelerator's Questions & Answers forum. Still living in Paris, he left the enterprise world and created his own company, Things Are Moving (http://www.thingsaremoving.com), that specializes in mobile development. I would like to thank all my friends and colleagues who have given me their support, and all those who were there when I created my very first mobile application (that did not do much at the time I must admit). I'd also like to thank all of the very knowledgeable people who took the time to review my book and gave me more than just review notes. You guys went the extra mile, and I am very grateful for it. But most of all, I'd like to thank my wife, who gave me her full support in this journey (even during bad times, that support never flinched). Also, to my children who had to see their father writing every weekend instead of spending quality time with them. To everyone, thank you! About the Reviewers Stephen Feather is an Appcelerator Titanium Titan, holding TCMD and TCAD certifications, and a frequent speaker on mobile strategies for small businesses and nonprofit organizations. In 1994, he started his own consulting firm working directly with communication companies such as Netscape, Microsoft, and Oracle in the early days of the Internet. In 1996, he wrote Javascript by Example, 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 and providing support to colleges and universities throughout the Southeastern United States. In 2009, he cofounded Feather Direct, recognizing a need for quality mobile application development, reputation management, and SEO services for smaller organizations. He volunteers his time to assist and train a new generation of mobile app developers through online forums and local user groups. Jude Osborn is an experienced, well-travelled Software Developer, having led and developed projects across the web, mobile, and desktop spaces and in locations spanning the globe. Jude is passionate about new development technologies, and right now is especially giddy about JavaScript frameworks and mobile. Jude currently works with Google's Creative Lab (on behalf of the web development agency, Potato) on prototypes and experimental software projects. Every morning he walks across Sydney's Pyrmont bridge soaking up the sunshine and looking forward to the next amazing technological challenge. When he's not cutting code and trying crazy new techs, Jude loves creating Littlest Pet Shop YouTube videos with his daughter, barely managing to compete in Starcraft's gold league with his son, and enjoying a nice glass of wine with his beautiful, amazing, and supportive wife. 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 [email protected] 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. TM 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. Table of Contents Preface 1 Chapter 1: Stopwatch (with Lap Counter) 9 Creating our project 9 What have we here? 12 The UI structure 12 Why do we use views? 13 Now on to the code 13 It all starts with a window 14 Displaying the current time with big numbers 14 We can now do our first run 16 Starting and stopping the stopwatch 16 We see the buttons, but they don't do much yet! 18 Stopwatch is not defined, but it's okay 19 Keeping up with lap times 21 Capturing lap times 21 Showing lap times in a scrollable list 22 Resetting the timer 23 Summary 25 Chapter 2: Sili, the assistant that just listens 27 Creating our project 28 The user interface structure 28 Coding the application 29 Let's do some scaffolding 29 Table of Contents Let's see how this looks 33 Recording with a click on a single button 34 What good is a buffer if we're not using it? 35 Listing stored recordings 36 Be sure to call it! 38 Listening to a recording 38 Deleting old recordings 39 Summary 41 Chapter 3: The To-do List 43 Creating our project 44 The user interface structure 44 Let's get this show on the road 45 The database 45 Defining the structure 46 Implementing our model 46 The user interface 47 The header view 48 The tasklist 49 The button bar 49 Let's have a look 50 Adding a new task 54 Listing all the existing tasks 56 Before executing the code 57 Marking a task as completed 58 Filtering out completed tasks 59 Activating the filter 60 Deleting the completed tasks 61 Close the door, you're letting the heat out 62 Summary 62 Chapter 4: Interactive E-book for iPad 63 The user interface structure 63 Before writing any code 64 A native module 65 Where do I get it? 66 Creating our project 67 Adding the module to our project 68 Now we can code 69 The user interface 69 Importing the PageFlip module 69 Adding some colorful views 70 Making sure the pages actually turn 71 Orientation 71 [ ii ] Table of Contents The rich HTML page 73 The map view 74 The video player 75 Final assembly 76 Summary 77 Chapter 5: You've Got to Know When to Hold 'em 79 Creating our project 80 The application structure 80 The main application window 82 Moving on to the code 82 Coding the user interface 83 Sparing our fingers 86 Preparing for our first run 87 The portfolio management window 88 Coding what we have designed 89 The form at the top 90 The stock list 93 Navigating between the two windows 94 Let's see if it works 95 Moving stocks around 96 Saving our portfolio 96 Keeping up on our objective 97 Portfolio management 98 Saving 98 Retrieving 98 Updating a particular stock 99 How much is our portfolio worth? 99 Wiring the preference service to the UI 100 Adding a new stock to the list 100 Creating a custom look for our table rows 101 One more thing before we can test 102 Saving all that 103 What if there are stocks already? 104 Retrieving the stock values from the Internet 105 Knowing where to get it 105 Let's see what we get from it 106 Retrieving one stock 106 Creating an HTTPClient object 107 Opening the HTTPClient object 108 Sending the request itself 108 Retrieving all stocks in a single call 108 Calling the web service 109 [ iii ]
Description: