This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Learn » eZ Publish » Building native mobile applications...

Building native mobile applications with the eZ Publish REST API

Thursday 13 October 2011 4:21:48 pm

  • Currently 4 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Android sample application

Open Eclipse and select “New -> Android Project” from the “File” menu.

New Android project

 

Enter the following information for the project:

  • Project name: “Reader”
  • Build target: “Android 2.3.3”
  • Application name: “Reader”
  • Package name: “com.ez”
  • Create activity: “JSONListActivity” (and make sure that the checkbox is marked)
  • Min SDK version: “10”

Then, click the “Finish” button. You can inspect the project structure in the left pane.

Android project structure

 

Next, select “Window” -> “Android SDK and AVD Manager”. In the resulting dialog, select “Virtual devices” from the left panel and click the “New...” button.

AVD Manager

 

Enter a name for your device, and choose an SDK target and screen resolution. Set the SD Card size to 12MiB (this is just to specify a card size for the Android emulator).

Creating an AVD

 

Setting up the main view

Our application will present multiple screens of information, one with a list view and the second with a details view. The Android SDK provides a convenient way to quickly display a list of data using a superclass called “android.app.ListActivity”. This activity already provides a list and content view, ready to use and populate with data.

Open “JSONListActivity.java” and change the superclass of “JSONListActivity” to extend “ListActivity”, removing the setting of the “ContentView” from the “onCreate” method.

public class JSONListActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}
 

Since we are going to operate on nodes, we need to create a business object that will hold node-related information. Select “New -> Class” from the “File” menu in the “src/com.ez” package. Enter “Node” as the class name, then click the “Finish” button.

New Java Class

 

Because we are going to pass node objects into the detail view, we need to implement a “java.io.Serializable” interface and implement the “serialVersionUID” property (this is a unique value used to recognize a serialized object; most IDEs can generate this for you, or you can create one yourself):

package com.ez;

public class Node implements java.io.Serializable {
    private static final long serialVersionUID = 432509327611624427L;
}
 

We will store the eZ Publish node ID and object name within the Node business object, thus we need to add two properties:

package com.ez;

public class Node implements java.io.Serializable {
    private static final long serialVersionUID = 432509327611624427L;
    private int id;
    private String name;
}
 

Next, we need to add getter and setter methods. Eclipse provides a very convenient way to automate this process. Select “Generate Getters and Setters...” from the “Source” menu. In the resulting window, mark the checkboxes for the “id” and “name” properties, then click the “OK” button.

Generating getters and setters

 

Finally, we need to implement an override of the “toString()” method, which is going to be used to display the node name in the list view:

package com.ez;

public class Node implements java.io.Serializable {
    private static final long serialVersionUID = 432509327611624427L;
    private int id;
    private String name;

    public void setId(int id) {
        this.id = id;
    }
    
    public int getId() {
        return id;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
    
    @Override
    public String toString() {
        return name;
    }
}
 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)

Proudly Developed with from