Adding Animation on Dialog

Web Hosting
In this tutorial, I will show you how to add animation in your dialog. See sample below!

Adding enter and exit animations to your DialogFragment's dialog is a three-step process:
  1. define the enter and exit animations;
  2. add your animations to a style;
  3. set the style as your dialog's "window animations".
That's the gist of it. In greater detail, and assuming you want fade in and fade out animations, this is what you need to do.

First, define the animations. Add a fade_in_dialog.xml file to your res/anim folder which has the following xml code...

<?xml version="1.0" encoding="utf-8"?>
<alpha
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:interpolator="@android:anim/accelerate_interpolator"
  android:fromAlpha="0.0"
  android:toAlpha="1.0"
  android:duration="400" />

And a fade_out_dialog.xml file to your res/anim folder which has the following xml code...

<?xml version="1.0" encoding="utf-8"?>
<alpha
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:interpolator="@android:anim/decelerate_interpolator"
  android:fromAlpha="1.0"
  android:toAlpha="0.0"
  android:duration="400" />

Second, add a style to your res/styles.xml file defined as follows:

<style
  name="dialog_animation_fade" >
  <item name="android:windowEnterAnimation">@anim/fade_in_dialog</item>
  <item name="android:windowExitAnimation">@anim/fade_out_dialog</item>
</style>

Third (and final!), add the following code to your DialogFragment.onStart() method:

@Override
public void onStart()
{
  super.onStart();

  // safety check
  if (getDialog() == null)
    return;

  // set the animations to use on showing and hiding the dialog
  getDialog().getWindow().setWindowAnimations(
      R.style.dialog_animation_fade);
  // alternative way of doing it
  //getDialog().getWindow().getAttributes().
  //    windowAnimations = R.style.dialog_animation_fade;

  // ... other stuff you want to do in your onStart() method
}


Web Hosting
Done! Your dialogs should now fade in and fade out when shown and dismissed respectively. That's it!

Android Dialog

Web Hosting
In this tutorial, I will show you how to create a dialogs in android. Here's a sample code below.

Alert Dialog Example

 AlertDialog alertDialog1 = new AlertDialog.Builder(
                    MainActivity.this).create();

            // Setting Dialog Title
            alertDialog1.setTitle("Alert Dialog");

            // Setting Dialog Message
            alertDialog1.setMessage("Welcome to gaudicos.blogspot.com");

            // Setting Icon to Dialog
            alertDialog1.setIcon(R.drawable.ic_launcher);

            // Setting OK Button
            alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to execute after dialog
                    // closed
                    Toast.makeText(getApplicationContext(),
                            "You clicked on OK", Toast.LENGTH_SHORT).show();
                }
            });

            // Showing Alert Message

            alertDialog1.show();

Output: 




Confirm Dialog Example

AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(
      MainActivity.this);
 
// Setting Dialog Title
alertDialog2.setTitle("Confirm Delete...");
 
// Setting Dialog Message
alertDialog2.setMessage("Are you sure you want delete this file?");
 
// Setting Icon to Dialog
alertDialog2.setIcon(R.drawable.ic_launcher);
 
// Setting Positive "Yes" Btn
alertDialog2.setPositiveButton("YES",
       new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
               // Write your code here to execute after dialog
               Toast.makeText(getApplicationContext(),
                       "You clicked on YES", Toast.LENGTH_SHORT)
                       .show();
           }
       });
// Setting Negative "NO" Btn
alertDialog2.setNegativeButton("NO",
       new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
               // Write your code here to execute after dialog
               Toast.makeText(getApplicationContext(),
                       "You clicked on NO", Toast.LENGTH_SHORT)
                       .show();
               dialog.cancel();
           }
       });
 
// Showing Alert Dialog

alertDialog2.show();

Output:






YesNoCancel Dialog Example


// Creating alert Dialog with three Buttons
 
AlertDialog.Builder alertDialog3 = new AlertDialog.Builder(
       MainActivity.this);
 
// Setting Dialog Title
alertDialog3.setTitle("Save File...");
 
// Setting Dialog Message
alertDialog3.setMessage("Do you want to save this file?");
 
// Setting Icon to Dialog
alertDialog3.setIcon(R.drawable.ic_launcher);
 
// Setting Positive Yes Button
alertDialog3.setPositiveButton("YES",
       new DialogInterface.OnClickListener() {
 
           public void onClick(DialogInterface dialog, int which) {
               // User pressed Cancel button. Write Logic Here
               Toast.makeText(getApplicationContext(),
                       "You clicked on YES", Toast.LENGTH_SHORT)
                       .show();
           }
       });
// Setting Positive Yes Btn
alertDialog3.setNeutralButton("NO",
       new DialogInterface.OnClickListener() {
 
           public void onClick(DialogInterface dialog, int which) {
               // User pressed No button. Write Logic Here
               Toast.makeText(getApplicationContext(),
                       "You clicked on NO", Toast.LENGTH_SHORT)
                       .show();
           }
       });
// Setting Positive "Cancel" Btn
alertDialog3.setNegativeButton("Cancel",
       new DialogInterface.OnClickListener() {
 
           public void onClick(DialogInterface dialog, int which) {
               // User pressed Cancel button. Write Logic Here
               Toast.makeText(getApplicationContext(),
                       "You clicked on Cancel", Toast.LENGTH_SHORT)
                       .show();
           }
       });
// Showing Alert Dialog

alertDialog3.show();

Output:




And lastly the Customized Dialog. See code below!

final Dialog dialog = new Dialog(context);

//Getting the screen resolution
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.date);
if((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_LARGE) ==
Configuration.SCREENLAYOUT_SIZE_LARGE){
   dialog.getWindow().setLayout(350, 290);
}else{
}
//end getting the screen resolution
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ml_logo);
//dialog.getWindow().setBackgroundDrawableResource(R.drawable.bg_header);
dialog.setTitle("Select Date From:");

Button btn_datefrom = (Button) dialog.findViewById(R.id.back);
Button btn_cancel = (Button) dialog.findViewById(R.id.cancel);
btn_datefrom.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DatePicker dp_date = (DatePicker) dialog.findViewById(R.id.dp_date);

int   day_from  = dp_date.getDayOfMonth();
int   month_from= dp_date.getMonth()+1;
int   year_from = dp_date.getYear();

String date_from = Integer.toString(month_from)+" "+Integer.toString(day_from)+", "+Integer.toString(year_from);
String cdate_from = Integer.toString(year_from)+Integer.toString(month_from)+Integer.toString(day_from);
SavePreferences("compare_from", cdate_from);
SimpleDateFormat dateFormat = new SimpleDateFormat(
           "MM dd, yyyy");
   Date myDate = null;
  
       try {
myDate = dateFormat.parse(date_from);
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   SimpleDateFormat timeFormat = new SimpleDateFormat("MMM dd, yyyy");
   String fdate_from = timeFormat.format(myDate); 
dialog.dismiss();
SavePreferences("date_from", fdate_from);
et_datefrom.setText(LoadPreferences("date_from", ""));
}
});

btn_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});

dialog.show();


Web Hosting
That's it. Hope this simple tutorial may help you. Happy Coding...

JSON Tutorial II

Web Hosting
In this tutorial, I will show you some example of retrieving data from webservice that return a json format. See output below.


Create a separate class and named it JSONParser.java. See code below!

package com.example.retrieveapi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url) {

// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}
}


Next is in your MainActivity.java. See code below!.

package com.example.retrieveapi;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;



import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MainActivity extends ListActivity {

// url to make request
private static String url = "http://api.androidhive.info/contacts/";
JSONArray contacts = null;
// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";
private Runnable search, returnRes;
private ProgressDialog m_ProgressDialog = null;
ArrayList<HashMap<String, String>> list;

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
   StrictMode.setThreadPolicy(policy);
   
search = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
runOnUiThread(returnRes);
}catch (Exception ex){
        ex.printStackTrace();
}
}
};
Thread thread =  new Thread(null, search, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(this,"Please wait...", "Connecting...", true);
list = new ArrayList<HashMap<String,String>>();
   returnRes = new Runnable() {

@Override
public void run() {
       
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try{
contacts = json.getJSONArray(TAG_CONTACTS);
//Toast.makeText(getApplicationContext(), Integer.toString(contacts.length()), Toast.LENGTH_SHORT).show();
for(int i=0; i <= contacts.length(); i++){
JSONObject c = contacts.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
String email = c.getString(TAG_EMAIL);
String address = c.getString(TAG_ADDRESS);
String gender = c.getString(TAG_GENDER);
JSONObject phone = c.getJSONObject(TAG_PHONE);
String mobile = phone.getString(TAG_PHONE_MOBILE);
String home = phone.getString(TAG_PHONE_HOME);
String office = phone.getString(TAG_PHONE_OFFICE);
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id);
map.put("name", name);
map.put("email", email);
map.put("address", address);
map.put("gender", gender);
map.put("mobile", mobile);
map.put("home", home);
map.put("office", office);
list.add(map);
}
}catch(Exception e){
e.printStackTrace();
}
             
             
       

ListAdapter adapter = new SimpleAdapter(getApplicationContext(), list, R.layout.list_item,
new String[] {TAG_ID, TAG_NAME, TAG_ADDRESS, TAG_EMAIL, TAG_GENDER, TAG_PHONE_HOME, TAG_PHONE_MOBILE, TAG_PHONE_OFFICE },
new int[] {R.id.tv_id, R.id.tv_name, R.id.tv_address, R.id.tv_email, R.id.tv_gender, R.id.tv_hide_home, R.id.tv_hide_mobile, R.id.tv_hide_office}); 
         
ListView lv = getListView();
lv.setAdapter(adapter);
         
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
// TODO Auto-generated method stub
String tv_num1 = ((TextView) view.findViewById(R.id.tv_hide_mobile)).getText().toString();
String tv_num2 = ((TextView) view.findViewById(R.id.tv_hide_home)).getText().toString();
String tv_num3 = ((TextView) view.findViewById(R.id.tv_hide_office)).getText().toString();
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle("Contact");
    alertDialog.setMessage("Mobile: "+tv_num1+"\n"+"Home: "+tv_num2+"\n"+"Office: "+tv_num3);
    alertDialog.setIcon(R.drawable.ic_launcher);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
               // Write your code here to execute after dialog closed
               dialog.dismiss();
               }
       });
 
       // Showing Alert Message
       alertDialog.show();
}
});
       
m_ProgressDialog.dismiss();
}
};
}

}

And I have 3 XML layout here. Just see code below!

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

   <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>

content.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_num1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Mobile" />

    <TextView
        android:id="@+id/tv_num2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tv_num1"
        android:text="Home" />

    <TextView
        android:id="@+id/tv_num3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tv_num2"
        android:layout_below="@+id/tv_num2"
        android:text="Office" />

</RelativeLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <TextView
        android:id="@+id/tv_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="ID" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tv_id"
        android:layout_alignBottom="@+id/tv_id"
        android:layout_alignParentLeft="true"
        android:text="NAME" />

    <TextView
        android:id="@+id/tv_address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tv_name"
        android:layout_below="@+id/tv_name"
        android:text="Address" />

    <TextView
        android:id="@+id/tv_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tv_address"
        android:text="Email" />

    <TextView
        android:id="@+id/tv_gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tv_email"
        android:layout_below="@+id/tv_email"
        android:text="Gender" />

    <TextView
        android:id="@+id/tv_hide_mobile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tv_gender"
        android:layout_alignBottom="@+id/tv_gender"
        android:layout_toRightOf="@+id/tv_address"
        android:visibility="gone"
        android:textSize="5sp"
        android:text="Mobile" />

    <TextView
        android:id="@+id/tv_hide_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tv_hide_mobile"
        android:layout_alignBottom="@+id/tv_hide_mobile"
        android:layout_toRightOf="@+id/tv_hide_mobile"
        android:textSize="5sp"
        android:visibility="gone"
        android:text="Home" />

    <TextView
        android:id="@+id/tv_hide_office"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tv_hide_home"
        android:layout_alignBottom="@+id/tv_hide_home"
        android:layout_toRightOf="@+id/tv_hide_home"
        android:textSize="5sp"
        android:visibility="gone"
        android:text="Office" />

</RelativeLayout>


And lastly in your AndroidManifest.xml. See code below!

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.retrieveapi"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.retrieveapi.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Web Hosting
It is important to declare a user_permission from the internet. And ON your WIFI in running this application. That's it, hope this may help you. Happy coding.!

JSON Tutorial

Web Hosting
In this tutorial, I will show you how to pass and retrieve data on a webservice. Here's the sample code below. Create Activity and named it Sample.java.

package.com.your_package

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

public class Sample {
public final static String ServerIP = "192.168.13.249";
public final static String URL = "http://192.168.13.249/developer/Mobile/1.0/sample/sample.asmx/sample";
 
public Sample() 
{ }

//This part is receiving a data to pass in a web service

private JSONObject sendJsonRequest(String host, int port,String uri, JSONObject param) 
           throws ClientProtocolException, IOException, JSONException
{
   HttpClient httpClient = new DefaultHttpClient();
   HttpHost httpHost = new HttpHost(host, port);   
   HttpPost httpPost = new HttpPost(uri);
         //To make sure that data pass converted to json object.
   httpPost.addHeader("Content-Type", "application/json; charset=utf-8");


if (param != null)
{
   HttpEntity bodyEntity = new StringEntity(param.toString(), "utf8");
   httpPost.setEntity(bodyEntity);
}


HttpResponse response = httpClient.execute(httpHost, httpPost);
HttpEntity entity = response.getEntity();


String result = null;
if (entity != null) {
   InputStream instream = entity.getContent();
   BufferedReader reader = new BufferedReader(
        new InputStreamReader(instream));
   StringBuilder sb = new StringBuilder();


   String line = null;
   while ((line = reader.readLine()) != null)
       sb.append(line + "\n");


   result = sb.toString();
   instream.close();           
}


httpPost.abort();
return result != null ? new JSONObject(result) : null;


}

//Create a json object of your data input because the webservice needs a json object to pass.

public JSONObject Sample(String your_field1  String your_field2  String your_field3  String your_field4  String your_field5, String your_field6, String your_field7) throws Exception {
JSONObject result = null;
try
{
   JSONObject param = new JSONObject();
   param.put("samekey_api1", your_field1);
   param.put("samekey_api2", your_field2);
   param.put("samekey_api3", your_field3);
   param.put("samekey_api4", your_field4);
   param.put("samekey_api5", your_field5);
   param.put("samekey_api6", your_field6);
   param.put("samekey_api7", your_field7);


   result = sendJsonRequest(ServerIP, 80, URL, param);
   /*if (result == null)
   {
      result = "null";
   }*/
}
catch (Exception ex)
{
ex.printStackTrace();
}
return result;

}
}


And in your MainActivity.java. Simple call this code below.

//instantiating the function
SendoutMobile ws = new SendoutMobile();
resp= ws.SendoutMobile(your_field1your_field2  your_field3  your_field4  your_field5  your_field6  text4.getText().toString().replaceAll(",",""));

//to retrieve the data example        
String repscode = resp.getString("respcode");

Web Hosting

Swipe using Gesture

Web Hosting
In this tutorial, I will show you how to swipe left to right vice versa on your layout. For this tutorial I used Gesture Listener, here's the code. Just named it SimpleGestureFilter.java.

SimpleGestureFilter.java

package com.send_money.albert;

import android.app.Activity;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;


public class SimpleGestureFilter extends SimpleOnGestureListener{
    
 public final static int SWIPE_UP    = 1;
 public final static int SWIPE_DOWN  = 2;
 public final static int SWIPE_LEFT  = 3;
 public final static int SWIPE_RIGHT = 4;

 public final static int MODE_TRANSPARENT = 0;
 public final static int MODE_SOLID       = 1;
 public final static int MODE_DYNAMIC     = 2;

 private final static int ACTION_FAKE = -13; //just an unlikely number
 private int swipe_Min_Distance = 100;
 private int swipe_Max_Distance = 350;
 private int swipe_Min_Velocity = 100;

 private int mode      = MODE_DYNAMIC;
 private boolean running = true;
 private boolean tapIndicator = false;

 private Activity context;
 private GestureDetector detector;
 private SimpleGestureListener listener;


 public SimpleGestureFilter(Activity context,SimpleGestureListener sgl) {

  this.context = context;
  this.detector = new GestureDetector(context, this);
  this.listener = sgl; 
 }

 public void onTouchEvent(MotionEvent event){
  
   if(!this.running)
  return;  
  
   boolean result = this.detector.onTouchEvent(event); 
  
   if(this.mode == MODE_SOLID)
    event.setAction(MotionEvent.ACTION_CANCEL);
   else if (this.mode == MODE_DYNAMIC) {
  
     if(event.getAction() == ACTION_FAKE) 
       event.setAction(MotionEvent.ACTION_UP);
     else if (result)
       event.setAction(MotionEvent.ACTION_CANCEL); 
     else if(this.tapIndicator){
      event.setAction(MotionEvent.ACTION_DOWN);
      this.tapIndicator = false;
     }
  
   }
   //else just do nothing, it's Transparent
 }

 public void setMode(int m){
  this.mode = m;
 }

 public int getMode(){
  return this.mode;
 }

 public void setEnabled(boolean status){
  this.running = status;
 }

 public void setSwipeMaxDistance(int distance){
  this.swipe_Max_Distance = distance;
 }

 public void setSwipeMinDistance(int distance){
  this.swipe_Min_Distance = distance;
 }

 public void setSwipeMinVelocity(int distance){
  this.swipe_Min_Velocity = distance;
 }

 public int getSwipeMaxDistance(){
  return this.swipe_Max_Distance;
 }

 public int getSwipeMinDistance(){
  return this.swipe_Min_Distance;
 }

 public int getSwipeMinVelocity(){
  return this.swipe_Min_Velocity;
 }


 @Override
 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
   float velocityY) {

  final float xDistance = Math.abs(e1.getX() - e2.getX());
  final float yDistance = Math.abs(e1.getY() - e2.getY());

  if(xDistance > this.swipe_Max_Distance || yDistance > this.swipe_Max_Distance)
   return false;

  velocityX = Math.abs(velocityX);
  velocityY = Math.abs(velocityY);
        boolean result = false;

  if(velocityX > this.swipe_Min_Velocity && xDistance > this.swipe_Min_Distance){
   if(e1.getX() > e2.getX()) // right to left
    this.listener.onSwipe(SWIPE_LEFT);
   else
    this.listener.onSwipe(SWIPE_RIGHT);
   
   result = true;
  }
  else if(velocityY > this.swipe_Min_Velocity && yDistance > this.swipe_Min_Distance){
   if(e1.getY() > e2.getY()) // bottom to up 
    this.listener.onSwipe(SWIPE_UP);
   else
    this.listener.onSwipe(SWIPE_DOWN);
   
   result = true;
  }

   return result;
 }

 @Override
 public boolean onSingleTapUp(MotionEvent e) {
  this.tapIndicator = true;
  return false;
 }

 @Override
 public boolean onDoubleTap(MotionEvent arg0) {
  this.listener.onDoubleTap();;
  return true;
 }

 @Override
 public boolean onDoubleTapEvent(MotionEvent arg0) {
  return true;
 }

 @Override
 public boolean onSingleTapConfirmed(MotionEvent arg0) {
  
  if(this.mode == MODE_DYNAMIC){        // we owe an ACTION_UP, so we fake an       
     arg0.setAction(ACTION_FAKE);      //action which will be converted to an ACTION_UP later.                                    
     this.context.dispatchTouchEvent(arg0);  
  }   
     
  return false;
 }


    static interface SimpleGestureListener{
     void onSwipe(int direction);
     void onDoubleTap();
 }


}


For me, I apply it on my tabmenu. H
ere's the complete code below. I just named it TabMenuActivity.java

TabMenuActivity.java

package com.send_money.albert;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;

import com.send_money.albert.SimpleGestureFilter.SimpleGestureListener;


@SuppressWarnings("deprecation")
public class TabMenuActivity extends TabActivity implements OnTabChangeListener, SimpleGestureListener {


   private static TabHost tabHost;
   private View currentView;
   private int currentTab;
   
   
private void setupTabHost() {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
}

private SimpleGestureFilter detector;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

detector = new SimpleGestureFilter(this,this);

setupTabHost();
tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

setupTab1(new TextView(this), "Transaction");
setupTab2(new TextView(this), "Charges");



tabHost.setOnTabChangedListener(this);
}

private void setupTab1(final View view, final String tag) {
View tabview1 = createTabView(tabHost.getContext(), tag);
Intent trans = new Intent(this, Send_Money.class);
TabSpec tab1= tabHost.newTabSpec(tag);
tab1.setIndicator(tabview1).setContent(trans);


tabHost.addTab(tab1);


}

private void setupTab2(final View view, final String tag) {
View tabview2 = createTabView(tabHost.getContext(), tag);
Intent rates = new Intent(this, Send_Money_Rates.class);
TabSpec tab2= tabHost.newTabSpec(tag);
tab2.setIndicator(tabview2).setContent(rates);


tabHost.addTab(tab2);

}

private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}



@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
   // TODO Auto-generated method stub
      this.detector.onTouchEvent(ev);
      return super.dispatchTouchEvent(ev);
}


@Override
public void onSwipe(int direction) {
   // TODO Auto-generated method stub

     switch (direction) {

     case SimpleGestureFilter.SWIPE_RIGHT : 
     Send_Money_Menu.tabHost.setCurrentTab(0);   
     break;
     case SimpleGestureFilter.SWIPE_LEFT :  
     Send_Money_Menu.tabHost.setCurrentTab(1);
         break;
     } 

}



@Override
public void onDoubleTap() {
// TODO Auto-generated method stub

}
@Override
   public void onTabChanged(String tabId)
   {
       currentView = tabHost.getCurrentView();
       if (tabHost.getCurrentTab() > currentTab)
       {
        Toast.makeText(getApplicationContext(), Integer.toString(tabHost.getCurrentTab())+ " " + Integer.toString(currentTab), Toast.LENGTH_SHORT).show();

        RelativeLayout rl = (RelativeLayout) currentView.findViewById(R.id.rl_fade1);
        RelativeLayout r2 = (RelativeLayout) currentView.findViewById(R.id.main_info);
    Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.flip_in);
    rl.startAnimation(hyperspaceJump);
    r2.startAnimation(hyperspaceJump);
   
   
       }
       else
       {

        Toast.makeText(getApplicationContext(), Integer.toString(tabHost.getCurrentTab())+ " " + Integer.toString(currentTab), Toast.LENGTH_SHORT).show();
        RelativeLayout rl = (RelativeLayout) currentView.findViewById(R.id.rl_child);
    Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.flip_in);
    rl.startAnimation(hyperspaceJump);
   
       }
       
       currentTab = tabHost.getCurrentTab();
       
      
   
   

   }




   
}



And lastly the layout. Just named it main.xml.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/main1" />
        
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#696969" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#000" />

       <TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />

    </LinearLayout>

</TabHost>

Web Hosting
That's all, hope this tutorial may help you.