Fling Gesture in Android

By | April 12, 2012

On implementing the onGestureListener you can get the events like Fling LongPress Scroll ShowPress SingleTap Its really simple, otherwise we have to calculate the distance between the touchdown and touchup event to check a fling event is happened or not. [java] import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.GestureDetector.OnGestureListener; import… Read More »

Java check memory Allocation

By | April 7, 2012

[java] class test { public static void main(String args[]) { Runtime r = Runtime.getRuntime(); long mem1, mem2; Integer someints[] = new Integer[1000]; System.out.println("Total memory is: " +r.totalMemory()); mem1 = r.freeMemory(); System.out.println("Initial free memory: " + mem1); r.gc(); mem1 = r.freeMemory(); System.out.println("Free memory after garbage collection: "+ mem1); for(int i=0; i<1000; i++) someints[i] = new Integer(i); // allocate integers… Read More »

How to take screenshot of application and store it in SDCARD?

By | October 26, 2011

The first part is explained in this Tutorial, that is taking the screenshot of the application (View). The second part is storing it in the SDCARD. This is possible by compressing the image bitmap to bytes and then store. [java] ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 40, bytes); File f = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg"); try… Read More »

How to listen to the softkeyboard done button in android?

By | July 13, 2011

Instead of using a button on the view we can use the softkeyboard done button to trigger an action. The action can include calling another activity or retrieving the data from the EditText etc. The main.xml contains an Edittext [xml] <?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="match_parent" android:singleLine="true" android:inputType="textNoSuggestions"… Read More »

Merge two layout xml in android

By | June 26, 2011

Merging layout is an excellent feature in android. Separate xml can be included in a single xml. For this first i create a main.xml file [xml] <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="Account" android:id="@+id/account" android:layout_below="@+id/title" android:padding="10dip" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TextView> <EditText android:id="@+id/youtube_feed_TF" android:hint="Username" android:layout_marginLeft="10dip" android:inputType="textEmailAddress" android:layout_below="@+id/account" android:layout_centerHorizontal="true" android:layout_width="fill_parent" android:padding="10dip" android:layout_height="wrap_content" ></EditText> <include layout="@layout/footer2button"/> </RelativeLayout> [/xml] In the bottom… Read More »

C++ program to add two complex nos.

By | June 18, 2011

The program contains a class complex with two member variables x and y and a string class with one member variable. Two objects are created for complex class and string class and accepted values through read () function and their values are added using the operator overloaded function and assigned to the third object for each class. Values… Read More »

C++ program append the two text files

By | June 18, 2011

Three file objects are created using the fstream class one for first, second for second file and third for the appended file. The first two files are opened in the input mode and third in the append mode. The first file is opened and checked for error condition if the file exist its contents are written to the… Read More »

C++ program to copy the contents of a text file to another

By | June 18, 2011

Two file objects are created using the fstream class for the two files, one for source file and another destination file. The first file is opened and its contents are copied to the second file using get ( ) and put ( ) function. Each time the source file is opened error checking is done to ensure that… Read More »

Applet FlowLayout Example

By | May 16, 2011

The FlowLayout class puts components in a row, sized at their preferred size. Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps. The hgap and vgap arguments specify the number of pixels to put between components. [java] import java.applet.*; import java.awt.*; /* <applet code="FlowLayoutApplet" width=300 height=200> </applet> */ public class… Read More »

Listening incoming sms message in Android

By | May 1, 2011

When a new sms message is received by the device, a Broadcast Receiver is registered. For this IntentFilter filter = new IntentFilter(SMS_RECEIVED); registerReceiver(receiver_SMS, filter); should be included . Also sms are sent in PDU’s(Protocol Description Units) format, which act as an encapsulation. Inorder to extract from PDU to byte array messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); method is used. When… Read More »

Android: Conversion to Dalvik format failed: Unable to execute dex: null

By | April 28, 2011

This error often comes when your android project size is large. Try the following steps to remove the error 1. Clean the project Project > Clean 2. Increase the memory allocated in eclipse.ini Open the eclipse.ini file in the the Eclipse folder. Then edit -Xms128m to -Xmx512m or something higher Hope this help you

Android frame Animation

By | April 23, 2011

A series of frames is drawn one after the other at regular intervals. For this create a xml which contains ImageView for showing the animation [xml] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="#FFFFFF" android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/Image" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:background="@drawable/d1" android:layout_height="wrap_content"/> <Button android:id="@+id/startFAButtonId" android:layout_width="wrap_content" android:layout_gravity="center_horizontal" android:layout_height="wrap_content" android:text="Start Animation" /> </LinearLayout> [/xml] The main java file is… Read More »

Android dialog with ListView

By | April 21, 2011

For implementing a ListView, we first create a xml which contains a ListView named list.xml [xml] <?xml version="1.0" encoding="utf-8"?> <LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <ListView     android:id="@+id/listview"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     /> </LinearLayout> [/xml] Next we create a Dialog Object and inflate the above xml and when the listItem is… Read More »

Applying a shape to xml in android

By | April 15, 2011

By adding a custom shape we can make the layout more attractive. For this we have to create a xml file and specify this in the main layout xml file First make a xml inside the drawable folder. [xml] <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#F2F2F2"/> <stroke android:width="1dp" android:color="#000000" /> <corners android:radius="5dp" /> </shape> [/xml] Then in the main file specify… Read More »