Archive for August, 2011

Forging Titanium Episode 4: A Utility Application Template

Wednesday, August 31st, 2011

Editor’s note: This and future episodes of Forging Titanium are available here.

In Episode 2, we took a look at a framework for displaying a stack of windows in a cross-platform navigation controller. This week, we’ll be implementing a template for a simple two-stage utility application, while isolating our cross-platform navigation code to a single component.

This week we will be building upon our technique of creating custom components, while adding in an important API for creating component-oriented applications: Application-level events. By firing and listening for custom events, we can ensure that components in our system do not need to have knowledge of how other components behave – they just need to know how to indicate to the rest of the application that an important event has happened.

Find out how use this technique to create a two-stage utility application in this week’s episode of Forging Titanium.

Episode Resources:



Versioning Your Android App

Wednesday, August 31st, 2011

Editor’s note: This blog post is a basic tutorial. The most up-to-date version is available in the wiki.

To change the version of the app add the following code to your tiapp.xml

tiapp.xml

<manifest android:versionCode="2" android:versionName="8.675.309"/>
</android>

  1. versionCode
    The versionCode cannot be a floating point number like “0.9″, it needs to be a whole number like “2″. The versionCode must be an int and each time it is submitted to the market must be greater than the last time.
  2. versionName
    The versionName can be anything you want.

More info on versioning in Android: http://developer.android.com/guide/publishing/versioning.html

 

Appcelerator Office Hours

Monday, August 29th, 2011

Appcelerator Office Hours is a regular online meeting to assist Titanium developers and users.

For 60 minutes every other week, a member of our Developer Relations team will host this session discussing the Titanium Project.

Potential session topics include:

  • Native Android Development
  • Native iPhone Development
  • Cross Platform Mobile Development in Titanium
  • Working with Local Data
  • Working with Remote Data
  • Extending Titanium Studio
  • Extending Titanium through Modules

When there’s not a specific topic, the Office Hours will fall back to an open Q&A for existing developers. If you have some ideas about what you’d like to do but don’t know how to get started, drop by so that we can get you started.

To participate in Office Hours just head over and register.

Handling Remote Data with HTTPClient and JSON

Monday, August 29th, 2011

Editor’s note: This blog post is a basic tutorial. The most up-to-date version is available in the wiki.

Between RESTful and SOAP based web services, there’s an endless supply of data out there just waiting for you to pick it up. Wouldn’t it be great to query this data directly from your Appcelerator app? Of course it would, and fortunately Appcelerator has a simple and familiar interface for doing so.

Titanium.Network.HTTPClient, as its name implies, allows you to make client calls to HTTP web services. It is a specialized implementation of the XmlHttpRequest specification that works with your native Appcelerator code. Let’s take a look at how we can use this interface to query data from a remote source and use it in your app.

Titanium.Network.HTTPClient skeleton

So let’s breakdown what’s happening here in this snippet. After we create a variable to hold our target URL, we create the HTTPClient. When we do so, we set up 2 important event handlers:

  • onload – This is the function that will be called upon successful response from the target URL. The response data can be processed using 3 different properties of the HTTPClient:
    • this.responseText – Contains the raw text response from the target URL. This is the property that would be used when processing JSON or other plain text data.
    • this.responseXML – Contains any XML formatted data from the response. As you might expect, this property is most appropriate for processing SOAP and other XML based web services.
    • this.responseData – Contains your response data in binary format.
  • onerror – This is the function that will be called in the event of an error in your response. To help troubleshoot errors, there are again 3 properties you can check, though this time one belongs to the event object:
    • this.responseText – Like with onload, this contains any text data that was returned with your error response.
    • this.status – Contains the returned status code of the error.
    • e.error – Contains additional error information included in the event object e.

As you can see, these 2 event handlers are the heavy lifters when it comes to HTTPClient. They determine how the data will be handled once it is returned asynchronously from your HTTPClient call.

One final property we’ll set is timeout which will abort our asynchronous call after the specified number of milliseconds. This prevents a flaky web service from stealing control from your app’s flow for too long.

To actually send the prepared HTPPClient call, we simply open() our HTTPClient connection with a connection type (either GET or POST) and our target URL. Once the connection is opened, we then send our asynchronous request via send(). And that’s it. From here on out, all of the HTTPClient flow is handled by our previously defined event handlers.

Sample App: ‘Fighters’

So now that you understand the nuts and bolts of a basic HTTPClient request, let’s get to a full sample app. We’re going to retrieve a static JSON file that includes a list of fighters names and nicknames, then display that data in a Titanium.UI.TableView.

We will be working with remote JSON formatted data. JSON is far more lightweight and easier to work with in a Javascript environment than the typical alternative of XML. You always need to be cognizant of how much data you are forcing your user to retrieve on each call. I’ll leave it at that for now as a discussion of JSON vs. XML could be a blog post in its own right.

app.js

json.txt (from our target URL)

As you can see, we basically filled out the HTTPClient skeleton from above with the specific functionality of our app. With a successful response in onload we are going to parse the fighters JSON array via the JSON.parse() function. This returns a Javascript JSON array object through which we will iterate.

Each JSON object we find in the fighters JSON array represents a fighter with a name and nickname. We will create a custom Titanium.UI.TableViewRow that displays both of these values. In the end, we will have an app that looks like this:

Helpful Links

Meet Platform Evangelist – Aaron Saunders

Friday, August 26th, 2011

Editors Note: This is a post that’s part of a series on Developer Relations at Appcelerator and the people behind the team.

Tell us who you are?

My name is Aaron Saunders I am a Software Developer, that just could not get away from the code! I have a MBA have managed large development teams and large consulting engagements but in the end I just enjoy writing software. Over twenty years experience in Open Source Software Development, specifically J2EE, but jumped on the mobile bandwagon about 18 months ago.

What is your title at Appcelerator and what does it mean exactly?

To me it means that I am getting paid for what I have been doing for the last year.

When I started with Appcelerator I quickly became addicted to the QA Forums, answering questions became my way of reaching into t he scary places of the platform that I might not find on my own. All of the questions I answered or read helped me become a better mobile developer and provided me insights I would have never found on my own… I was able to help myself by helping others.

Tell us about your Appcelerator history, when you joined etc?

I haven’t started yet

What do you love about your work at Appcelerator?

The same thing that I love about what I do for a living; I started writing software when I was in 6th grade and I thought it was a fun hobby. All these years later, I am still doing my hobby and getting paid for it. Everyday I wake up to a potentially new challenge or new problem to solve using technology that is shaping the future for us all.

What does it mean to work for Appcelerator?

I haven’t started yet, will tell you in a later blog posting

What are you working on for Appcelerator?

Initially just doing what I am doing already, but I hope to get certified for training.

What can we find in your laptop bag?

In my bag you will find a 17in quad core i7 mbp and macbook air a iPhone4, iphone3Gs, ipod 32GB touch, iPad2 3G, blackberry Curve, DroidX, Alka Seltzer and a bunch of batteries and cables

What was the last book you read?

I must admit that I havent actually finished anybook in awhile, i jump around and read chapters, Linchpin by Seth Godin, The Presentation Secrets of Steve Jobs are  the most recent

What is your favorite mobile device?

iPhone

Any advice to new users of Titanium?

Be committed to  the platform, it may be a rough start to get use to the approach, but the benefits are well worth the initial adjustment. Also keep things in perspective, you are writing mobile applications in javascript!!! Not objective-C and not Java… come how can you not love that!!

Your contact information?

  • Blog: blog.clearlyinnovative.com
  • Twitter: aaronksaunders
  • LinkedIn: http://www.linkedin.com/in/aaronksaunders
  • GitHub: https://github.com/aaronksaunders