Shortlink

Loading PhoneGap library for different devices

Maintaining single codebase while building native mobile applications is one of the reasons for using PhoneGap. PhoneGap provides a separate JavaScript library for different devices. Based on the device you have to load the appropriate PhoneGap JS files.
Say, your application is targeting the Android, iPhone and Blackberry platforms, you can have the PhoneGap JS file (phonegap-versionNumber.js in the earlier versions and cordova-versionNumber.js in the current version) provided for each of these platforms renamed to
phoneGap-android.js, phoneGap-iphone.js, phonegap-blackberry.js (or)
cordova-android.js, cordova-iphone.js, cordova-blackberry.js

Based on the device that is accessing the application one of these three files can be loaded like shown below.

var userAgent = navigator.userAgent.toLowerCase();

if (userAgent.match(/android/)) {
        document.write("<script src='phonegap-android.js'></script>");
    } 
    else if (userAgent.match(/iphone/)){
        document.write("<script src='phonegap-iphone.js'></script>");
    }
    else if (userAgent.match(/blackberry/)){{
        document.write("<script src='phonegap-blackberry.js'></script>"); 
    }
Shortlink

Video lectures on Sencha Touch 2.0

You can view few introductory video sessions on Sencha Touch 2.0. You can find the videos in DuraSoft site as well.

The plan is to upload atleast 2 videos per week.

Shortlink

Update on video sessions in Sencha Touch 2.0

My work on creating video sessions in Sencha Touch 2.0 is progressing at a good speed. Thanks to the increasing number of inquiries regarding this, which is keeping me on my toes. Looks like it’ll take couple of more days before uploading a sizeable number of videos in this topic.

Shortlink

Global variables in JavaScript

It’s normal to get caught in the web of global variables, while working with JavaScript. Global variables tend to make the code less readable and maintainable. Douglas Crockford suggests a pattern that can be used to maintain global variables in our code.

Let’s say you have the following code.

var userName = "";
var password = "";
var userType = "";

function loadCredentialsFromLocalStorage(){
 userName = localStorage.getItem("userName");
 password = localStorage.getItem("password");
 userType = localStorage.getItem("userType");
}

The global variables userName, password and userType variables can be written as:

var AGLOBALNAMESPACENAME = {}; 
AGLOBALNAMESPACENAME.user = {
               userName : "", 
               password : "", 
               userType : ""
           }; 

function loadCredentialsFromLocalStorage(){
 AGLOBALNAMESPACENAME.user.userName = localStorage.getItem("userName");
 AGLOBALNAMESPACENAME.user.password = localStorage.getItem("password");
 AGLOBALNAMESPACENAME.user.userType = localStorage.getItem("userType");
}

In the code above, you can create a variable giving it a Global namespace name and have all the ‘actual’ global variables assigned to it. The declaration of the global variables can be moved to a separate file as well. Hence the code becomes lot more readable and easy to maintain.

Shortlink

Video sessions on Sencha Touch 2.0

Starting from next week you can view a 10-15 mins(upper limit) video sessions on working with Sencha Touch 2.0 library. The sessions will be hosted on YouTube and will be made accessible from this blog and DuraSoft site. The video sessions will be simple, short and concise.

The objective is to make you comfortable developing mobile web applications using Sencha Touch 2.0.

Let’s crack some real code!!!