Friday, January 11, 2013

ADF Mobile - Device Native Database Access and Usage

This will be a third update for my sample ADF Mobile application. Read about previous versions from here - ADF Mobile - Geo Location Synchronization. This update is focused primarily on device native database access and operations. I'm using located GPS points as data source and populating on device SQL Lite database with locations retrieved from GPS. Logged data review functionality is implemented as well - user can view altitude graph and load logged path as point layer on top of Google Maps.

Added features:

1. ADF Mobile Springboard support demonstrating multiple ADF Task Flow usage and access

2. ADF Mobile UI validation behavior and conditional logic

3. Device native database access and usage

4. Data visualization with ADF DVT components

5. Multi-point layer display on top of Google Maps

6. iPhone right/left swipe actions

Download sample application code - PosLogApp.zip. This sample contains two ADF Task Flows, both of them are loaded using ADF Mobile Springboard - Tracker (logs GPS positions) and Routes (logs and displays route data):


Same as in the previous version - Tracker logs current GPS position. Once Tracker is activated it will log GPS position change continuously until it will be stopped by the user:


In the same ADF Task Flow - Tracker, we can view current GPS position on the Google Maps:


Second ADF Task Flow - Routes allows to enter new route name and date (current date by default). When Start is activated - it will log each GPS position received from the Tracker into native device database until user will stop route logging:


From this screen user have option to view a list of previously recorded routes - Show button:


List is clickable - user can click on the selected route to view information about it. Information about logged GPS position for the selected route is retrieved from database - in the first screen we can see number of GPS positions logged. 1033 positions were logged for this route (maximum is set to be 10000):


We can view logged altitude information for the route - I was driving uphill and then downhill:


Route path itself can be visualized on top of Google Maps from logged GPS points:


If you want to delete logged route, simply swipe to the right and press Delete button:


You want to know about implementation details? All right - here is ADF Task Flow view for the router part:


Page with route name and date is default, next we can view route list and remove routes with refresh through the method call. We can view details - number of logged GPS points, altitude graph and route path constructed from logged GPS points.

Here is the database structure, two tables simple master/detail - ROUTES and POINTS. This script is executed during initial application activation on the device. Basically it creates *.db file with SQL Lite database on the device:


SQL file must be loaded programmatically, from custom lifecycle listener class. We must define this class in adfmf-application.xml file:


Application lifecycle method - start(), will be executed automatically and it will load database structure initially:


Connection to the database is constructed by retrieving reference to the SQL Lite database file on device:


Here you can see code to insert information about new route - regular SQL syntax and PreparedStatement:


This code snipped shows retrieval of GPS logged positions and constructing array of such points (later displayed in altitude graph and path on top of Google Maps):


In order to be able to load Google Maps in ADF Mobile, you must set Google Maps key in adf-config.xml file. Sample application is provided with dummy key, you must set your own:


Xcode Organizer tool displays installed applications on iPhone, I can see database file for my application. Organizer gives option to download application contents together with database file:


We can extract downloaded archive and access database file:


Performance of device native database is pretty good, I recorded around 10000 GPS location points in total - browsing through this dataset and loading is smooth:


12 comments:

Ben said...

Thanks Andrejus, I am looking to do something similar with the local DB. Do the POJOs interacting with the local DB need to be written by hand or is there a way to generate them? Also, the app does not work when deployed on Android, are changes needed to deploy to Android?

Andrej Baranovskij said...

Hi,

You need to write POJO's by hand, no generation at this point.

I wasn't testing on Android. In theory, only deployment profile should be changed. What is not working in particular?

Regards,
Andrejus

Galea Augustin said...

Hi Andrejus,
I have tested on Android(Samsung Tablet) and it work fine.

Augustin

Andrej Baranovskij said...

Perfect ! Thanks Augustin for testing !

Andrejus

Ayon Ghosh said...

Hi Andrejus,

I am not sure if this is the right place to ask you this question, but I am facing a serious issue with ADF Mobile. I am trying to create a contact on my Android emulator (running ICS). I have used both the createContact method of DeviceFeatures data control as well as JavaScript (using PhoneGap which is provided with AMX) but I am unable to create a new contact. The Contact object returned has id as -1 and all other fields empty. I have gone through all Oracle documentation on this topic but I still don't know what I am missing out on.

Can you kindly help me in this regard? I am using JDeveloper 11g R2 (11.1.2.3.0)

Thanks and regards,
Ayon

Andrej Baranovskij said...

Hi,

I will need to take a look into this, wasnt creating contacts yet.

Andrejus

Anonymous said...

Hi,
With my very little knowledge in ADF Mobile, I tried to write a application that has a local SQLite database. Problem I faced to import DBConnectionFactory and LifeCycleListenerImpl file in other Java file. When I tried to import the above two files like :

import application.(does not show DBConnectionFactory or LifeCycleListenerImpl option)

what else i have to do.

best regards,

Mazhar.

Anonymous said...

Hi,

This is really very informative blog.
I downloaded the app and when I am trying to run it on android emulator I am seeing a blank page and in the logs I see an error "SQLite database failed to load from /CachedGeoposition.db". Any idea on this?

Regards,
Chida

Anonymous said...

Hi Galea Augustin,
Can you please tell me which tablet you have tried this?

Samsung Galaxy Tab3 its not working..
can you please tell me the reason?

how can we fix this issue?

Thanks
Rajeev

Andrej Baranovskij said...

I was trying with iPad, it works.

Andrejus

Unknown said...

I got this message, can you help finding the link for it please.Message from ADF when deploying:

he application may not function correctly because the following dependent libraries are missing:
/Oracle/Middleware11123/jdeveloper/jdev/extensions/oracle.adf.mobile/lib/adfmf.springboard.jar

Pavan said...

I have built this application using MAF 2.0 and installed
Also I have built the same using application MAF 2.3 and installed.
After opening the app, I am getting blank white screen and thus unable to use the app.
I have to clear data and use the app.
please help