ADF Mobile : Your First Navigation and Device Interaction new mobile application

ADF Mobile : Your First Navigation and Device Interaction

Now ADF Mobile is generally availble, it is now time to create your first ADF Mobile application. In this post I will show you how to create a simple application that contains of two pages with navigation. A bonus for this post is that you will see how to get a picture from the filesystem (or by using the device camera) from within your ADF mobile application

Getting started

To work with ADF mobile you need to download the JDeveloper 11.1.2.3 and the ADF mobile extension and install both. After installing JDeveloper and adding the ADF Mobile extension, you will be able to create a new ADF Mobile Application. In the new gallery you wil find the ‘Mobile Application’ under the applications node.

New Mobile Application

Accept all the defaults and the JDeveloper application is created for you. What you see are two projects. One called the application controller, and a second one, the viewController. JDeveloper also adds application-level and project-level artifacts.

InitialProject

The applicationController contains several artefacts such as the Datacontrol definition, files for skinning, and a class called LifeCycleListenerImpl. This class can be used to add your own functionality during the different stages of the application life cycle. In the viewController you only see a file called adfmf-feature.xml. This file is used to add, remove, or edit the application features embedded within the mobile application. At an application level, the adfmf-application.xml file is created, which enables you to configure the mobile application.
You will also find application level files that are created for you such as platform specific images for splashscreens and application icons. These can be customized.

applevel

That is all you need to get started, and luckily, it is all created for you.

Your first simple ADF Mobile Application

Lets create a two simple java classes to be our data provider.

package nl.amis.technology.mobile.mobile;
public class Contact {
public Contact(String firstname, String lastname) {
super();
this.firstname = firstname;
this.lastname = lastname;
}
private String firstname;
private String lastname;
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getFirstname() {
return firstname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getLastname() {
return lastname;
}
}

And

package nl.amis.technology.mobile.mobile;
import java.util.ArrayList;
import java.util.List;
public class Contacts {
private List l_contacts = null;
public Contacts() {
super();
}
public Contact[] getContacts(){
Contact[] contacts = null;
l_contacts = new ArrayList();
l_contacts.add (new Contact("Luc", "Bors"));
l_contacts.add (new Contact("Aino", "Andriessen"));
l_contacts.add (new Contact("Paco", "van der Linden"));
l_contacts.add (new Contact("Trainee", "Number three"));
l_contacts.add (new Contact("Trainee", "Number four"));
contacts = (Contact[]) l_contacts.toArray(new Contact[l_contacts.size()]);
return contacts;
}
}

Now create a datacontrol based on the Contacts class.

createDataControl

With the datacontrol in place, it is now time to create the page that will use the Contact collection.

Creating features, taskflows and pages

Go to the adfmf-feature.xml file in order to add a new feature. This can be done by clicking the plus icon. For now, lets call this feature ‘contacts’.

addFeature

This only adds an entry in the xml file, but the actual page or taskflow implementing the feature is not created. This is also an action that can be done from within the adfmf-feature.xml file. By clicking the plus icon (you must be on the content tab for the feature) you can pick either AMX page or taskflow. Choose taskflow and continue.

createTaskflow

The taskflow editor now appears with the empty newly created taskflow. Now it is time to add view activities to the taskflow. If you are familiar with ADF development, this the exact same approach as if you were building a ‘regular’ ADF application. Just drag the viewactivities from the component pallet onto the taskflow diagram and add navigation between them. In this case I created two viewactivities. One to show the list, and a second on create a picture of the selected contact.

taskflow

Creating the pages

The next step is creating the actual pages. This can be done by doubleclicking the view activities on the taskflow diagram. Start with the list page. In the create page wizard, uncheck ‘both’ action checkboxes. There is no need got these now.

CreateListPage

On the list page it makes sense to show the content in a ‘List’ layout. With ADF Mobile and JDeveloper you can create this exactly the way you want. Drag and drop the contact collection from the datacontrol onto the page and select ‘ADF Mobile List View’ from the context menu.

Drop as List

In the ListView gallery you can pick from a lot of different Lists, but for now, just stick with the default. For the list view only display the last name. No need for the firstname, however, if you really want to….. just add it. The result should look somewhat like this:

resultOne

This page will work if all went according to plan. The next step is to add navigation to the second page.
Adding navigation
In order to navigate to the second page, and to see the selected trainee on this second page you need to do two things. The page needs to know when to navigate. For that, we can use the action property of the <amx:listItem> component. Change the action property to “add” which corresponds to the navigation case defined in the taskflow. Either type it, or select it from the dropdown.

listItemAction

Next make sure that the selected row is made available on the second page. For this a setPropertyListener can be used (Hey, you already knew that from your ADF experience). Set the from property to #{row}, and the to property to #{pageFlowScope.row}.

setProp

Now create the second page by doubleclicking on the viewactivity in the taskflow editor, or via invocing the new gallery and pick create new ADF Mobile Page (AMX). In the header facet the #{pageFlowScope.row} reference can be used to display the whole name of the selected contact.

&lt;amx:facet name="header"&gt;<br />
&lt;amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/&gt;<br />
&lt;/amx:facet&gt;

Creating the picture

This page will be used to take a picture of the contact. This looks pretty complicated but as a matter of fact, it is very straightforward. ADF Mobile ships with a deviceFeature datacontrol. On of the operations in here is the ‘getPicture’. Drag this operation from the datacontrol onto your page, and drop it as a ADF Mobile Button.
getPicture

In the Edit Action Binding set destinationType to 1 so the image is returned as a fileName, and specify width and height for the image.
getPicture-settings
You might want to play with the sourcetype. On a simulator this makes no sense, but on an actual device you can invoke the camera by setting sourceType = 1.

An action binding is added to the corresponding pagedefinition file. Again, you already know this from regular ADF development.

&lt;methodAction id="getPicture" RequiresUpdateModel="true" Action="invokeMethod" MethodName="getPicture"<br />
IsViewObjectMethod="false" DataControl="DeviceFeatures"<br />
InstanceName="data.DeviceFeatures.dataProvider"<br />
ReturnName="data.DeviceFeatures.methodResults.getPicture_DeviceFeatures_dataProvider_getPicture_result"&gt;<br />
&lt;NamedData NDName="quality" NDType="int"/&gt;<br />
&lt;NamedData NDName="destinationType" NDValue="1" NDType="int"/&gt;<br />
&lt;NamedData NDName="sourceType" NDType="int"/&gt;<br />
&lt;NamedData NDName="allowEdit" NDType="boolean"/&gt;<br />
&lt;NamedData NDName="encodingType" NDType="int"/&gt;<br />
&lt;NamedData NDName="targetWidth" NDValue="150" NDType="int"/&gt;<br />
&lt;NamedData NDName="targetHeight" NDValue="200" NDType="int"/&gt;<br />
&lt;/methodAction&gt;

Now drop the returnvalue of the getPicture from the datacontrol on your page as an outputtext. Remove that textfield immediately. The Dnd action was only nessecary in order to create a binding for this returnvalue. It can now be used as the source for an <amx:image> component.

&lt;amx:image id="file" source="#{bindings.Return.inputValue}"/&gt;

Finally add a button to navigate back to the list page. The page would look like this:

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br />
&lt;amx:view xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>" xmlns:amx="<a href="http://xmlns.oracle.com/adf/mf/amx">http://xmlns.oracle.com/adf/mf/amx</a>"<br />
xmlns:dvtm="<a href="http://xmlns.oracle.com/adf/mf/amx/dvt">http://xmlns.oracle.com/adf/mf/amx/dvt</a>"&gt;<br />
&lt;amx:panelPage id="pp1"&gt;<br />
  &lt;amx:facet name="header"&gt;<br />
     &lt;amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/&gt;<br />
  &lt;/amx:facet&gt;<br />
  &lt;amx:commandButton actionListener="#{bindings.getPicture.execute}" text="getPicture" disabled="#{!bindings.getPicture.enabled}" id="cb1"/&gt;<br />
  &lt;amx:image id="file" source="#{bindings.Return.inputValue}"/&gt;<br />
  &lt;amx:commandButton action="return" text="List" id="cb2"/&gt;<br />
&lt;/amx:panelPage&gt;<br />
&lt;/amx:view&gt;

Deploying and testing

Before being able to test the application you need to create a deployment profile. Go to your application properties and select “new deployment profile” and create one for ADF Mobile for iOS. Accept the defaults for now.
profile

Now you can deploy the application to an iOS simulator or device.
After deploying to an iOS simulator the application works. Click on the application icon to start the application. The app starts and you will see the list view. Click (or tab on a real device) on one of the names in the list view. The Picture view opens empty with the name of the selected contact in the header. Now you can invoke the getPicture button. .
startscreen Listview getPictureButton
On a real device the camera can be invoked if you would set sourcetype = camera (or 1), on the simulator, you get to pick an image from the gallery. After taking the picture (or selecting it), the image displays in the application, right where we want it.
selectFromGalery result
I created this application on a Macbook so I can use the iOS simulator to run the application. However, the exact same application will run on an iPhone, iPad if you deploy it to the device instead of deploying it to the simulator. And it will also run on Android devices. The only thing you need to do is create a deployment profile for Android and deploy to the actual device.

Footnote
This blogpost is created under the assumption that you have already installed all SDK’s for Android Development, and the xCode for iOS development. Also all settings for Android and iOS development in JDeveloper need to be set and point to the android SDK and xCode locations. Running on Android Simulators is extemely slow, so you will probably need to connect your device and deploy to it in order to test your application. I will propbably write more on these topics in the near future.

One Response

  1. Diego June 6, 2014