Monday 28 January 2013

Start with Phonegap Application In Android

Phonegap Application In ANDROID

Start With Phonegap in ANDROID:

       

Minimum Requirements 

 

       Identical to Android Minimum Requirements

 Supported Android Devices

  1.     Android 2.1
  2.     Android 2.2
  3.     Android 2.3
  4.     Android 3.x
  5.     Android 4.x

Setup New Project:


From file menu click android project
Add name and click finish


  Thus the new project will be created ,

 

  Next You have add Cordova (Phonegap) jar file in your application.

 

  From this link you can download updated jar file Cordova(PhoneGap).jar

 

  Downlaod and add to your project:

 

  Right click on your project go to Build Path  >>> Configure build path >>

 

Add external jar click add add your jar file



 Simple project:





 

Add xml file in your res folder:

Cordova.xml & Plugins.xml
You will get the xml file along with downloaded jar file

Now Main _Activity



import org.apache.cordova.DroidGap;

import android.os.Bundle;

public class MainActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("http://seasonofrejoice.blogspot.in/");
    }
}

OR

import org.apache.cordova.DroidGap;

import android.os.Bundle;

public class MainActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
    }
}

You can go for WebView Also:


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
       
        WebView mainWebView = (WebView) findViewById(R.id.webView1);
       
        WebSettings webSettings = mainWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
       
        mainWebView.setWebViewClient(new MyCustomWebViewClient());
        mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
       
        mainWebView.loadUrl("file:///android_asset/www/index.html");
       

    }
   
    private class MyCustomWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}


For Webview XML file




  <WebView
        android:id="@+id/webView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     
    />

Manifest File:

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidphonegap"
    android:versionCode="1"
    android:versionName="1.0" >
     <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
   <uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.VIBRATE" />
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />  
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
        <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.androidphonegap.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>




 For More And More information you can go for this below link:






Wednesday 23 January 2013

TabLayout Example in Android

Android Tab-layout:



Android TabLayout


XML Code:


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

<RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@drawable/trans">

<TabWidget
 android:id="@android:id/tabs"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/signup"
 android:layout_alignParentBottom="true" />

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs" >
           
<LinearLayout
 android:id="@+id/first"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
</LinearLayout>

<LinearLayout
 android:id="@+id/second"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
</LinearLayout>

<LinearLayout
 android:id="@+id/third"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
</LinearLayout>

</FrameLayout>
</RelativeLayout>
</TabHost>

JAVA Code


import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Tabactivity extends Activity {

TabHost tabHost;
TabSpec firstTab,secondTab,thirdTab;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabactivity);     

tabHost = (TabHost)findViewById(R.id.tabhost);

tabHost.setup();

 firstTab = tabHost.newTabSpec("First");
 secondTab = tabHost.newTabSpec("Second");
 thirdTab = tabHost.newTabSpec("Third");

firstTab.setIndicator("",getResources().getDrawable(R.drawable.home));
firstTab.setContent(R.id.first);
secondTab.setIndicator("",getResources().getDrawable(R.drawable.redicon));
secondTab.setContent(R.id.second);
thirdTab.setIndicator("",getResources().getDrawable(R.drawable.exit));
thirdTab.setContent(R.id.third);

tabHost.addTab(firstTab);
tabHost.addTab(secondTab);
tabHost.addTab(thirdTab);

}
}

 

            

Thursday 17 January 2013

Custom Alert Dialog Box in Android


The screenshots are:


page1
page2

XML Layout:


page1:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/transp" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="162dp"
        android:gravity="center"
        android:layout_marginTop="120dp"
       >

        <EditText
            android:id="@+id/Username"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Username"
            android:typeface="serif"
            android:padding="10dp">

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/two"
            android:layout_width="155dp"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/signup"
            android:text="Exit"
            android:textColor="#fff"
            android:textSize="19dip"/>

        <Button
            android:id="@+id/one"
            android:layout_width="155dp"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/button2"
            android:background="@drawable/liginbtn"
            android:textColor="#fff"
            android:text="Enter"
            android:textSize="19dip" />

        <EditText
            android:id="@+id/password"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/Username"
            android:ems="10"
            android:inputType="textPassword"
            android:typeface="serif"
            android:paddingTop="10dp"
            android:text="Password" />

    </RelativeLayout>

</LinearLayout>

Page2:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#222"
    android:orientation="vertical"
    android:padding="8dip" >

    <LinearLayout
        android:id="@+id/mExitDialogDesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dip"
        android:paddingTop="15dip" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Enter Valid Username And Password"
            android:textColor="#fff"
            android:textSize="20dip"
            android:typeface="serif"
            android:layout_gravity="center"
            android:gravity="center"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/mExitDialogTitleBorder"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_below="@id/mExitDialogDesc"
        android:background="#4BBAE3"
        >
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/mExitDialogTitleBorder"
        android:baselineAligned="false"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:padding="15dip"
        android:weightSum="2" >

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dip" >

            <Button
                android:id="@+id/Button"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:background="@drawable/liginbtn"
                android:text="Enter"
                android:typeface="serif"
                android:textColor="#fff"
                android:textSize="19dip" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dip" >

            <Button
                android:id="@+id/mCloseExitDialog"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:background="@drawable/signup"
                android:text="Exit"
                android:typeface="serif"
                android:textColor="#fff"
                android:textSize="19dip" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

Java code:


import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class alertdialog extends Activity {
   
    private Button Login,signup;
    Dialog dialogbox;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.sample);

        Login = (Button) findViewById(R.id.one);
        signup=(Button)findViewById(R.id.two);
       
        Login.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dialogbox = new Dialog(alertdialog.this);
                dialogbox.setContentView(R.layout.exit_dialog_box);
                dialogbox.setTitle("");
                dialogbox.setCancelable(true);
                Button button = (Button) dialogbox.findViewById(R.id.Button);
                button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialogbox.dismiss();
                }
                });
                dialogbox.show();
            }
        });

        }
}

Wednesday 9 January 2013

Intent Service in Android with simple example



  Android application with complete code:


First page

The xml code:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/trans" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="162dp"
        android:gravity="center"
        android:layout_marginTop="100dp"
        android:background="@drawable/transp">
        <EditText
            android:id="@+id/Username"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Username" >
            <requestFocus />
        </EditText>
        <EditText
            android:id="@+id/password"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:ems="10"
            android:inputType="textPassword"
            android:text="Password" />

        <Button
            android:id="@+id/button2"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/liginbtn"
            android:text="Exit" />
        <Button
            android:id="@+id/one"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/button2"
            android:background="@drawable/liginbtn"
            android:text="Enter" />

    </RelativeLayout>

</LinearLayout>

second page


Here the code:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:orientation="horizontal"
    android:background="@drawable/trans">
       <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/layer13" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Janmejoy"
        android:layout_marginLeft="20dp"/> 
    </LinearLayout>

Here the code begins.......

"MainActivity"


package com.example.example;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
   
    Button Login,Exit;
    EditText username,password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.sample);           
       
    Login=(Button)findViewById(R.id.one);
    Exit=(Button)findViewById(R.id.button2);
    username=(EditText)findViewById(R.id.Username);
    password=(EditText)findViewById(R.id.password);
   
    Login.setOnClickListener(new OnClickListener() {
       
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
           
            Intent intent=new Intent(MainActivity.this,First.class);
            startActivity(intent);
            finish();
           
        }
    });
Exit.setOnClickListener(new OnClickListener() {
       
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
           
            System.exit(0);
            finish();
           
        }
    });
       
    }
}

"NextActivity:


package com.example.example;

import android.app.Activity;
import android.os.Bundle;

public class First extends Activity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intentpage);
    }
}

You must add the next activity in Manifest file

<activity android:name=".First" android:label="@string/app_name" > </activity>



Sunday 6 January 2013

Sliding Drawer in Android


"Guide to create Sliding Drawer in Android in both side,Left to right and Right to left"


Next Image


For creating sliding view in both direction


"If you want to create sliding drawer animation in right to left no need to add any view in layout you can simply use slider widget (answer here)

but in case of both sides sliding drawer you need to call the view in your layout .In this layout i have created view in com.example.example.SlidingDrawer."


Main Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/back">
   
    <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
   
   
    <com.example.example.SlidingDrawer
        xmlns:my="http://schemas.android.com/apk/res/com.example.example"
        android:id="@+id/drawer"
        my:direction="leftToRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        my:handle="@+id/handle"
        my:content="@+id/content">
        <include
            android:id="@id/content"
            layout="@layout/contentlayout" >
            </include>
        <ImageView
            android:id="@id/handle"
            android:layout_width="wrap_content"
            android:layout_height="40px"
            android:src="@drawable/ic_launcher" />
    </com.example.example.SlidingDrawer>
    <com.example.example.SlidingDrawer
        xmlns:my="http://schemas.android.com/apk/res/com.example.example"
        android:id="@+id/drawer"
        my:direction="rightToLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        my:handle="@+id/handle"
        my:content="@+id/content">
        <include
            android:id="@id/content"
            layout="@layout/contentlayout" >
            </include>
        <ImageView
            android:id="@id/handle"
            android:layout_width="wrap_content"
            android:layout_height="40px"
            android:src="@drawable/ic_launcher" />
    </com.example.example.SlidingDrawer>
</RelativeLayout>

content layout:


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

 Mainactivity.java

package com.example.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import com.example.example.SlidingDrawer;

public class MainActivity extends Activity {

   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sliding);
       
      
   
   }
}


Here comes the view:

public class SlidingDrawer extends ViewGroup {

    public static final int   Orientationright      = 0;
    public static final int   Orientationbottom  = 1;
    public static final int   Orientationleft        = 2;
    public static final int   Orientationtop        = 3;

// Based on your requirement you can add the orientation 


 public static interface OnDrawerOpenListener {
      
        public void onDrawerOpened();
    }
   
    public static interface OnDrawerCloseListener {
      
   
        public void onDrawerClosed();
    }
   
    public static interface OnDrawerScrollListener {
      
        public void onScrollStarted();
      
        public void onScrollEnded();
    }
   
   
    public SlidingDrawer( Context context, AttributeSet attrs )
    {
        this( context, attrs, 0 );
    }
   
   
    public SlidingDrawer( Context context, AttributeSet attrs, int defStyle )
    {
        super( context, attrs, defStyle );
        TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SlidingDrawer, defStyle, 0 );
      
        int orientation = a.getInt( R.styleable.SlidingDrawer_direction, Orientationbottom );
        moveVertical = ( orientation == Orientationbottom || orientation == Orientationtop );
        Bottom_Offset = (int)a.getDimension( R.styleable.SlidingDrawer_bottom_Offset, 0.0f );
        Top_Offset = (int)a.getDimension( R.styleable.SlidingDrawer_top_Offset, 0.0f );
        Onsingletap = a.getBoolean( R.styleable.SlidingDrawer_allowSingleTap, true );
        animateclick = a.getBoolean( R.styleable.SlidingDrawer_animateOnClick, true );
        invert = ( orientation == Orientationtop || orientation == Orientationleft );
      
        int handleId = a.getResourceId( R.styleable.SlidingDrawer_handle, 0 );
        if ( handleId == 0 ) { throw new IllegalArgumentException( "Exception "
                + "a valid child." ); }
      
        int contentId = a.getResourceId( R.styleable.SlidingDrawer_content, 0 );
        if ( contentId == 0 ) { throw new IllegalArgumentException( "The content attribute required  "
                + " valid child." ); }
      
        if ( handleId == contentId ) { throw new IllegalArgumentException( "The content and handle attributes refer "
                + " different children." ); }
        mHandleId = handleId;
        mContentId = contentId;
      
        final float density = getResources().getDisplayMetrics().density;
        mTapThreshold = (int)( tap_threshold * density + 0.5f );
        Maxtapvelocity = (int)( Max_velocity * density + 0.5f );
        minorvelocity = (int)( Min_velocity * density + 0.5f );
        majorvelocity = (int)( Maj_velocity * density + 0.5f );
        maxacceleration = (int)( Max_acceleration * density + 0.5f );
        velocityunits = (int)( velocityunit * density + 0.5f );
      
        if( invert ) {
            maxacceleration = -maxacceleration;
            majorvelocity = -majorvelocity;
            minorvelocity = -minorvelocity;
        }
      
        a.recycle();
        setAlwaysDrawnWithCacheEnabled( false );
    }
    .....
protected void onLayout( boolean changed, int l, int t, int r, int b )
    {
      final View handle = mHandle;
       
        int handleWidth = handle.getMeasuredWidth();
        int handleHeight = handle.getMeasuredHeight();
       
    final View content = mContent;
       
        if ( moveVertical ) {
            handleLeft = ( width - handleWidth ) / 2;
            if ( invert ) {
              
                handleTop = mExpanded ? height - Bottom_Offset - handleHeight : Top_Offset;
                content.layout( 0, Top_Offset, content.getMeasuredWidth(), Top_Offset + content.getMeasuredHeight() );
            } else {
                handleTop = mExpanded ? Top_Offset : height - handleHeight + Bottom_Offset;
                content.layout( 0, Top_Offset + handleHeight, content.getMeasuredWidth(), Top_Offset + handleHeight + content.getMeasuredHeight() );
            }
        } else {
            handleTop = ( height - handleHeight ) / 2;
            if( invert ) {
                handleLeft = mExpanded ? width - Bottom_Offset - handleWidth : Top_Offset;
                content.layout( Top_Offset, 0, Top_Offset + content.getMeasuredWidth(), content.getMeasuredHeight() );
            } else {
                handleLeft = mExpanded ? Top_Offset : width - handleWidth + Bottom_Offset;
                content.layout( Top_Offset + handleWidth, 0, Top_Offset + handleWidth + content.getMeasuredWidth(), content.getMeasuredHeight() );
            }
        }
       
        handle.layout( handleLeft, handleTop, handleLeft + handleWidth, handleTop + handleHeight );
        mHandleHeight = handle.getHeight();
        mHandleWidth = handle.getWidth();
    }
  
 ....Use can use Touchevent:

public boolean onTouchEvent( MotionEvent event )
    {
    switch ( action ) {
                case MotionEvent.ACTION_MOVE:
                    moveHandle( (int)( moveVertical ? event.getY() : event.getX() ) - mTouchDelta );
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity( velocityunits );
                   
                    float yVelocity = velocityTracker.getYVelocity();
                    float xVelocity = velocityTracker.getXVelocity();
                    boolean negative;
.....
.....
}
 For Animate open and close:

private void animateClose( int position )
    {
        prepareTracking( position );
        performFling( position, maxacceleration, true );
    }
   
    private void animateOpen( int position )
    {
        prepareTracking( position );
        performFling( position, -maxacceleration, true );
    }
   
    private void performFling( int position, float velocity, boolean always )
    {
        AnimationPosition = position;
        AnimatedVelocity = velocity;
        ..
.....
...
....}
       
    For more information you can try this SlidingDrawer