Tuesday, November 26, 2013

Jquery Mobile Pinch Zoom Image with Fixed Headers

Recently I came across the requirement to build a mobile app with image zooming capabilities. It needed to be something similar to what Twitter uses for displaying tweeted images. Twitter of course codes it using native iOS and Android APIs. My requirement was to do the same thing using jquery mobile so it would be easily cross platform. Lucky for me I came across an open source JQM plugin that allows for pinch zoom of images. With a few tweaks I managed to get this working with JQM. I load the image content dynamically in the 'pageshow' event so that the image content can be altered as required for the page.

Library for pinch zoom (uses html canvas)


Modified version with fixed headers for JQM


Modify image and canvas parameters as required to suit your application requirement..

Tuesday, June 11, 2013

Push Notifications in iOS Using Cordova + Java APNS

Below is an overview on implementing push notifications in a cordova (phonegap) ios application..

1. Setup the required provisioning profile for developing push notifications in member center of apple developer site.

2. Setup your Cordova iOS application

- Download the latest version of cordova from http://cordova.apache.org/#download (the version I used was 2.8).
- Unzip the downloaded cordova folder and follow the instructions in the README file of the cordova-ios folder to setup a cordova ios project. Be sure to set the project bundle id to be the same as the one you gave for the provisioning profile setup for push notifications.

3. Create a iOS plugin for enabling push notifications in cordova ( currently this functionality isn't built in to cordova)

Follow the tutorial http://cordova.apache.org/docs/en/edge/guide_plugin-development_index.md.html#Plugin%20Development%20Guide , to create an ios plugin. In the objective c plugin class, call the registration method for push notifications.

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];

4. Setup the required methods in AppDelegate to handle the incoming notifications. See http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

5. Create the push notification java server and invoke push notifications from it. I used java-apns library and followed this tutorial : http://developement.sebastian-bothe.de/?page_id=40.

Now you will have a complete setup for push notifications in iOS. Creating your own cordova plugin, instead of using an existing plugin gives you more control on how the push notifications will work in the app. Coming from an iOS development background, rather than a web development background, I found building my own objective c plugin to be easier and more flexible.

Tuesday, February 26, 2013

Solving problems using GA in Matlab

This was an assignment in the 1st semester of my MSc. in AI, at University of Moratuwa for the subject 'Evolutionary Computing'.

Given below are some example problems and how I solved them using the GA Optimization toolkit in Matlab 2012Rb.

Problem 1 : solving simultaneous equations

2x+y = 8
x+y = 6

Select 'Double Vector' for the population. Set 'Number of variables' as 2. Set 'Integer variable indices' as [1,2]. Use the correct fitness function and run the GA using the rest of the default values.

The fitness function I used is given below..

function fitness = optimization(params)
fitness1 = 8 - 2* params(1) - params(2);
fitness2 = 6 - params(1) - params(2);
if(fitness1 < 0 )
    fitness1 = -fitness1;
if(fitness2 < 0 )
    fitness2 = -fitness2;
fitness = fitness1 + fitness2;

You can change the default values and observe how the output value changes..

Problem 2 : solving a profit optimization problem

Suppose a fruit seller has 5 different kinds of fruits to sell. They are, mango(m), banana(b), strawberry(s), peach(p), orange(o). Suppose the profit from selling each fruit is as follows, mango - 30,banana - 15, strawberry - 50, peach - 20, orange - 10. If the fruit seller wants to make a profit of 10,000 how many fruits of each type should he sell?

Select Double Vector for the population. Since there are 5 types of fruits. You need a chromosome with 5 genes. Set 'Number of variables' as 5. You should specify that the minimum value for each variable is 0 by giving the lower bound as the vector [0,0,0,0,0]. You should also specify that the variables can only take integer values by giving the 'Integer variable indices' as [1,2,3,4,5]. Next you must specify the fitness function.

The fitness function I used is given below:

function fitness = fruits(params)
m = params(1);
b = params(2);
s = params(3);
p = params(4);
o = params(5);
fitness = 10000 - m*30-b*15-s*50-p*20-o*10;
if (fitness < 0)
    fitness = -1*fitness;

After setting these values you can simply run the GA with the rest of the default values. The output I got was,
m = 26, b = 230, s= 19, p = 95, o = 292 which gives a profit of exactly 10,000.

The corresponding graphs are give below..

You can change the default values and observe how the output value changes..

Thursday, January 17, 2013

Monitor HTTP/HTTPS connections on iOS/Android device

This post is basically a guide on how to setup your pc as a proxy to monitor HTTP/HTTPS traffic on an iOS/Android device.

Step 1: Download and install Charles on your pc


You can try the 30 day free trail..

Step 2 :

Check the ip on your pc. Set this as the proxy on your phone, in network settings. Make sure the port is set to 8888 (this is the posrt Charles listens on).

Optional : If you are listening to HTTPS traffic on your phone you need to install the charles certificate on your phone.

see http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/

Step 3 :

Now you can start a recording session in Charles and monitor the web traffic on your phone:) This is an easy way to monitor web traffic from mobile applications.


Since Charles is trial software, I recently switched to using Fiddler2 (Fiddler Web Debugger (v4.4.5.3)).

Setup is similar to Charles but in the case of Fiddler you need to explicitly set permissions in Fiddler allowing remote devices to connect..

Tools -> Fiddler Options -> Connections Tab -> check Allow remote computers to connect :)

Monday, January 14, 2013

Distributed Computing for Artificial Intelligence

I am just completing the 1st semester of studies in the MSc. in Artificial Intelligence offered by the University of Moratuwa. During our first semester we followed a course on Distributed Computing for Artificial Intelligence. The course was lectured by Dr. Janaka Wijayanayake. It was a very interesting course especially since it was very relevant to my current field of work in mobile applications development. Below I am sharing some of the work we did for the subject..

Enhanced by Zemanta