Monday, 22 December 2014

Check Network Connection Using BroadCast

Java Class

public class NetworkStatus extends BroadcastReceiver{

public static  boolean isConnected;

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub

isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

  if(isConnected)
   {
       Toast.makeText(context, "Internet Connection Lost", Toast.LENGTH_LONG).show();
     
   }
   else
   {
       Toast.makeText(context, "Internet Connected", Toast.LENGTH_LONG).show();
     
          // new RequestService(context);

       
   }
}

}


ManiFest XML

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aditmicrosys.easylife"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

 
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/appicon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name="com.aditmicrosys.easylife.Splash_Screen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 <receiver android:name="com.aditmicrosys.comman.NetworkStatus" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

</application>

JSON Pars With MVC

Link Of Demo Project

Download source code


Sunday, 14 December 2014

Android Activity Animation From Left To right

Animation xml files:

right_slide_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_decelerate_interpolator">
  
     <translate
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="300"/>

</set>

left_slide_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    
    <translate
         android:fromXDelta="0" 
         android:toXDelta="-100%p" 
         android:duration="300"/>
</set>

FirstActivity.java


    Button b_next = (Button)findViewById(R.id.button1);
    b_next.setOnClickListener(new OnClickListener() {
  @Override
   public void onClick(View arg0) {
  // TODO Auto-generated method stub
      
                    Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                    startActivity(intent);
                    overridePendingTransition(R.anim.right_slide_in, R.anim.left_side_out);
                    FirstActivity.this.finish(); 

}
     });

Friday, 12 December 2014

Google Map with Multiple Marks Using For loop And Click Event On Marks

XML



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</RelativeLayout>



Java Code


public class MainActivity extends FragmentActivity {

GoogleMap googleMap;
double locationCount = 1.32656;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap=fm.getMap();

LatLng latelong = null;

for (int i = 0; i < 10; i++)
{

double lat = 47.612194+(locationCount*i);
double log = -122.344831+(locationCount*i);
latelong=new LatLng(lat, log);

googleMap.addMarker(new MarkerOptions().position(latelong).title("2121 1st Ave, Suite 101 Seattle, WA 98121"));

if(i==0)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latelong, 15));

}


googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub


Toast.makeText(MainActivity.this, "Pankaj Saad", Toast.LENGTH_SHORT).show();

//when pass true in return title on marks is not show
return false;
}
});



}
}


Manifast XML


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mapwithmultipalmarks"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

 
     <uses-permission android:name="android.permission.INTERNET"/>
   
   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>
     
     
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
     
         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAEmq9Ag26cjIe_pYybYrRWSNz8scOAd64" />
    </application>


</manifest>

Google Map with multiple marks at Click on map

Main XML



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>



Java Code


public class MainActivity extends FragmentActivity {


GoogleMap googleMap;
SharedPreferences sharedPreferences;
   int locationCount = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
     
        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if(status!=ConnectionResult.SUCCESS)
        { // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        }
        else
        { // Google Play Services are available

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map
            googleMap.setMyLocationEnabled(true);

            // Opening the sharedPreferences object
            sharedPreferences = getSharedPreferences("location", 0);

            // Getting number of locations already stored
            locationCount = sharedPreferences.getInt("locationCount", 0);

            // Getting stored zoom level if exists else return 0
            String zoom = sharedPreferences.getString("zoom", "0");

            // If locations are already saved
            if(locationCount!=0){

                String lat = "";
                String lng = "";

                // Iterating through all the locations stored
                for(int i=0;i<locationCount;i++){

                    // Getting the latitude of the i-th location
                    lat = sharedPreferences.getString("lat"+i,"0");

                    // Getting the longitude of the i-th location
                    lng = sharedPreferences.getString("lng"+i,"0");

                    // Drawing marker on the map
                    drawMarker(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
                }

                // Moving CameraPosition to last clicked position
                googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))));

                // Setting the zoom level in the map on last position  is clicked
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(Float.parseFloat(zoom)));
            }
        }

        googleMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public void onMapClick(LatLng point) {
                locationCount++;

                // Drawing marker on the map
                drawMarker(point);

                /** Opening the editor object to write data to sharedPreferences */
                SharedPreferences.Editor editor = sharedPreferences.edit();

                // Storing the latitude for the i-th location
                editor.putString("lat"+ Integer.toString((locationCount-1)), Double.toString(point.latitude));

                // Storing the longitude for the i-th location
                editor.putString("lng"+ Integer.toString((locationCount-1)), Double.toString(point.longitude));

                // Storing the count of locations or marker count
                editor.putInt("locationCount", locationCount);

                /** Storing the zoom level to the shared preferences */
                editor.putString("zoom", Float.toString(googleMap.getCameraPosition().zoom));

                /** Saving the values stored in the shared preferences */
                editor.commit();

                Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();

            }
        });

        googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng point) {

                // Removing the marker and circle from the Google Map
                googleMap.clear();

                // Opening the editor object to delete data from sharedPreferences
                SharedPreferences.Editor editor = sharedPreferences.edit();

                // Clearing the editor
                editor.clear();

                // Committing the changes
                editor.commit();

                // Setting locationCount to zero
                locationCount=0;

            }
        });
    }

    private void drawMarker(LatLng point){
        // Creating an instance of MarkerOptions
        MarkerOptions markerOptions = new MarkerOptions();

        // Setting latitude and longitude for the marker
        markerOptions.position(point);

        // Adding marker on the Google Map
        googleMap.addMarker(markerOptions);
    }

 

}


Mainifast XML


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mapwithmultipalmarks"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

 
     <uses-permission android:name="android.permission.INTERNET"/>
   
   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>
     
     
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
     
         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAEmq9Ag26cjIe_pYybYrRWSNz8scOAd64" />
    </application>


</manifest>




Thursday, 11 December 2014

Sliding Drawer

Main XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#e0e0e0" >

        <TextView
            android:id="@+id/menu_Id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:padding="15dp"
            android:text="Menu"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:padding="15dp"
            android:text="@string/hello_world"
            android:textColor="#000000" />
    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/DrawerLayout_Id"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="Hello" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>
     
        <include
            android:id="@+id/menuLayout_Id"
            layout="@layout/menu_item" />
 
     
    </android.support.v4.widget.DrawerLayout>

</LinearLayout>




Java Class

public class MainActivity extends Activity {


TextView menu;
private DrawerLayout drawerLayout;
LinearLayout LeftDrawer;
boolean menuStatus=true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
 
        menu = (TextView)findViewById(R.id.menu_Id);
        drawerLayout = (DrawerLayout)findViewById(R.id.DrawerLayout_Id);
        LeftDrawer = (LinearLayout)findViewById(R.id.menuLayout_Id);
     
        menu.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub


if(menuStatus)
{
menuStatus=false;
drawerLayout.openDrawer(LeftDrawer);
}
else
{
menuStatus=true;
drawerLayout.closeDrawer(LeftDrawer);
}

}
});
     
    }
}


Menu_Item XML



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
 android:layout_gravity="start"
    android:background="@android:color/transparent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="Item 1" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="Item 2" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="Item 3" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="Item 4" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


Link of Picasso and Java Code

Download Jar file of Picasso

Java Code

Picasso.with(Context).load("Image Url").into("ImageView object");

Link of ImageLoading (Lazy Loading)

Download Image Loading Class

Java Code

ImageLoader ImageLoader imageLoading = new ImageLoader(FacebookLogin.this);
imageLoading.DisplayImage("Image url", ImageView Object, false);

 

Date ( 10-11-2014 To 10-Nov-2014 ) And Time Conversion ( 13:30 To 1:30 PM )

Date Conversion

public class DateAndTimeFormateConvertion {

// Date Conversion 31/11/2014 To 31-Nov-2014
public String DateConvertString(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);

}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}


// Convert Date 2014/11/31 To 31-Nov-2014
public String DateConvertStringEdit(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("yyyy/MM/dd").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);

}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}


//Convert Date 1/Nov/2014 To 1-11-2014
public String DateConvertInteger(String str)
{
String DateString="";
try
{
SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = format1.parse(str);
DateString = format2.format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Convertion Exception :"+e.getMessage());

}
return DateString;
}




Time Conversion


//Time Convertion 13:30 To 1:30 PM
public String TimeConversion(String time)
{
String timeCon="";
if(time.equalsIgnoreCase(""))
{
return timeCon;
}
else
{
DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
Date date;
try {
date = dateFormat.parse(time);
DateFormat dateFormate1 = new SimpleDateFormat("h:mma");
timeCon = dateFormate1.format(date);//.toLowerCase(); // "12:18am"
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return timeCon;
}
}
}

Decimal Format 2 or 3 Digit


Decimal  format without comma Like (2000.00)



public class DoubleValueFormate {

static DecimalFormat formatter = new DecimalFormat("0.00");
static DecimalFormat threeDigitformatter = new DecimalFormat("0.000");

static DecimalFormat fourDigitformatter = new DecimalFormat("0.0000");

Double value=0.0;


static public String getValue(String value) {

if(value.equalsIgnoreCase("null")|| value.equalsIgnoreCase(""))
{
return "";
}
else
{
double doubleValurFormate  = Double.parseDouble(value);
return formatter.format(doubleValurFormate);
}
}



static public String getValue3Digit(String value) {

if(value.equalsIgnoreCase("null")|| value.equalsIgnoreCase(""))
{
return "";
}
else
{
double doubleValurFormate  = Double.parseDouble(value);
return threeDigitformatter.format(doubleValurFormate);
}
}


static public String getValue4Digit(String value) {

if(value.equalsIgnoreCase("null")|| value.equalsIgnoreCase(""))
{
return "";
}
else
{
double doubleValurFormate  = Double.parseDouble(value);
return fourDigitformatter.format(doubleValurFormate);
}


}


}


Decimal  format with comma Like (2,00,000,000.00)


public class NumberForamteClass {

static NumberFormat formatter  = NumberFormat.getNumberInstance();

public static String get4Digit(String value)
{
formatter.setMinimumFractionDigits(4);
formatter.setMaximumFractionDigits(4);
if(value.equalsIgnoreCase(""))
{
return"";
}
else
{
return ""+formatter.format(Double.parseDouble(value));
}
}

public static String get3Digit(String value)
{
formatter.setMinimumFractionDigits(3);
formatter.setMaximumFractionDigits(3);
if(value.equalsIgnoreCase(""))
{
return"";
}
else
{
return ""+formatter.format(Double.parseDouble(value));
}
}
}




Wednesday, 10 December 2014

List View Swipe to open some item (Delete or Edit Button) from Right Side

Main XML 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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="com.example.listviewwithswipetoshowsomeitem.MainActivity" >

    <com.example.listviewwithswipetoshowsomeitem.SwipeListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/SwipeListViewId" />

</RelativeLayout>



Main Java Class

public class MainActivity extends Activity {

SwipeListView mListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mListView = (SwipeListView)findViewById(R.id.SwipeListViewId);
        mListView.setAdapter(new SwipeListViewAdapterClass());
    }
}


Adapter Class

class SwipeListViewAdapterClass extends BaseAdapter
    {

@Override
public int getCount() {
// TODO Auto-generated method stub
return 20;
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(final int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View view = getLayoutInflater().inflate(R.layout.item, null);
View left_item_Layout = (View)view.findViewById(R.id.item_left);
View Right_item_Layout = (View)view.findViewById(R.id.item_right);
TextView Name = (TextView)view.findViewById(R.id.item_left_txt);
TextView Right_Item_Name = (TextView)view.findViewById(R.id.item_right_txt);
Name.setText("Item "+position);
Right_Item_Name.setText("Delete");
LinearLayout.LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
left_item_Layout.setLayoutParams(lp1);
LinearLayout.LayoutParams lp2 = new LayoutParams(300, LayoutParams.MATCH_PARENT);
Right_item_Layout.setLayoutParams(lp2);
Right_Item_Name.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Delete Button Clicked Position "+position, Toast.LENGTH_SHORT).show();
}
});
return view;
}
   
    }
    


Adapter Class Row Or listview Row XML


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <RelativeLayout
        android:id="@+id/item_left"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/item_left_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:padding="12dp"
            android:textColor="#000000" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/item_right"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#FF0000" >

        <TextView
            android:padding="20dp"
            android:id="@+id/item_right_txt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:textColor="#FFFFFF" />
    </RelativeLayout>

</LinearLayout>




SwipeListView  Java Class


public class SwipeListView extends ListView {
 
    private Boolean mIsHorizontal;
    private View mPreItemView;
    private View mCurrentItemView;
    private float mFirstX;
    private float mFirstY;
    private int mRightViewWidth = 300;
    private final int mDuration = 100;
    private final int mDurationStep = 10;
    private boolean mIsShown;
    private boolean mIsFooterCanSwipe = false;
    private boolean mIsHeaderCanSwipe = false;

    public SwipeListView(Context context) {
        super(context);
    }

    public SwipeListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SwipeListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

   
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float lastX = ev.getX();
        float lastY = ev.getY();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mIsHorizontal = null;
                mFirstX = lastX;
                mFirstY = lastY;
                int motionPosition = pointToPosition((int)mFirstX, (int)mFirstY);

                if (motionPosition >= 0) {
                    View currentItemView = getChildAt(motionPosition - getFirstVisiblePosition());
                    mPreItemView = mCurrentItemView;
                    mCurrentItemView = currentItemView;
                }
                break;

            case MotionEvent.ACTION_MOVE:
                float dx = lastX - mFirstX;
                float dy = lastY - mFirstY;

                if (Math.abs(dx) >= 5 && Math.abs(dy) >= 5) {
                    return true;
                }
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                if (mIsShown && (mPreItemView != mCurrentItemView || isHitCurItemLeft(lastX))) {
                    System.out.println("1---> hiddenRight");
                   
                    hiddenRight(mPreItemView);
                }
                break;
        }

        return super.onInterceptTouchEvent(ev);
    }

    private boolean isHitCurItemLeft(float x) {
        return x < getWidth() - mRightViewWidth;
    }

   
    private boolean judgeScrollDirection(float dx, float dy) {
        boolean canJudge = true;

        if (Math.abs(dx) > 30 && Math.abs(dx) > 2 * Math.abs(dy)) {
            mIsHorizontal = true;
        } else if (Math.abs(dy) > 30 && Math.abs(dy) > 2 * Math.abs(dx)) {
            mIsHorizontal = false;
        } else {
            canJudge = false;
        }

        return canJudge;
    }

   
    private boolean judgeFooterView(float posX, float posY) {
        // if footer can swipe
        if (mIsFooterCanSwipe) {
            return true;
        }
        // footer cannot swipe
        int selectPos = pointToPosition((int)posX, (int)posY);
        if (selectPos >= (getCount() - getFooterViewsCount())) {
            // is footer ,can not swipe
            return false;
        }
        // not footer can swipe
        return true;
    }

  
    private boolean judgeHeaderView(float posX, float posY) {
        // if header can swipe
        if (mIsHeaderCanSwipe) {
            return true;
        }
        // header cannot swipe
        int selectPos = pointToPosition((int)posX, (int)posY);
        if (selectPos >= 0 && selectPos < getHeaderViewsCount()) {
            // is header ,can not swipe
            return false;
        }
        // not header can swipe
        return true;
    }

   
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        float lastX = ev.getX();
        float lastY = ev.getY();
        // test footer and header
        if (!judgeFooterView(mFirstX, mFirstY) || !judgeHeaderView(mFirstX, mFirstY)) {
            return super.onTouchEvent(ev);
        }
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                break;

            case MotionEvent.ACTION_MOVE:
                float dx = lastX - mFirstX;
                float dy = lastY - mFirstY;
                // confirm is scroll direction
                if (mIsHorizontal == null) {
                    if (!judgeScrollDirection(dx, dy)) {
                        break;
                    }
                }

                if (mIsHorizontal) {
                    if (mIsShown && mPreItemView != mCurrentItemView) {
                       
                        hiddenRight(mPreItemView);
                    }

                    if (mIsShown && mPreItemView == mCurrentItemView) {
                        dx = dx - mRightViewWidth;
                    }

                    // can't move beyond boundary
                    if (dx < 0 && dx > -mRightViewWidth) {
                        mCurrentItemView.scrollTo((int)(-dx), 0);
                    }

                    return true;
                } else {
                    if (mIsShown) {
                      
                        hiddenRight(mPreItemView);
                    }
                }

                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                clearPressedState();
                if (mIsShown) {
                   
                    hiddenRight(mPreItemView);
                }

                if (mIsHorizontal != null && mIsHorizontal) {
                    if (mFirstX - lastX > mRightViewWidth / 2) {
                        showRight(mCurrentItemView);
                    } else {
                      
                        hiddenRight(mCurrentItemView);
                    }

                    return true;
                }

                break;
        }

        return super.onTouchEvent(ev);
    }

    private void clearPressedState() {
        // TODO current item is still has background, issue
        mCurrentItemView.setPressed(false);
        setPressed(false);
        refreshDrawableState();
        // invalidate();
    }

    private void showRight(View view) {
        Message msg = new MoveHandler().obtainMessage();
        msg.obj = view;
        msg.arg1 = view.getScrollX();
        msg.arg2 = mRightViewWidth;
        msg.sendToTarget();

        mIsShown = true;
    }

    private void hiddenRight(View view) {
        if (mCurrentItemView == null) {
            return;
        }
        Message msg = new MoveHandler().obtainMessage();//
        msg.obj = view;
        msg.arg1 = view.getScrollX();
        msg.arg2 = 0;

        msg.sendToTarget();

        mIsShown = false;
    }

  
    @SuppressLint("HandlerLeak")
    class MoveHandler extends Handler {
        int stepX = 0;

        int fromX;

        int toX;

        View view;

        private boolean mIsInAnimation = false;

        private void animatioOver() {
            mIsInAnimation = false;
            stepX = 0;
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (stepX == 0) {
                if (mIsInAnimation) {
                    return;
                }
                mIsInAnimation = true;
                view = (View)msg.obj;
                fromX = msg.arg1;
                toX = msg.arg2;
                stepX = (int)((toX - fromX) * mDurationStep * 1.0 / mDuration);
                if (stepX < 0 && stepX > -1) {
                    stepX = -1;
                } else if (stepX > 0 && stepX < 1) {
                    stepX = 1;
                }
                if (Math.abs(toX - fromX) < 10) {
                    view.scrollTo(toX, 0);
                    animatioOver();
                    return;
                }
            }

            fromX += stepX;
            boolean isLastStep = (stepX > 0 && fromX > toX) || (stepX < 0 && fromX < toX);
            if (isLastStep) {
                fromX = toX;
            }

            view.scrollTo(fromX, 0);
            invalidate();

            if (!isLastStep) {
                this.sendEmptyMessageDelayed(0, mDurationStep);
            } else {
                animatioOver();
            }
        }
    }

    public int getRightViewWidth() {
        return mRightViewWidth;
    }

    public void setRightViewWidth(int mRightViewWidth) {
        this.mRightViewWidth = mRightViewWidth;
    }

   
    public void setFooterViewCanSwipe(boolean canSwipe) {
        mIsFooterCanSwipe = canSwipe;
    }

    public void setHeaderViewCanSwipe(boolean canSwipe) {
        mIsHeaderCanSwipe = canSwipe;
    }

    public void setFooterAndHeaderCanSwipe(boolean footer, boolean header) {
        mIsHeaderCanSwipe = header;
        mIsFooterCanSwipe = footer;
    }
}

Share Preference

Share Preference class (SessionStore Class)




public class SessionStore {


public static final String CONSINOR="consinor";

public static final String USER_ID = "userId";
public static final String USER_NAME = "userName";
public static final String PWD = "pwd";


public static final String CUSTOMER_ID = "customerId";
public static final String IPADD = "ipaddress";


public static boolean save(Context context,String name,String userName ,String pwd,String userId,String customerId,Boolean ischecked,String IpAdress) {
Editor editor =context.getSharedPreferences(name, Context.MODE_PRIVATE).edit();
editor.putBoolean("isChecked",ischecked );
editor.putString(USER_ID, userId);
editor.putString(USER_NAME, userName);
editor.putString(PWD, pwd);


editor.putString(CUSTOMER_ID, customerId);
editor.putString(IPADD, IpAdress);

return editor.commit();
}

public static HashMap<String, String> getUserDetails(Context context,String name){
SharedPreferences  pref = context.getSharedPreferences(name, Context.MODE_PRIVATE);
HashMap<String, String> user = new HashMap<String, String>();
// user
user.put("isChecked", ""+pref.getBoolean("isChecked", false));

// user login
user.put(USER_ID, pref.getString(USER_ID, null));

// user pwd
user.put(CUSTOMER_ID, pref.getString(CUSTOMER_ID, null));
user.put(IPADD, pref.getString(IPADD, null));
user.put(USER_NAME, pref.getString(USER_NAME, null));
user.put(PWD, pref.getString(PWD, null));



// return user
return user;
}

public static void clear(Context context, String name ) {
Editor editor = context.getSharedPreferences(name, Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
}

}


Main Java Class



//Save share preference
 SessionStore.save(LoginActivity.this,consinorid, semail, spass,consinor);

//Get share preference 

HashMap<String, String> user = new HashMap<String, String>();
user = SessionStore.getUserDetails(getApplicationContext(), "Name of preference");
String name = user.get(SessionStore.USER_NAME);

//Clear Share Preference

SessionStore.clear(getApplicationContext(),"Name of preference");