Thursday, December 25, 2014

More Is Yet to Come...

Hello Everyone,

Well, It's the end of 3rd semester and I must say this was a hectic one.

So, the most challenging thing I was able to do in this semester was a semester project for one of the subjects as I will describe further.

The project was about comparing audio files and finding a match between them. It wasn't a surprise that it was titled as "Detect Audio Misappropriations". When I first started working on this one I was a bit curious about how an audio file is actually structured from inside except the fact that all data is binary. As I learnt more about different audio file extensions the picture became clear. One thing I liked about this project was the problem statement which was very well structured as it came in bits and pieces every week and I had to dwell in some new concepts. I will try to describe the whole process I followed in the project but one of the concepts I struggled with was Fast Fourier Transform which is a part of Electrical Engineering. I really wish I would have taken some Electrical Engineering classes to form my basics about it. I also feel that I made it tough for myself somehow by writing the algorithm myself. So, this project was a team project and we were suppose to handle 3 file extensions ".wav", ".mp3" & ".ogg".

For any format below was the process:

a) Validate the format by reading its header data (Every format has its header and the header has specific values for each format).
b) If the header was in valid format, the file was converted in a canonical format which apparently was ".wav".
c) Then the audio data of the file was read (samples).
d) 16384 samples were read in each iteration and this was termed as 1 bin of samples.
e) Each sample was processed through Hanning Window and Fast Fourier Transform and a single value was generated for every bin.
f) Further these values were compared for two files to detect a match.

This is actually a brief description of the process and it actually involves some more important concepts which might be too thorough for this post.

While I was working on this project, I also tried to implement one of the great research papers by Haitsma & Kalker (http://ismir2002.ismir.net/proceedings/02-FP04-2.pdf). We were able to implement about 90% of this research paper but we got stuck due to less knowledge about terms such as frequency bands. I would say there is a scope of improvement of what we now have implemented and scope is handling silence in audio.

For now, the developed product takes two directories or files and compares all the files in first directory to all the files in the second directory and reports a match if there is same audio content of more than 5 seconds. Future improvements can be handling silence as I mentioned above.

This process was interesting to come up with and I really thank one of my friends Raymond Li who worked as a great class mate.

Below is the github link to the project:
https://github.com/vishalrajpal/Assignment-7

Please feel free to drop your suggestions. Thanks for reading.

Vishal

Wednesday, August 6, 2014

Heap (Priority Queue) Library

Hello Everyone,

As promised, below is the repository for the Heap Library.

https://github.com/vishalrajpal/Heap

Now the library uses a generic approach and will be more helpful. The repository's README.md file has other helpful information. Feel free to try and implement it. I look forward for your suggestions.

Thanks,
Vishal

Monday, June 23, 2014

Heaps (Max-Min)

Hello Everyone,

Midst the Algorithms class this Summer, we were being taught some efficient Data Structures in terms of handling large Data. One of them was Heaps which is a very interesting one. Our Professor  Zhifeng Sun told us that there are less libraries for Heaps and hence inspired me to right one with almost all the supported operations by Heaps. Though I look forward to improve the library, some applications I found were such as finding a winner among many people and this application can be extended over many other similar applications. With Heaps you can achieve this O(1) time i.e. constant time. It also appeared interesting to me as when working with Multi-Platform mobile applications we generally see that the application takes time to process even 100 records in an array and our aim is to find a single record which satisfies our needs. Heaps can effectively reduce that time from O(n) to O(logn). Though this library for now works only for integers, I am thinking to extend it to <AnyType>. Below is the list of operations supported by the library:

/* Heap Operations
1) DeleteMax/ExtractMax: ------ Running Time: O(logn)
2) Query Max/Min: ------- Running Time: O(1)
3) InsertElement: ----- Running Time: O(logn)
4) Heapify: ----- Running Time: O(logn)
5) Build Heap: ------ Running Time: O(nlogn)
6) Find K Min/Max Elements: ------ Running Time: O(klogn)
*/


The library supports operations for both the Max-Heap and Min-Heap. Below is the github
URL from which you will get a thorough understanding and it can be used as a
plugin/module for PhoneGap & Titanium applications though it might need some additional
work.

https://github.com/vishalrajpal/TestHeap

I look forward for your suggestions on improving it.

Thanks,
Vishal

Saturday, May 31, 2014

PhoneGap 3.x Mobile Application Development Hotshot - Review

Hello folks,

Around 6 months back, I got an opportunity from Packt Publishing to review one of their new books

http://www.packtpub.com/phonegap-3-x-mobile-application-development-hotshot/book

Since, this was the first time for me I was actually not sure about the process and actually was not sure how to review but I think they made me understand the process and I reviewed in the last 6 months.

So, something about the book. It is a great book by author Kerri Shotts and I the book has almost 10-12 practical applications which will really go deep into PhoneGap. They published almost a week before. So if you are interested, a beginner and have some know how of PhoneGap, you can go for it.

Thanks,
Vishal

Monday, April 28, 2014

Student - A Character Revisited

Hello Folks,

First, It feels challenging, sometimes scared and responsible to be a Student again after giving a pause to my work back there in India. While, I am writing this post I got an idea to keep this post as more elaborate with my till-now experience here in Seattle-US.

A great city with a good Spring season (Flowers all around with Sun starring them). So getting back to the title now, It wasn't that easy to incorporate rather recall all those characteristics I had in myself during my student life. I really took some time to go back to past and recall how I took classes, the way I paid attention and the way I dealt with some of the difficult assignments at that time. But this was all in that 1 week before the classes started. Since, I arrived 1 week earlier I got some time to recall them. But after the classes started, its now that I feel I can look around to some other things.

Something about the University: Northeastern University, Seattle is a great to place to study at. India being a country with high traditional values, its not that easy to capitulate those values and just settle quickly at this new land. But, I think the university played a role for me and making me comfortable though slowly and always teaching me lessons on the way. The staff working close with Students (I really think this point is very similar to what APIIT had), good technology infrastructure (I was surprised by the size of the projector in the lecture room, even more when I presented a co-op presentation on it. I will come to what co-op is.... :) ), their hospitality are some good qualities to mention. I think all the reasons I thought had something optimistic in it.

Coming on to the subjects I took:

a) Programming Design Paradigm (PDP)
b) Database Systems (DB)
c) Co-op Seminar (This is what I was talking about above)

I really think that all the three subjects I took in my first semester were really good. PDP of which I will mention some of the assignments we got as examples, DB which sometimes went very deep into the memory calculations we would need to access some data and finally co-op which is about some great behavioral skills to have in you.

Starting with PDP which is a pure programming course based on Scheme programming language had assignments every week. This was no less than 40 hours per week which we generally spend at work.

I know that almost all of you must be familiar of the Pitcher/Jugs problem which is famous being a Google Interview Question. We got an assignment which told us to have some Pitchers and a desired amount and we had to determine the moves in which we could achieve the desired amount. I think this was a great question as I really enjoyed developing it. The whole week, my brain had almost n pitchers with any quantities.



The image above shows an example. Just to explain The solve function takes a list of Pitchers which is one of 8 liters, 5 and 3 respectively and the desired amount is 4 liters. The result is a list of moves where a number is the jug/pitcher number. I would suggest you to try these moves by making an assumption that the first pitcher is initially filled completely and you cannot waste any water, you only have this amount of water. This was the first time I implemented the breadth-first search algorithm which was a good experience.

Another assignment I found interesting was the N-level tree. Try the video below:


So, I press T and a new tree is created, pressing N while a tree is selected creates a new child and d while a tree/child is selected deletes it. I think this was really a good one.

We had almost 10 assignments and its not possible to describe everyone of them here, but these are some good ones.

The Database Systems which also had submissions every week involved concepts such as Indexing, Cost calculation, stored procedures and user-defined functions. I think seeing the course content is what encouraged me to take this subject and it was a good experience.

Some other things I would like to mention is the speed of speaking of native people here in US. It really made me thought when one day, I tried to ask the bus driver if this was the stop I wanted to get down and in spite of asking him 3 times I couldn't grab his answer properly and got down at the stop and more funny thing was that the stop was the wrong one. I think, till the time you try to understand what have they said, its gone. But, I remember the lessons from Asif's Sir class during my under graduation which have helped me a bit. Some picky things such as "(pronunciation of P is Phee not Peee") I hope I am still write.

The next semester is about to begin and the vacation is like it never started. I think gone are the days when during the vacation, I would be at home enjoying the best food in the world. I must say food is one thing I miss almost every time.
I hope you enjoyed reading the post though and as always feel free to give any suggestions on the things mentioned in the post.

Thanks,
Vishal

Monday, January 21, 2013

PhoneGap 2.3.0 Plugin to Extract .zip file

Hi All,

You must be familiar with the PhoneGap plugin to Extract .zip files. As there are some changes for plugin development in version 2.3.0, I have created a new repo for 2.3.0 and the plugin seems to be working after some changes. Below is the repo URL:

https://github.com/vishalrajpal/PhoneGap-ZipFile-Plugin-2.3.0

Thanks,

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.

Friday, December 9, 2011

PhoneGap and Gigya API Implementation

I was stuck regarding facebook implementation through PhoneGap. Though Phonagap provides a plug-in but you need to have facebook application installed on your device and that created a question for me. So here is it with the implementation of childBrowser PhoneGap plugin and the GIGYA API.
Initial Steps
1. Do have a registered Gigya account. you will get a API KEY and the site which you are adding needs to be a valid server as you will be hosting a small html page.
2. Create a new phonegap project.
3. Implement the childBrowser Plug-I. This post helped me as I was implementing it for the first time
http://simonmacdonald.blogspot.com/2011/09/phonegap-android-childbrowser-revamp.html

4.  Here is the code....

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Child Browser Example</title>
    <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
    <script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
    <script type="text/javascript" charset="utf-8" src="childbrowser.js"></script>
    <script src="jquery-1.4.3.min.js"></script>
    <script src="jquery.min.js"></script>
    <script src="jquery.mobile-1.0a1.min.js"></script>
    <script type="text/javascript" charset="utf-8">


    function init(){
        document.addEventListener("deviceready", onDeviceReady, false);
        gigya.services.socialize.addEventHandlers({}, {  
            onLogin:DisplayEventMessage, 
            onConnectionAdded:DisplayEventMessage, 
            onConnectionRemoved:DisplayEventMessage 
           } 
        ); 
    }
    
    function DisplayEventMessage(eventObj) { 
        alert(eventObj.eventName + " event happened"); 
    } 
   
    function onDeviceReady() {
        alert("PhoneGap is ready");
    }
   
    function locationChanged(newurl)
    {
        //alert("The JS got this url = " + newurl);
        console.log(newurl);
       var access=newurl.split("#");
       var token=access[1].split("=");
       //alert(token[0]);
       if(token[0]=="access_token")
       {
//Status URL...Through which status on facebook will be set
var statusurl="https://socialize.gigya.com/socialize.setStatus?status=welcome&oauth_token="+token[1];
            //window.open(statusurl);
            localStorage.accessToken=token[1];
            window.plugins.childBrowser.close();
            window.location="Messages.html";
            console.log(statusurl);
       }
    }
   
    function openNew(statusurl)
    {
        alert(statusurl);
         window.plugins.childBrowser.openExternal(statusurl);
    }
    function closed() {
        alert("The JS got a close event");
    }
   
    function showPage(locbar) {
        window.plugins.childBrowser.onLocationChange = locationChanged;
        window.plugins.childBrowser.onClose = closed;
        var url="https://socialize.gigya.com/socialize.login?client_id=yourGigyaAPIKEY&redirect_uri=http:yourSite/yourPage.html&x_provider=facebook&response_type=token";
        showBrowser(url,locbar);
    }
   
    function showBrowser(url,locbar)
    {
        window.plugins.childBrowser.showWebPage(url, {showLocationBar: locbar});
       
    }
    </script>
  </head>
  <body onload="init()" id="stage" class="theme">
    <a href="#" class="btn large" onclick="showPage(true); return false;">Login to Facebook</a></p>


  </body>
</html>

So, thats it.. you don't need to have a facebook app installed on your device..
Will come up with more things on this.
Any suggestions gracefully accepted....




Thursday, July 21, 2011

PhoneGap

It has been a long time......and a month and half after leaving APIIT....
This post is regarding the recent and still growing technology i.e. 
PhoneGap


Basically again a mobile technology but not specifically for a 
particular mobile OS. Open source, simple and easy to use..
Approx all the native features of any smartphone are accessible..
currently it is serving 6 mobile OS including Nokia, iPhone, 
Android, Blackberry...


The technology basically uses the features of HTML5, Javascript and CSS3...
HTML5 has some awesome features to go through...
APIITians you have a nice oppurtunity around....




Good Luck



Saturday, May 28, 2011

Android-"Tic-Roid": A post worth my life..

I had thought of writing this post after the application will be fully developed.though its not completed yet....Hence I owe my thanks to the precious suggestions and efforts by anyone for the development of this application....I will try to include all the people whom I would like to thank in this post..n I hope I don't miss anyone..

The most thankful my parents....My father knew I needed an Android device..and hence he gifted me one on his Birthday 6/04/2011...There are many instances. I have only mentioned the recent one..

1) Next my room-ies....ahh.. Shoaib Ahmed (Bauna) & Akshat Goyal (akki)....Shoaib mark my words...either you will be hired as a tester one day..or I will be hiring you for the same purpose...The moment I made some changes I used to let shoaib use the application ...and in a small duration of 5 minutes he had some faults which he told me to remove...you made my app efficient brother.. :)

Akshat Goyal..No one except u nd shoaib can bear me in hard situations.... without you today's assignment was nothing....thanx fr everything ... :)

2) Naveen Malik: We have worked tgether at many instances...but the most I will remember is the midpoint one....u really helped me...and I knw u will get a job near by Delhi..."fir Army Canteen mein khana khana beithke" :)

3) Tushar Sahni: "zero kaante mein level kaise banayega" these lines on the first day my topic was accepted inspired me to make the levels more tougher...

4) Jagrat Singh: You are also the lucky one amongst us......you have a bright future...stay as you are.. :)

5) Anish Nikhil & Ankit Ojha (Baba): @Anish sale nigro would have thought abt my suggestion starting mein..situation would have been different..neways still everything is fine..I knw u will manage it..
 @Baba..The day u came to my rum nd said..."1 android ka program run karne mein 2 din lag gaya bc"..That was the day I started learning android..thanx fr that

6)Mohit Awasthi: The day you came to my room...the day went cool...thats it....thanx fr that..

7) Manoj Chauhan & Santosh Kumar : I knw WE three together can do many things..but what I feel is that over confodence beats us smetimes.......else Constructors will shine some day...just remember what we had thought in the recent talks...

8) Narendra Anand: Try to be happy...sale jo hota hai na sahi k liye hota hai..."panauti" fat kam karle thoda...
    Arvind Mahto (Bundu): I will always remember you as you came nd met me on the very frst day in the    
    college

9)  Sandeep Gupta, Rohit Mishra, Saurav Shekhar, Sreejith M.V, Puneet Akhouri: Thanx fr showing trust in me.....@Sandeep..I will always remember those lines you said when I was trying that Bluetooth one// "are try karta reh ho jayega...".....The words inspired me that day...nd will inspire me in future....@ Rohit Mishra use your truthfulness as a weapon...u will go far...@Saurav...finally everything normal brother...I hope I met your expectations..@Sreejith: I knw u were ryt in the recent thing..I would suggest to concenterate on other things which would be beneficial enough to u nd your career...@Puneet...this is the third time I am saying this...I m sorry I could not meet your expectations at IBM ...but one day I will....

10) Sir Aagrah Mandloi: Simply thanks for teaching me...Sir..

11) Seema Sharma: I didn't wanted the way it is going on.....yup I manipulate things smetimes...bt nt to harm you..and this is what u gotta understand...neways its all upto you...gud luck..

12) Milky Jain: "Tu taunt bahut maarti hai"  :) I think thats enough..hpe u understand.

13) Shweta Roy: "kisike haath na aayegi ye ladki.." n sahi mein aisa hi hai..1 hi hai abhi to..

14) Simanta Chakrabarty, Nitesh Choyal, Nandan Dutta, Manish Malviya, Bhupendra Singh, Sajal Garg, Sonal Saket, Amit kumar, Rajeev and the whole CMT branch....will miss you all....




Wednesday, March 2, 2011

Android: Capture the best moments

I was expecting to write a new post on lambu's birthday...but it didn't happened..So here is another android application through which you can capture an image an view it as and when you capture it as a thumbnail....

My Activity

package com.apiit.TryCamera;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class TryCamera extends Activity implements SurfaceHolder.Callback{
private Camera camera;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SurfaceView surface=(SurfaceView)findViewById(R.id.surface);
final SurfaceHolder holder=surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(150, 150);
Button tke=(Button)findViewById(R.id.take_btn);
tke.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
takePicture();
}

});
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {

try{
camera = camera.open();
camera.setPreviewDisplay(holder);
camera.startPreview();
}
catch(IOException e)
{

}
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
}

private void takePicture(){
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
// TODO Do something when the shutter closes.
}
};
PictureCallback rawCallback = new PictureCallback() {

public void onPictureTaken(byte[] data, Camera camera) {
// TODO Do something with the image RAW data.

}
};
PictureCallback jpegCallback = new PictureCallback() {

public void onPictureTaken(byte[] data, Camera camera) {
// Save the image JPEG data to the SD card
FileOutputStream outStream=null;

FileInputStream fstream = null;
Bitmap bmp;
try {
File root=Environment.getExternalStorageDirectory();
File jpgfile=new File(root,"vinsol.jpg");
outStream=new FileOutputStream(jpgfile);
outStream.write(data);
outStream.flush();
outStream.close();
fstream = new FileInputStream(Environment.getExternalStorageDirectory() + "/" + "vinsol.jpg");
bmp = BitmapFactory.decodeStream(fstream);
ImageView iv=(ImageView)findViewById(R.id.image);
iv.setImageBitmap(bmp);

} catch (FileNotFoundException e) {
Log.d("CAMERAIO", e.getMessage());
} catch (IOException e) {
Log.d("CAMERAIO", e.getMessage());
}
camera.startPreview();
}
};
}





Layout


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="300dip"
android:id="@+id/surface"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:layout_width="70dip"
android:layout_height="wrap_content"
android:text="Take Picture"
android:id="@+id/take_btn"/>
<ImageView
android:layout_marginTop="10dip"
android:layout_marginLeft="-5dip"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:id="@+id/image"/>

</LinearLayout>
</LinearLayout>





Important Points

You must be able to see a <SurfaceView> tag in my layout..
When you need to update the content of the view rapidly you need to use the SurfaceView..
as is the case of the camera (Updated frequently)

                                                                     A) Initial Screen

B) Captured Image Thumbnail


As I could not run the application on a device...the screenshot is not showing the proper preview...


Enjoy...Suggestions required.. 
 




Friday, February 18, 2011

A Tribute!!!

Paying a tribute to Pratik Dehane (B.M.S). You are in our hearts brother and we miss you often.
I still remember the charm and sharpness you had but GOD had some different plans for you..
Miss you always brother


Thursday, February 17, 2011

Android Animation

Hello Fellows!!!
First of all, as per the previous post I will be showing the way I did all that stuff.

Note: You must have android-sdk installed and it should be updated and run successfully in eclipse.
          Google and even I prefer eclipse GYNAMEDE to develop Android Applications

In eclipse New--->Android Project--->Name your project with a proper package name.
Now you will be having a activity class generated just copy and the paste the code mentioned below:

My Activity

public class DeveloperAnimate extends Activity {
    /** Called when the activity is first created. */
View me,me1,me2,me3=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        me=(View)findViewById(R.id.View01);
        me1=(View)findViewById(R.id.View02);
        me2=(View)findViewById(R.id.View03);
        me3=(View)findViewById(R.id.View04);
        Animation a = AnimationUtils.loadAnimation(this, R.anim.try1);
a.reset();
Animation b=AnimationUtils.loadAnimation(this, R.anim.try2);
b.reset();
Animation c=AnimationUtils.loadAnimation(this, R.anim.try3);
c.reset();
Animation d=AnimationUtils.loadAnimation(this, R.anim.try4);
d.reset();
me=(View)findViewById(R.id.View01);
   me1=(View)findViewById(R.id.View02);
   me2=(View)findViewById(R.id.View03);
   me3=(View)findViewById(R.id.View04);
   me.clearAnimation();
   me1.clearAnimation();
   me2.clearAnimation();
   me3.clearAnimation();
   me.startAnimation(a);
   me1.startAnimation(b);
   me2.startAnimation(c);
   me3.startAnimation(d);
   final int display=6000;
   Thread splash=new Thread()
   {
      int wait=0;
      public void run()
      {
      try{
      super.run();
      while(wait<display)
      {
      sleep(100);
      wait+=100;
      }
        }catch(Exception e)
        {
       
        }finally
        {
        startActivity(new Intent(DeveloperAnimate.this,MenuScreen.class));
        finish();
        }
        }
       
       };
       splash.start();
   
      }



Now the layout i.e. main.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<ImageView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/image"
android:src="@drawable/tryfinal"
    />
</LinearLayout>   




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<View 
android:id="@+id/View02" 
android:layout_width="2dip"     
android:layout_height="400dip" 
android:background="#2B497B"
android:visibility="invisible"
android:paddingLeft="250dip"
android:layout_marginLeft="230dip">
  </View>
</LinearLayout>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<View 
android:id="@+id/View01" 
android:layout_width="2dip"     
android:layout_height="325dip" 
android:visibility="invisible"
android:background="#2B497B"
android:paddingLeft="50dip"
android:layout_marginLeft="85dip">
  </View>
 </LinearLayout>


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<View 
android:id="@+id/View03" 
android:layout_width="300dip"     
android:layout_height="3dip" 
android:visibility="invisible"
android:background="#2B497B"
android:paddingLeft="50dip"
android:layout_marginTop="90dip">
  </View>
 </LinearLayout>


  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<View 
android:id="@+id/View04" 
android:layout_width="300dip"     
android:layout_height="3dip" 
android:visibility="invisible"
android:background="#2B497B"
android:paddingLeft="50dip"
android:layout_marginTop="195dip"
>
  </View>
 </LinearLayout>
</FrameLayout>


Now the animation files i.e. try1.xml,try2.xml,try3.xml,try4.xml i.e. 4 lines which I have animated I will be posting one of them because others are quite similar.
Note: These are the animation files. Therefore there is a different way of creating the animation XML
New-->Android XML-->select Animation from the appeared dialog box 



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/accelerate_interpolator">
 <translate 
    android:fromXDelta="-600" 
    android:toXDelta="50" 
    android:duration="900" />
       <alpha    
xmlns:android="http://schemas.android.com/apk/res/android"    
android:fromAlpha="1.0"    
android:toAlpha="0.0"    
android:duration="3000" /> 
</set>


Define the Animation i.e. four files and run the project you will see the result.
Again need suggestions guys....