Posts

Facebook SDK for android - How to share Session throughout all activities

A problem which I faced when using Facebook SDK for android was in my app login happens through one activity and posting to Facebook happens through another activity. So I had to retrieve the session which is opened in the LoginActitvity. Actually solution was simpler than I thought. To get the session from an another activity you can use the below method. private void getSession() { Session.openActiveSession(this, false, callback); } private Session.StatusCallback callback = new Session.StatusCallback() { public void call(Session session, SessionState state, Exception exception) { if (session.isOpened()) { //Do something } } };

Adding a Foursquare, Google+ like sliding drawer to your android app

Image
Currently Android SDK does not support such a feature. But this kind of designs are very popular between the users. But there are many open source libraries which facilitates sch omplementation. https://github.com/jfeinstein10/SlidingMenu is an open sorce sliding drawer library which is used many poplar android applications. Using this is prettry simple. This video  explains how to integrate with your android project. After the integration is done you can create a sliding drawer like this. Add the following code to onCreate() method of your activity.     menu = new SlidingMenu(this);     menu.setMode(SlidingMenu.LEFT);     menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);     menu.setShadowWidth(5);     menu.setFadeDegree(0.0f);     menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);     menu.setBehindWidth(150); //change width according to your device     menu.setMenu(R.layou...

Create new Java Class files at runtime

When we write programs usual method is to write all the code compile it and run. But when we try to complex things some times we may want to generate a new class and use it at runtime. As an example I wanted to create a class which parse a xml message and create a new Java object from that data. This is used in web server. So that result object varies according to the web service which is deployed. The solution was to inspect the service at deployment time and create a new parser class according to that in the service deployment time. It has to be noted that this parser had to be generated as a .class file and dynamically added to the classpath. So the result was to use a bytecode manupulation library. There are few bytecode manuplulation libraries available as ASM and JavaAssist . I used JavaAssist for this. The reason for using JavaAssist is it is simple to create a new class from the scratch using JavaAssit. When we create new class files using JavaAssit we have to create all t...

How to get the base class of a Array using java reflection.

If we use Java reflection to get the class of a object like String[][] strings; Java reflection will return [[Ljava.lang.String. But sometimes you may want to get the bases class e.g in this case java.lang.String. Following method can be used to do that. If you want to get the bass class of array object a you use this as Class c=getTypeOfArray(a.getClass()); public static Class getTypeOfArray(Class c){ Class cls=null; while(true){ if(c.isArray()){ c=c.getComponentType(); }else{ cls=c; break; } } return cls; }

GSoC 2012 with Apache Photark, A great experience.

Image
Google summer of code is one of the worlds leading opensource development programs. It is held anually by Google inc. Many enthusiastic students participate each year for this. In every year many number of students try to take part of this program. But nearly 1000 students only get selected for this event.  I was lucky to take part in 2012 program for the first time. I took part on GSoC 2012 under Apache Software Foundation for their incubator project Photark . The interesting thing was my initial plan was to participate on another organization which develops a CMS. I also worked with them nearly one month. But then I realized what they are expecting and what I am interested is not matching. So I looked for another organization and found this interesting project. But then there was little time for application closing period.  So I quickly checcout the code base play with it for little time, drafted a proposal and submitted it. Then Mr. Suhothayan Sriskandara...

How to get current time and date using JavaScript.

Getting system date and time using JavaScript is easy. But some steps has to follow to convert it to a readable format. These functions will help you to get rid of the hassle . //returns date in format 01/01/2012 function getCurrentDate() { var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() return (month + "/" + day + "/" + year); } //returns time in format 05:45 AM function getCurrentTime() { var time = ""; var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); if (minutes < 10) { minutes = "0" + minutes; } var h; if (hours > 12) { h = hours - 12; } if (h < 10) { h = '0' + h; } time += (h + ":" + minutes + " "); if (hours > 11) { time += ("PM"); } else { time += ("AM"); } ...

How to build a maven project without tests

When we build a large project using maven it takes a lot of time because of tests  runs. So we can build quickly by disabling the tests. We can do that using the following command. mvn - Dmaven . test . skip = true install