Tuesday, December 4, 2012

"PotLuck": Guess what do you have in your Pot?

Initiated by Namit and myself..It happened to be a successful gathering with around 40 different dishes and guess what I won't be able to categorize them due to their versatility. "PotLuck" I wasn't knowing the meaning of it though being my 2nd PotLuck lunch at DP, but yes it had to be known. It has a great meaning which says "What do you have in your Pot and that depends on your luck..." isn't that interesting?...











When I was pursuing my B.E, I got various chances to organize such things being in a kind of team, but this was the first instance at DP. I enjoyed a lot and ate up to the brim that afternoon. Thanks to everyone who was a part of such a great gathering and the Photo Session was another unforgettable thing :)

Saturday, September 22, 2012

Titanium FTPModule: My First Social step towards Titanium

Finally something new....
A Titanium module to Upload/Download files to/from a FTP Server. Its published on the marketplace.
You can use this module in your Titanium Mobile Application by providing a FTP server with valid credentials for accessing it and Upload/Download files to/from FTP.

For further details you can read the Documentation for the Module on the Marletplace.

Below is the link for the module at the Appcelerator's Marketplace:

https://marketplace.appcelerator.com/apps/3160

I will happy to see some suggestions here as well as reviews on the Marketplace.
Note: This module is for an Android Titanium Application till date.

Tuesday, February 21, 2012

PhoneGap Android Plugin to Extract ZipFile.

Hello Folks,

Its about after 2 months I thought of writing a post. So here is it. I was thinking to extract a .zip file from PhoneGap on android and I ended up implementing a plugin for it.

Include the below .java file with the same package mentioned.

/*
     Author: Vishal Rajpal
     Filename: ExtractZipFilePlugin.java
     Date: 21-02-2012
*/

package com.phonegap.plugin.ExtractZipFile;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.json.JSONArray;
import org.json.JSONException;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

public class ExtractZipFilePlugin extends Plugin {

    @Override
    public PluginResult execute(String arg0, JSONArray args, String arg2) {
        PluginResult.Status status = PluginResult.Status.OK;
        JSONArray result = new JSONArray();
        try {
            String filename = args.getString(0);
            File file = new File(filename);
            String[] dirToSplit=filename.split("/");
            String dirToInsert="";
            for(int i=0;i<dirToSplit.length-1;i++)
            {
                dirToInsert+=dirToSplit[i]+"/";
            }
            BufferedOutputStream dest = null;
            BufferedInputStream is = null;
            ZipEntry entry;
            ZipFile zipfile;
            try {
                zipfile = new ZipFile(file);
                Enumeration e = zipfile.entries();
                while (e.hasMoreElements())
                  {
                      entry = (ZipEntry) e.nextElement();
                      is = new BufferedInputStream(zipfile.getInputStream(entry));
                      int count;
                      byte data[] = new byte[102222];
                      String fileName = dirToInsert + entry.getName();
                      File outFile = new File(fileName);
                      if (entry.isDirectory())
                      {
                          outFile.mkdirs();
                      }
                      else
                      {
                          FileOutputStream fos = new FileOutputStream(outFile);
                          dest = new BufferedOutputStream(fos, 102222);
                          while ((count = is.read(data, 0, 102222)) != -1)
                          {
                              dest.write(data, 0, count);
                          }
                          dest.flush();
                          dest.close();
                          is.close();
                      }
                  }
            } catch (ZipException e1) {
                // TODO Auto-generated catch block
                return new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                return new PluginResult(PluginResult.Status.IO_EXCEPTION);
            }
           
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
        }
        return new PluginResult(status);
    }

}


Include the below .js file in your phonegap project.

/*
     Author: Vishal Rajpal
     Filename: ZipPlugin.js
     Date: 21-02-2012
*/

var ExtractZipFilePlugin=function(){
};

PhoneGap.addConstructor(function()
{
    PhoneGap.addPlugin('ExtractZipFilePlugin', new ZipPlugin());
});

ExtractZipFilePlugin.prototype.extractFile = function(file, successCallback, errorCallback)
{
    alert(file);
    return PhoneGap.exec(successCallback, errorCallback, "ZipPlugin", "extract", [file]);
};



Lastly include this plugin in the plugins.xml of your project.


<plugin name="ZipPlugin" value="com.phonegap.plugin.ExtractZipFile.ExtractZipFilePlugin" />

Usage i.e. .html file

<!--
     Author: Vishal Rajpal
     Filename: index.html
     Date: 21-02-2012
-->

<html>
<head>
<script type="text/javascript" src="phonegap-1.3.0.js"></script>
<script type="text/javascript" src="ZipPlugin.js"></script>

<script type="text/javascript">

document.addEventListener("deviceready",onDeviceReady);

function onDeviceReady()
{
}

function extractFile(fileName)
{
    alert(fileName);
    var ZipClient = new ExtractZipFilePlugin();
    ZipClient.extractFile('sdcard/'+fileName,win,fail,'ExtractZipFilePlugin');
}
function win(status)
{
   alert('Success'+status);
}
 
function fail(error)
{
    alert(error);
}
</script>
</head>
<body>
<input type="button" value="Extract Zip File" onClick="extractFile('SampleDir/AnotherDir/SampleFile.zip');"/>
</body>

</html>

The default location for the file has to be sdcard then it can be as many directories or no directory i.e.
extractFile('SampleFile.zip');

The plugin will work both ways.

Thanks. Any suggestions or comments will be helpful.