Announcing Titanium4j Mobile 2.0
Submitted by Ef on Wed, 08/22/2012 - 17:25
Forums:
Titanium Mobile development is now better then ever. Release 2.0 of our Java API for Appcelerator Titanium Mobile is finally here and we are excited to share with you what we've been working on for the past few months. The Goal of this release was to improve the way you develop Titanium applications by providing features and capabilities beyond what is available in the JavaScript based Titanium development model.
In this version we rewrote the framework from the ground up, fixed a handful of bugs and added an entire set of new features. Let's take a look at some of the most prominent ones.
This example will not only show you how to use UI Components and layouts but how you can even integrate Touch4j to display charts for example. Titanium does not provide a charting package. So we think beeing able to use Touch4j and Titanium in the same application using the same code base is a feature that we are sure you will come to love and appreciate.
This demo illustrates the following set of API's
With this example you will learn how to leverage Geolocation and Google Maps in your apps.
This demo will help you understand how to use :
This example will show you how to :
Titanium4j Mobile 2.0 is a big release with a ton of new things and extra cool features.
As always, you can find the Emitrom team and the rest of the Emitrom community in the Forum or by contacting the support team
We are really excited to see what you will build with Ti4j 2.0 !
Happy coding!
Cleaner ,simpler and more intuitive API
In 1.0 the API looked as follows:
Button button = UI.createButton();
button.setTitle("Tap me");
button.addClickHandler(new TiEventListener<ClickEvent>() {
@Override
protected void onEvent(ClickEvent event) {
Titanium.alert("Hello, World");
}
});
While this was working pretty well, it had some limitations. First, Components were created through factory methods and not contructors. And because all objects were mostly thin wrappers around GWT JavaScriptObjects, extending them to create custom composites was not possible. Below is a taste of what the new API in 2.0 looks like:
Button button = new Button("Tap me");
button.addClickHandler(new InteractionHandler() {
@Override
public void onClick(InteractionEvent event) {
Titanium.alert("Hello,World");
}
});
As you can see, button is now a first class Java object with a real constructor. Because all components are now real java objects, they are easy to extend as depicted in the following code snippet:
import com.emitrom.gwt4.ti.mobile.client.ui.Window;
/**
* Implements the MainWindow of the application
*/
public class CalculateWindow extends Window {
private static final CalculateWindow INSTANCE = new CalculateWindow();
public static CalculateWindow get(){
return INSTANCE;
}
private CalculateWindow(){
this.setWidth(320);
this.setHeight(480);
this.setTop(0);
this.setLeft(0);
this.setTitle("Loan Calculator");
this.setBarImage("assets/navbar.png");
this.setBackgroundImage("assets/background.png");
this.add(CalculateView.get());
}
}
Server side Integration
Integrating your mobile app with any type of server is an important aspect, especially for enterprise applications. Titanium4j Mobile 2.0 now adds support for all GWT server side transport mechanisms From RequestBuilder to GWT-RPC via RequesFactory everything is supported giving you more power then the regular JavaScript based Titanium API. Integrating stuff like Spring , EJB or Hibernate is easy as in any other enterprise Java application . For example making an AJAX request is simpler and follows the very same approach as any regular GWT based application:
requestBuilder = new RequestBuilder(RequestBuilder.GET, XML_FEED_URL);
try {
API.get().info("Sending request");
requestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
API.get().info("Xml Response received");
LoadingIndicatior.get().hide();
EventBusUtil.get().fireEvent(new XmlLoadedEvent(response.getText()));
}
@Override
public void onError(Request request, Throwable exception) {
API.get().error("Request error : " + exception.getMessage());
}
});
} catch (RequestException e) {
Titanium.alert("Request Exception", e.getMessage());
}
GWT JSON Support
In this release we also added the ability to use the GWT JSON API to parse JSON responses from the server giving you a more robust and more importantly a strong typed way to parse JSON. See an example for this below:
private void parseJsonResponse(String jsonString) {
API.get().info("Response : ");
API.get().info(jsonString);
JSONValue value = JSONParser.parseStrict(jsonString);
JSONObject object = value.isObject();
JSONObject results = object.get("results").isObject();
JSONArray items = results.get("item").isArray();
for (int i = 0; i < items.size(); i++) {
JSONObject item = items.get(i).isObject();
String title = item.get("title").isString().stringValue();
String description = item.get("description").isString().stringValue();
String link = item.get("link").isString().stringValue();
fillTableViewRows(title, description, link);
}
//more code here
}
Powerful Examples
In this release we added real world examples to help you build amazing apps. Let s look at some of them :1) The loan Calcutor
This example will not only show you how to use UI Components and layouts but how you can even integrate Touch4j to display charts for example. Titanium does not provide a charting package. So we think beeing able to use Touch4j and Titanium in the same application using the same code base is a feature that we are sure you will come to love and appreciate.
2) My Recipes
This demo illustrates the following set of API's
- RequestBuilder.
- XML Loading and Parsing.
- JSON Loading and Parsing.
- How to use the TableView Component.
- SQL API.
- Webview.
3) Exercise Tracker
With this example you will learn how to leverage Geolocation and Google Maps in your apps.
4) Holyday Memories
This demo will help you understand how to use :
- Camera.
- Video.
- Audio.
- File and Directory API.
- ScrollView Component.
5) Photo Sharing
This example will show you how to :
- Send Emails.
- Integrete social media in your app.
- FileSystem API's.
Titanium4j Mobile 2.0 is a big release with a ton of new things and extra cool features.
As always, you can find the Emitrom team and the rest of the Emitrom community in the Forum or by contacting the support team
We are really excited to see what you will build with Ti4j 2.0 !
Happy coding!

android crash in Ti.UI.createButtonBar()
Dear Sir:
Ti.UI.createButtonBar() is deprecated starting 1.8.1 and will be removed in 1.9.0. Any usage of this will result in an application crash
[WARN][dalvikvm( 398)] threadid=1: thread exiting with uncaught exception (group=0x4001d800)
regards
anson
Android ?
Are you using the ButtonBar in Android or iOS ?
Dear Sir:
Dear Sir:
both,
IOS is ok, and run test on Android., exception happened.
regards
anson
Not supported on Android
ButtonBar is not supported on Android.
We might move it to the ui.ios package to make it more clear.
Cheers,
Pat
ButtonBar
Dear Pat:
Thanks you for quickly answered.
yes , you are right , my misunderstanding for this.,
But TI4j , it's really good ..and helpful !!
regards
anson
source repo for examples?
I looked on your github and svn repos for the source code for the titanium4j-3.0 samples mentioned in this post.
Can you direct me to sample code that shows how to use requestbuilder, rpc and requestfactory?
Is there sample code that documents the correct usage for the widgets in titanium4j-3.0?
Some resources
We are in the process of opensourcing the examples. Please give us some time
In the meantime here s what can get you going :
RequestBuilder + JSON + XML : http://emitrom.com/node/359
RPC : http://emitrom.com/node/34
The RPC still uses Ti4j 1.0 API but i think it s pretty to port it to 2.0
We dont have nothing ready for RequestFactory yet but we are working on it.
If there is something specific you want to know about widgets just hit us in the forum and we will get back to you asap.
Cheers,
Pat.
re: some resources
Thanks for your reply. Questions:
(1) is there a similar RPC class in titanium4j.3.0 ?
(2) are the widgets in titanium4j.3.0 native to the platform (ios, android, etc.)?
RPC class
1) There is no such a thing like a "RPC class" inside Ti4j. The RPC class in the demo i showed you is the default one that gets created when you create a GWT project (GreetingsService).
2) Yes. Ti4j createds native applications for Android and iOS. Not HTML5 based one.