Mobile App Development with Titanium Studio 12-29-2013, 10:37 AM
#1
Mobile App Development with Titanium Studio [iOS/Andriod/BB]
http://www.appcelerator.com/
Introduction:
Titanium Studio by Appcelerator Inc. is a Rapid Application Development IDE platform to develop mobile applications for a wide range of mobile platforms with portability in mind. You code an app and then you can build it for multiple mobile platforms such as iOS, Android, and Blackberry.
It is a cross platform suite that can be installed on Windows, Linux, and Mac and consists of the Appcelerator Platform, NodeJS Framework, and any emulator you should choose to use. There is a catch with iOS however. You can only build iOS apps on a Mac based computer. As such, being a PC user, I will focus this tutorial on the Android Platform.
This tutorial will simply cover the very basics of getting started.
Installation:
-Java
Java 6 is required. Java 7 will absolutely not work in my experience. It took me hours of fiddling to figure this out. Its just not supported. Perhaps in future versions this may be supported, but not at this time to my knowledge.
-Titanium
--NodeJS
--Android Emulator
Titanium Studio theoretically comes with the ability to install the required software to function including NodeJS and Android. However in my experience this often doesn't work as well as it should. If it works as it should, NodeJS should be installed as part of the package, and if you go to the "Getting Started" tab in Titanium on the Dashboard you can install and configure your SDK's. Under the Android Management console you need to install the Rev 17 platform (Android version 2.2 if I recall), and the latest version available. Once this is done there should be a green check mark next to the Android SDK under getting started in Titanium.
However you may be required to go to the following sites and download + configure manually one or both of these software packages.
NodeJS: http://nodejs.org
Android Emulator: http://developer.android.com/sdk/index.html
At that point you can go to the Titanium Preferences screen and enter the installation paths manually. Once this is done, in the case of Android, you will still need to go and configure the Android package to install the minimum and maximum versions as described above.
Creating a new project:
Go to File -> New -> "Mobile Project". On the popup screen, for the purposes of this tutorial, we'll select "Single Window Application". It will now ask you for a few details. The first is the project name. I will enter testApp1 for this tutorial. Next is the AppId. This should be a unique name in the format com.companyname.apptitle. So for example, I would use com.adepttechs.testApp1. Nothing else on this page is required however feel free to enter any details you would like and hit finish.
You have an app! If you were to build this now you would have an a.pp with a blank white screen.
Building an App:
All it takes to build an app is to hit Run. This will build an apk in the project direcory and run it in the android emulator.
Getting Started Programming:
In order to start programming you need to locate the app.js file. This is where all the magic happens. On the left side there is a folder pane with a "Resources" folder. Expand the folder and you will find your app.js. Click on that filename to open the project and you will see some existing code. This is the code that creates that mobile app with a white background and nothing else. But that isnt too exciting is it. You can check out this code and study it for yourself, but for the purposes of this tutorial I would suggest you delete everything there.
Creating a Window:
This creates the code for a simple window with a black background color. Now this merely creates the object. It does not display it. in order to display the window you need to use the code homeWin.open(). homeWin references the name of the variable/object "homeWin" we created. The open() tells the system to display the window.
Adding an image:
This creates an image object that can be placed on a window. The name of this is object is "bannerImg" and its attributes are specified in the top, left, width, height fields. This can be expressed in percentages or fixed pixel values. The image field contains the location and name of the image in relation to the project install directory. so if my project was saved in /home/geoff/titanium/testApp1/, then the image should be placed in /home/geoff/titanium/testApp1/Resources/images/.
Now we're not done. Like the Window, the image object has been created, but not added. To add the image to the window we need to use the code homeWin.add(bannerImg);
Labels:
We can also add text fields, called labels, to our app.
The attributes should be self explanatory. This creates a text field half way down the window centred across the full width with a white background and black text.
Our code so far:
So to add it all together, at this point we should have an app.js file that looks something like
Event Listeners:
We can also make these objects respond to touch input. How about we make the Banner image show an alert when pressed? We do this with this piece of code
Again we reference the object we want to apply the event listener to, and then specify what we want done.
Storing data:
We can easily store integer data within the app by using - We can do the same thing for Strings using
"identifier" is a string identifier used to recall the stored data. data is whatever you wish to place there.
To retrieve the data stored is simply a matter of referencing the identifier using the code Titanium.App.Properties.getInt("identifier"); or in the case of a string,
if/while statements:
These are pretty straight forward as well.
Databases:
Titanium has decent support for SQLite built in. I'm not going to get into how to create an sqlite db but I will cover basic data input/extraction.
To set up an existing database to use in Titanium you use the following code
To run queries you use db.execute. For example an insert is as simple as:
However if you want to SELECT data, you need to put the output of the query in a variable like so:
Conclusion:
And that's it for now. This is just an intro tutorial for getting started with Titanium. There is a lot more that can be done with Titanium although there are some limitations. There are a lot of available resources to handle more advanced capabilities on their developer site as well as other developer contributed modules and code... Check out some of these other resources:
http://docs.appcelerator.com/titanium/la...uick_Start
http://docs.appcelerator.com/titanium/latest/
http://www.appcelerator.com/developers/
http://developer.appcelerator.com/questions/newest
Questions comments or concerns let me know. I may yet update and add to this as well... So while ill consider it complete for now... if questions arise i may add to it.
http://www.appcelerator.com/
Introduction:
Titanium Studio by Appcelerator Inc. is a Rapid Application Development IDE platform to develop mobile applications for a wide range of mobile platforms with portability in mind. You code an app and then you can build it for multiple mobile platforms such as iOS, Android, and Blackberry.
It is a cross platform suite that can be installed on Windows, Linux, and Mac and consists of the Appcelerator Platform, NodeJS Framework, and any emulator you should choose to use. There is a catch with iOS however. You can only build iOS apps on a Mac based computer. As such, being a PC user, I will focus this tutorial on the Android Platform.
This tutorial will simply cover the very basics of getting started.
Installation:
-Java
Java 6 is required. Java 7 will absolutely not work in my experience. It took me hours of fiddling to figure this out. Its just not supported. Perhaps in future versions this may be supported, but not at this time to my knowledge.
-Titanium
--NodeJS
--Android Emulator
Titanium Studio theoretically comes with the ability to install the required software to function including NodeJS and Android. However in my experience this often doesn't work as well as it should. If it works as it should, NodeJS should be installed as part of the package, and if you go to the "Getting Started" tab in Titanium on the Dashboard you can install and configure your SDK's. Under the Android Management console you need to install the Rev 17 platform (Android version 2.2 if I recall), and the latest version available. Once this is done there should be a green check mark next to the Android SDK under getting started in Titanium.
However you may be required to go to the following sites and download + configure manually one or both of these software packages.
NodeJS: http://nodejs.org
Android Emulator: http://developer.android.com/sdk/index.html
At that point you can go to the Titanium Preferences screen and enter the installation paths manually. Once this is done, in the case of Android, you will still need to go and configure the Android package to install the minimum and maximum versions as described above.
Creating a new project:
Go to File -> New -> "Mobile Project". On the popup screen, for the purposes of this tutorial, we'll select "Single Window Application". It will now ask you for a few details. The first is the project name. I will enter testApp1 for this tutorial. Next is the AppId. This should be a unique name in the format com.companyname.apptitle. So for example, I would use com.adepttechs.testApp1. Nothing else on this page is required however feel free to enter any details you would like and hit finish.
You have an app! If you were to build this now you would have an a.pp with a blank white screen.
Building an App:
All it takes to build an app is to hit Run. This will build an apk in the project direcory and run it in the android emulator.
Getting Started Programming:
In order to start programming you need to locate the app.js file. This is where all the magic happens. On the left side there is a folder pane with a "Resources" folder. Expand the folder and you will find your app.js. Click on that filename to open the project and you will see some existing code. This is the code that creates that mobile app with a white background and nothing else. But that isnt too exciting is it. You can check out this code and study it for yourself, but for the purposes of this tutorial I would suggest you delete everything there.
Creating a Window:
Code:
var homeWin = Ti.UI.createWindow({
title: "testApp1",
backgroundColor: "#000000",
exitOnClose: true,
});Adding an image:
Code:
var bannerImg = Ti.UI.createImageView({
top: 0%,
left: 10%,
width: 50%,
height: 50%,
image:'/images/banner.png',
});This creates an image object that can be placed on a window. The name of this is object is "bannerImg" and its attributes are specified in the top, left, width, height fields. This can be expressed in percentages or fixed pixel values. The image field contains the location and name of the image in relation to the project install directory. so if my project was saved in /home/geoff/titanium/testApp1/, then the image should be placed in /home/geoff/titanium/testApp1/Resources/images/.
Now we're not done. Like the Window, the image object has been created, but not added. To add the image to the window we need to use the code homeWin.add(bannerImg);
Labels:
We can also add text fields, called labels, to our app.
Code:
var myLabel = Ti.UI.createLabel({
text: "Hi new App Developers!",
top: 50%,
height: 100,
width: "100%",
textAlign: "center",
color: "#FFFFFF",
backgroundColor: "#000000",
});The attributes should be self explanatory. This creates a text field half way down the window centred across the full width with a white background and black text.
Our code so far:
So to add it all together, at this point we should have an app.js file that looks something like
Code:
// Window
var homeWin = Ti.UI.createWindow({
title: "testApp1",
backgroundColor: "#000000",
exitOnClose: true,
});
// Image
var bannerImg = Ti.UI.createImageView({
top: 0%,
left: 10%,
width: 50%,
height: 50%,
image:'/images/banner.png',
});
// Text Label
var myLabel = Ti.UI.createLabel({
text: "Hi new App Developers!",
top: 50%,
height: 100,
width: "100%",
textAlign: "center",
color: "#FFFFFF",
backgroundColor: "#000000",
});
// Put it all together
homeWin.add(bannerImg);
homeWin.add(myLabel);
homeWin.open();We can also make these objects respond to touch input. How about we make the Banner image show an alert when pressed? We do this with this piece of code
Code:
bannerImg.addEventListener('click',function(e){
alert('This is an event driven alert!');
});Again we reference the object we want to apply the event listener to, and then specify what we want done.
Storing data:
We can easily store integer data within the app by using
Code:
Titanium.App.Properties.setInt("identifier", data);Code:
Titanium.App.Properties.setString("identifier", data);"identifier" is a string identifier used to recall the stored data. data is whatever you wish to place there.
To retrieve the data stored is simply a matter of referencing the identifier using the code Titanium.App.Properties.getInt("identifier"); or in the case of a string,
Code:
Titanium.App.Properties.getString("identifier");if/while statements:
These are pretty straight forward as well.
Code:
while (i < 10) {
i++;
}
if(i == 10) {
// Do something
}Databases:
Titanium has decent support for SQLite built in. I'm not going to get into how to create an sqlite db but I will cover basic data input/extraction.
To set up an existing database to use in Titanium you use the following code
Code:
var db = Ti.Database.install('/yourdatabase.db', 'TestApp1');To run queries you use db.execute. For example an insert is as simple as:
Code:
db.execute('INSERT INTO dbTable VALUES ("","")');However if you want to SELECT data, you need to put the output of the query in a variable like so:
Code:
var myVar = db.execute('SELECT something FROM myTable WHERE rowid = 1');Conclusion:
And that's it for now. This is just an intro tutorial for getting started with Titanium. There is a lot more that can be done with Titanium although there are some limitations. There are a lot of available resources to handle more advanced capabilities on their developer site as well as other developer contributed modules and code... Check out some of these other resources:
http://docs.appcelerator.com/titanium/la...uick_Start
http://docs.appcelerator.com/titanium/latest/
http://www.appcelerator.com/developers/
http://developer.appcelerator.com/questions/newest
Questions comments or concerns let me know. I may yet update and add to this as well... So while ill consider it complete for now... if questions arise i may add to it.

![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)











