February 17, 2011

Android SQLite Library Example Code

Posted in Android Development tagged , , , , , , at 11:00 pm by tetontech

I have just uploaded QCDBAccess.  It is a SQLite wrapper for Android that is easy to use, thread-safe, and allows you to use transactions if you choose.  It is the same code that has been available for QCAndroid hybrid application developers for a few years.  I thought I would pull it out and give it its own life for those that want to use it on their own.

You can download it from SourceForge and find out more about it, including the API, at the QuickConnectFamily site.

As with all of the things I’m making available I have tried to make this as easy to use, highly functional, and small as possible.

The jar file is only 8k in size but the library doesn’t restrict your use of the databases in any way.

Here is a simple example of how to use the library to do a query against a SQLite database file included in your applications’ assets directory.  Notice that I’m checking to see if the user has entered a name to query against in an EditText object from the user interface.  If they have then I’m going to use a prepared statement.  The EditText object in this example has been passed into the method in which this code exists.

String sql = “SELECT * FROM user”;

String[] statementParams = null;

EditText nameInput = (EditText)methodParameters.get(1);

String name = nameInput.getEditableText().toString().trim();

if(name.length() > 0){

sql += ” WHERE name = ?”;

statementParams = new String[1];

statementParams[0] = name;


try {

retVal = DataAccessObject.getData(theActivity, “demo.sqlite”, sql, statementParams);

} catch (DataAccessException e) {



The DataAccessResult variable retVal is going to be returned from this method later.  This DataAccessResult is a Bean that contains resultant field names, the records returned from the query, and a database error description if and only if a database error happened.

the getData method is passed the Activity with which the database is associated with.  This is usually the main Activity in an Android Application.  The second parameter is the name of the SQLite database file to be used.  The third parameter is SQLite SQL assembled either as a standard or prepared statement.  The last parameter is an array of Objects that are to be bound to the ? characters if the SQL is a prepared statement or null if it is not a prepared statement.

Inserting data is done in very much the same fashion.  Once again I have an EditText object in the UI from which I’m getting the name to be inserted into the table.  I’m also generating a unique identifier just to make this a little more interesting.  You could do an auto incremented id in your table if you want.

EditText nameInput = (EditText)parameters.get(1);

String nameToAdd = nameInput.getEditableText().toString().trim();

String[]statementParams = {UUID.randomUUID().toString(), nameToAdd};

DataAccessResult aResult = null;

try {

aResult = DataAccessObject.setData(theActivity, “demo.sqlite”,



return aResult;

} catch (Exception e) {



Notice that once again I have chosen to use a prepared statement.  I’m doing this to avoid SQL insertion attacks.  It never hurts to avoid those.

If you are going to do several insertions you should use transactions to make sure you data stays clean.  There is a startTransaction method and an endTransaction method in the DataAccessObject.  Use those before and after multiple setData calls and you will be safe.

March 26, 2010

Using HTML Links to Trigger Activity in Hybrid Applications

Posted in Android Development, Blackberry development, iPhone development, mac development tagged , , , , , , , , , , , at 5:28 pm by tetontech

For those of you who are wanting to use <a> link tags to trigger behavior I have put together an example of how to make these work.

The main problem when you want to use a link rather than a button, div, image, or some other HTML element is to stop the standard behavior of loading the new page.  This is readily accomplished using QuickConnect since the framework includes a method with the signature ‘stopDefault(event)’.

Any time you call this method the default behavior of any type of event whether it be load a page, scroll, etc. is not executed.  The code behind this method is very strait forward as you can see here.

//stop an event from doing its’ default behavior

function stopDefault(event){





The fully working QuickConnect example code is seen below.  This example will also be included in the next beta download and the first QC v1.6 release.  This example is built off of the ViewSwapping example and includes an addition of how to interact with the in-app map QuickConnect behavior.  Because of this the index.html file code is very similar to that seen in my previous post.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” http://www.w3.org/TR/html4/strict.dtd>




<base href=“mobile/”>

<meta http-equiv=“content-type” content=“text/html; charset=utf-8”>

<meta name=“viewport” content=“width=device-width, minimum-scale=1.0, maximum-scale=1.6”>

<meta name=“apple-mobile-web-app-capable” content=“YES”>

<link rel=“stylesheet” href=“main.css”>

<script type=“text/javascript” src=“Parts/parts.js” charset=“utf-8”></script>

<script type=“text/javascript” src=“../QCJSLib/setupQC.js” charset=“utf-8”></script>

<script type=“text/javascript” src=“main.js” charset=“utf-8”></script>


<body onload=“load();”>

<div id=‘view1’ class=‘view’>

<a href=“” onclick=‘showView(2)’ >Show View 2</a>

<p>Here is some text for display in View 1.</p>


<div id=‘view2’ class=‘view’ style=‘background-color:lightgreen;’>

<a href=“” onclick=‘showView(1)’ >Show View 1</a>

<p>Here is some text for display in View 2.</p>


<a href=“” onclick=‘triggerShowMap()’>Show Map</a>



The main difference shown here is that the buttons have been replaced by link (anchor) tags.  Notice that the src attribute is set to an empty string.  It can be set to anything but what ever it is set to is ignored because of a call to the stopDefault method described above.

Additionally I have included a link that activates the in-app map behavior.  This new map activation link is the last element shown in the body tag.

Since the CSS hasn’t changed between this example and the previous one I will not provide it again.  You can see it in my previous post.

The Javascript is very similar.  As you can see here the only difference between the ShowView example code and the UsingLinksAsTriggers is the inclusion of a call to the stopDefault method.

function load()




var currentView = null;

function showView(viewNumber){

//stop the loading of the new page since this is triggered by a link


var nextView = document.getElementById(‘view’+viewNumber);

//if there is a view to change to


//if at least one view has been displayed


currentView.style.zIndex = 0;

currentView.style.opacity = 0;


nextView.style.zIndex = 10;

nextView.style.opacity = 1.0

//reset currentView

currentView = nextView;



The method for showing a map inside your application, triggerShowMap, is much like the method in the ShowMap example.  The difference is once again the addition of the call to stopDefault.

function triggerShowMap(event)


//stop the loading of the new page since this is triggered by a link


//a location consists of a latitude, a longitude, and a description

var locationsArray = new Array();

var rexburg = new Array();



rexburg.push(“County Court House”);


var wyoming = new Array();



wyoming.push(“Wyoming Place”);


var wilderness = new Array();



wilderness.push(“River of No Return Wilderness”);


var sandwichShop = new Array();



sandwichShop.push(“Somewhere Sandwiches”);



*  possible map types are standard, satelite, hybrid

*  The showMap method call is part of the QuickConnect Framework.

*  It is not a standard call


var showDeviceLocation = true;

showMap(locationsArray, showDeviceLocation, ‘standard’);


The examples shown here don’t use the QuickConnect mappings and stacks but the same call to stopDefault would need to be made if you were calling the standard ‘handleRequest’ method.  I usually put the stopDefault call in the first control function executed for the given command.

Hopefully this clears up how to use a link within hybrid applications.

December 30, 2009

Apple Push now Available

Posted in Uncategorized tagged , , , , , , , , at 12:14 am by tetontech

The QuickConnectFamily framework now includes support for Apple push functionality.  In addition to retrieving any update information for you and sending it to your JavaScript when your app starts if a push is received when your app is running your JavaScript is passed the notification.

Hopefully you can use it.

August 4, 2009

New License

Posted in iPhone development tagged , , , , , , , at 5:59 pm by tetontech

Because of the confusion over the LPGP license of QuickConnectiPhone it is now available under the MIT license.  It is still open source and free to use to create either open or closed, free or for-cost applications.

I hope this clears up any licensing issues you may have had.

July 31, 2009

QuickConnect 1.5 Release Candidate 1 now Available!

Posted in iPhone development tagged , , , , , , , , , , , , at 10:38 pm by tetontech

After many setbacks, like a very major hard drive crash and a bug in sourceForge, I have finally been able to release QC 1.5 Release Candidate 1.  It is now the default download for the project on sourceForge.

It includes:

  • Transaction handling for native databases from the JavaScript DataAccessObject.  The example project, NativeDatabaseTransactions, includes:
    • start transaction
    • commit
    • and rollback
  • A fix to the native footers disappearing when the orientation changed
  • Synced the Dashcode project with the latest code and fixed the run error caused by the rotating image
  • A fix that correctly handles all types of URLs such as mailTo, http, https, maps, youtube, etc.
  • A total of 32 QCiPhone examples
    • not all of the examples have been updated to the latest code set.  That will be completed for the final release.  If you are willing to volunteer to help with updating the examples please contact me.

March 12, 2009

AJAX and JSON. An example on the iPhone

Posted in iPhone development tagged , , , , , , , at 7:55 pm by tetontech

Since the iBlog example went away, it was too complex to understand easily, there has been a need for an example of how to do use AJAX and JSON together.  JSON is a great way to retrieve data from a server since the data is easily converted into one or more JavaScript objects.  The QuickConnectiPhone framework makes it very easy to make JSON requests and I have created an example called JSONDataExample that will be included in QC 1.5 Beta 4.

For the JSONDataExample application I found an open server that can serve up JSON strings.  It is a Yahoo! image description service.  I’ll use this service in this example.

To start with, here is the final product running in the emulator and launched from Dashcode.

A list of Thumbnail images built using JSON

A list of Thumbnail images built using JSON

The QuickConnectiPhone source code to accomplish this is very small.  As always we start with the mappings in the mappings.js file for which the code is seen below.  We first map the command pictures to a Business Control Function called loadPictureDataBCF.  This BCF is responsible for making our AJAX call.

mapCommandToBCF(‘pictures’, loadPictureDataBCF);

mapCommandToVCF(‘pictures’, displayPictureDataVCF);

Next we map the pictures command to a View Control Function, displayPictureDataVCF, that is responsible for updating the display based on the data retrieved from the service.  Having completed our mappings for the pictures command we can now create the two control functions.

The loadPictureDataBCF function is created in the functions.js file and makes use of the QuickConnectiPhone AJAX wrapper ServerAccessObject.  This wrapper is designed to make your use of AJAX as simple as possible.

The code below shows a new ServerAccessObject being created.  The constructor is passed the URL of the service without any parameters.

function loadPictureDataBCF(parameters){

var pictureService = new ServerAccessObject(http://search.yahooapis.com/ImageSearchService/V1/imageSearch&#8217;);

pictureService.getData(ServerAccessObject.TEXT, true,‘appid=YahooDemo&query=england&output=json’);


Once pictureService has been created it is now ready for use.  Since we are retrieving data from the server we use the ServerAccessObject’s getData method.  The three parameters are:

  1. The data type being requested (use text when requesting JSON)
  2. A boolean indicating if a forced refresh should be enforced (true means never used cached data)
  3. The query parameters to append to the URL
This code is all that is required to get data from a server or service.  The QuickConnectiPhone framework will handle all of the data passing and ensure that it gets passed to the displayPictureDataVCF View Control Function that was mapped earlier.
The displayPictureDataVCF is responsible for parsing the string into a JavaScript object and then updating the view.  The results parameter is a JavaScript array that contains the results of any and all calls to Business Control Functions.  It is an array because you can have any number of BCF’s mapped to a single command.  The framework executes them all and places each result in this results parameter.
Each result has a data attribute in addition to an error attribute and a few others.  This data attribute contains the JSON string requested in the BCF we saw earlier.  Since this JSON string contains all of the information we want we use the JSON library, included in QuickConnectiPhone, to generate a JavaScript object by calling JSON.parse.

function displayPictureDataVCF(results, parameters){

var dataObject = JSON.parse(results[0].data);

var resultSet = dataObject.ResultSet;

var overViewDisplay = document.getElementById(‘overView’);

overView.innerHTML = ‘Total Results: ‘+resultSet.totalResultsAvailable;

overView.innerHTML += ‘<br/>Results Retrieved: ‘+resultSet.totalResultsReturned+‘<hr/>’;

var allImageDescriptions = resultSet.Result;

var numImageDescriptions = allImageDescriptions.length;

var body = document.getElementsByTagName(‘body’)[0];


for(var i = 0; i < numImageDescriptions; i++){

var anImageDescription = allImageDescriptions[i];

var aDisplay = document.createElement(‘div’);

aDisplay.className = ‘imgDisplay’;


var aThumbnail = document.createElement(‘img’);

aThumbnail.src = anImageDescription.Thumbnail.Url;




Once we have the JavaScript object we iterate over all of the image descriptions, build elements to display the data and add them to the body of the page being displayed.  We are now done.

I hope this helps you see how to do JSON calls to a service using QuickConnectiPHone.

March 5, 2009

Creating Line Graphs on the iPhone

Posted in Uncategorized tagged , , , , , , , , , , at 11:49 pm by tetontech

I have finally been able to complete the line graphs(charts) portion of the Charting and Graphing QuickConnect library and am working on getting a final bug out of the Bar and Pie charts.

I plan on producing a video on how these are used and how to create them in your code but thought that a quick view of what is coming in V 1.5 beta 2 would be of interest.

I have put a few images here for you to see. The first is a line graph showing two separate data series being displayed. If you touch the data points, either directly or by moving your finger over them, the value and description of the point is displayed in the display area of the chart. You can also cycle through the values of a series by using the forward and backward arrows or by moving your finger across the color display bar.

A two series line chart

A two series line chart

The next image is of the same data but drawn as a filled line chart.

A two data series filled line chart

A two data series filled line chart

If you touch any of the data points the series that contains that value is brought to the front as you can see in this next image.

A two series filled line chart showing the second series in front.

A two series filled line chart showing the second series in front.

I have tried to make this as easy to use as I can.  Here is the code to create the filled chart.

var fill = false;

var shadow = true;

lineDisplay.chart = new QCLineChart(document.getElementById(‘lineChartDisplay’), ‘Animals’, shadow, fill);

lineDisplay.chart.addSeries(‘Some Animals’,[[‘cats’,15], [‘hipos’,2], [‘fish’,7], [‘dogs’,4]

, [‘bears’,20], [‘mice’,3], [‘elephants’,7], [‘dogs’,10], [‘kangaroo’,18]]);

lineDisplay.chart.addSeries(‘Other Animals’,[[‘gorillas’,10], [‘snakes’,5], [‘robins’,3],[‘rats’,4], [‘moose’,15], [‘deer’,14], [‘tigers’,0 ], [‘jaguar’,9], [’emu’,9]]);


To change it to a standard non-filled chart just change the fill variable to false.

February 28, 2009

Detecting Device information on the iPhone

Posted in iPhone development tagged , , , , , , , , , , , , at 9:49 pm by tetontech

Detecting the device specific information for the device your application is running on is very easy. The code below shows how this is done in QuickConnectiPhone 1.5 Beta 2 that will soon be released.  It is found in the GetDeviceInfoVCO.m file.

I am gathering the following and putting it in an array so that the data can be passed up to the JavaScript.

  1. The device unique identifier
  2. The name of the device
  3. The localized version of the model of the device (iPhone, iPod Touch)
  4. The system name (iPhone OS)
  5. The system version (2.2.1, etc.)
  6. The language and locale used on the device(en_US)
  7. The short version of the time zone (MST)

UIDevice *aDevice = [UIDevice currentDevice];

NSLocale *currentLocale = [NSLocale currentLocale];

NSTimeZone *timeZone = [NSTimeZone systemTimeZone];

NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];

NSMutableArray *passingArray = [[NSMutableArray alloc] initWithCapacity:5];

[passingArray addObject: [aDevice uniqueIdentifier]];

[passingArray addObject: [aDevice name]];

[passingArray addObject: [aDevice localizedModel]];

[passingArray addObject: [aDevice systemName]];

[passingArray addObject: [aDevice systemVersion]];

[passingArray addObject: [defs objectForKey:@”AppleLocale”]];

NSString *timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortStandard locale:currentLocale];

if([timeZone isDaylightSavingTimeForDate:[NSDate date]]){

timeZoneString = [timeZone localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:currentLocale];


[passingArray addObject: timeZoneString];

The JavaScript to display this information, found in the functions.js file of the DeviceDescriptionExample, is seen here.

function displayDeviceInfoVCF(data, paramArray){

document.getElementById(‘devDisplay’).innerText = ‘UDID: ‘+paramArray[0]+‘\n\ndevice name: ‘+paramArray[1]+‘\n\nmodel: ‘+paramArray[2]

+‘\n\nsystem: ‘+paramArray[3]+‘\n\nOS version: ‘+paramArray[4]+‘\n\nLanguage and Locale: ‘+paramArray[5]+‘\n\nTimeZone: ‘+paramArray[6];


Here is an image of this code running in the DeviceDescriptionExample application incuded in QC 1.5

A display of the information about the device running the application

A display of the information about the device running the application

February 7, 2009

QuickConnectiPhone 1.1.3 now available

Posted in iPhone development tagged , , , , , , , , , , , , , , , , , , , at 11:37 pm by tetontech

QCiPhone version 1.1.3 includes the following changes.

  1. Example applications updated to 1.1.3
  2. apostrophes in the data of native databases now handled correctly.
  3. a stopBounce() function added in the JavaScript.  It stops the UIWebView from bouncing when the interface fits in the view.  Thanks
    to Aarpn for the initial code.  I’ll work on getting it to be more
  4. A Default.png file added so you can replace it with your own.

If you are interested, QCiPhone 1.5 Beta 1 is now available.  The announcement is here

November 29, 2008

QuickConnectiPhone 1.0 RC3 available

Posted in iPhone development, mac development, misc, PHP tagged , , , , , , , , , , , , , , , , , , , , at 7:38 am by tetontech

The latest release candidate, 3, is now available for QuickConnectiPhone a framework that allows you to build your installable iPhone applications in HTML, CSS, and JavaScript. If you want to create an iPhone application but don’t have time to or maybe don’t want to learn Objective-C you can use QuickConnect instead.

This release, like RC 2, includes an installer.

It also includes support for embedding Google maps in your installable JavaScript application. This new functionallity, in addition to the previously added capabilities of GPS location, acceleration, JavaScript debugging in Xcode, device vibration and sound, etc., adds new power to your applications easily. All you need to do is make one JavaScript method call that includes the locations where you want a pin dropped and a description. The framework does the rest and your custom map is displayed.

Database access is just as easy. A wrapper for the SQLite database used natively on the iPhone is included in the framework. It supplies you with two methods, getData and setData, that are easily used to access and modify your data.

AJAX is also supported by a wrapper with getData and setData methods.

In addition, this installer will install QuickConnectMac. You can now quickly port your JavaScript application from your iPhone to a Mac. Most of this porting will consist of changing your HTML and CSS to fit the larger screen.

Also, QuickConnectPHP is included. This is an implementation of the QuickConnect framework in PHP. It allows you to create web applications quickly and easily using the same engineered approach that you use for your iPhone and Mac applications. It includes a MySQL wrapper that supplies both of the getData and setData methods as well.

Next page

<span>%d</span> bloggers like this: