Fusion Middleware Documentation
Advanced Search


Oracle Enterprise Pack for Eclipse Developing Mobile Applications with Oracle Mobile Application Framework (OEPE Edition)
Close Window

Table of Contents

Show All | Collapse

4 Defining a Mobile Application

This chapter describes using the Oracle Mobile Application Framework overview editors to define the display behavior of the mobile application's springboard and navigation bar and how to designate content by embedding application features.

This chapter includes the following sections:

4.1 Introduction to Defining Mobile Applications

A mobile application can have one or more view controller-type projects, each of which describes a set of features in an maf-feature.xml file. As described in Chapter 3, "Getting Started with Mobile Application Development," MAF provides you with the maf-application.xml configuration file for the mobile application itself, and the maf-feature.xml file, which you use to define the content of the application. While you can manually change these files, MAF provides two overview editors that enable you to build these files declaratively:

  • the MAF Application Editor, which provides a declarative interface for editing the maf-application.xml file; and

  • the Mobile Feature Editor, which provides a declarative interface for editing the maf-feature.xml file.

4.1.1 Using the MAF Application Editor for maf-application.xml

The MAF Application Editor enables you to configure the maf-application.xml file to describe a mobile application and its resources. Each page of the editor enables you to add or update the elements of the configuration file. From these pages you have access to registered features (created with the MAF Feature Editor), navigation, device access, security, feature archives, and plugins. For more information, see Section 4.4, "Setting the Basic Information for a Mobile Application."

4.1.2 Using the Mobile Feature Editor for maf-features.xml

The MAF Feature Editor enables you to add features to your application by editing the maf-features.xml file. You create the features with this editor, and specify the characteristics (ID, name, description, vendor information, version, lifecycle event listener, security, and images for navigation and for the springboard) through the editor. For more information, see Section 4.10, "Setting the Basic Configuration for the Application Features."

4.2 Using the Oracle MAF Perspective

In Eclipse, a perspective is a collection of views arranged in a specific layout that is suitable for a type of development. MAF has its own perspective which you should use when you are developing MAF applications. It gives you access to menu and toolbar options that we describe elsewhere in this manual.

To change to the Oracle MAF perspective:

  1. In the IDE, click Window > Open Perspective > Other.

    Alternatively, click This image is described in the surrounding text.

  2. In the Open Perspectives dialog, choose Oracle MAF. Click OK.

4.3 About the Mobile Application Configuration File maf-application.xml

The maf-application.xml configuration file enables you to set the basic configuration of the mobile application by designating its display name, a unique application ID (to prevent naming collisions) and also by selecting the application features that will display on the application springboard (the equivalent of a home page on a smartphone). Further, this file enables you to create the user preferences pages for the mobile application. This file, which is generated by Oracle Enterprise Pack for Eclipse after you complete the application creation wizard as described in Section 3.2, "Creating an Application Workspace," is composed of the elements listed in Table 4-1.

Table 4-1 Elements of the Application Descriptor File

Element Description

<adfmf:application>

The root element of maf-application.xml.

<adfmf:description>

A description of the application.

<adfmf:featureReference>

A feature reference denotes which of the application features packaged in the FAR (Feature archive file) or defined in the maf-feature.xml file is relevant to the content of the mobile application. You define the character and content of mobile applications by selecting feature references. For more information about FARs, see Section 4.14, "Working with Feature Archive Files."

<adfmf:preferences>

Enables you to set the user preference options and behavior at the application level. You can also set how user preferences display and behave for the application features in the maf-feature.xml file. For more information, see Chapter 13, "Enabling User Preferences."

<adfmf:login>

Enables you to set the login page for an application feature. For more information, see Chapter 21, "Securing Mobile Applications."

<adfmf:navigation>

Enables you to define the behavior of the navigation bar and the springboard. A springboard is a home page in which all of the application icons and labels for the embedded application features are organized in a List View. A springboard provides a top-level view of all of the applications available to a user, who can page through and select applications. For more information, see Section 4.6, "Configuring the Springboard and Navigation Bar Behavior."


Example 4-1 illustrates the maf-application.xml file for an application called Acme Sales, a mobile application whose content includes a customer contacts application (<adfmf:featureReference id="customers" showOnNavigationBar="true"/>) which displays on the springboard, as shown in Figure 4-1.

Example 4-1 The maf-application.xml File

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:adfmf="http://xmlns.oracle.com/adf/mf"
                   name="Acme Sales"
                   id="com.company.AcmeSales"
                   appControllerFolder="ApplicationController"
                   version="1.0"
                   vendor="Oracle"
                   listener-class="application.LifeCycleListenerImpl">
    <adfmf:description>Sample Application</adfmf:description>
<adfmf:featureReference id="Customers"
                        showOnSpringboard="true"
                        showOnNavigationBar="true"/>
<adfmf:featureReference id="HCM"
                        showOnSpringboard="true"
                        showOnNavigationBar="true"/>
<adfmf:featureReference id="PROD"
                        showOnSpringboard="true"
                        showOnNavigationBar="true"/>
    <adfmf:preferences>
        <adfmf:preferenceGroup id="Root.Security" label="Security">
            <adfmf:preferenceText id="OracleSecurityProvider_serviceURL"
                                  label="Security URL"
                                  default="http://somecomputer.example.com:someaddress/
                                           idaas_rest/rest/tokenservice1/tokens/getprofile"/>
            
            <adfmf:preferenceText id="OracleADFMobile_UserName" label="User Name" default="sean"/>
            <adfmf:preferenceText id="OracleADFMobile_Password" label="Password" default="welcome1" 
                                                                secret="true"/>
        </adfmf:preferenceGroup> 
    </adfmf:preferences>
    <adfmf:navigation>
        <adfmf:springboard enabled="false"/>
        <adfmf:navigationBar enabled="true"/>
    </adfmf:navigation>
</adfmf:application>

Figure 4-1 Application Features Displaying in the Mobile Application's Springboard

This image is described in the surrounding text

You can modify these elements declaratively using the MAF Application Editor, shown in Figure 4-2, or manually using the XML Editor or the Source editor. You can use these approaches interchangeably.

Figure 4-2 The MAF Application Editor for the maf-application.xml File

This image is described in the surrounding text

4.4 Setting the Basic Information for a Mobile Application

The MAF Application Editor enables you to set the name, application ID, and how the mobile application displays. You can also enter vendor and version information, select or create a lifecycle event listener (see Section 4.8), and define a custom URL scheme (see Section 4.5).

To access the MAF Application Editor:

  • From the Project Explorer, expand the Application folder, then expand the MAF folder and double-click MAF Application Editor.

4.4.1 How to Set the ID and Display Behavior for a Mobile Application

The Application page of the MAF Application Editor, shown in Figure 4-2, enables you to name the mobile application and control the display of the mobile application within the springboard and navigation bar.

Before you begin:

Open the MAF Application Editor for the maf-application.xml file by double-clicking MAF Application Editor (located in the MAF node of the assembly project in the Project Explorer panel, as shown in Figure 4-3).

Figure 4-3 Selecting MAF Application Editor in the Project Explorer

This image is described in the surrounding text

To set the basic information for a mobile application:

  1. Choose the Application page by selecting the application's name in the Outline.

    Note:

    By default, the editor opens the Application page.

    Figure 4-4 shows the portion of the application page where you define the basic information.

    Figure 4-4 Setting the Basic Information for the Mobile Application

    This image is described in the surrounding text
  2. Enter a display name for the application in the Name field. This attribute can be localized. For more information, see Section 4.12.1, "Working with Resource Bundles."

    Note:

    MAF uses the value entered in this field as the name for the iOS archive (.ipa or .app) file that it creates when you deploy the application to an iOS-powered device or simulator. For more information, see Section 19.2.6, "How to Create an iOS Deployment Configuration."

  3. Accept the default, or enter a unique ID in the Id field.

    To avoid naming collisions, Android and iOS use reverse package names, such as com.company.application. Oracle Enterprise Pack for Eclipse prefixes com.company as a reverse package to the application name, but you can overwrite this value with another as long as it is unique and adheres to the ID guidelines for both iOS- and Android-powered devices. For iOS application, see the "Creating and Configuring App IDs" section in iOS Team Administration Guide (available from the iOS Developer Library at http://developer.apple.com/library/ios). For Android, refer to the document entitled "The AndroidManifest.xml File," which is available from the Android Developers website (http://developer.android.com/guide/topics/manifest/manifest-intro.html). You can overwrite this ID in the deployment profiles described in Section 19.2.4, "How to Create an Android Deployment Configuration" and Section 19.2.6, "How to Create an iOS Deployment Configuration."

    Note:

    To ensure that an application deploys successfully to an Android-powered device or emulator, the ID must begin with a letter, not with a number or a period. For example, an ID comprised of a wholly numeric value, such as 925090 (com.company.925090) will prevent the application from deploying. An ID that begins with letters, such as hello925090 (com.company.hello925090) will enable the deployment to succeed.

  4. Enter a short, but detailed summary of the application that describes the application's purpose in the Description field.

  5. Enter the version in the Version field.

  6. Enter the name of the vendor who originated this application in the Vendor field.

  7. Click Browse next to the Lifecycle Event Listener field to invoke the Edit Property dialog, shown in Figure 4-5, to register the event listener that enables runtime calls for start, stop, activate, and deactivate events. You must enter the fully qualified class name of the event listener. This is an optional field.

    Note:

    If you place the mouse pointer over the label for Lifecycle Event Listener, Oracle Enterprise Pack for Eclipse displays a tooltip describing the listener class.

    Figure 4-5 Retrieving the Application Event Listener

    This image is described in the surrounding text

    The default application listener class is application.LifeCycleListenerImpl. MAF does not register this class by default, because it starts the JVM and therefore may not be preferable for each mobile application. You must instead register this class manually using the Select Class dialog, shown in Figure 4-5. After you close this dialog, Oracle Enterprise Pack for Eclipse updates the <adfmf:application> element with a listener-class attribute, as illustrated in Example 4-2.

    Note:

    The application lifecycle listener must remain within the application controller project (its default location).

    Example 4-2 Adding the listener-class Attribute

    <adfmf:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xmlns:adfmf="http://xmlns.oracle.com/adf/mf"
                       name="OracleMobileApplication"
                       id="com.company.OracleMobileApplication"
                       appControllerFolder="ApplicationController" 
                       listener-class="application.LifeCycleListenerImpl"
                       version="1.1"
                       vendor="Oracle">
       <adfmf:description>This is a mobile application</adfmf:description>
       <adfmf:featureReference id="feature1"/>
    </adfmf:application>
    

    For more information, see Section 4.8, "About Lifecycle Event Listeners."

4.5 Invoking a Mobile Application Using a Custom URL Scheme

A custom URL scheme can be used to invoke a native application from other applications.

To invoke a mobile application from another application, perform the following:

  1. Register a custom URL scheme. You configure this URL scheme in the MAF Application Editor using the URL Scheme field, as shown in Figure 4-4. The URL with this scheme can then be used to invoke the mobile application and pass data to it.

  2. In the application controller project, create a custom URL event listener class (for example, CustomURLEventListener) that is notified of the URL. This class must implement the oracle.adfmf.framework.event.EventListener interface that defines an event listener. For more information on the oracle.adfmf.framework.event.EventListener interface, see Java API Reference for Oracle Mobile Application Framework.

    Override and implement the onMessage(Event e) method that gets called with the URL that is used to invoke this mobile application. The Event object can be used to retrieve useful information about URL payload and the application state. To get URL payload, use the Event.getPayload method. To get the application state at the time of URL event, use the Event.getApplicationState method. For more information, see the Event class in Java API Reference for Oracle Mobile Application Framework.

  3. Register an application lifecycle event listener (ALCL) class. For more information, see Section 4.4, "Setting the Basic Information for a Mobile Application" and Section 4.8, "About Lifecycle Event Listeners."

    Get an EventSource object in the start method of the ALCL class that represents the source of the custom URL event:

    EventSource openURLEventSource = EventSourceFactory.getEventSource(EventSourceFactory.OPEN_URL_EVENT_SOURCE_NAME);
    

    Create and add an object of the custom URL event listener class to the event source:

    openURLEventSource.addListener(new CustomURLEventListener());
    

A mobile application can invoke another native application in two ways:

  • Using an amx:goLink on an MAF AMX page whose URL begins with the custom URL scheme registered by the native application. For example:

    <amx:goLink text="Open App" id="gl1" url="mycustomurlscheme://somedata"/>
    
  • Using an HTML link element on an HTML page whose href attribute value begins with the custom URL scheme registered by the native application. For example:

    <a href="mycustomurlscheme://somedata">Open App</a>
    

4.6 Configuring the Springboard and Navigation Bar Behavior

You can configure the mobile application to control the display behavior of the springboard and the navigation bar in the following ways:

  • Hide or show the springboard and navigation bar to enable the optimal usage of the mobile device's real estate. These options override the default display behavior for the navigation bar, which is shown by default unless otherwise specified by the application feature.

  • Enable the springboard to slide from the right. By default, the springboard does not occupy the entire display, but instead slides from the left, pushing the active content (which includes the navigation bar's Home button and application features) to the right.

4.6.1 How to Configure Application Navigation

The Navigation options of the Applications page, shown in Figure 4-6, enable you to hide or show the navigation bar, select the type of springboard used by the application, and define how the springboard reacts when users page through applications.

Figure 4-6 The Navigation Options of the Application Page

This image is described in the surrounding text

Before you begin:

You must select MAF Application Editor from assembly project > MAF in the Project Explorer to open maf-application.xml.

To set the display behavior for the navigation bar:

  1. Select Show Navigation Bar to enable the mobile application to display its navigation bar (instead of the springboard), by default, as shown in Figure 4-7.

    Figure 4-7 The Navigation Bar, Shown By Default

    This image is described in the surrounding text

    If you deselect Show Navigation Bar, then you hide the navigation bar when the application starts, presenting the user with the springboard as the only means of navigation. Because the navigation bar serves the same purpose as the springboard, hiding it can, in some cases, remove redundant functionality.

  2. Select Show toggle button to hide the navigation bar when the content of a selected application feature is visible. Figure 4-8 illustrates this option, showing how the navigation bar illustrated in Figure 4-7 becomes hidden by the application feature content.

    Figure 4-8 Hiding the Navigation Bar

    This image is described in the surrounding text

    This option is selected by default; the navigation bar is shown by default if the show or hide state is not specified by the application feature.

To set the display behavior for the springboard:

  1. To display the springboard select Show Springboard. This is selected by default.

  2. Select Show on application launch to enable the mobile application to display the springboard to the end user after the mobile application has been launched.

  3. Select Show Springboard Toggle Button to enable the display of the springboard button, shown in Figure 4-9, that displays within an application feature. Figure 4-7, "The Navigation Bar, Shown By Default" shows this button within the context of an application feature.

    Figure 4-9 The Springboard Toggle Button

    This image is described in the surrounding text

To set the slide out behavior for the springboard:

  1. Select Slide Right for Animation. The springboard occupies an area determined by the number of pixels (or the percent) entered for the Width option. If you select <none>, then the springboard cannot slide from the right (that is, MAF does not provide the animation to enable this action). The springboard takes the entire display area.

  2. Set the width (in pixels). The default width of a springboard on an iOS-powered device is 320 pixels. On Android-powered devices, the springboard occupies the entire screen by default, thereby taking up all of the available width.

    Note:

    If the springboard does not occupy the entire area of the display, then an active application feature occupies the remainder of the display. For more information, see Section 4.6.3, "What Happens When You Set the Animation for the Springboard."

4.6.2 What Happens When You Configure the Navigation Options

Setting the springboard and navigation bar options updates or adds elements to the maf-application.xml file's <adfmf:navigation> element. For example, selecting None results in the code updated with <springboard enabled="false"> as illustrated in Example 4-3.

Example 4-3 Preventing the Displaying the Springboard

<adfmf:application>
  ...
  <adfmf:navigation>
     <adfmf:navigationBar enabled="true"/>
     <adfmf:springboard enabled="false"/>
  </adfmf:navigation>
</adfmf:application>

Tip:

By default, the navigation bar is enabled, but the springboard is not. If you update the XML manually, you can enable the springboard as follows:

<adfmf:application>
  ...
<adfmf:navigation>
    <adfmf:springboard enabled="true"/>
  </adfmf:navigation>
  ...
</adfmf:application>

Example 4-4 illustrates how the enabled attribute is set to true when you select Default.

Note:

Because the springboard fills the entire screen of the device, the navigation bar and the springboard do not appear simultaneously.

Example 4-4 Enabling the Display of the Default Springboard

<adfmf:application>
  ...
  <adfmf:navigation>
     <adfmf:navigationBar enabled="true"/>
     <adfmf:springboard enabled="true"/>
  </adfmf:navigation>
</adfmf:application>

4.6.3 What Happens When You Set the Animation for the Springboard

Example 4-5 shows the navigation block of the maf-application.xml file, where the springboard is set to slide out and occupy a specified area of the display (213 pixels).

Example 4-5 Configuring Springboard Animation

<adfmf:navigation>
   <adfmf:navigationBar enabled="true"
                        displayHideShowNavigationBarControl="true"/>
   <!-- default interpretation of width is pixels -->
   <adfmf:springboard enabled="true"
                      animation="slideright"
                      width="213"
                      showSpringbaordAtStartup="true"/>
</adfmf:navigation>

The following line disables the animation:

<adfmf:springboard enabled="true" animation="none"/>

The following line sets the springboard to occupy 100 pixels from the left of the display area and also enables the active application feature to occupy the remaining portion of the display:

<adfmf:springboard enabled="true" animation="slideright" width="100px"/>

In addition to the animation, Example 4-5 demonstrates the following:

  • The use of the showSpringboardAtStartup attribute, which defines whether the springboard displays when the application starts. (By default, the springboard is displayed.)

  • The use of the navigationBar's displayHideShowNavigationBarControl attribute.

To prevent the springboard from displaying, set the enabled attribute to false.

4.6.4 What You May Need to Know About Custom Springboard Application Features with HTML Content

The default HTML springboard page provided by MAF uses the following technologies, which you may also want to include in a customized login page:

  • Cascading Style Sheets (CSS)—Defines the colors and layout.

  • JavaScript—The <script> tag embedded within the springboard page contains references to the methods described in Chapter B, "Application Container APIs" that call the Apache Cordova APIs. In addition, the HTML page uses JavaScript to respond to the callbacks and to detect page swipes. When swipe events are detected, JavaScript enables the dynamic modification of the style sheets to animate the page motions.

    A springboard authored in HTML (or any custom HTML page) can leverage the Apache Cordova APIs by including a <script> tag that references the base.js library. You can determine the location of this library (or other JavaScript libraries) by first deploying an MAF application and then locating the www/js directory within platform-specific artifacts in the deploy directory. For an Android application, the www/js directory is located within the Android application package (.apk) file at:

    application workspace directory/deploy/deployment profile name/deployment profile name.apk/assets/www/js
    

    For iOS, this library is located at:

    application workspace directory/deploy/deployment profile name/temporary_xcode_project/www/js
    

    For more information, see Section B.1, "Using MAF APIs to Create a Custom HTML Springboard Application Feature."

  • WebKit—Provides smooth animation of the icons during transitions between layouts as well as between different springboard pages. For more information on the WebKit rendering engine, see http://www.webkit.org/.

Springboards written in HTML are application features declared in the maf-feature.xml file and referenced in the maf-application.xml file.

4.6.5 What You May Need to Know About Custom Springboard Application Features with MAF AMX Content

Like their HTML counterparts, springboards written using MAF AMX are application features that are referenced by the mobile application, as described in Section 4.7.1, "How to Designate the Content for a Mobile Application." Because a springboard is typically written as a single MAF AMX page rather than as a task flow, it uses the gotoFeature method, illustrated by the method expression in Example 4-6, to launch the embedded application features.

Note:

A custom springboard page (authored in either HTML or MAF AMX) must reside within a view controller project which also contains the maf-feature.xml file. For more information, see Section 4.7.1, "How to Designate the Content for a Mobile Application."

The default springboard (adfmf.default.springboard.jar) is an MAF AMX page that is bundled in a Feature Archive (FAR) JAR file and deployed with other FARs that are included in the mobile application. This JAR file includes all of the artifacts associated with a springboard, such as the DataBindings.cpx and PageDef.xml files. This file is only available after you select Default as the springboard option in the maf-application.xml file. Selecting this option also adds this FAR to the application classpath. For more information, see Section 19.3, "Deploying Feature Archive Files (FARs)."

The default springboard (springboard.amx, illustrated in Example 4-6) is implemented as an MAF AMX application feature.

Example 4-6 The Default Springboard page, springboard.amx

<?xml version="1.0" encoding="UTF-8" ?>
<amx:view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:amx="http://xmlns.oracle.com/adf/mf/amx"
          xmlns:dvtm="http://xmlns.oracle.com/adf/mf/amx/dvt">
   <amx:panelPage id="pp1">
      <amx:facet name="header">
         <amx:outputText value="#{bindings.name.inputValue}" id="ot3"/>
      </amx:facet>
      <amx:listView var="row"  
                    value="#{bindings.features.collectionModel}"
                    fetchSize="#{bindings.features.rangeSize}"
                    id="lv1"
                    styleClass="amx-springboard">
         <amx:listItem showLinkIcon="false"  
                       id="li1"
                       actionListener="#{bindings.gotoFeature.execute}">
            <amx:tableLayout id="tl1"
                             width="100%">
               <amx:rowLayout id="rl1">
                  <amx:cellFormat id="cf11"  
                                  width="46px"
                                  halign="center">
                      <amx:image source="#{row.image}"  
                                 id="i1"
                                 inlineStyle="width:36px;height:36px"/>
                  </amx:cellFormat>
                  <amx:cellFormat id="cf12"  
                                  width="100%"
                                  height="43px">
                     <amx:outputText value="#{row.name}" 
                                     id="ot2"/>
                  </amx:cellFormat>
               </amx:rowLayout>
            </amx:tableLayout>
               <amx:setPropertyListener from="#{row.id}" 
                                        to="#{pageFlowScope.FeatureId}"/>
         </amx:listItem>
      </amx:listView>
   </amx:panelPage>
</amx:view>

As shown in Figure 4-10, an MAF AMX file defines the springboard using a List View whose List Items are the mobile application's embedded application features. These application features, once deployed, are displayed by their names and associated icons. The gotoFeature method of the AdfmfContainerUtilities API provides the page's navigation functions. For a description of using this method to display a specific application feature, see Section B.2.6, "gotoFeature." See also Section 6.3.15, "How to Use List View and List Item Components."

Figure 4-10 The Default Springboard

This image is described in the surrounding text

MAF provides the basic tools to create a custom springboard (or augment the default one) in the ApplicationFeatures data control. This data control, illustrated in Figure 4-11, enables you to declaratively build a springboard page using its data collections of attributes that describe both the mobile application and its application features. For an example of a custom springboard page, see the APIDemo sample application. For more information on this application (and other samples that ship with MAF), see Appendix F, "Mobile Application Framework Sample Applications."

Figure 4-11 ApplicationFeatures Data Control

This image is described in the surrounding text

The methods of the ApplicationFeatures data control enable you to add navigation functions. These adfmf.containerUtilities methods are described in Table 4-2. For more information, see Section B.2, "The MAF Container Utilities API." See also Chapter 7, "Using Bindings and Creating Data Controls."

Table 4-2 ApplicationFeature Methods

Method Description

gotoDefaultFeature

Navigates to default application feature.

gotoFeature

Navigates to a specific application as designated by the parameter that is passed to this method.

gotoSpringboard

Navigates to the springboard.

hideNavigationbar

Hides the navigation bar.

showNavigationbar

Displays the navigation bar (if it is hidden).

resetFeature

Resets the application feature that is designated by the parameter passed to this method.


4.6.6 What You May Need to Know About the Runtime Springboard Behavior

If you chose the Show on application launch option and defined the slideout width to full size of the screen, then MAF loads the default application feature in the background at startup. When the mobile application hibernates, MAF hides the springboard.

4.7 Configuring the Application Features within a Mobile Application

Each mobile application must have at least one application feature.

4.7.1 How to Designate the Content for a Mobile Application

Figure 4-14 shows the Feature References page, which enables you to build the content for the mobile application. As noted in Section 4.3, "About the Mobile Application Configuration File maf-application.xml," the mobile application descriptor file's <adfmf:featureReference> element designates these application features.

Example 4-7 Designating Feature References in the maf-application.xml File

<adfmf:featureReference id="Prod"
                        showOnNavigationBar="true"
                        showOnSpringboard="true"/>
<adfmf:featureReference id="Customers"
                        showOnNavigationBar="true"
                        showOnSpringboard="true"/>
<adfmf:featureReference id="HCM"
                        showOnNavigationBar="true"
                        showOnSpringboard="true"/>
<adfmf:featureReference id="custom_springboard"
                        showOnNavigationBar="false"
                        showOnSpringboard="false"/>
<adfmf:navigation>
   <adfmf:springboard enabled="true">
      <adfmf:springboardFeatureReference id="custom_springboard"/>
   </adfmf:springboard>
</adfmf:navigation>

Example 4-7 shows some of the defined feature references and their associated attributes. The MAF Application Editor displays these feature references in the Feature References table. Figure 4-14 shows the defined feature references for HCM and PROD that represent the Customers and Products application features, respectively.

Figure 4-12 Registered Features in the Application Page

This image is described in the surrounding text

Using Registered Features, you enter the references to the application feature and set its display within the mobile application's springboard, as shown in Figure 4-12.

In addition, the page enables you to set the order in which the application features display on the navigation bar and springboard. At runtime, the width of the device screen can limit the number of application features that display on the navigation bar. Those that cannot be accommodated on the navigation bar display under a More tab, as shown in Figure 4-37. Users can reorder the application features within the More tab by using the Edit function.

Figure 4-13 The More Tab

This image is described in the surrounding text

Note:

Because building a mobile application is an iterative process, you can add, delete or update feature references as new FARs become available (and new application features are added to the maf-feature.xml file).

Figure 4-14 Designating Application Features Using the Feature References Page

This image is described in the surrounding text

Before you begin:

You must have application features configured in the MAF Application Editor, as described in Section 4.10, "Setting the Basic Configuration for the Application Features." In addition, you must open the MAF Application Editor.

To designate feature references:

  1. Select Registered Features in the outline of the MAF Application Editor.

  2. Click This image is described in the surrounding text Browse to open the Register Mobile Feature dialog, as shown in Figure 4-15.

    Figure 4-15 Registering Features for an Application

    This image is described in the surrounding text

    This dialog lists all of the application features described in the <adfmf:feature> elements of the maf-feature.xml file Using this dialog ensures that the id attributes of both the <adfmf:featureReference> and <adfmf:feature> elements match. See also Section 4.7.2, "What You May Need to Know About Feature Reference IDs and Feature IDs."

  3. Select the select the ID of the application feature you want to register with the application. You can use Shift and Ctrl to select more than one, and click OK.

    You can also add references to application features that are contained in an imported feature archive (FAR) file. For more information, see Section 4.14.1, "Importing a FAR as an Application Library."

  4. In the Registered Features page of the MAF Application Editor, as shown in Figure 4-14 use the up- and down-arrows to arrange the display order of the feature references.

    The top-most application feature is the default application feature. Depending on the security configuration for this application, MAF can enable users to login anonymously to view unsecured content, or it can prompt users to provide their authentication credentials. For more information, see Section 21.1, "About Mobile Application Framework Security."

    Note:

    The top-most ID in the Feature References table is the first application feature to display within the mobile application. See, for example, the Feature 1 application feature illustrated in Figure 4-7.

    Figure 4-16 Reordering Feature References

    This image is described in the surrounding text
  5. Set the springboard and navigation bar display behavior for the application feature by selecting true or false from the dropdown lists in the rows of the Show on Navigation Bar and Show on Springboard columns. Figure 4-17 shows selecting these options to prevent an application feature from displaying in the navigation bar.

    Tip:

    Set these options to false if the application uses a custom springboard or if the application feature will display as a sliding window. For more information, see Section 4.8.6, "Enabling Sliding Windows."

    Figure 4-17 Changing the Navigation Options

    This image is described in the surrounding text

    The springboard and the navigation bar display by default (that is, these attributes are set to true). If both the navigation bar and springboard attributes are set to false, then the application feature only displays if it is in the first position. See also Section B.2.11, "hideNavigationBar" and Section B.2.12, "showNavigationBar."

    Note:

    Because springboard features do not display on the navigation bar or within the springboard of a mobile application, Show on Navigation Bar and Show on Springboard must both be set to false for feature references used as custom springboard application features. See also Section 4.6.5, "What You May Need to Know About Custom Springboard Application Features with MAF AMX Content."

4.7.2 What You May Need to Know About Feature Reference IDs and Feature IDs

A mobile application can contain many projects and can therefore also include multiple maf-feature.xml files. In the application configuration file, a feature reference relates to a feature described by an maf-feature.xml file. The ID of an <adfmf:featureReference> identifies where the corresponding application feature is defined. In other words, the id attributes for <adfmf:featureReference> elements in the maf-application.xml file must be the same as the id attribute defined for <adfmf:feature> element in maf-feature.xml. For example, <adfmf:featureReference id="customers"> in maf-application.xml is defined by <adfmf:feature id="customers"> in maf-feature.xml. Oracle Enterprise Pack for Eclipse audits the references between the application and feature descriptor files in the same mobile application, and warns you when it finds discrepancies. As shown in Figure 4-18, Oracle Enterprise Pack for Eclipse highlights the mismatch within the code between a feature reference and the features declared in the features application descriptor file with a wavy underline and a Reference not Found warning, which in this case is a feature reference ID defined as Prid rather than the correct Prod.

Figure 4-18 Auditing id Attributes

This image is described in the surrounding text

The feature IDs must be unique across an application. Because application features can be reused, use proper naming conventions to ensure that their feature IDs are unique.

Note:

Do not add an MAF view controller project as a dependency of another MAF view controller project or as a dependency of a mobile application controller project. Doing so adds an <adfmf:feature> element in the added view controller project with the same id attribute as the <admf:feature> element in the maf-feature.xml file of the original MAF view controller project. As a result, the deployment framework terminates the deployment, because it detects that the id attributes for the <adfmf:feature> element are not unique across the mobile application.

4.8 About Lifecycle Event Listeners

Within the MAF runtime, classes implement various LifeCycleListener methods to communicate with event notifications sent from the native operating system frameworks to the JVM. These event notifications describe various states (starting, stopping, or hibernating) for both the mobile application and its embedded application features. MAF invokes the class functions to the JVM using a generic invoke message.

The MAF Application Editor (for maf-application.xml) and MAF Feature Editor (for maf-feature.xml) enable you to declaratively add a lifecycle listener class that MAF calls when events occur. After you enter a fully qualified class name (including the package) using the Class and Package Browser in the editor's LifeCycle Event Listener Class field, Oracle Enterprise Pack for Eclipse populates the XML page with the listener-class attribute. For mobile applications, this attribute is included in the <adfmf:application> element, as shown in Example 4-8.

Example 4-8 The listener-class Attribute in the maf-application.xml File

<adfmf:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:adfmf="http://xmlns.oracle.com/jdev/adfmf"
                   id="app-20110308"
                   name="#{strings.Title}"
                   vendor="Oracle"  version="1.0"
                   listener-class="oracle.adfmf.application.AppListener">
 
...
 
</adfmf:application>

Within the maf-feature.xml file, the listener-class attribute is contained within the <adfmf:feature> attribute, as shown in Example 4-9.

Example 4-9 The listener-class Attribute in the maf-feature.xml File

...
 
   <adfmf:feature id="mycompany.phonelist"
                 name="Phone List"
                 icon="mycompany.phonelist/phoneicon.png"  
                 listener-class="oracle.adfmf.feature.LifeCycleListener">
                 image="mycompany.phonelist/phoneimage.png"
      <adfmf:content id="general">

         <adfmf:amx file="mycompany.phonelist/phone.amx"/>
      </adfmf:content>
 
   </adfmf:feature>
 
...

After you create a mobile application, Oracle Enterprise Pack for Eclipse creates a lifecycle listener class for the application called LifeCycleListenerImpl.java. You can implement specific methods using this file, as illustrated in Chapter 17, "Enabling Push Notifications." The Lifecycle Events sample application provides an example of declaring the event listener class in both the maf-application.xml and maf-feature.xml files.

To work with this sample application, select File > New MAF Examples, then select LifecycleEvents and click Finish.

4.8.1 Events in Mobile Applications

Lifecycle listener classes for mobile applications must implement the start, stop, activate, and deactivate methods of the LifeCycleListener interface, as illustrated in Example 4-10 to execute the application lifecycle events.

Example 4-10 The LifeCycleListener Interface for a Mobile Applications

package oracle.adfmf.application;
 
public interface LifeCycleListener
{
   void start();
   void stop();
   void activate();
   void deactivate();
}

Note:

The application lifecycle listener is executed with an anonymous user (that is, there is no user associated with any of its methods and no secure web service is called).

The AppListener class, shown in Example 4-11, uses the LifeCycleListener method calls for starting or stopping events as well as those used when the application is about to hibernate (deactivate) or return from hibernating (activate). For more information, see Section 4.8.2, "Timing for Mobile Application Events." See also the LifeCycleListener interface in Java API Reference for Oracle Mobile Application Framework.

Example 4-11 Implementation of the LifeCycleListener Interface

package some.package;
import oracle.adfmf.application.LifeCycleListener;
 
public class AppListener implements LifeCycleListener
{
    public AppListener()
    {
        super();
    }
    public void start()
    {
        // Perform application startup tasks...
    }
    public void stop()
    {
        // Perform tasks to stop the application...
    }
    public void activate()
    {
        // Perform appplication activation tasks...
    }
    public void deactivate()
    {
        // Perform application deactivation tasks...
    }
}

The application controller project of the LifeCycleEvents sample application, described in Appendix F, "Mobile Application Framework Sample Applications," contains a class (LifeCycleListenerImpl.java) that implements the LifeCycleListener interface.

Note:

Managed beans and data bindings must be initialized before the startup lifecycle code executes.

4.8.2 Timing for Mobile Application Events

MAF calls application lifecycle methods at specific times during the mobile application's startup, shutdown, and hibernation. Table 4-3 describes when these methods are called and also notes their Objective-C counterparts.

Table 4-3 MAF Lifecycle Methods

Method Timing When Called Usage Relation to iOS Application Delegate Methods

start

Called after the mobile application has completely loaded the application features and immediately before presenting the user with the initial application feature or the springboard. This is a blocking call.

When the application process starts.

Uses include:

  • Determining if there are updates to the mobile application.

  • Requesting a remote server to download data to the local database.

This event does not correspond to a specific application delegate method. It is called after the maf-application.xml and maf-feature.xml files have loaded, just prior to hiding the splash screen.

stop

Called as the mobile application begins its shutdown.

When the application process terminates.

Uses include:

  • Logging off from any remote services.

  • Uploading any data change to the server before the application is closed.

This is called in the applicationWillTerminate: method on the application delegate.

activate

Called as the mobile application activates from being situated in the background (hibernating). This is a blocking call.

After the start method is called.

Uses include:

This is called in the applicationDidBecomeActive: method on the application delegate.

deactivate

Called as the mobile application deactivates and moves into the background (hibernating). This is a blocking call.

Before the stop method is called.

Uses include:

This is called in the applicationWillResignActive: method on the application delegate.


4.8.3 Using the activate and deactivate Methods to Save Application State

Because checkpointing saves the application state, you can enable users to continue using the last page of a mobile application that was active before it began to hibernate by adding checkpoint entries to the activate and deactivate methods. The lifecycle listener reads the checkpoint entries added to the activate class and allows the processes to resume after the application has returned from hibernating; users can continue with application uninterrupted by not having to log in a second time. If the application is terminated during hibernation, you can enable the application to resume by specifying that checkpoint information be written to a database or to a device's cache directory as part of the deactivate method. The application resumes at the same page by reading this checkpoint information during activation.

4.8.4 About Application Feature Lifecycle Listener Classes

A mobile application feature lifecycle listener class, such as FeatureListenerPhoneList, illustrated in Example 4-13, must implement the activate and deactivate methods of the LifeCycleListener interface, as shown in Example 4-12.

Example 4-12 Application Feature LifeCycleListener Interface

package oracle.adfmf.feature;
public interface LifeCycleListner
{
   void activate();
   void deactivate();
}

Example 4-13 illustrates a class called FeatureListenerPhoneList that uses the activate and deactivate methods by implementing the LifeCycleListener to show and hide the application feature as described in Table 4-4. These methods hide the application feature when it hibernates, or display it when it returns from hibernating.

Note:

As noted in Java API Reference for Oracle Mobile Application Framework, both the activate and deactivate methods are blocking calls. Because these methods freeze the user interface until they have executed completely, any long-running process included within them will delay the activation of an another application feature. If an application does not require a long-running process to complete before it is deactivated, include it in a background thread rather than within these methods.

Example 4-13 Implementing the Application Feature Lifecycle

package some.package;
import oracle.adfmf.feature.LifeCycleListener;
public class FeatureListenerPhoneList implements LifeCycleListener
{
    public FeatureListenerPhoneList()
    {
        super();
    }
    public void activate()
    {
        // Perform application activation tasks...
    }
    public void deactivate()
    {
        // Perform application deactivation tasks...
    }
}

Tip:

The LifeCycle Events sample application provides an example of using the LifeCycleListener interface at the application feature level through the Feature1Handler.java and Feature2Handler.java files. These files are located within the view controller project's Application Sources folder.

4.8.5 Timing for Activate and Deactivate Events in the Application Feature Lifecycle

By implementing an application feature lifecycle listener class, you enable an application feature to automatically obtain any data changes to the applicationScope variable or to application feature-specific variables that changed when the application feature was deactivated. Table 4-4 describes when the activate and deactivate events are fired for an application feature. For more information, see Java API Reference for Oracle Mobile Application Framework.

Table 4-4 The activate and deactivate Methods for Application Features

Method Timing When Called Usage

activate

Called before the current application feature is activated.

Called when a user selects the application feature for the first time after launching a mobile application, or when the application has been re-selected (that is, brought back to the foreground).

Uses include:

  • Reading the applicationScope variable.

  • Setting the current row on the first MAF AMX view.

deactivate

Called before the next application feature is activated, or before the application feature exits.

Called when the user selects another application feature.

You can, for example, use the deactivate event to write the applicationScope variable, or any other state information, for the next application feature to consume.


4.8.6 Enabling Sliding Windows

By implementing the oracle.adfmf.framework.api.AdfmfSlidingWindowUtilities interface in the application lifecycle listener (ALCL), you can use an application feature as a sliding window, which displays concurrently with the other application features that display within the navigation bar or springboard. You can use a sliding window to display content that always present within the application, such as a global tool bar, or for temporary (pop-up) content, such as a help window. For information on displaying application features within the springboard or navigation bar, see Section 4.7.1, "How to Designate the Content for a Mobile Application." For information on using the methods of the AdfmfSlidingWindowUtilities API, refer to Java API Reference for Oracle Mobile Application Framework.

4.9 About the Mobile Application Feature Configuration File

The maf-feature.xml file, an example of which is illustrated in Example 4-14, enables you to configure the actual mobile application features that are referenced by the <adfmf:featureReference> element in the corresponding maf-application.xml file.

Example 4-14 The maf-feature.xml File

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf:features xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:adfmf="http://xmlns.oracle.com/adf/mf">
    <adfmf:feature id="PROD" 
                   name="Products" 
                   icon="images/logo.png">
        <adfmf:constraints>
        </adfmf:constraints>
        <adfmf:description>Products</adfmf:description>
        <adfmf:content id="PROD.1">
            <adfmf:amx file="PROD/products_page.amx"/>
        </adfmf:content>
    </adfmf:feature>
    <adfmf:feature id="HCM" 
                   name="Contents" 
                   icon="images/directory.png">
        <adfmf:description>People Finder</adfmf:description>
        <adfmf:content id="HCM.1">
            <adfmf:remoteURL connection="Connections1"/>
        </adfmf:content>
    </adfmf:feature>
    <adfmf:feature id="Customers.1" 
                   name="Customers" 
                   icon="images/people.png">
        <adfmf:constraints>
            <adfmf:constraint property="user.roles" 
                              operator="equal" 
                              value="field sales"/>
            <adfmf:constraint property="user.roles" 
                              operator="not" 
                              value="consultant"/>
        </adfmf:constraints>
        <adfmf:description>Customers</adfmf:description>
        <adfmf:content id="Customers.2">
            <adfmf:localHTML url="Customers/customers_page.html"/>
        </adfmf:content>
    </adfmf:feature>
</adfmf:features>

By defining the elements of the maf-feature.xml file, you set the behavior for the application features by, in turn, defining the child elements of the <Feature> element, the top-most element in the XML file under the root element, <adfmf:features>. The <Feature> element itself describes the basic information of the application feature, including its name, version, and whether or not it participates in security. For the latter, see Chapter 21, "Securing Mobile Applications." The child elements of the <Feature> elements are listed in Table 4-5. Like the MAF Application Editor for the maf-application.xml descriptor file, you can update this file with these elements (or edit them) declaratively using the MAF Feature Editor for the maf-feature.xml file, described in Section 4.10, "Setting the Basic Configuration for the Application Features."

Table 4-5 Child Elements of <Feature> Element

Element Description

<adfmf:content>

Describes the format that the application feature uses for a particular device or user. The content (generally, the user interface) of an application feature can be written as MAF AMX pages, HTML5 pages, or be delivered from web pages hosted on a remote web server. For more information on designating content as a web application, see Chapter 12, "Implementing Application Feature Content Using Remote URLs."

<adfmf:constraint>

Determines whether a given application feature can be displayed in the application at runtime. Constraints can be used to allow or prevent the use of an application feature based on such criteria as user roles or device properties. For more information, see Chapter 14, "Setting Constraints on Application Features."


4.10 Setting the Basic Configuration for the Application Features

Each mobile application must have at least one application feature. Because each application feature can be developed independently from one another (and also from the mobile application itself), the MAF Feature Editor for the maf-feature.xml file enables you to define the child elements of <adfmf:features> to differentiate the application features by assigning each a name, an ID, and setting how their content can be implemented. Using the MAF Feature Editor for application features, you can also control the runtime display of the application feature within mobile application and designate when an application feature requires user authentication.

4.10.1 How to Define the Basic Information for an Application Feature

The MAF Feature editor, shown in Figure 4-19, enables you to add an application feature, designate its basic information, and its display icons.

Figure 4-19 The General Tab of the Application Feature

This image is described in the surrounding text

Before you begin:

If an application feature uses custom images for the navigation bar and springboard rather than the default ones provided by MAF, you must create these images to the specifications described the Android Developers website (http://developer.android.com/design/style/iconography.html) and in the "Custom Icon and Image Creation Guidelines" chapter in iOS Human Interface Guidelines, which is available from the iOS Developer Library (http://developer.apple.com/library/ios/navigation/).

You place these images in the view controller project's viewContent directory. See also Section 4.11.2, "What You May Need to Know About Selecting External Resources."

In addition, you must open the MAF Feature Editor.

To set the basic information for the application feature:

  1. In the outline, click Right-click This image is described in the surrounding text to open the New Object dialog.

  2. Type a unique identifier for the application feature for the feature you are creating.

  3. Complete the fields in the MAF Feature Editor, shown in Figure 4-20, and then click OK. To complete this dialog:

    • Enter a display name for the application feature in the Name field.

    • If needed, change the location for the application feature to any directory within the public_html directory (the default parent directory). Enter this location in the Directory field.

    • To include the newly defined application feature in the mobile application, add a new <adfmf:featureReference> element to the maf-application.xml file with the id attribute that matches the value that you entered in the Feature ID. Choose Add a corresponding feature reference to maf-application.xml. The table in the Feature References page, shown in Figure 4-14, includes the feature reference after you complete the dialog. See also Section 4.7.2, "What You May Need to Know About Feature Reference IDs and Feature IDs."

      Figure 4-20 Adding an Application Feature

      This image is described in the surrounding text
  4. Enter a brief description of the application's purpose in the Description field. This is an optional value.

  5. Enter the originator of the application feature in the Vendor field. This is an optional value.

  6. Enter the version number of the application feature in the Version field. This is an optional value.

  7. Enter the fully qualified class name (including the package, such as oracle.adfmf.feature) using the Class and Package Browser in the Lifecycle Event Listener field to enable runtime calls for start, stop, hibernate, and return to hibernate events. For more information, see Section 4.8, "About Lifecycle Event Listeners." This is an optional value.

  8. If your application uses security, select the Enable Security checkbox.

  9. In the Navigation Bar Icon and Springboard Image fields, browse to, and select, images from the project to use as the icon in the navigation bar and also an image used for the display icon in the springboard. You can also drag and drop the image files from the Project Explorer into the file location field. This is an optional value.

4.11 Defining the Content Types for an Application Feature

The content type for an application feature describes the format of the user interface, which can be constructed using MAF AMX components or HTML(5) tags. An application feature can also derive its content from remotely hosted pages that contain content appropriate to a mobile context. These web pages might be a JavaServer page authored in Apache Trinidad for smartphones, or be comprised of ADF Faces components for applications that run on tablet devices. The application features embedded in a mobile application can each have different content types.

Tip:

Design a mobile application with more than one content type.

While a mobile application includes application features with different content types, applications features themselves may have different content types to respond to user- and device-specific requirements. For information on how the application feature delivers different content types, see Chapter 14, "Setting Constraints on Application Features." Adding a child element to the <adfmf:content> element, shown in Example 4-15, enables you to define how the application feature implements its user interface.

Example 4-15 The <adfmf:content> Element

<adfmf:content id="Feature1">
      <adfmf:amx file="FeatureContent.amx">
</adfmf:content>

4.11.1 How to Define the Application Content

Once you have created features in the MAF Feature Editor, you define their content by right-clicking on each of the features to bring up the New Object dialog, shown in Figure 4-21. This dialog provides you with a selection of target content-related elements. The selections in this dialog let you control the type of content delivered for an application feature as well as the navigation and springboard icon images that it uses.

Each content type has its own set of parameters. As shown in Figure 4-21, for example, you must specify the location of the MAF AMX page or task flow for the application features that you implement as MAF AMX content. In addition, you can optionally select a CSS file to give the application feature a look and feel that is distinct from other application features (or the mobile application itself), or select a JavaScript file that controls the actions of the MAF AMX components.

Figure 4-21 Defining the Implementation of the Application Feature

This image is described in the surrounding text

Before you begin:

Each content type has its own prerequisites, as follows:

  • AMX Page—The default content type for application features, which includes both individual MAF AMX pages. You can build the MAF AMX content declaratively using a set of mobile-specific user interface components, ADF data bindings, and data controls that integrate device services, such as a camera, and data visualization tools, such as charts, graphs, and thematic maps. For information on building an MAF AMX page, see Chapter 5, "Creating MAF AMX Pages."

    An application feature implemented as MAF AMX requires an existing view (that is, a single MAF AMX page). Including a JavaScript file provides rendering logic to the MAF AMX components or overrides the existing rendering logic. Including a style sheet (CSS) with selectors that specify a custom look and feel for the application feature, one that overrides the styles defined at the mobile application level that are used by default for application features. In other words, you ensure that the entire application feature has its own look and feel.

    If you create the MAF AMX pages as well as the mobile application that contains them, you can create both using the wizards available from File > New. Alternatively, you can create an MAF AMX page using the context menu shown in Figure 4-22 that appears when you right-click the view project in the Project Explorer and then choose New.

    Note:

    When manually editing references to task flows, MAF AMX pages, CSS and JavaScript files in the maf-feature.xml file, keep in mind that file systems used on devices may enforce case-sensitivity and may not allow special characters. To ensure that these files can be referenced, check the mobile device specification.

    Figure 4-22 Context Menu for Creating an MAF Page

    This image is described in the surrounding text
  • Task Flow—A task flow page defines the path through the application, from feature to feature. Task flow files include control flow specifications and activities; activities include calling methods, using routers, calling another task flow, returning from a task flow, and displaying view pages. For more information, see Section 5.2, "Creating Task Flows."

  • Local HTML—Reference a HTML page that is packaged within your mobile application. Such HTML pages can reference JavaScript, as demonstrated by the HelloWorld sample application described in Appendix F, "Mobile Application Framework Sample Applications." Consider using this content type to implement application functionality through usage of the Cordova JavaScript APIs if the MAF is not best suited to implementing your application's functionality. For more information about JavaScript APIs and the MAF, see Appendix B, "Application Container APIs."

  • Remote URL—A reference to a web application. You can enhance an existing web application for mobile usage and extend device services. Remote content can complement both MAF AMX and local HTML content by providing a local data cache and a full set of server-side data and functionality. The remote URL implementation requires a valid web address as well as a hosted mobile application. For more information, see Chapter 12, "Implementing Application Feature Content Using Remote URLs."

To create new application content:

  1. Select an application feature listed in the Outline of the MAF Feature Editor.

  2. Click the right mouse button and select New, as shown in Figure 4-23.

    Figure 4-23 Context Menu for New Feature

    This image is described in the surrounding text
  3. In the New Object dialog, expand the Content node, if necessary and choose one of the following content types to correspond with the generated ID, and then click OK:

  4. Define the content-specific parameters:

    • For an AMX Page, click Browse to specify an existing page, or click Create to open the New MAF Page dialog. See Figure 4-27.

    • For a Task Flow, click Browse to specify an existing page, or click Create to open the New MAF Task Flow dialog.

    • For a Local HTML file, click Browse to specify an existing page, or click Create to open the New Mobile HTML Page dialog. See Figure 4-24.

    • For a Local HTML file, click Browse to specify an existing page, or click Create to open the New Mobile HTML Page dialog. See Figure 4-24. Select the parent folder for this file and give it a descriptive file name for later use. Choose whether to save the file as HTML or as XHTML, then click Finish. Because this is an application feature, this page is stored within the Web Content folder of the view controller project.

      Figure 4-24 Creating the Local HTML Page as the Content for an Application Feature

      This image is described in the surrounding text
    • For remote URL content, select the connection, as shown in Figure 4-25, that represents address of the web pages on the server (and the location of the launch page).

      Figure 4-25 Selecting the Connection for the Hosted Application

      This image is described in the surrounding text

      You can create this connection by first clicking Create and then completing the Create URL Connection dialog, shown in Figure 4-26. For more information on this dialog, see the online help for Oracle Enterprise Pack for Eclipse. This connection is stored in the connections.xml file.

      Figure 4-26 Creating a URL Connection

      This image is described in the surrounding text

To designate the application feature content as an AMX Page:

  1. Select the parent folder for your new AMX page.

  2. Give your page a descriptive name that will make it easier to identify when working on your mobile application.

  3. Click Finish to save the page. The New MAF Page dialog is shown in Figure 4-27.

    Figure 4-27 Selecting MAF AMX as the Content Type

    This image is described in the surrounding text

4.11.2 What You May Need to Know About Selecting External Resources

To enable deployment, all resources referenced by the following attributes must be located within the ViewContent directory of the view project.

MAF does not support resources referenced from another location, meaning that you cannot, for example, enter a value outside of the public_html directory using ../ as a prefix.

4.12 Working with Localized Content

Localization is the process of adapting an application for a specific local language or culture by translating text and adding locale-specific components. By configuring the MAF application and its user interface pages to use different locales, you enable an MAF application to appear as though it has been authored for the language set on the mobile device. For example, if you intend to broaden the use of an MAF application by enabling it to be viewed by French speakers, you can localize the application so that its text strings and images used in both the device's springboard and within the MAF web view display in French (that is, products is transformed into les produits, and so on).

Oracle Enterprise Pack for Eclipse supports automatic translation of these text resources into 28 languages. Oracle Enterprise Pack for Eclipse supports localization MAF components using the abstract class java.util.ResourceBundle, which provides locale-specific resources. While the support for localization is included in the Oracle Enterprise Pack for Eclipse MAF implementation, the design time editor does not support this automatically. You can enter the text strings manually for localization.

After you define translatable strings (such as validator error messages, or attribute control hints), Oracle Enterprise Pack for Eclipse stores them in a project-level resource bundle file. MAF specifies English language text resources (although you can use any tool to generate resource bundle files in other languages). You can configure a mobile application to store translatable UI strings at both the application and view project level.

4.12.1 Working with Resource Bundles

MAF uses only XLIFF (XML Localization Interchange File Format) files for localization, meaning that Oracle Enterprise Pack for Eclipse produces resource bundle .xlf files to store the strings. For information on XLIFF, see

http://docs.oasis-open.org/xliff/xliff-core/xliff-core.html.

4.12.1.1 How to Enter a String in a Resource Bundle

At the project level, you create resource bundle files when you use the resource bundle dialog, accessed by opening the MAF Feature editor or MAF Application editor, then clicking the Externalize button next to the Name field. This opens the Externalize String dialog, which enables you to automatically create text resources in the base resource bundle for maf-application.xml and maf-feature.xml attributes listed in Table 4-6 and Table 4-7.

At the application level, you can use the MAF Application editor to localize strings for such attributes as application names or preference page labels, which are listed in Table 4-6.

Table 4-6 Localizable MAF Application Attributes

Element Attribute(s)

<adfmf:Application>

name

<adfmf:PreferenceGroup>

label

<adfmf:PreferencePage>

label

<adfmf:PreferenceBoolean>

label

<adfmf:PreferenceText>

label

<adfmf:PreferenceNumber>

label

<adfmf:PreferenceList>

label

<adfmf:PreferenceValue>

name


At the project (view controller) level, you can use the MAF Feature editor to localize application feature-related attributes listed in Table 4-7.

Table 4-7 Localizable Application Feature Attributes

Element Attribute(s)

<adfmf:Feature>

name

<adfmf:Constraint>

value

<adfmf:Parameter>

value

<adfmf:PreferencePage>

label

<adfmf:PrefrenceGroup>

label

<adfmf:PreferenceBoolean>

label

<adfmf:PreferenceText>

label

<adfmf:PreferenceNumber>

label

<adfmf:PreferenceList>

label

<adfmf:PreferenceValue>

name


To create localized strings in a resource bundle:

  1. Select an attribute in the MAF Feature editor, such as Name in Figure 4-28, and click Externalize. This opens the Externalize String dialog.

  2. Select an existing property from the list and click OK.

    Figure 4-28 Selecting the Edit Externalized String Dialog

    This image is described in the surrounding text
  3. In the Externalize String dialog, shown in Figure 4-29, create a new string resource by clicking Create a New Property. Enter a display value, a key, a description and then click OK.

    Figure 4-29 Select Edit Externalized String Dialog

    This image is described in the surrounding text

    Note:

    To edit an existing externalized string, select one from the list of existing properties and then click the pencil icon. This opens the Edit Externalized String dialog, from which you can change the value of the string and its description, but not the key.

4.12.1.2 What Happens When You Add a Resource Bundle

After you add a resource in the Select Text Resource dialog, Oracle Enterprise Pack for Eclipse creates a new project resource bundle containing the specified display name string and key file in the ADF Meta-INF file, as shown by mafapplication.xliff.

If an attribute has been localized for the first time, Oracle Enterprise Pack for Eclipse adds an <adfmf:loadbundle> element whose basename attribute refers to the newly created resource bundle.

Oracle Enterprise Pack for Eclipse also changes the localized attribute string to an EL expression that refers to the key of the string defined in the resource bundle. For example, Oracle Enterprise Pack for Eclipse changes an application name attribute called Acme Sales to name="#{acmeBundle.Acme_Sales}" based on the ACME_SALES value entered for the Key in the Select Text Resource Dialog.

Oracle Enterprise Pack for Eclipse adds each additional string that you localize to the same resource bundle file because there is only one resource bundle file at the application level.

Each maf-application.xml and maf-feature.xml file contains only one adfmf:loadBundle element. When you deploy an application, the resource bundles are converted into the language format expected by the runtime.

4.12.1.3 How to Localize Strings in MAF AMX Components

You can create resource bundles for attributes of such MAF AMX components as the text attribute of <amx:commandButton>. Table 4-8 lists these MAF AMX (amx) components.

Table 4-8 Localizable Attributes of MAF AMX Components

Component Attribute

<amx:inputDate>

label

<amx:inputNumberSlider>

label

<amx:panelLabelAndMessage>

label

<amx:selectBooleanCheckBox>

label

<amx:selectBooleanSwitch>

label

<amx:selectItem>

label

<amx:selectManyCheckBox>

label

<amx:selectManyChoice>

label

<amx:selectOneButton>

label

<amx:selectOneChoice>

label

<amx:selectOneRadio>

label

<amx:commandButton>

text

<amx:commandLink>

text

<amx:goLink>

text

<amx:inputText>

label, value, hintText

<amx:outputText>

value


To use strings in MAF AMX components:

  1. Select an attribute in an AMX editor, such as the value attribute defined for the <amx:selectOneButton> component in Figure 4-30.

    Figure 4-30 Externalizing Strings by Properties

    The surrounding text describes this image.
  2. Click the right mouse button and select Source > Externalize Strings. This opens the Externalize Strings dialog, shown in Figure 4-31.

  3. In the Externalize Strings dialog, edit the string resources by entering a display name, key, and then click Finish.

    Figure 4-31 Adding a String to a Resource Bundle

    The surrounding text describes this image.

4.12.1.4 What Happens When You Create Project-Level Resource Bundles for MAF AMX Components

When you localize a component, such as the value attribute for a <amx:outputText> component in Example 4-16, Oracle Enterprise Pack for Eclipse transforms the string into an EL expression (such as #{viewControllerBundle.NewPage_header} in Example 4-16).

Example 4-16 Localizing an MAF AMX Component

<amx:facet name="header">
      <amx:outputText value="#{viewControllerBundle.NewPage_header}"
       id="ot1" />
    </amx:facet>

In addition, Oracle Enterprise Pack for Eclipse creates the resource bundle under the project default package, similar to ViewControllerBundle.xlf in Example 4-17. In the generated <amx:loadBundle> component, the basename represents this package.

Example 4-17 The <amx:loadBundle> Component

<amx:loadBundle basename="mycomp.mobile.ViewControllerBundle"
                 var="viewcontrollerBundle" 
                 id="lb1"/>

4.12.1.5 What You May Need to Know About Localizing Image Files

If an image contains text or reflects a specific country or region (for example, a picture of a flag), you can specify an alternate image as part of the localization process, through the same XLIFF file process used for externalizing strings. See Figure 4-32.

Figure 4-32 Externalizing Images in the XLIFF File

Surrounding text describes Figure 4-32 .

You cannot hard-code the image, such as icon="/feature1/test.png". Instead, you must edit the ViewControllerBundle.xlf file manually by adding a <trans-unit> element for the image path, as illustrated in Example 4-18.

Example 4-18 Defining the Resource for an <amx:image> Component

<amx:image id="i1" source="#{viewControllerBundle.NewPage_icon2JPG}"
 shortDesc="#{viewControllerBundle.NewPage_myFavoriteImage}" />
         <trans-unit id="NewPage_icon2JPG">
             <source>/icon2.JPG</source>
             <target/>
         </trans-unit>
         <trans-unit id="NewPage_myFavoriteImage">
             <source>My Favorite Image</source>
             <target/>
         </trans-unit>
<trans-unit id="IMAGEPATH">
     <source>/feature1/test.jpg</source>
     <target/>
</trans-unit>

Note:

The image location defined in the <source> element in Example 4-18 is relative to the location of the application feature file in ViewController\public_html. Alternatively, you can enter the name of the image file, such as <source>test.png</source>. See also Section 4.11.2, "What You May Need to Know About Selecting External Resources."

After you update ViewControllerBundle.xlf, Oracle Enterprise Pack for Eclipse automates the construction of an EL expression for the source attribute for the icon attribute.

4.12.1.6 How to Edit a Resource Bundle File

After you have created the XLIFF file, or Java class file, you can edit it using the source editor. If you are using one of the MAF editors, you can invoke the Externalize command on the file.

4.12.1.7 What You May Need to Know About XLIFF Files for iOS Applications

One or more XLIFF files must exist at the location described by the <adfmf:loadBundle> element. A family of XLIFF files includes the following:

  • Base XLIFF File—The name of the base XLIFF file must match the last token in the path specified by the basename attribute. This file bears the .xlf extension, such as ViewControllerBundle.xlf. In the following definition, the file is called ViewControllerBundle:

    <adfmf:loadBundle var="stringBundle" basename="view.ViewControllerBundle"/>
    
  • Zero, or more, localized XLIFF Files—There can be zero (or many) localized XLIFF files for each base XLIFF file. For each file:

    • The file extension must be .xlf.

    • Must be co-located in the same directory as the corresponding base XLIFF file.

    • The file name is in the following format:

      <BASE_XLIFF_FILE_NAME>_<LANGUAGE_TOKEN>.xlf
      

      Where:

      • <BASE_XLIFF_FILE_NAME> is the base XLIFF file name, without the .xlf extension.

      • <LANGUAGE_TOKEN> is in the following format:

        <ISO-639-lowercase-language-code>
        

        Note:

        MAF does not support countries or regions.

        For example, for Spain, the language token is es.

      For example, localized file names for XLIFF files referencing a base XLIFF named stringBundle.xlf for language codes en, es, and fr would be:

      • stringBundle_en.xlf

      • stringBundle_es.xlf

      • stringBundle_fr.xlf

4.12.1.8 Internationalization for iOS Applications

The localizable elements of the maf-application.xml and maf-feature.xml files reference internationalized strings through the use of EL-like strings in the attributes listed in Table 4-7 and Table 4-6. Because these configuration files are read early in the application lifecycle, these strings are not evaluated as EL statements at runtime. Instead, these strings are taken as the full key for the translated string in the native device translation infrastructure.

Although the Expression Language syntax is "${BUNDLE_NAME.STRING_KEY}", MAF uses the entire string enclosed by "#{}" as the key to look up the translated string. These strings are in the form of #{bundleName.['My.String.ID']}, where the XLIFF string is separated by periods and #{bundleName.['MyStringID']}, which is used only for string identifiers that are not separated by periods. Example 4-19 illustrates the latter, such as #{strings.CONTACTS}, that modify the name attribute. For the iOS native framework, the deployment ensures that the content of that statement matches the proper key in the *.string file used for translation.

Only the attributes that are displayed to the end user, or control the location of content displayed to the end user, support the use of internationalized strings. These include the following attributes:

  • The <adfmf:application> element's name attribute

  • The <adfmf:feature> element's name attribute

  • The <adfmf:feature> element's icon attribute

  • The <adfmf:feature> element's image attribute

  • The <adfmf:content> element's icon attribute

  • The <adfmf:content> element's image attribute

Example 4-19 shows an application feature with name, icon, and image attributes use internationalization strings.

Example 4-19 Internationalization Using Strings

<adfmf:feature id="CTCS" name="#{strings.CONTACTS}"  
                         icon="#{strings.CONTACTS_ICON}"
                         image="#{strings.CONTACTS_IMAGE}">
        <adfmf:constraints>
            <adfmf:constraint property="user.roles" 
                              operator="contains" 
                              value="employee" />
        </adfmf:constraints>
        <adfmf:description>The HTML Device Contacts</adfmf:description>
        <adfmf:loadBundle basename="mobile.adfmf-stringsBundle"
                          var="strings"/>
        <adfmf:content id="CTCS.Generic">
            <adfmf:constraints />
            <adfmf:localHTML url="contacts.html" />
        </adfmf:content>
  </adfmf:feature>

When you define the <adfmf:loadBundle> elements, as shown in Example 4-20, you create the mapping of bundle names to actual bundles. The bundle name is used when the expression is evaluated.

Example 4-20 Mapping Bundle Names Using <adfmf:loadBundle>

<adfmf:constraints>
      <adfmf:constraint property="user.roles"
                        operator="contains"
                        value="employee" />
   </adfmf:constraints>
        <adfmf:description>The HTML Device Contacts</adfmf:description>
        <adfmf:loadBundle basename="mobile.adfmf-featureBundle" 
                          var="mobileBundle"/>
        <adfmf:loadBundle basename="mobile.adfmf-stringsBundle" 
                          var="strings"/>

MAF's runtime holds the <adfmf:loadBundle> elements until it first accesses the JVM. It sends a message to the JVM to initialize the mapping of the base names of the packages to EL names of the bundles. Example 4-21 illustrates the structure of the message sent to the JVM.

Example 4-21 The Message Initializing Mapping of Base Names to EL Names

{classname:"oracle.adfmf.framework.api.Model",method:"setBundles",
 params:[[{basename:"mobile.adfmf-featureBundle",elname:"mobileBundle"},
          {basename:"mobile.adfmf-stringsBundle",elname:"strings"}]]}

4.13 Skinning Mobile Applications

MAF's use of CSS (Cascading Style Sheet) language-based skins ensures that all application components within a mobile application (including those used in its constituent application features) share a consistent look and feel. Rather than altering how a mobile application looks by re-configuring MAF AMX or HTML components, you can instead create, or extend, a skin that changes how components display. Any changes made to a skin take effect when an application starts, because MAF applies skins at runtime.

As noted in Section 3.2.2, "What Happens When You Create an MAF Application," the artifacts resulting from the creation of an application controller project include two skinning-related files, maf-config.xml and maf-skins.xml. You use these files to control the skinning for the mobile application. The maf-config.xml file designates the default skin family used to render application components and the maf-skins.xml file enables you to customize the default skin family or define a new one.

4.13.1 About the maf-skins.xml File

After you create a mobile application, Oracle Enterprise Pack for Eclipse populates the maf-skins.xml file to the mobile application's src/META-INF node. The file itself is populated with the empty adfmf-skins tag and the skin and skin-addition tags can be added later.

Example 4-22 The maf-skins.xml file, populated with adfmf-skins tag

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf-skins xmlns="http://xmlns.oracle.com/adf/mf/skin"></adfmf-skins>

Note:

You can determine the skin value at runtime using EL expressions. For more information, see Section 4.13.11, "Enabling Dynamic Skin Selection at Runtime."

MAF applies skins as a hierarchy, with device-specific skins occupying the top tier, followed by platform-specific skins, and then the base skin, mobileAlta. In terms of MAF's mobileAlta skin family, this hierarchy is expressed as follows:

  1. mobileAlta.<DeviceModel> (for example, mobileAlta.iPhone5,3)

  2. mobileAlta.iOS or mobileAlta.Android

  3. mobileAlta

MAF gives precedence to selectors defined at the device-specific level of this hierarchy. In other words, MAF overwrites a selector defined in mobileAlta.iOS with the mobileAlta.iPhone definition for the same selector. The <extends> element, described in Section 4.13.3, "About the maf-skins.xml File," defines this hierarchy for the MAF runtime. For more information on how skins are applied at various levels, see Section 4.13.10, "What You May Need to Know About Skinning."

4.13.2 What You May Need to Know About MAF Styles

The underlying skinning styles for the base skin family, mobileAlta, are defined in the amx.css, amx-mobileAlta-1.2.css, and amx-v1.2.css files. These files, which define the selectors for MAF AMX pages, reside in the www\css directory. To access this directory, you must first deploy a mobile application to a simulator or device and then traverse to the deployment subdirectory of the assembly project (for example, assembly project\.main.android). The www\css directory resides within the platform-specific artifacts generated by the deployment. For iOS deployments, the directory is located within the temporary_xcode_project directory. For Android deployments, this directory is located in the build/release/assets or build/debug/assets directory of the Android application package (.apk) file.

Caution:

Do not write styles that rely on the MAF DOM structures. Further, some of the selectors defined in these files may not be supported.

4.13.3 About the maf-skins.xml File

The maf-skins.xml file, located in the META-INF node of the application controller project, uses the <skin> and the <skin-addition> elements. Use the <skin> element to create a new skin by extending an existing skin. The <skin-addition> element adds a style sheet to an existing skin.

By default, this file is empty, but the elements listed in Table 4-9 describe the child elements that you can use to populate this file to extend mobileAlta or to define the CSS files that are available to the application. You use the <skin> element to create new skins or to extend an existing skin.

Table 4-9 Child Elements of the <skin> Element

Elements Description

<id>

A required element that identifies the skin in the maf-skins.xml file. The value you specify must adhere to one of the following formats:

  • skinFamily-version

  • skinFamily-version.platform

For example, specify mySkin-v1.iOS if you want to register a skin for your application that defines the appearance of your application when deployed to an Apple iPad or iPhone. Substitute iOS by iPad or iPhone if the skin that you register defines the appearance of your application on one or other of the latter devices. Specify .android if you want to register a skin that defines the appearance of your application when deployed to the Android platform.

<family>

A required element that identifies the skin family.

<extends>

Use this element to extend an existing skin by specifying the skin id of the skin you want to extend.

<skin>
  <id>mySkin-v1</id>
  <family>mySkin</family>
  <extends>mobileAlta-v1.2</extends>
  <style-sheet-name>styles/myskin.css</style-sheet-name>
  <version>
    <name>v1</name>
  </version>     
</skin>

<style-sheet-name>

Use a relative URL to specify the location of the CSS file within your mobile application's project. For example, the maf-skins.xml file in the SkinningDemo sample application contains the following reference to the v1.css style sheet in the css directory of the application controller project:

<style-sheet-name>css/v1.css</style-sheet-name>

<version>

Specify different versions of a skin. For more information, see Section 4.13.7, "How to Version MAF Skins."


Table 4-10 lists elements that you can use to define the <skin-addition> element in an MAF CSS when you integrate a style sheet into an existing skin.

Table 4-10 The <skin-addition> Child Elements

Element Description

<skin-id>

Specify the ID of the skin that you need to add an additional style sheet to. Possible values include the skins provided by MAF (for example, mobileAlta-v1.2.iOS) or a custom skin that you create.

<style-sheet-name>

Use a relative URL to specify the location of the CSS file within your mobile application's project. For example, the maf-skins.xml file in the SkinningDemo sample application contains the following reference to the v1.css style sheet in the css directory of the application controller project:

<style-sheet-name>css/v1.css</style-sheet-name>


Example 4-23 illustrates designating the location of the CSS file in the <style-sheet-name> element and the target skin family in <skin-id>.

Example 4-23 Using the <skin-addition> Element

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf-skins xmlns="http://xmlns.oracle.com/adf/mf/config">
  <skin-addition>
    <skin-id>mobileAlta-v1.2.iOS</skin-id>
    <style-sheet-name>skins/mystyles.iphone.addition1.css</style-sheet-name>
  </skin-addition>
</adfmf-skins>

You can use the <skin-id> and <style-sheet-name> elements to render to a particular iOS or Android device, or alternatively, you can define these elements to handle the styling for all of the devices of a platform. Table 4-11 provides examples of using these elements to target all of the devices belonging to the iOS platform, as well as specific iOS device types (tablets, phones, and simulators).

Tip:

Consider using the DeviceDemo sample application, described in Appendix F, "Mobile Application Framework Sample Applications," to retrieve information about the device model.

Table 4-11 Platform- and Device-Specific Styling

Device Example

iPhone

<skin-addition>
   <skin-id>mobileAlta-v1.2.iPhone5,1</skin-id>
   <style-sheet-name>iPhoneStylesheet.css</style-sheet-name>
</skin-addition>

iPad

<skin-addition>
   <skin-id>mobileAlta-v1.2.iPad4,2</skin-id>
   <style-sheet-name>iPadStylesheet.css</style-sheet-name>
</skin-addition>

iPhone Simulator

<skin-addition>
   <skin-id>mobileAlta-v1.2.iPhone Simulator x86_64</skin-id>
   <style-sheet-name>iPhoneSimStylesheet.css</style-sheet-name>
</skin-addition>

All iOS Devices

<skin-addition>
   <skin-id>mobileAlta-v1.2.iOS</skin-id>
   <style-sheet-name>iOSSimStylesheet.css</style-sheet-name>
</skin-addition>

4.13.4 How to Add a Custom Skin to an Application

To add a custom skin to your application, first create a CSS file with in the application controller project's ViewContent directory and then refer it from maf-skins.xml using either the skin-addition or skin tag.

To add a custom skin to an application:

  1. From the Main Menu, select File > New > Other and then type CSS in the filter. Select Web > CSS File.

  2. In the New CSS File wizard, specify a name and directory (subdirectory of the ViewContent directory) for the CSS file.

  3. Click OK.

4.13.5 How to Specify a Skin for an Application to Use

You configure values in the maf-config.xml file that determine what skin the application uses.

To specify a skin for an application to use:

  1. In the Project Explorer, expand the assembly project, then adf, then META-INF, then double-click maf-config.xml file to open it in the XML Editor.

  2. In the maf-config.xml file, specify the value of the <skin-family> element for the skin you want to use and, optionally, the <skin-version> element, as shown in Figure 4-33.

    Figure 4-33 Editing maf-config.xml

    This image is described in the surrounding text

    To see the file in the Source Editor, click the Source tab at the bottom of the XML Editor. Example 4-24 shows the configuration required to make a mobile application use the mobileAlta.v1.2 skin.

    Example 4-24 Configuration to Specify a Skin for an Application

    <adfmf-config xmlns="http://xmlns.oracle.com/adf/mf/config">
      <skin-family>mobileAlta</skin-family>
      <skin-version>v1.2</skin-version>
    </adfmf-config>
    

Note:

Set an EL expression as the value for the <skin-family> element if you want to dynamically select the skin the application uses at runtime. For more information, see Section 4.13.11, "Enabling Dynamic Skin Selection at Runtime."

To add a new style sheet to a skin

  1. In the Project Explorer, expand the application project > src, > META-INF folders, then double-click the file maf-skins.xml to open it in the XML Editor.

  2. Switch to the Design tab. Select and right-click the adfmf-skins tag. Select Add Child > skin-addition.

    • Select skin-id tag under skin-addition tag. Go to the Content column and enter the identifier of the skin to which you want to add a new style (for example, mobileAlta-v1.2).

    • Right click skin-addition tag and select Add Child > style-sheet-name. Select the style-sheet-name tag and go to the Content column. Specify the path of the css file relative to the ViewContent folder. For example, if you created the css file at ViewContent/css/myaddedcss.css, then enter css/myaddedcss.css as the value

  3. Save the file maf-skins.xml.

Caution:

Creating custom styles that use DOM-altering structures can cause mobile applications to hang. Specifically, the display property causes rendering problems in the HTML that is converted from MAF AMX. This property, which uses such values as table, table-row, and table-cell to convert components into a table, may result in table-related structures that are not contained within the appropriate parent table objects. Although this problem may not be visible within the application user interface itself, the logging console reports it through a Signal 10 exception.

4.13.6 How to Register a Custom Skin

You register a custom skin by adding the property values to the maf-skins.xml file that identify the custom skin to your application.

To register a custom skin:

  1. In the Project Explorer, expand Application Project > src > META-INF and double-click maf-skins.xml to open it in the XML Editor.

  2. Switch to the Design tab. Select and right click adfmf-skins tag. Select Add Child > skin.

  3. Expand the skin node and notice that id and family tags are created by default. You can right click and select Add Child > extends or Add Child > style-sheet-name to create extends and style-sheet-name respectively.

  4. Select any of the following fields and go to the Content column in order to edit the values as follows:

    • family—Enter a value for the family name of your skin.

      You can enter a new name or specify an existing family name. If you specify an existing family name, you need to version skins, as described in Section 4.13.7, "How to Version MAF Skins," to distinguish between skins that have the same value for family.

      The value you enter is set as the value for a <family> element in the maf-skins.xml where you register the skin that you create. At runtime, the <skin-family> element in the application's maf-config.xml uses this value to identify the skin that an application uses.

    • id—Enter an ID for the skin that uses one of the following naming formats: skinFamily-version or skinFamily-version.platform. For example, mySkinFamily-v1.1.android.

    • extends—Enter the name of the parent skin that you want to extend. For example, if you want your custom skin to extend the mobileAlta-v1.2 skin, enter mobileAlta-v1.2.

    • style-sheet-name—Enter or select the name of the style sheet.

  5. Save the file maf-skins.xml.

4.13.7 How to Version MAF Skins

You can specify version numbers for your skins in the maf-skins.xml file using the <version> element. Use this optional capability if you want to distinguish between skins that have the same value for the <family> element in the maf-skins.xml file. This capability is useful in scenarios where you want to create a new version of an existing skin in order to change some existing behavior. Note that when you configure an application to use a particular skin, you do so by specifying values in the maf-config.xml file, as described in section Section 4.13.5, "How to Specify a Skin for an Application to Use."

You specify a version for your skin by entering a value for the <version> element in the maf-skins.xml file.

Best Practice:

Specify version information for each skin that you register in the application's maf-skins.xml file.

To version a MAF skin:

  1. In the Project Explorer, expand the application project > src > META-INF, then double-click maf-skins.xml to open it in the XML Editor.

  2. Switch to the Design tab. Select and right click skin tag. Select Add Child > version.

  3. Right-click on version and select Add Child > default. Select default tag, go to the Content column and set the value of default as true if you want your application to use this version of the skin when no value is specified in the <skin-version> element of the maf-config.xml file, as described in Section 4.13.5, "How to Specify a Skin for an Application to Use."

  4. Select name tag under skin tag and go to the Content column. Enter the value of the name field. For example, enter v1 if this is the first version of the skin.

  5. Save the file maf-skins.xml.

4.13.8 What Happens When You Version Skins

The version information that you configure for skins takes precedence over platform and device values when an application applies a skin at runtime. At runtime, a mobile application applies a device-specific skin before it applies a platform-specific skin. If skin version information is specified, the application first searches for a skin that matches the specified skin version value. If the application finds a skin that matches the skin version and device values, it applies this skin. If the application cannot find a skin with the specified skin version in the device-specific skins, it searches for a skin with the specified version in the platform-specific skins. If it does not find a skin that matches the specified version in the available platform-specific skins, it searches the base skins.

Example 4-25 shows an example maf-skins.xml that references three skins (customFamily-v1.iphone5,3, customFamily-v2.iPhone and customFamily-v3.iPhone). Each of these skins have the same value for the <family> element (customFamily). The values for the child elements of the <version> elements distinguish between each of these skins.

At runtime, an application that specifies customFamily as the value for the <skin-family> element in the application's maf-config.xml file uses customFamily-v1.iphone5,3 because this skin is configured as the default skin in the maf-skins.xml file (<default>true</default>). You can override this behavior by specifying a value for the <skin-version> element in the maf-config.xml file, as described in Section 4.13.5, "How to Specify a Skin for an Application to Use." For example, if you specify v2 as a value for the <skin-version> element in the maf-config.xml file, the application uses customFamily-v2.iPhone instead of customFamily-v1.iphone5,3 that is defined as the default in the maf-skins.xml file.

If you do not specify the skin version to pick (using the <skin-version> element in the maf-config.xml file), then the application uses the skin that is defined as the default using the <default>true</default> element in the maf-skins.xml file. If you do not specify a default skin, the application uses the last skin defined in the maf-skins.xml file. In Example 4-25, the last skin to be defined is customFamily-v3.iPhone.

Example 4-25 maf-skins.xml File with Versioned Skin Files

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf-skins xmlns="http://xmlns.oracle.com/adf/mf/skin">
  <skin id="s1">
    <family>customFamily</family>
    <id>customFamily-v1.iphone5,3</id>
    <extends>customFamily-v1.iOS</extends>
    <style-sheet-name>iphone.css</style-sheet-name>
    <version>
      <default>true</default>
      <name>v1</name>
    </version>
  </skin>
  <skin id="s2">
    <family>customFamily</family>
    <id>customFamily-v2.iPhone</id>
    <extends>customFamily-v1.iOS</extends>
    <style-sheet-name>iphone-v2.css</style-sheet-name>
    <version>
      <name>v2</name>
    </version>
  </skin>
  <skin id="s3">
    <family>customFamily</family>
    <id>customFamily-v3.iPhone</id>
    <extends>customFamily-v1.iOS</extends>
    <style-sheet-name>iphone-v3.css</style-sheet-name>
    <version>
      <name>v3</name>
    </version>
  </skin>
</adfmf-skins>

4.13.9 Overriding the Default Skin Styles

For an MAF AMX application, you can designate a specific style for the application feature implemented as MAF AMX, thereby overriding the default skin styles set at the application-level within the maf-config.xml and maf-skins.xml files. You add individual styles to the application feature using a CSS file as the Includes file.

4.13.9.1 How to Apply New Style Classes to an Application Feature

The Includes section in the MAF Feature Editor for the maf-feature.xml files enables you to add a cascading style sheet (CSS) to an MAF AMX application feature.

Figure 4-34 The Includes Section

This image is described in the surrounding text

Before you begin:

Create an MAF task flow as described in Section 5.2, "Creating Task Flows." Create or add a Cascading Style Sheet (CSS) file for the skin. You can create the CSS file by right clicking the ViewContent folder of the view controller project, and then select File > New > Other and type CSS in the filter. Then, select Web > CSS File.

How to add a style to an application feature:

  1. Open the file maf-feature.xml. Ensure that there is a feature that has AMX Page as the content type.

  2. In the Outline section, expand Features > feature name > Contents > Feature Id and select Includes. On selection, the Includes section will appear on the right side of the editor, as shown in Figure 4-35.

    Figure 4-35 Selecting the StyleSheet Option

    This image is described in the surrounding text
  3. Select the Browse button to select a file for inclusion in the Includes section. This opens the Select CSS Stylesheet or JavaScript File dialog, as shown in Figure 4-35.

  4. Select the CSS file that you created earlier under the ViewContent directory of the view controller project.

    Note:

    The .css file must reside within the view controller project; you cannot include a .css file that resides in the application controller project.

    Figure 4-36 Selecting the CSS for the Application Feature

    This image is described in the surrounding text
  5. Save the file maf-feature.xml.

4.13.10 What You May Need to Know About Skinning

The CSS files defined in the maf-skins.xml file, illustrated in Example 4-26, show how to extend a skin to accommodate the different display requirements of the Apple iPhone and iPad. These styles are applied in a descending fashion. The SkinningDemo sample application provides a demonstration of how customized styles can be applied when the application is deployed to different devices. You can find this example by selecting File > New > MAF Examples, then selecting SkinningDemo from the MAF Examples page.

For example, at the iOS level, the stylesheet (mobileAlta in Example 4-26) is applied to both an iPhone or an iPad. For device-specific styling, define the <skin-id> elements for the iPhone and iPad skins. The skinning demo application illustrates the use of custom skins defined through this element.

Example 4-26 Skinning Levels Defined in the maf-skins.xml File

<?xml version="1.0" encoding="UTF-8" ?>
<adfmf-skins xmlns="http://xmlns.oracle.com/adf/mf/skins">
    <skin>
        <id>mobileAlta-v1.2.iPhone</id>
        <family>mobileAlta</family>
        <extends>mobileAlta-v1.2.iOS</extends>
        <style-sheet-name>skins/mobileAlta-v1.2.iphone.css</style-sheet-name>
    </skin>
    <skin>
        <id>mobileAlta-v1.2.iPad</id>
        <family>mobileAlta</family>
        <extends>mobileAlta-v1.2.iOS</extends>
        <style-sheet-name>skins/mobileAlta-v1.2.ipad.css</style-sheet-name>
    </skin>
    <skin>
        <id>mobileAlta-v1.2.iPod</id>
        <family>mobileAlta</family>
        <extends>mobileAlta-v1.2.iOS</extends>
        <style-sheet-name>skins/mobileAlta-v1.2.ipod.css</style-sheet-name>
    </skin>
    <!--  Skin Additions -->
    <skin-addition>
        <skin-id>mobileAlta-v1.2.iPhone</skin-id>
        <style-sheet-name>skins/mystyles.iphone.addition1.css</style-sheet-name>
    </skin-addition>
    <skin-addition>
        <skin-id>mobileAlta-v1.2.iPhone</skin-id>
        <style-sheet-name>skins/mystyles.iphone.addition2.css</style-sheet-name>
    </skin-addition>
    <skin-addition>
        <skin-id>mobileAlta-v1.2.iOS</skin-id>
        <style-sheet-name>skins/mystyles.ios.addition2.css</style-sheet-name>
    </skin-addition>
</adfmf-skins>

4.13.11 Enabling Dynamic Skin Selection at Runtime

You can configure your application to enable end users select an alternative skin at runtime. You can find this example by selecting File > New > MAF Examples, then selecting SkinningDemo from the MAF Examples page. You can configure this functionality when you want end users to render the application using a skin that is more suitable for their needs.

Figure 4-37 shows how you might implement this functionality by displaying buttons to allow end users to change the skin the application uses at runtime. Configure the buttons on the page to set a scope value that can later be evaluated by the skin-family property in the application's maf-config.xml file.

Figure 4-37 Changing an Application's Skin at Runtime (on iOS)

The surrounding text describes this image.

4.13.11.1 How to Enable End Users Change an Application's Skin at Runtime

You enable end users change an application's skin by exposing a component that allows them to update the value of the skin-family property in the application's maf-config.xml file.

To enable end users change an application's skin at runtime:

  1. Open the page where you want to configure the component(s) that you use to set the skin family property in the maf-config.xml file.

  2. Configure a number of components (for example, button components) that allow end users to choose one of a number of available skins at runtime, as shown in Figure 4-37.

    Example 31-6 shows how you configure amx:commandButton components that allow end users to choose available skins at runtime, as shown in Figure 4-37. Each amx:commandButton component specifies a value for the actionListener attribute. This attribute passes an actionEvent to a method (skinMenuAction) on a managed bean named skins if an end user clicks the button.

    Example 4-27 Using a Component to Set the Skin Family

    ...
    <amx:commandButton text="Switch to Alta" 
         actionListener="#{applicationScope.SkinBean.switchToMobileAlta}" id="cb1"/>
    <amx:commandButton text="Switch to Fusion Fx"
         actionListener="#{applicationScope.SkinBean.switchToMobileFusionFx}" id="cb2"/>
    ...
    
  3. Write a managed bean in the application's view controller project to store the value of the skin selected by the end user. Example 4-28 shows a method that takes the value the end user selected and uses it to set the value of skinFamily in the managed bean. Example 4-28 also shows a method that resets all features in the application to use the new skin.

    Example 4-28 Managed Bean to Change an Application's Skin

    package application;
     
    import javax.el.ValueExpression;
    import oracle.adfmf.amx.event.ActionEvent;
    import oracle.adfmf.framework.FeatureInformation;
    import oracle.adfmf.framework.api.AdfmfContainerUtilities;
    import oracle.adfmf.framework.api.AdfmfJavaUtilities;
    import oracle.adfmf.java.beans.PropertyChangeListener;
    import oracle.adfmf.java.beans.PropertyChangeSupport;
     
    public class SkinBean
     
    {
        private String skinFamily = "mobileAlta";
        private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
     
        public void setSkinFamily(String skinFamily) {
            String oldSkinFamily = this.skinFamily;
            this.skinFamily = skinFamily;
            propertyChangeSupport.firePropertyChange("skinFamily", oldSkinFamily, skinFamily);
     
        }
     
        public String getSkinFamily() {
            return skinFamily;
        }
     
        public void addPropertyChangeListener(PropertyChangeListener l) {
            propertyChangeSupport.addPropertyChangeListener(l);
        }
     
        public void removePropertyChangeListener(PropertyChangeListener l) {
            propertyChangeSupport.removePropertyChangeListener(l);
        }
     
        public void switchToMobileAlta(ActionEvent ev){
            this.switchSkinFamily("mobileAlta");
        }
     
        public void switchToMobileFusionFx(ActionEvent ev) {
            this.switchSkinFamily("mobileFusionFx");
        }
     
        public void switchSkinFamily(String family) {
            this.setSkinFamily(family);
            // reset all the features individually as follows to load the new skin
            FeatureInformation[] features = AdfmfContainerUtilities.getFeatures();
            for (int i = 0; i < features.length; i++) {
                AdfmfContainerUtilities.resetFeature(features[i].getId());
            }
        }
    }
    
  4. In the Project Explorer, expand the Application Resources panel, expand Descriptors > ADF Meta-INF node and double-click the maf.config.xml file.

  5. In the maf-config.xml file, write an EL expression to dynamically evaluate the skin family:

    <skin-family>#{applicationScope.SkinBean.skinFamily}</skin-family>

4.13.11.2 What Happens at Runtime: How End Users Change an Application's Skin

At runtime, the end user uses the component that you exposed to select another skin. In Example 4-27, this is one of a number of amx:commandButton components. This component submits the value that the end user selected to a managed bean that, in turn, sets the value of a managed bean property (skinFamily). At runtime, the <skin-family> property in the maf-config.xml file reads the value from the managed bean using an EL expression. The managed bean in Example 4-28 also reloads the features in the application to use the newly-specified skin.

Tip:

Similar to the <skin-family> property, you can use an EL expression to set the value of the <skin-version> property in the maf-config.xml file at runtime.

As an alternative to resetting the application's features individually to load the new skin, as demonstrated in Example 4-28, you can invoke the resetApplication method from the following class:

oracle.adfmf.framework.api.AdfmfContainerUtilities

For more information, see Java API Reference for Oracle Mobile Application Framework.

4.14 Working with Feature Archive Files

The maf-application.xml file references at least one application feature. These application features, when packaged into a JAR file known as a Feature Archive file (FAR), provide the reusable content that can be consumed by other mobile applications. A FAR is essentially a self-contained collection of everything that an application feature requires, such as icon images, resource bundles, HTML files, JavaScript files, or other implementation-specific files. As described in Section 19.3, "Deploying Feature Archive Files (FARs)," the contents of a FAR includes a single maf-feature.xml file, which identifies each of the packaged application features by a unique ID. You can edit this file, as described in Section 4.9, "About the Mobile Application Feature Configuration File," to update such feature properties as content implementation (local or remote HTML files or MAF AMX pages) and display based on such factors as user roles and privileges, or device properties. A mobile application can reference one FAR, several of them, or none at all.

You can add a FAR to a MAF application using the MAF Application editor. Once added, the features it contains are available for referencing. Unless you reference them, the FAR features are not used. When referenced, any connections that the FAR uses must be set in the consuming application. You cannot customize the FAR's contents, nor can you reuse its individual artifacts. A mobile application consumes the FAR in its entirety. For example, a FAR's task flow cannot be the target of a task flow call activity.

Note:

If the feature archive contains an AMX page that uses Geographic Map, you need to set a number of properties in the application's adf-config.xml file. See Section 6.5.18.1, "Configuring Geographic Map Components With the Map Provider Information."

4.14.1 Importing a FAR as an Application Library

You can import a FAR as an application library to make its features accessible to your MAF application.

To import a FAR as an application library:

  1. In the Project Explorer, expand the folder for the top-level assembly project, then expand the MAF folder.

  2. Double-click MAF Application Editor to open maf-application.xml.

  3. Right-click on the Feature Archives folder and choose New > Feature Archive.

  4. Give the archive a name, or accept the default name (featureArchive1, where subsequent archives will be numbered in sequence).

  5. Click the Browse button for the URI field to open the Mobile Feature Archive Location dialog, then type in the URI at which the FAR can be located. Oracle Enterprise Pack for Eclipse verifies that the selected file contains feature definitions, and that the location is accessible.

  6. When you have specified the URI and Oracle Enterprise Pack for Eclipse has verified it, click OK.

4.14.2 What You May Need to Know About Using a FAR to Update the sync-config.xml File

The sync-config.xml file enables the mobile application to not only cache the data retrieved from server-side resources accessed through various types of web services (SOAP, REST-XML, or REST with JSON payloads) to the embedded SQLite database, but also enables the application to update this data within the cache and to the server-side resource.

The sync-config.xml file is included in the Feature Archive file when the view controller project is deployed as a FAR. Like the connections.xml file, MAF merges the contents of the sync-config.xml file in the FAR (jar-sync-config.xml) with those of the consuming application's sync-config.xml file after you add the FAR to the application. Because the sync-config.xml file describes the web service endpoints used by the mobile application, you can update the endpoints for all of the web services used by the application features that comprise a mobile application by adding a FAR.

After you add the FAR to the application, MAF logs messages that prompt you to verify and, if needed, modify the application's sync-config.xml and connections.xml files. As illustrated in Figure 4-38, these messages reflect the state of the sync-config.xml file in the consuming application.

Figure 4-38 The Messages Log

Surrounding text describes Figure 4-38 .

If the consuming application lacks the sync-config.xml file, then MAF adds the file to the application and writes a message similar to the following:

oracle.adfmf.framework.dt.deploy.features.deployers.SyncConfigMerger _logNoSyncConfigInAppUsingFar

WARNING: The application does not contain a synchronization file, "sync-config.xml". Creating one containing the synchronization configuration in the Feature Archive.

MAF writes a log message similar to the following that requests that you verify (or create) a connection if the sync-config.xml file's <ServerGroup> elements do not have corresponding <Reference> elements defined in the consuming application's connections.xml file:

oracle.adfmf.framework.dt.deploy.features.deployers.SyncConfigMerger _logAddedServerGroups

WARNING: The following server groups were added sync-config.xml by the Add to Application operation:{ ServerGroup1 - there is no existing application connection defined for this server group. Please create the connection. ServerGroup2 - verify its configuration.}

If the <ServerGroup> definitions in the consuming application's config-sync.xml file duplicate those of the counterpart config-sync.xml file included in the FAR, then MAF writes the following SEVERE-level message to the log:

oracle.adfmf.framework.dt.deploy.features.deployers.SyncConfigMerger _logDuplicateServerGroups

SEVERE: Cannot merge the server groups from the Feature Archive because the following definitions already exist:

ServerGroup1

ServerGroup2

4.14.3 What Happens When You Add a FAR as a View Controller Project

When you add a FAR as a view controller project:

  • MAF generates a view controller project that bears the same name as the imported FAR. This view controller project contains the default structure and metadata files of a MAF view controller project. In particular, the FAR view controller project includes the maf-feature.xml file. If the MAF application contains other view controller projects, you must ensure that none of these projects include application features with the same ID.

  • As with a FAR imported as a library, the information in the connections.xml file located in the Feature Archive JAR is merged into the consuming application's connections.xml file. MAF will create a connections.xml file if one does not already exist in the target application. Likewise, the sync-config.xml file is merged into the consuming applications's sync-config.xml file.

  • MAF makes any .class and JAR files included in the FAR available as a library to the view controller project by copying them into its lib directory (such as C:\jdeveloper\mywork\application\FAR view controller project\lib). MAF compiles these files into a file called classesFromFar.jar.

  • Unlike a FAR imported as a library, you can customize the files of a view controller project.

  • Like a FAR imported as a library, every application feature declared in the FAR's maf-feature.xml file becomes available to the consuming application.

4.14.4 What You May Need to Know About Enabling the Reuse of Feature Archive Resources

To ensure that the resources of a FAR can be used by an application, both the name of the FAR and its feature reference IDs must be globally unique; ensure there are no duplicate feature reference IDs in the maf-application.xml file. Within the FAR itself, the DataControl.dcx file must be in a unique package directory. Rather than accepting the default names for these package directories, you should instead create a unique package hierarchy for the project. You should likewise use a similar package naming system for the feature reference IDs.

4.15 Integrating Cordova Plugins into Mobile Applications

Because applications created by MAF are hybrid mobile applications, they use the Apache Cordova JavaScript APIs to access the native device APIs. As described in Plugin Development Guide in the Cordova Apache Documentation (available through http://cordova.apache.org/), a Cordova plugin is composed of native code built using platform-specific SDKs (Xcode or the Android SDK) and JavaScript.

MAF does not ship with third-party Cordova plugins; they must instead be developed using the SDKs for the platform to which they will be deployed. In other words, you create a plugin for an iOS application using Xcode and use the Android SDK to create plugins for applications targeted to Android-powered devices. In addition to creating the plugin itself, you must also provide any accompanying instructions (that is, a readme or a manifest file) that describe how to add the plugin's resources to the application.

You must ensure that any third-party plugin complies with the version of Cordova supported by MAF. If MAF supports a version of the API that differs from the one used by the plugin, then the functionality that it enables may become unavailable to the mobile application.

Note:

Plugins must be compatible with Cordova 2.2.0, the only version supported by MAF.

4.15.1 How to Integrate Cordova Plugins for iOS and Android

The Cordova Plugins page, illustrated in Figure 4-39, enables you to integrate the plugins to the mobile application by updating the platform-specific XML files (cordova.plist file for iOS and the config.xml file for Android) as described by the plugin instructions that are provided by the developer of the plugin.

Figure 4-39 The Cordova Plugins Page

This image is described in the surrounding text

OEPE manages plugins with file mapping instructions, used at deployment time, to copy the artifacts to the desired places.

OEPE allows you to copy to the source project. This may be useful for development. The IDE allows for these files to be removed so that all files will be deployed using the file mapping.

You can drag and drop using the Browse dialog to create mapping, according to the following file filters:

foo.xyz mapping means copy foo.xyz to the target root directory

*.xyz mapping means copy all files with xyz extension in the current directory.

**.xyz mapping means copy all files with extension xyz in all subdirectories.

**\foo\**\*.xyz mapping means copy all files with xyz extension that are contained with in a foo subdirectory.

Before you begin:

Perform the following:

  • Obtain the plugin integration instructions from the plugin developer.

  • Obtain the plugin itself (the source code, the JavaScript file, and any additional libraries, resources, or assets).

  • Table 4-12 lists the directories that you manually create in the application controller and view controller projects. Once created, copy the plugin artifacts to the directories. The primary components of a plugin, JavaScript file and the plugin binary libraries, are located in different projects (the view controller project and the application controller project) within a mobile application.

    Table 4-12 Locations of Directories to Create Plugin Artifacts

    Artifact File Location Description

    Assets

    application workspace directory\ApplicationController\src\plugins\Plugin Name\Platform\assets

    This folder contains plugin assets. This Android-only artifact is optional.

    JavaScript Files

    application workspace directory\ViewController\public_html\plugins\Plugin Name\Platform\js

    This directory contains the plugin JavaScript files. This folder is required and must contain a JavaScript file.

    Plugin Library

    application workspace directory\ApplicationController\src\plugins\Plugin Name\Platform\bin

    Contains the plugin binary. This is a required folder, one which must contain this content.

    Dependent Libraries

    application workspace directory\ApplicationController\src\plugins\Plugin Name\Platform\libs

    Copy any additional, dependent libraries to this location. This is an optional folder.

    Native Libraries

    application workspace directory\ApplicationController\src\plugins\Plugin Name\Platform\native-libs

    For Android only. Copy native Android libraries to this location.

    Resources

    application workspace directory\ApplicationController\src\plugins\Plugin Name\Platform\res

    Copy additional plugin resources folder. This is an optional folder.


    These items are only visible in Oracle Enterprise Pack for Eclipse when the view includes .* resources. For more information, see Section 3.2.2, "What Happens When You Create an MAF Application."

  • For application features authored in MAF AMX, the task flow's managed bean must contain a handler method that uses the invokeContainerJavaScriptFunction as follows:

    AdfmfContainerUtilities.
    invokeContainerJavaScriptFunction(featureid, methodname, new Object[]
                                                             { params... })
    

    This method invokes JavaScript. For an example implementation, see the ManagedBean.java file in the APIDemo sample application. This sample application is available from File > New > MAF Examples.

    For more information about the invokeContainerJavaScriptFunction, see Section B.2.14, "invokeContainerJavaScriptFunction" and Java API Reference for Oracle Mobile Application Framework.

  • If you obtain the plugin-related artifacts and the JavaScript files from a FAR, as described in Section 4.15.4, "What You May Need to Know About Integrating Plugins Using FARs," then you must ensure that the plugin has an accompanying JavaScript file. If the FAR consumed by the mobile application does not include the JavaScript file, then you must obtain one, or create one using the FAR developer's instructions. You must also add the FAR to the application as described in Section 4.14.1, "Importing a FAR as an Application Library."

To add an Android plugin:

  1. In the Project Explorer, expand the folder for the top-level assembly project, then expand the MAF folder.

  2. In the outline, right-click Plug-Ins and choose New > Cordova Plug-in.

  3. Complete the Insert Plugin dialog, shown in Figure 4-40.

    Figure 4-40 Adding an Android Plugin

    This image is described in the surrounding text
    • Name—The name of the plugin. This is the name of the folder containing the plugin artifacts as well as the value logged to the deployment when errors are detected.

    • Platform—Choose Android.

    • Qualified Name—The fully qualified name of the plugin. This name is provided by the manifest or readme file and maps to the name attribute of the plugin element in the config.xml file.

    • Implementation Class—The name of the class that implements the plugin. This name, which is provided by the manifest or readme file, is typically a Java package followed by a class name. It maps to the value attribute of the plugin element in the config.xml file.

  4. If the plugin requires its own Android resources, enter the Java package that these resources should appear under in Resource Package. Otherwise, leave this field blank. This is an optional value.

To add an iOS plugin:

  1. In the Project Explorer, expand the folder for the top-level assembly project, then expand the MAF folder.

  2. In the outline, right-click Plug-Ins and choose New > Cordova Plug-in.

    • Name—The name of the plugin. This is the name of the folder containing the plugin artifacts as well as the value logged to the deployment when errors are detected.

    • Platform—Choose iOS.

    • Fully Qualified Name—The fully qualified name of the plugin. This name is provided by the manifest or readme file and maps to the <key> element in the cordova.plist file.

    • Implementation Class—The name of the class that implements the plugin. This name is provided by the manifest or readme file and is typically the name of an Objective-C class. It maps to the <string> element in the cordova.plist file.

  3. Complete the Insert Plugin dialog, shown in Figure 4-41.

    Figure 4-41 Adding an iOS Plugin

    This image is described in the surrounding text
    • Name—The name of the plugin. This is the name of the folder containing the plugin artifacts as well as the value logged to the deployment when errors are detected.

    • Platform—Choose iOS.

    • URI—the uniform resource indicator for the plugin. Click the Browse button to search for it, or drag it directly from an open folder into the URI spot in the MAF Application Editor.

    • Fully Qualified Name—The fully qualified name of the plugin. This name is provided by the manifest or readme file and maps to the <key> element in the cordova.plist file.

    • Implementation Class—The name of the class that implements the plugin. This name is provided by the manifest or readme file and is typically the name of an Objective-C class. It maps to the <string> element in the cordova.plist file.

    • Linker Flags — Enter any additional linker flags required by the plugin. You must add an option to link to the plugin library, such as -l BarcodeScanner. For example:

      -l BarcodeScanner -lc++ -liconv -framework CoreVideo -framework AssetsLibrary
      -framework AVFoundation
      

      Consult the readme file to determine if any additional libraries are required.

To enable a local HTML content to reference the plugin's JavaScript file:

  1. Open the MAF Feature Editor from the Project Explorer, then choose the application feature that uses the plugin.

  2. Click Content and then select Local HTML.

  3. Reference the JavaScript file using a <script> tag in the HTML document, such as <script type="text/javascript" src="../../../../www/js/barcodescanner.js"></script> in Example 4-29.

    Example 4-29 Referencing the Plugin JavaScript File Using the <script> Tag

    <!DOCTYPE html>
    <html>
      <head>
        <meta name="viewport" content="user-scalable=no,height=device-height,width=device-width" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
        <script type="text/javascript">if (!window.adf) window.adf = {};  
                                          adf.wwwPath = "../../../../www/";</script>
        <script type="text/javascript" src="../../../../www/js/base.js"></script>
        <script type="text/javascript" src="../../../../www/js/barcodescanner.js"></script>
        <script type="text/javascript" charset="utf-8">
            function scanBarcode()
            {
              window.plugins.barcodeScanner.scan(
                                                 function(result) {
                                                  if (result.cancelled)
                                                    updateContentNode("the user cancelled the scan");
                                                  else
                                                  updateContentNode("We got a barcode: " +
                                                    result.text);
                                                 },
                                                 function(error) {
                                                    updateContentNode("scanning failed: " + error);
                                                 }
                                                )
            }
     
            function updateContentNode(newContent)
            {
              $("#content").html(newContent);
            }
          </script>
      </head>
      <body onload="onBodyLoad()">
     
        <!-- MAIN PAGE -->
        <div data-role="page" id="main" data-url="main.jspx" data-position="fixed">
          <div data-role="header" data-position="fixed">
            <h1>
              Barcode Scanner Test
            </h1>
          </div>
          <div data-role="content" id="content">
            No barcode scanned yet
          </div>
          <div data-role="footer" data-position="fixed">
            <div data-role="navbar">
              <ul>
                <li>
                    <a href="javascript:try{scanBarcode();}catch(e){alert(e.description);}"
                    data-rel="dialog" data-transition="pop">Scan barcode</a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </body>
    </html>
    

4.15.2 What Happens When You Configure a Plugin

Using the MAF Application Editor populates the maf-application.xml file with a <adfmf:cordovaPlugins> element. Refer to Tag Reference for Oracle Mobile Application Framework for more information on this element and its child elements.

Example 4-30 The <adfmf:cordovaPlugins> Element

<adfmf:cordovaPlugins>
    <adfmf:plugin name="BarcodeScanner" platform="iOS" 
                 implementationClass="CDVBarcodeScanner"
                 fullyQualifiedName="ios.apache.cordova.barcodeScanner">
      <adfmf:iosPluginInfo>
        <adfmf:linkerFlags>-l BarcodeScanner     
                           -lc++
                           -liconv
                           -framework CoreVideo
                           -framework AssetsLibrary
                           -framework AVFoundation</adfmf:linkerFlags>
      </adfmf:iosPluginInfo>
    </adfmf:plugin>
    <adfmf:plugin platform="Android" name="BarcodeScanner"
                  implementationClass="com.phonegap.pluigns.barcodescanner.BarcodeScanner"
                  fullyQualifiedName="BarcodeScanner">
      <adfmf:androidPluginInfo>
        <adfmf:resourcePackageName>com.google.zxing.client.android</adfmf:resourcePackageName>
        <adfmf:androidManifestActivities>&lt;activity android:name=".CaptureActivity"
              android:screenOrientation="landscape"
              android:clearTaskOnLaunch="true"
              android:stateNotNeeded="true"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
              android:windowSoftInputMode="stateAlwaysHidden"&gt;
              ...
         </adfmf:androidManifestActivities>
      </adfmf:androidPluginInfo>
    </adfmf:plugin>
  </adfmf:cordovaPlugins>
</adfmf:application>

4.15.3 How to Add Plugin Preferences

On both the application-level and application feature-level user preferences pages, the Cordova plugin preferences display either at the bottom of a user preference page beneath the preferences defined by the preferences elements described in Chapter 13, "Enabling User Preferences" or as a child preference page that opens from a preference group or from a single item preference list selection.

Before you begin:

Refer to Preferences and Settings Programming Guide, which is available through the iOS Developer Library (http://developer.apple.com/library/ios/navigation/) for information on the Settings bundle (Settings.bundle) and its contents (such as the Root.plist file and the .strings file).

To merge the Cordova plugin preferences at the bottom of a preference page of an iOS application:

  1. Create a resource (res) file within the application controller project for the plugin, such as:

    application workspace directory\ApplicationController\src\plugins\plugin name\iOS\res
    
  2. Copy the Settings bundle (Settings.bundle ) file into the plugin's res folder.

To merge the Cordova plugin preferences as a child page in an iOS application:

  1. Create a resource (res) folder within the application controller project for the plugin, such as:

    application workspace directory\ApplicationController\src\plugins\plugin name\iOS\res
    
  2. Copy the Settings bundle (Settings.bundle) file into the plugin's res folder.

  3. Rename the Root.plist file to PluginName.Root.plist, where PluginName is the name of the plugin. For example, rename this file BarcodeScanner.Root.plist.

  4. Define a sting ID and localizable value for the title of the child page in the plugin's .strings file. This ID must be PluginName.page.title where PluginName is the name of the plugin. For example:

    "PluginName.page.title" = "Some Localized Page Title";

To merge the Cordova plugin preferences at the bottom of a preference page of an Android application:

  1. Create a resource (res) folder for the plugin in the application controller project, such as:

    application workspace directory\ApplicationController\src\plugins\plugin name\Android\res
    
  2. Copy the resources that contain the preferences.xml file into the plugin's res folder. For more information the preferences.xml file and defining subscreens, see "Defining Preferences in XML" in Settings guide, available from the Android Developers website (http://developer.android.com/guide/topics/ui/settings.html) or the Android SDK documentation. For information on how the MAF deployment framework converts preferences, see Section C.2, "Converting Preferences for Android."

To merge the Cordova plugin preferences as a child page in an Android application:

  1. Copy the resources that contain the preferences.xml file into the plugin's res folder.

  2. Nest the set of preferences (illustrated in Example 4-31) within another PreferenceScreen element as illustrated in Example 4-32.

    Example 4-31 Preferences

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
          <PreferenceCategory android:title="@string/preferences_scanning_title">
                <CheckBoxPreference android:key="preferences_decode_1D"
                                    android:defaultValue="true" 
                                    android:title="@string/preferences_decode_1D_title"/>
                ...
           </PreferenceCategory>
            ...
     
    </PreferenceScreen>
    

    Example 4-32 illustrates defining an android:key attribute to wrap the PreferenceScreen element.

    Example 4-32 A Set of Preferences Wrapped in a PreferenceScreen Element

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
      <PreferenceScreen android:key="wrapperScreen" android:title="Barcode Scanner">
          <PreferenceCategory android:title="@string/preferences_scanning_title">
                <CheckBoxPreference android:key="preferences_decode_1D"
                                    android:defaultValue="true"
                                    android:title="@string/preferences_decode_1D_title"/>
                ...
           </PreferenceCategory>
            ...
      </PreferenceScreen>
    </PreferenceScreen>
    
  3. If the preference page requires localization, define the string values in the localized strings.xml files. For more information on the strings.xml files, see the "String Resources" section in App Resources Guide, available from the Android Developers website (http://developer.android.com/guide/topics/resources/index.html) or the Android SDK documentation. For information on how the MAF deployment framework handles the strings.xml file, see Section C.2.3, "Strings.xml."

4.15.4 What You May Need to Know About Integrating Plugins Using FARs

Although the components of a mobile application may be created by a single developer, an application may typically be comprised from resources provided by different developers. Adding third-party plugins illustrates the latter case, with a FAR developer first creating and testing an application feature that uses a plugin before deploying the view controller project as a Feature Archive file (FAR). The FAR developer publishes this FAR to an Application Assembler developer and provides a set of instructions (such as a readme file) for integrating the plugin as well as the JavaScript file. The FAR developer may also provide the Application Assembler developer with a ZIP file of the plugin binary library. The Application Assembler then adds a FAR to a mobile application and uses the instructions to integrate the JavaScript file and plugin binary libraries into the mobile application's projects. The mobile application is subsequently tested, deployed as a platform-specific package, and published. Specifically, the collaboration between the FAR developer and the Application Assembler is comprised of the following:

  1. The FAR developer uses Xcode or the Android SDK to create the Cordova plugin library (resulting in an .a file for iOS or a JAR file for Android). To enable MAF applications to consume this library, the developer performs the following:

    1. Creates a mobile application. The developer includes the plugin binary to various locations within the application controller project and then adds the JavaScript file to the public_html directory in the view controller project. For a user interface implemented as MAF AMX, the JavaScript file is referenced in the maf-feature.xml file using the Insert Includes dialog, as described in Section 4.11.1, "How to Define the Application Content." For HTML-based user interfaces, reference this file using a JavaScript includes.

      For MAF AMX-authored application features, JavaScript is invoked by including the invokeContainerJavaScriptFunction method in a Java handler. For more information, see Section B.2.14, "invokeContainerJavaScriptFunction" and Java API Reference for Oracle Mobile Application Framework.

      In an HTML-authored application feature, JavaScript is called directly by referencing the location of the JavaScript file in the <script> tag.

    2. Integrates the Cordova plugin using the Cordova Plugins page of the maf-application.xml overview editor and its dialogs.

    3. Deploys the application to a device for testing.

    4. Deploys the view controller project as a FAR. This FAR itself may include such artifacts as MAF AMX and HTML pages that reference the Cordova plugins as well as the JavaScript files.

      Note:

      The FAR may not always include the JavaScript file.

    5. Although not included in the FAR, the FAR developer provides the Application Assembler developer with a set of instructions to integrate the plugin into a mobile application. Because these instructions are specific to both the development organization and the plugin itself, the means and format through which they are conveyed (such as a metadata file or a readme file), results from agreements between the FAR and Application Assembler developers. Example 4-33 illustrates a portion of the a README.md file that describes how to integrate an iOS plugin:

      Example 4-33 The README.md File

      ...
      ## Adding the plugin to your project ##
      * Copy the .h, .cpp and .mm files to the Plugins directory in your project.
      * Copy the .js file to your www directory and reference it from your html file(s).
      * In the `Supporting Files` directory of your project, add a new plugin by editing  
       the file `Cordova.plist` and in the `Plugins` dictionary adding the following
       key/value pair:
        * key: `org.apache.cordova.barcodeScanner`
        * value: `CDVBarcodeScanner`
       Add the following libraries to your Xcode project, if not already there:
        * AVFoundation.framework
        * AssetsLibrary.framework
        * CoreVideo.framework
        * libiconv.dylib
      ...
      
  2. The Application Assembler adds the FAR mobile application, as described in Section 4.14.1, "Importing a FAR as an Application Library."

  3. Unless the FAR developer provides a ZIP file of the plugin binary, the Application Assembler must build the plugin using the platform-specific SDKs. The plugin is packaged in the platform-specific package (the .a file for iOS or a JAR file for Android).

  4. The Application Assembler developer adds the plugin binary libraries to the application controller project and the JavaScript file to the public_html directory of the view controller project.

  5. Using the Cordova Plugins page of the maf-application.xml overview editor and its dialogs, the Application Assembler developer updates the platform-specific XML files (that is, the cordova.plist file for iOS and the config.xml file for Android) as specified in the instructions. The MAF deployment uses this configuration to incorporate the plugins into the mobile application.