Today there are many companies who are planning to develop mobile applications, either as a way of showing their information in a more accessible way or to attract new customers. It is a blooming industry for developers and users of this technology, because of the app stores, where any developer can upload an applications and make money with it. This involves creating apps for the different available platforms (Android, IOS Blackberry, Windows Phone), but programming for each platform is more expensive and takes a lot more time than programming using a tool such as Appcelerator and its development environment Titanium.
Appcelerator is a tool that enables developers of all levels, program applications that can be installed on various platforms for smartphones. I will show a basic tutorial to create a simple application using Appcelerator Studio. One advantage of Appcelerator is that we can program our applications following the MVC architecture (Model-View-Controller) where, using XML and CSS we can separate the user interface, the business logic and data.
To create our new application we will select the framework Alloy in File->New->Mobile App Project
In the next window, we will give a name and an ID to our project. The name of the project will be mylibrary. Additionally we can choose our deployment platform app. Remember that we should have the necessary SDK.
Finally, select the version of Titanium SDK to use and this will finish the wizard setup.
Before continuing let's explain briefly the mylib application.
It is a simple application that uses a list and several labels to display a list of books of interest. Selecting one of them will show information about the book, such as the author's name and the publishing date.
The structure of a project in Alloy Appcelerator it is as shown in the picture
The app directory contains the models, views, controllers and application assets.
To continue, we create a new model. Right click on the project name and select new->Alloy Model The setup wizard will help us create the model, for it, we will write as the model name "books" and will add the fields. In our case, it will only be "title" for the title of the book, "author" for the name of the author and "date" for the publishing date of the book.
We click "OK" and our model has been created.
The next step is to modify the driver app/controllers/index.js The code should look as follows:
//Guardamos el libro book.save();
The previous code creates a new model called mybooks and the information is saved for the first book created
We continue to modify the index view in app/views/index.xml to list our books created in the controller.
In this code, we create a new Collection "books" and define the view of the table that will display the title and author of the book. Additionally we initialize the onclick event, for when pressing the element it will display the screen with additional information of the book.
We must create the method "detailsHandler" in our index.js controller to define its operation We return to the file app/controllers/index.js and add the following:
As we can see, we need to create a new controller that will be called "bookdetails". For it, we shall go in the directory "controllers" and add a new "Alloy Controller". This will create bookdetails.js and bookdetails.xml.
Open Bookdetails.xml and create the new view, copy the following code:
We have created a new screen with three labels about book's information.
We now open the bookdetails.js file and copy the following:
That is all for now. To test our application, we selected a virtual or real device in the device selector and press Run. In my case I will use a virtual device with Android 4.1.1.
When finished compiling our application, it will look like this:
We can add more books from a REST or manually, to enrich our library.
In a future blog we will explain how to apply styles to the screens and Labels to make our application look much better.
As we just saw in this example, Appcelerator is a tool that lets you create applications in a very simple and professional manner. Thanks to the Alloy framework our applications has the MVC architecture, which allows us to separate the user interface, business logic and data.
The biggest asset of this tool is that you can create a cross-platform application, by writing the code in a single programming language, saving time and money.