Now it's time to write some simple mobile app using Titanium Developer. Venturing in the APIs we some help - KitchenSink example app and documentation.
Folder build will contain binary builds of your app. Resources folder holds all files and code of your app. File tiapp.xml contains application configuration, including list of windows (2 by default), like this:
If we specify only one window - no tabs will be used. In Resources we will find:
about.html android index.css index.html index.js
index.html is the main window of our application (defined in tiapp.xml). Folders "android" i "iphone" can be used to add specific files or code for selected os (they can overwrite files in Resources).
It's quite strange to code a mobile app in HTML/CSS/JS. What you have to do is:
Make HTML templates
Write some CSS styles
Write JavaScript code that will handle the app functionality
You can go with basic web-like apps that doesn't use native widgets, or write a lot of JavaScript code that uses Titanium AVI to create app interface using widgets. Application built with native widgets is presented in Hybrid iPhone Apps with Titanium Mobile.
The Mobile API isn't documented well, and you will have to digg in Kitchen Sink or do a lot of debuging, testing.
So we start with an application that will show RSS channel entries from a selected website (in this case filmaster.com). For comparison I'll make two windows - two tabs. One will show RSS entries using native widgets, and second one using HTML.
Where jquery.jfeed.pack.js is a jfeed jQuery plugin (RSS parsing), jquery.utils.min.js is a jquery-utils plugin (needed by me to handle UTF-8 strings with non-ascii characters - like Polish language ;)). The HTML/CSS page will show the site logo on orange background and message about loading RSS channel. index.js and weblike.js for the second window (tab) will contain code implementing their functionality.
The code uses jFeed plugin to download RSS channel and put the result in the page weblike.html.
The window looks like this:
. For Polish feed there are problems with non-ascii characters. Such problems can be solved by $.UTF8decode() from jQuery-utils.
So using web technologies we created simple application, that (nicely finished) can be used to promote the website or serve as a mobile version of it. Now lets try do the same with native widgets.
For index.js I wrote such code:
window.onload=function(){jQuery.getFeed({url:'http://filmaster.pl/planeta/rss/',success:function(feed){vardata=[];vardesc_data=[];for(vari=0;i<feed.items.length&&i<5;i++){varitem=feed.items[i];data[i]={title:$.UTF8decode(item.title),hasChild:true};desc_data[$.UTF8decode(item.title)]=$.UTF8decode(item.description);}vartableView=Titanium.UI.createTableView({data:data,title:'Tytuł'},function(eventObject){// Now call some eventhandler function to handle the click event object// Took this from the Kitchen Sinkvara=Titanium.UI.createAlertDialog();a.setTitle(eventObject.rowData.title);a.setMessage(desc_data[eventObject.rowData.title]);a.show();});//add view to current windowTitanium.UI.currentWindow.addView(tableView);// show viewTitanium.UI.currentWindow.showView(tableView);}});};
Which in android gives:
In this JavaScript code there is Titanium.UI.createTableView (doc) - native widget available through the API. This will show a native table view on each system. Clicking on an entry will show it's description through Titanium.UI.createAlertDialog widget - doc.
Titanium Developer has some big potential, but it really needs well written documentation (like PyQt4 one?) and short examples of common tasks and code patterns.
Comment article