Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Appcelerator Titanium Smartphone App Development Cookbook Second Edition
Appcelerator Titanium Smartphone App Development Cookbook Second Edition

Appcelerator Titanium Smartphone App Development Cookbook Second Edition: Over 100 recipes to help you develop cross-platform, native applications in JavaScript

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Appcelerator Titanium Smartphone App Development Cookbook Second Edition

Chapter 2. Working with Local and Remote Data Sources

In this chapter, we'll cover the following topics:

  • Reading data from remote XML via HTTPClient
  • Displaying data using a TableView
  • Enhancing your TableViews with custom rows
  • Filtering your TableView with the SearchBar control
  • Speeding up your remote data access with Yahoo! YQL and JSON
  • Creating a SQLite database
  • Saving data locally using a SQLite database
  • Retrieving data from a SQLite database
  • Creating a "pull to refresh" mechanism in iOS

Introduction

As you are a Titanium developer, fully understanding the methods available for you to read, parse, and save data is fundamental to the success of the apps you'll build. Titanium provides you with all the tools you need to make everything from simple XML or JSON calls over HTTP, to the implementation of local relational SQL databases.

In this chapter, we'll cover not only the fundamental methods of implementing remote data access over HTTP, but also how to store and present that data effectively using TableViews, TableRows, and other customized user interfaces.

Prerequisites

You should have a basic understanding of both the XML and JSON data formats, which are widely used and standardized methods of transporting data across the Web. Additionally, you should understand what Structured Query Language (SQL) is and how to create basic SQL statements such as Create, Select, Delete, and Insert. There is a great beginners' introduction to SQL at http://sqlzoo.net if you...

Reading data from remote XML via HTTPClient

The ability to consume and display feed data from the Internet, via RSS feeds or alternate APIs, is the cornerstone of many mobile applications. More importantly, many services that you may wish to integrate into your app will probably require you to do this at some point, so it is vital to understand and be able to implement remote data feeds and XML. Our first recipe in this chapter introduces some new functionality within Titanium to help facilitate this need.

If you are intending to follow the entire chapter and build the MyRecipes app, then pay careful attention to the Getting Ready section for this recipe, as it'll guide you through setting up the project.

Getting ready

To prepare for this recipe, open Appcelerator Studio, log in and create a new mobile project, just as you did in Chapter 1: Building Apps Using Native UI Components. Select Classic and Default Project, then enter MyRecipes as the name of the app, and fill in the rest of...

Displaying data using a TableView

TableViews are one of the most commonly used components in Titanium. Almost all of the native apps on your device utilize tables in some shape or form. They are used to display large lists of data in an effective manner, allowing for scrolling lists that can be customized visually, searched through, or drilled down to expose child views. Titanium makes it easy to implement TableViews in your application, so in this recipe, we'll implement a TableView and use our XML data feed from the previous recipe to populate it with a list of recipes.

How to do it...

Once we have connected our app to a data feed and we're retrieving XML data via the XHR object, we need to be able to manipulate that data and display it in a TableView component. Firstly, we will need to create an array object called data at the top of our refresh function in the recipes.js file; this array will hold all of the information for our TableView in a global context. Next, we need to...

Enhancing your TableViews with custom rows

So far, we've created a TableView that, though totally usable and showing the names of our recipes from the XML feed, is a bit bland. To customize our table, we'll need to create and add custom TableRow objects to an array of rows, which we can then assign to our TableView object. Each of these TableRow objects is essentially a type of view, to which we can add any number of components, such as Label, ImageView, and Button.

Next up, we'll create our TableRow objects and add to each one the name of the recipe from our XML feed, the publication date, and a thumbnail image, which we'll get from the images folder in our Resources directory. If you do not have an images directory already, create one now and copy the images from the source code for this chapter.

How to do it...

Open your recipe.js file and replace the refresh function with the following code:

function refresh() {

        var data = []; //empty data array

        //declare...

Filtering the TableView using a SearchBar component

What happens when your user wants to search for all that data in your TableView? By far the easiest way is to use the SearchBar component. This is a standard control that consists of a searchable text field with a cancel button, that sits ontop of your TableView using the table view's searchBar property.

In this next recipe, we'll implement in our MyRecipes app a SearchBar component that filters our recipes based on the title property.

How to do it...

First of all, create a SearchBar component. Do this before your TableView is defined. Then we'll create the event listeners for SearchBar:

//define our search bar which will attach 
//to our table view
var searchBar = Ti.UI.createSearchBar({
    showCancel:true,
    height:43,
    top:0
});

//print out the searchbar value whenever it changes
searchBar.addEventListener('change', function(e){
  //search the tableview as user types
console.log('user searching for:...

Introduction


As you are a Titanium developer, fully understanding the methods available for you to read, parse, and save data is fundamental to the success of the apps you'll build. Titanium provides you with all the tools you need to make everything from simple XML or JSON calls over HTTP, to the implementation of local relational SQL databases.

In this chapter, we'll cover not only the fundamental methods of implementing remote data access over HTTP, but also how to store and present that data effectively using TableViews, TableRows, and other customized user interfaces.

Prerequisites

You should have a basic understanding of both the XML and JSON data formats, which are widely used and standardized methods of transporting data across the Web. Additionally, you should understand what Structured Query Language (SQL) is and how to create basic SQL statements such as Create, Select, Delete, and Insert. There is a great beginners' introduction to SQL at http://sqlzoo.net if you need to refer to...

Reading data from remote XML via HTTPClient


The ability to consume and display feed data from the Internet, via RSS feeds or alternate APIs, is the cornerstone of many mobile applications. More importantly, many services that you may wish to integrate into your app will probably require you to do this at some point, so it is vital to understand and be able to implement remote data feeds and XML. Our first recipe in this chapter introduces some new functionality within Titanium to help facilitate this need.

If you are intending to follow the entire chapter and build the MyRecipes app, then pay careful attention to the Getting Ready section for this recipe, as it'll guide you through setting up the project.

Getting ready

To prepare for this recipe, open Appcelerator Studio, log in and create a new mobile project, just as you did in Chapter 1: Building Apps Using Native UI Components. Select Classic and Default Project, then enter MyRecipes as the name of the app, and fill in the rest of the details...

Displaying data using a TableView


TableViews are one of the most commonly used components in Titanium. Almost all of the native apps on your device utilize tables in some shape or form. They are used to display large lists of data in an effective manner, allowing for scrolling lists that can be customized visually, searched through, or drilled down to expose child views. Titanium makes it easy to implement TableViews in your application, so in this recipe, we'll implement a TableView and use our XML data feed from the previous recipe to populate it with a list of recipes.

How to do it...

Once we have connected our app to a data feed and we're retrieving XML data via the XHR object, we need to be able to manipulate that data and display it in a TableView component. Firstly, we will need to create an array object called data at the top of our refresh function in the recipes.js file; this array will hold all of the information for our TableView in a global context. Next, we need to disseminate...

Enhancing your TableViews with custom rows


So far, we've created a TableView that, though totally usable and showing the names of our recipes from the XML feed, is a bit bland. To customize our table, we'll need to create and add custom TableRow objects to an array of rows, which we can then assign to our TableView object. Each of these TableRow objects is essentially a type of view, to which we can add any number of components, such as Label, ImageView, and Button.

Next up, we'll create our TableRow objects and add to each one the name of the recipe from our XML feed, the publication date, and a thumbnail image, which we'll get from the images folder in our Resources directory. If you do not have an images directory already, create one now and copy the images from the source code for this chapter.

How to do it...

Open your recipe.js file and replace the refresh function with the following code:

function refresh() {

        var data = []; //empty data array

        //declare the http client...

Filtering the TableView using a SearchBar component


What happens when your user wants to search for all that data in your TableView? By far the easiest way is to use the SearchBar component. This is a standard control that consists of a searchable text field with a cancel button, that sits ontop of your TableView using the table view's searchBar property.

In this next recipe, we'll implement in our MyRecipes app a SearchBar component that filters our recipes based on the title property.

How to do it...

First of all, create a SearchBar component. Do this before your TableView is defined. Then we'll create the event listeners for SearchBar:

//define our search bar which will attach 
//to our table view
var searchBar = Ti.UI.createSearchBar({
    showCancel:true,
    height:43,
    top:0
});

//print out the searchbar value whenever it changes
searchBar.addEventListener('change', function(e){
  //search the tableview as user types
console.log('user searching for: ' + e.value);
});

//when the return...
Left arrow icon Right arrow icon

Key benefits

  • Leverage your JavaScript skills to write mobile applications using Titanium Studio tools with the native advantage
  • Deploy your application on the App Store and Google Play
  • Add your own IOS native modules in objective-C, in an easy-to-follow step-by-step format

Description

This book will take you through the process of building cross-platform, native UI applications for the mobile from scratch. You will learn how to develop apps, how to use GPS, cameras and photos and how to build socially connected apps. You will also learn how to package them for submission to the App Store and Google Play. This cookbook takes a pragmatic approach to creating applications in JavaScript from putting together basic UIs, to handling events and implementation of third party services such as Twitter, Facebook and Push notifications. The book shows you how to integrate datasources and server APIs, and how to use local databases. The topics covered will guide you to use Appcelerator Studio tools for all the mobile features such as Geolocation, Accelerometer, animation and more. You’ll also learn about Alloy, the Appcelerator MVC framework for rapid app development, and how to transfer data between applications using URLSchemes, enabling other developers to access and launch specific parts of your app. Finally, you will learn how to register developer accounts and publish your very own applications on the App Store and Google Play.

Who is this book for?

This book is an essential for any developer learning or using JavaScript who wants to write native UI applications for iOS and Android. No knowledge of Objective-C, Swift and Java is required and you’ll quickly be developing native, cross-platform apps, in JavaScript!

What you will learn

  • Transfer data between applications with URL schemes, and make your application accessible to other mobile applications and services
  • Connect with remote services using JSON
  • Work with Google Maps and Apple Maps, GPS and annotate routes
  • Create animations and special effects
  • Integrate notifications and connect with social media services such as Facebook and Twitter
  • Build applications with Alloy MVC – a rapid application development framework
  • Design native APIs and use local databases

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2015
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781849697712
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 30, 2015
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781849697712
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 115.97
Creating Mobile Apps with Appcelerator Titanium
€36.99
Appcelerator Titanium Smartphone App Development Cookbook Second Edition
€36.99
Appcelerator Titanium Application Development by Example Beginner's Guide
€41.99
Total 115.97 Stars icon

Table of Contents

15 Chapters
1. Building Apps Using Native UI Components Chevron down icon Chevron up icon
2. Working with Local and Remote Data Sources Chevron down icon Chevron up icon
3. Integrating Maps and GPS Chevron down icon Chevron up icon
4. Enhancing Your Apps with Audio, Video, and Cameras Chevron down icon Chevron up icon
5. Connecting Your Apps to Social Media and E-mail Chevron down icon Chevron up icon
6. Getting to Grips with Properties and Events Chevron down icon Chevron up icon
7. Creating Animations, Transformations and Implementing Drag and Drop Chevron down icon Chevron up icon
8. Interacting with Native Phone Applications and APIs Chevron down icon Chevron up icon
9. Integrating Your Apps with External Services Chevron down icon Chevron up icon
10. Extending Your Apps with Custom Modules Chevron down icon Chevron up icon
11. Platform Differences, Device Information, and Quirks Chevron down icon Chevron up icon
12. Preparing Your App for Distribution and Getting It Published Chevron down icon Chevron up icon
13. Implementing and Using URL Schemes Chevron down icon Chevron up icon
14. Introduction to Alloy MVC Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(4 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Adam A. Dec 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Jason is well known in the Appcelerator Community for his top-notch work. This book was everything I expected and more. Whether you are new to Appcelerator or a seasoned veteran - this book has something to offer you. I plan to use this book as a benchmark for all new hires to my team.
Amazon Verified review Amazon
ade Dec 11, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very well written. Great recipes that will prove useful to people to both people new to the appcelerator platform or people with more experience. Well worth the purchase to have to hand.
Amazon Verified review Amazon
Amazon Customer Dec 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A very practical book containing many recipes you will definitely use in your apps. From simple to more complex, something for everyone!
Amazon Verified review Amazon
Jose Manuel Cerrejon Dec 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Jason Kneen is a great author and I read his first Edition with enthusiasm. It teaches you some tips with their great recipes. Now in this second edition write code based in Alloy, too. It's easy to follow a recipe step by step and achieve your goal. Very clear and recommended if you are an experienced Titanium user or a web developer who want to write Mobile apps with Javascript code using native UI components running on Android, iOS and Windows Phone.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.