Create a database with Titanium Mobile
Aug 18th
Many of the mobile projects we worked on required working with a database. In Titanium you can either use an existing database which is useful in some cases, or create a database from within the application.
Here are some guidelines on how to create and use a database:
Open/Create a database
var myDatabase = Ti.Database.open('myDatabase');
Titanium.Database.open opens the database passed as a parameter or creates a new one if the one specified does not exist.
Create a table
If the database is opened for the first time (created), you need to create a table.
var sql = 'CREATE TABLE IF NOT EXISTS my_table(' +
'id INTEGER PRIMARY KEY AUTOINCREMENT, my_column TEXT, my_column2 INT' +
')';
myDatabase.execute(sql);
Titanium.Database.DB.execute executes a SQL statement against the database. The function receives two parameters. The first one is the SQL string that will be executed and the second parameter can be one or more parameters to replace ? or an array of objects to be replaced in the SQL string using ? substitution.
Insert data
var sql = 'INSERT INTO my_table (my_column, my_column2) VALUES (?,?)'; myDatabase.execute(sql, 'My string', 4);
Update data
var sql = "UPDATE my_table SET my_column = ? WHERE id = ?";
myDatabase.execute(sql, 'New value', 1);
Retrieve data
var sql = 'SELECT * FROM my_table WHERE id = ?';
myDatabase.execute(sql, 1);
Delete data
var sql = 'DELETE FROM my_table WHERE id = ?';
myDatabase.execute(sql, 1);
Delete a table
myDatabase.execute('DROP TABLE IF EXISTS logs');
If you have any questions or comments, please feel free to use the comments section of this post or send them to us on Twitter or Facebook.
Titanium Module for Android Audio Recording
Aug 4th
We were watching over the Appcelerator Q&A page and saw that a lot of people are requesting a way to record audio without using Intents. Don’t get me wrong, the post published by Bill Dawson (Launching Activities and Using Content URIs in Android), was awesome and it really helped a lot, but we all needed a way to do this without using an interface that wasn’t customizable, so audioRecorder came into the equation.
I hope that this will be helpful and i would really love that all you guys out there, using it, comeback with proposal of new modules or updates and ideas to the current ones.
Fell free to contact us at: team[at]codeboxed[dot]com, and we will respond as soon as possible, i am sure there are a lot of people that can vouch for our rapid response time
, so don’t worry, we take all of the e-mail and messages very serious.
So lets talk a little about this new Titanium module called audioRecorder (com.codeboxed.audiorecorder).
The audioRecorder module has 14 methods that we thought would be of great use. I really recommend that if you don’t know what the audio encoders or audio formats represent on Android, go check this out: MediaRecorder Android Class, and learn more about it, but i am sure the documentation included with the module will be very easy to understand and make the use of the module very straight forward.
Some of the important features of the module are the following methods: setMaxDuration, setMaxFileSize, setRandomFileName, start, stop, playAudio
Here is some short info about some of them, info that you will also find in the documentation of the audioRecorder Titanium module:
Titanium Module for Box.net REST API
Aug 2nd
Box.net has a collection of web services which allows developers to connect to their platform and store/retrieve/manipulate/share files and folders. Their API is fairly simple to use from any programming language, and they have wrappers for most of the popular languages like PHP, Java, .NET, Ruby, etc. You can access their API through REST, SOAP and XML-RPC protocols.
We decided to try out the Box platform and develop a simple application in Titanium. The process itself was easy though time-consuming, as you have to write lots of code to use the API functions. Therefore, we wrote an API wrapper over the RESTful web service in order to cut-down on the development time. This is useful for any developer who wants to develop Titanium Mobile applications integrated with the Box platform.
Example application
In order to fully demonstrate the module’s integration with the Box API and show how easy-to-use, we implemented an example application. Download the example application from here or fork it from GitHub.
How to use
The Titanum Module has four methods which allows to call any of the API functions described on the official Box API Documentation.
Prerequisites
You need to be registered with a Box account, and create an application in order to obtain your own API key. This process is straight-forward and shouldn’t take you more than 5 minutes. Once you have your account set-up, go to the Box platform services site and create a new application.
Include the Titanium Module
var box = require('com.codeboxed.boxrestapi');
Use the module
.load(callback [Function - optional], options [Array - optional])
The first method which needs to be called in order to initialize the module. It is recommended to provide at least a callback function as a parameter. More >
How to install a Titanium Module
Aug 1st
Modules are a great way to add functionality to your applications, in addition to what the Titanium Mobile API provides. You can install modules that extend the UI, perform a specific task that cannot done otherwise or just combine Titanium API modules and objects in order to provide a high-level functionality.
There are two steps that you need to take in order to install a Titanium module:
Copy the module
- Go to /Library/Application Support/Titanium or to ~/Library/Application Support/Titanium
- Unarchive the .zip file and you will get a “modules” folder
- Copy the “modules” folder into one of the paths mentioned in step 1
Register the module
Register the module with your application by editing tiapp.xml and adding your module:
{MODULE_ID}
Example (for Titanium Image Gallery 0.2 for iPhone):
com.codeboxed.imagegallery
Use the module
var moduleReference = Ti.require('com.example.module');
Note: You might need to do a full rebuild in order for the module to be included properly.
Titanium Image Gallery module for iPad
Jul 18th
The 0.2 version of the Titanium Image Gallery module for iOS is ready to download. In this new version we optimized the image gallery for iPad and added new options to further customize the module.
Here is a snippet of code on how to customize the module:
// Import ImageGallery module
var ImageGallery = require('com.codeboxed.imagegallery');
var win = Ti.UI.currentWindow;
// Array with image objects
var imagesArray = [
{path:'1.jpg', caption:'Kitten 1'},
{path:'2.jpg', caption:'Kitten 2'}
];
// Initialize the Image Gallery
var imageGallery = ImageGallery.create({
images: imagesArray,
columns: 4, // Set the numbers of column (optional). Default is 4
thumbSize: 75, // Set the thumb image size (optional). Default is 75
thumbPadding: 5 // Set the thumb image padding (optional). Default is 5
});
// Add it to the current window
win.add(imageGallery);
We created a screencast showing the Image Gallery in action on the iPad simulator: More >
Titanium Module for Image Gallery
Jul 7th
We implemented a Titanium Module for using an image gallery in your mobile application. The code is based on the initial Image Gallery script.
The current module supports only one parameter (the local images array), but we are working on allowing it to be fully customizable and support remote images.
Here’s an example on how to use the module:
// Import ImageGallery module
var ImageGallery = require('com.codeboxed.imagegallery');
var win = Ti.UI.currentWindow;
// Array with image objects
var imagesArray = [
{path:'1.jpg', caption:'Kitten 1'},
{path:'2.jpg', caption:'Kitten 2'}
];
// Initialize the Image Gallery
var imageGallery = ImageGallery.create({
images: imagesArray
});
// Add it to the current window
win.add(imageGallery);
The module is pure Javascript and currently available only for iPhone, and soon for Android.
For installing instructions check the Github repository.
How to implement “More” Tab on Android
Jul 1st
The vast majority of iPhone applications have a tab named “More” which holds the rest of the tabs which are not displayed in the tab bar. This design is done by default by the application when there are more tabs that the tab bar could display.
Android, on the other hand, crowds all the tabs together and scrolls the tab title if necessary. Although some may prefer this design, we like the way iPhone handles it.
We decided to simulate this design on Android, which is in particular useful if you have to implement the same application on both platforms.
Check the code snippet: More >
We’ve released Titanium API Browser
Jun 9th
We recently released our own application for browsing the Titanium Mobile API. There are some other apps out there that solved this problem already, but we have ours free of cost, available on the main mobile/desktop platforms and promise to release an update within days Appcelerator releases a new API version.
The application is available for Mac, Windows and Android at the moment but we are working on releasing it for iPhone and Linux also.
If you want to give it a go, check out the application’s page.
Connect with Titanium Mobile to your databases
Jun 6th
Initially we created a Gist for connecting with Titanium to your databases which is for the Titanium Desktop API.
We modified the previous Gist to work with the Titanium Mobile API following some guidelines from the Google Javascript Style Guide.
To see the whole article click here: More >







