Those of you that have followed our platform for some time might remember the Tweetanium project. As we discussed during last week’s webinars we are breathing new life into this project. A mobile version of the application is being developed to demonstrate some best practices for cross platform mobile development with Titanium (i.e.) iPhone & Android. The desktop version of Tweetanium has also been redesigned and rebuilt from the ground up. Today we are releasing both versions of Tweetanium. The rest of this post will cover the desktop version in detail. A follow-up post will be coming out soon focused on Tweetanium mobile. Both versions are being released under the Apache 2.0 license and the code will be made available on Github later on this afternoon. Installable versions of Tweetanium Desktop will also be made available for download at that time.
Behind the Scenes
Application Structure
JavaScript
The bulk of the custom JavaScript code for Tweetanium can be found in 3 JavaScript files. The main JavaScript file is tweetanium.js. The core code makes use of the module pattern and is namespaced behind the Tweetanium variable to avoid polluting the global namespace. The module pattern, popularized by Yahoo!, enables us to create private variables & methods and helps keeps the code fairly consistent. The Tweetanium object exposes a number of sub-properties and methods that make interacting with the object pretty simple. Here is the basic outline of the Tweetanium object:
More complex/specific portions of the Tweetanium code are placed in separate files, but a similar pattern is followed and the code is added into the appropriate namespace under the pre-existing Tweetanium object (e.g.) tweet overlays, scrollers, etc. Lastly, there are also files whose names correspond with the window that are utilized in (e.g.) index.js & login.js. These files mostly contain some initialization code and window specific event handlers.
External Libraries
xAuth
In order to interact the Twitter API beyond simple searches (e.g.) tweet, reply, retweet, follow/unfollow, etc an application will need to utilize OAuth/xAuth. Tweetanium utilizes xAuth and does it’s integration via SpazCore. Below are the basic set of methods created in Tweetanium to deal with Authentication (Note: these are taken out of context so review the full source for the actual implementation).
Taking Advantage of CSS3 & Webkit
-webkit-box-shadow: 3px 3px #888;

-webkit-border-radius: 10px;
-webkit-box-shadow: inset 0 0 2px 2px #888;


System Notifications
Another common task required in many desktop applications is posting system notifications. Titanium Desktop makes creating system notifications simple and they look great across the various environments. They integrate nicely with Growl, Snarl, etc and generally have basic fallbacks in place for when these more advanced notification systems are not available. Tweetanium uses system notifications to indicate when new tweets have been found and creates a menu item that allows for the notifications to be enabled or disabled at will. Here is the basic code used to create & display the notification:
The resulting notifications look like:

Optimizing/Juicing
As I mentioned earlier many of the same optimization techniques used in standard browser development can be applied to Titanium Desktop development. In Tweetanium we’re using PNGCRUSH to help with image optimizations and Juicier to assist with minification & concatenation of the application’s CSS & JavaScript files. Juicer is a nice utility that allows us to keep the code organized in a way that is easier for development, but also simple to optimize for production. Juicer allows us to create dependencies between various CSS files and JavaScript files. For example the main index window includes only a minified index.js file. That file defines the set of dependencies it needs like jQuery, Tweetanium, etc. When we run juicer on this file it pulls in dependencies in the right order, concatenates the scripts, minifies them (via the YUI Compressor or Google Closure Compiler), obfuscates the code if desired and verifies the syntax via jslint if we want.
Some additional notes on this:
- In our case jslint is disabled when running via juicer because some of the external libraries fail to lint. The Tweetanium files themselves are linted separately.
- Spazcore is included separately and not pulled into the juicer dependencies because it defines it’s own set of dependencies and we are using a prebuilt version of SpazCore for Titanium.
- To help automates juicer runs we’ve created a simple little Python script called juicerize. After changing any of the projects CSS or JavaScript simply run this script and then test or package to see the changes.
In Closing
Our goal with Tweetanium is to provide a useful set of projects that developers can learn and pull from as needed. Tweetanium is not necessarily a full blown Twitter client although it does implement much of the functionality found in a number of popular clients. We’ll continue to refine & improve the application over time and use it to show off other platform features. Below is a short video of the application in action. Source code and downloads coming shortly…


This looks great! Developing crossplatform (desktop) apps was such a pain in the ass prior to the release of Titanium :)
Does anyone have any experience or luck using spazcore and xauth on a titanium mobile app??
Tweetanium Mobile will have an example of cross-platform xAuth to Twitter. posting code today.
Simply saying – THANK YOU : )
[...] source code for the Tweetanium mobile & desktop projects is now available on Github. Take it, fork it, learn from [...]
Tweetanium code released at GitHub has bugs related to file naming. The code inside index.html points to index.min.js but there is not such file in project – there is index.js only. Same in login
Please see the README. You need to run juicer to generate those files after defining valid xAuth keys.