Thursday 24 October 2013

Login Registration Demo

1)Create class Register.java
=======================
package com.example.demoproject;
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class Register extends Activity implements OnClickListener{
private CommanClass mCommanClass = null;
private Button btnSubmit = null;
private Button btnSkip = null;
private Button btnBack= null;
private EditText edtName_Of_Owner = null;
private EditText edtEmailID = null;
private EditText edtMobileNo = null;
private EditText edtPassword = null;
private EditText edtConfirmPassword = null;
private EditText edtChasisNo = null;
private String strUserId = null;
// private SharedPreferences mSharedPreferencesRead=null;
private SharedPreferences mSharedPreferencesWrite=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

setContentView(R.layout.xregister);
// viewfocus=(View)findViewById(R.id.viewfocus);
// mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
mSharedPreferencesWrite = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_WRITEABLE);
mCommanClass = new CommanClass();

edtName_Of_Owner = (EditText)findViewById(R.id.edtNameOfOwner);
edtEmailID = (EditText)findViewById(R.id.edtEmail_Id);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtPassword = (EditText)findViewById(R.id.edtPassword);
edtConfirmPassword = (EditText)findViewById(R.id.edtConfirmPassword);
edtChasisNo = (EditText)findViewById(R.id.edtChasisNumber);

btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(this);
btnSkip = (Button)findViewById(R.id.btnSkip);
btnSkip.setOnClickListener(this);
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
}


//************************************************************************************************************************************
//This class is used for get Add appointment
   private class Register_Vehical extends AsyncTask
   {
    private ProcessDialog mProcessDialog=null;
        protected void onPreExecute() {
           mProcessDialog = new ProcessDialog(Register.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
               super.onPreExecute();
        }
        protected String doInBackground(String... params) {
           String strURL = getResources().getString(R.string.REGISTER_VEHICAL_URL);
        ArrayList mNameValuePair = new ArrayList();
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.ID, String.valueOf(intID)));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.MOBILE_NO, edtMobileNo.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.EMAIL_ID, edtEmailID.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.PASSWORD, edtPassword.getText().toString().trim()));
           mNameValuePair.add(new BasicNameValuePair(Constant.REGISTER_VEHICAL_REQUEST.MOBILE_TYPE,"Android"));
       
    System.out.println("Register Value ==="+mNameValuePair.toString());
    return mCommanClass.PostConnection(strURL, mNameValuePair);
        }
       
        protected void onPostExecute(String result) {
        mProcessDialog.dismiss();
            if(result!=null){  
            System.out.println("RegisterResponse====="+result);
            try {
            JSONObject mJSONOBJECT = new JSONObject(result);
            String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
   
    if(strType.equalsIgnoreCase(Constant.JSON.OK)){
    JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.JSON.RESULT);
    strUserId = mJSONOBJECT_RESULT.getString(Constant.REGISTER_VEHICAL_RESPONSE.USER_ID);
    System.out.println("strUserId====="+strUserId.toString());
    SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, String.valueOf(strUserId));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_CHASIS_NO,edtChasisNo.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,edtName_Of_Owner.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,edtEmailID.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,edtMobileNo.getText().toString().trim());
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_PASSWORD, edtPassword.getText().toString().trim());
mSharedPreferencesEdit.commit();

Toast.makeText(Register.this,mJSONOBJECT_RESULT.getString(Constant.REGISTER_RESPONSE.RAGISTER_MESSAGE), Toast.LENGTH_SHORT).show();
Intent mIntent=new Intent(Register.this,Verification.class);
mIntent.setAction(Constant.REGISTER_VEHICAL.REGISTER_L_INTENT);
startActivity(mIntent);
finish();
}
else{
Toast.makeText(Register.this,mJSONOBJECT.getString(Constant.REGISTER__RESPONSE.RAGISTER__MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}                          
            }  
            else{
            Toast.makeText(Register.this,Constant.SERVERCONNERROR, Toast.LENGTH_SHORT).show();    
            }
            super.onPostExecute(result);
        }            
   }
 
private boolean check_not_null()
{
boolean blank = true;
if (edtName_Of_Owner.getText().toString().equals("") || edtEmailID.getText().toString().equals("")
|| edtMobileNo.getText().toString().equals("") || edtPassword.getText().toString().equals("")
|| edtConfirmPassword.getText().toString().equals("") || edtChasisNo.getText().toString().equals("")) {
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_REQUIRED_FIELD, Toast.LENGTH_SHORT).show();
blank = true;
}else if(edtMobileNo.getText().length() < 10){
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}
else {
if(CommanClass.isEmailValid(edtEmailID.getText().toString()) == false){
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.ENTER_VALID_EMAILID) , Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
if(!edtPassword.getText().toString().equals(edtConfirmPassword.getText().toString())){
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.PASSWORD_NOT_MATCH_MESSAGE), Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
}
return blank;
}



@Override
public void onClick(View v) {
if(v==btnSubmit){
if(!check_not_null() ){
if(mCommanClass.CheckNetwork(this)){
new Register_Vehical().execute("");
}
}
}
else if(v==btnSkip){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID,"-1");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,"");
mSharedPreferencesEdit.commit();

Intent mIntent = new Intent(Register.this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SKIP_INTENT);
startActivity(mIntent);
finish();
}
else if(v==btnBack){
finish();
}
}
}
2)create class Login.java
====================
package com.example.demoproject;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends Activity implements OnClickListener{
private EditText edtMobileNo = null;
private EditText edtPassword = null;
private Button btnSubmit = null;
private Button btnNewUSer = null;
private Button btnSkip = null;
private CommanClass mCommanClass = null;
private String strUserId = null, strVerified = null;
private String strMobileNo, strPassword = null; 
private SharedPreferences mSharedPreferencesWrite=null;
private SharedPreferences mSharedPreferencesRead=null;
private CheckBox chkRememberMe=null;
@Override
protected void onCreate(Bundle savedInstanceState){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.xlogin);
mSharedPreferencesWrite = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_WRITEABLE);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
mCommanClass = new CommanClass();
strUserId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, "");
chkRememberMe = (CheckBox)findViewById(R.id.chkbox_remember_psw);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtPassword = (EditText)findViewById(R.id.edtPassword);
btnSubmit = (Button)findViewById(R.id.btn_Submit);
btnSubmit.setOnClickListener(this);
btnNewUSer = (Button)findViewById(R.id.btnNewUser);
btnNewUSer.setOnClickListener(this);
btnSkip = (Button)findViewById(R.id.btnSkip);
btnSkip.setOnClickListener(this);
if(mSharedPreferencesRead.getBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,false)){
strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME,"");
strPassword = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD,"");
System.out.println("Mobile=="+strMobileNo);
System.out.println("Password=="+strPassword);
edtMobileNo.setText(strMobileNo);
edtPassword.setText(strPassword);
}
}
private ProcessDialog mProcessDialogLogin=null;
private class Login_Service extends AsyncTask
    {        
            protected void onPreExecute(){
            mProcessDialogLogin = new ProcessDialog(Login.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
                    super.onPreExecute();
            }        
            protected String doInBackground(String... params) {
 String strURL = getResources().getString(R.string.LOGIN_URL);  
     ArrayList mNameValuePair = new ArrayList();
     mNameValuePair.add(new BasicNameValuePair(Constant.LOGIN_REQUEST.MOBILE_NO,edtMobileNo.getText().toString().trim()));
 mNameValuePair.add(new BasicNameValuePair(Constant.LOGIN_REQUEST.PASSWORD,edtPassword.getText().toString().trim()));
 System.out.println("mNameValuePair=="+mNameValuePair.toString());
 return mCommanClass.PostConnection(strURL, mNameValuePair);  
            } 
            
            protected void onPostExecute(String result) {
            mProcessDialogLogin.dismiss();
           
            if(result!=null)
{
            System.out.println("Login=="+result.toString());
        try{
            JSONObject mJSONOBJECT = new JSONObject(result);
            String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
    if(strType.toString().trim().equalsIgnoreCase(Constant.JSON.OK)){
    JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.LOGIN_RESPONSE.RESULT);
strVerified = mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.STATUS);
strUserId = mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID);
JSONArray mJSONARRAY_LOGIN_VEHICAL_DETAIL = mJSONOBJECT_RESULT.getJSONArray(Constant.LOGIN_RESPONSE.VEHICLE_DETAIL);
    System.out.println("mJSONARRAY_SERVICE_RESULT=="+mJSONARRAY_LOGIN_VEHICAL_DETAIL.toString());
    // System.out.println("strUserId=="+strUserId.toString());
 
    for(int i = 0; i
     JSONObject mJSONOBJECT_VEHICAL_DETAIL = mJSONARRAY_LOGIN_VEHICAL_DETAIL.getJSONObject(i);
   
      mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.B_ID));
   
        mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.P_ID),
      mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.BD_ID));
   
        mJSONOBJECT_VEHICAL_DETAIL.getString(Constant.LOGIN_RESPONSE.M_ID),
    }
   
    String strUserID =  mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID);
    System.out.println("strUserId=="+strUserId.toString());
    SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.USER_ID));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.OWNER_NAME));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.MOBILE_NO));
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.EMAIL_ID));
mSharedPreferencesEdit.commit();
if(strVerified.toString().trim().equals(Constant.LOGIN_RESPONSE.STATUS_VALUE)){
Toast.makeText(Login.this,mJSONOBJECT_RESULT.getString(Constant.LOGIN_RESPONSE.MESSAGE).toString().trim(), Toast.LENGTH_SHORT).show();
Intent mIntent=new Intent(Login.this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SUBMIT_INTENT);
startActivity(mIntent);
finish();
}
else{
//Toast.makeText(Login.this,Constant.LOGIN.LOGIN_FAIL_MESSAGE, Toast.LENGTH_SHORT).show();
//LoginFailMessageDialog();
Intent mIntent=new Intent(Login.this,Verification.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SUBMIT_INTENT);
startActivity(mIntent);
finish();
}
}
else{
LoginFailMessageDialog();
}
} catch (Exception e) {
e.printStackTrace();
}                    
}
            else{
    Toast.makeText(Login.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
    }
                 super.onPostExecute(result);
            }
    }

@Override
public void onClick(View v) {
if(v == btnSubmit){
if(chkRememberMe.isChecked()){
strMobileNo=edtMobileNo.getText().toString().trim();
strPassword=edtPassword.getText().toString().trim();
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME, strMobileNo);
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD, strPassword);
mSharedPreferencesEdit.putBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,true);
mSharedPreferencesEdit.commit();
}
else{
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_USERNAME, "");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_REM_PASSWORD, "");
mSharedPreferencesEdit.putBoolean(Constant.LOGIN_SHAREPREFERENCE.LS_REMEMBER_ME,false);
mSharedPreferencesEdit.commit();
}
if(edtMobileNo.getText().toString().trim().equals("")|| (edtMobileNo.getText().length() < 10)){
Animation shake = AnimationUtils.loadAnimation(this,R.anim.shake);
edtMobileNo.startAnimation(shake);
Toast.makeText(this, Constant.LOGIN.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}  
else if(edtPassword.getText().toString().trim().equals("")){
Animation shake = AnimationUtils.loadAnimation(this,R.anim.shake);
edtPassword.startAnimation(shake);
Toast.makeText(this, Constant.LOGIN.FILL_PASSWORd,Toast.LENGTH_LONG).show();
}
else{
if(mCommanClass.CheckNetwork(Login.this)){
new Login_Service().execute("");
}
}
}
else if(v==btnNewUSer){
Intent miIntent = new Intent(this,RegisterVehical.class);
startActivity(miIntent);
}
else if(v==btnSkip){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID,"-1");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO,"");
mSharedPreferencesEdit.putString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID,"");
mSharedPreferencesEdit.commit();
 
Intent mIntent = new Intent(this,HomeScreen.class);
mIntent.setAction(Constant.LOGIN.LOGIN_SKIP_INTENT);
startActivity(mIntent);
}
}    
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void 
* @use This Dialog is used for show welcome msg when app start 
*/  
public void LoginFailMessageDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Login.this);
//alertDialogBuilder.setTitle(Constant.LOGIN.LOGIN_FAIL_MESSAGE);
alertDialogBuilder
.setMessage(Constant.LOGIN.LOGIN_FAIL_MESSAGE)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id){
edtPassword.setText("");
dialog.cancel();
}
 });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
3)create Comman Class.java
======================
package com.example.demoproject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

public class CommanClass {

private ConnectivityManager connectivity=null;
private NetworkInfo netinfo=null;
/**This method use for check Network Connectivity
*/
public boolean CheckNetwork(Context mContext) {
   this.connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
       this.netinfo= connectivity.getActiveNetworkInfo();
       if(netinfo!=null && netinfo.isConnected()==true)
       {      
        return true;
       }
       else
       {
        Toast.makeText(mContext, Constant.NETWORK_NOT_AVAILABLE, Toast.LENGTH_LONG).show();
        return false;      
       }
 
}
/**This method use for check Network Connectivity No Message
*/
public boolean CheckNetworkNoMessage(Context mContext) {
   this.connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
       this.netinfo= connectivity.getActiveNetworkInfo();
       if(netinfo!=null && netinfo.isConnected()==true)
       {
        return true;
       }
       else
       {
        return false;      
       }
}
//************************************************************************************************************************
/**This method use for email validation check
*/
public static boolean isEmailValid(String email)
    {
int lastDotIndex = 0;
        String regExpn = "[A-Z0-9a-z][A-Z0-9a-z._%+-]*@[A-Za-z0-9][A-Za-z0-9.-]*\\.[A-Za-z]{2,6}";

        CharSequence inputStr = email;
    Pattern pattern = Pattern.compile(regExpn,Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if(matcher.matches()){
     
    lastDotIndex = email.lastIndexOf(".");
    String substr = email.substring(lastDotIndex, email.length());
         
    String[] domains = {".aero", ".asia", ".biz", ".cat", ".com", ".coop", ".edu", ".gov", ".info", ".int", ".jobs", ".mil", ".mobi", ".museum", ".name", ".net", ".org", ".pro", ".tel", ".travel", ".ac", ".ad", ".ae", ".af", ".ag", ".ai", ".al", ".am", ".an", ".ao", ".aq", ".ar", ".as", ".at", ".au", ".aw", ".ax", ".az", ".ba", ".bb", ".bd", ".be", ".bf", ".bg", ".bh", ".bi", ".bj", ".bm", ".bn", ".bo", ".br", ".bs", ".bt", ".bv", ".bw", ".by", ".bz", ".ca", ".cc", ".cd", ".cf", ".cg", ".ch", ".ci", ".ck", ".cl", ".cm", ".cn", ".co", ".cr", ".cu", ".cv", ".cx", ".cy", ".cz", ".de", ".dj", ".dk", ".dm", ".do", ".dz", ".ec", ".ee", ".eg", ".er", ".es", ".et", ".eu", ".fi", ".fj", ".fk", ".fm", ".fo", ".fr", ".ga", ".gb", ".gd", ".ge", ".gf", ".gg", ".gh", ".gi", ".gl", ".gm", ".gn", ".gp", ".gq", ".gr", ".gs", ".gt", ".gu", ".gw", ".gy", ".hk", ".hm", ".hn", ".hr", ".ht", ".hu", ".id", ".ie", " No", ".il", ".im", ".in", ".io", ".iq", ".ir", ".is", ".it", ".je", ".jm", ".jo", ".jp", ".ke", ".kg", ".kh", ".ki", ".km", ".kn", ".kp", ".kr", ".kw", ".ky", ".kz", ".la", ".lb", ".lc", ".li", ".lk", ".lr", ".ls", ".lt", ".lu", ".lv", ".ly", ".ma", ".mc", ".md", ".me", ".mg", ".mh", ".mk", ".ml", ".mm", ".mn", ".mo", ".mp", ".mq", ".mr", ".ms", ".mt", ".mu", ".mv", ".mw", ".mx", ".my", ".mz", ".na", ".nc", ".ne", ".nf", ".ng", ".ni", ".nl", ".no", ".np", ".nr", ".nu", ".nz", ".om", ".pa", ".pe", ".pf", ".pg", ".ph", ".pk", ".pl", ".pm", ".pn", ".pr", ".ps", ".pt", ".pw", ".py", ".qa", ".re", ".ro", ".rs", ".ru", ".rw", ".sa", ".sb", ".sc", ".sd", ".se", ".sg", ".sh", ".si", ".sj", ".sk", ".sl", ".sm", ".sn", ".so", ".sr", ".st", ".su", ".sv", ".sy", ".sz", ".tc", ".td", ".tf", ".tg", ".th", ".tj", ".tk", ".tl", ".tm", ".tn", ".to", ".tp", ".tr", ".tt", ".tv", ".tw", ".tz", ".ua", ".ug", ".uk", ".us", ".uy", ".uz", ".va", ".vc", ".ve", ".vg", ".vi", ".vn", ".vu", ".wf", ".ws", ".ye", ".yt", ".za", ".zm", ".zw"};
     
    for(int i = 0 ; i < domains.length ; i ++ ){
    if(substr.trim().equals(domains[i])){
    return true;
    }
    }
    }
   
return false;
}
/**This function use for check service running or not*/
public static boolean IsServiceRunning(Context context,String package_class) {
   ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
   for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
       if (package_class.equals(service.service.getClassName())) {
           return true;
       }
   }
   return false;
}
/**This method use for PostConnection to Server
*/
public String PostConnection(String strUrl,ArrayList alstNameValuePair) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
// HttpConnectionParams.setConnectionTimeout(mHttpClient.getParams(), 60000); //Timeout Limit
//Pathe of serverside 
HttpPost mHttpPost = new HttpPost(strUrl);
if(alstNameValuePair!=null)
//post the valur you want to pass.
mHttpPost.setEntity(new UrlEncodedFormEntity(alstNameValuePair));
}
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpPost);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
 } 
 catch (Exception e) {
 e.printStackTrace();
 }
String strLine = null;
String strResult = "";
 
//convert response in to the string.
try {
if(mInputStream!=null){
 BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,HTTP.UTF_8), 8);
 StringBuilder mStringBuilder = new StringBuilder();
   while((strLine = mBufferedReader.readLine()) != null) {
  mStringBuilder.append(strLine + "\n");
 }
   strResult = mStringBuilder.toString();
   mInputStream.close();
}
  } 
  catch (Exception e) {
  e.printStackTrace();
   }
return strResult;
}
/**This method use for GetConnectionObject to Server
*/
public String GetConnectionObject(String strUrl) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
//Pathe of serverside 
HttpGet mHttpGet = new HttpGet(strUrl);
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
 } 
 catch (Exception e) {
// TODO Auto-generated catch block
Log.e(Constant.TAG,"Error in HttpClient,HttpPost,HttpResponse,HttpEntity");
 }
String strLine = null;
String strResult = null;
//convert response in to the string.
try{
 BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,"iso-8859-1"), 8);
 StringBuilder mStringBuilder = new StringBuilder();
   while((strLine = mBufferedReader.readLine()) != null){
  mStringBuilder.append(strLine + "\n");
 }
   mInputStream.close();
   strResult = mStringBuilder.toString();
  } 
  catch (Exception e) {
 //System.out.println("Error in BufferedReadering");
     Log.e(Constant.TAG,"Error in BufferedReadering");
   }
return strResult;   
}
}
4)Create class ProcessDialog.java
==============================
 package com.example.demoproject;

import android.R;
import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.Window;
import android.widget.TextView;

public class ProcessDialog extends Dialog{
private TextView title;       
     public ProcessDialog(Context context,String strtitle,String strbody) 
     {
         super(context);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.xcustomdialog);
         setCancelable(true);
         title = (TextView)findViewById(R.id.txtdialogtext);
         title.setText(Html.fromHtml(strbody.toString()));
         show();
     }
}

6)Constants
========
public static final String NETWORK_NOT_AVAILABLE = "Network not available";
public final static String SERVERCONNERROR = "Could not connect to server, Please try again.";
7)cycle_7.xml
==========




8)shake.xml
=========


Thursday 17 October 2013

How to Get Current Location

http://www.vogella.com/articles/AndroidLocationAPI/article.html
package com.example.currentlocationdemo;


import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements LocationListener {
  private TextView latitudeField;
  private TextView longitudeField;
  private LocationManager locationManager;
  private String provider;
  private double latitude,longitude;


/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    latitudeField = (TextView) findViewById(R.id.latituteField);
    longitudeField = (TextView) findViewById(R.id.longitudeField);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
        System.out.println("Provider " + provider + " has been selected.");
       // Toast.makeText(context, text, duration)
        onLocationChanged(location);
    } else {
    latitudeField.setText("Location not available");
      longitudeField.setText("Location not available");
    }
  }

  /* Request updates at startup */
  @Override
  protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(provider, 400, 1, this);
  }

  /* Remove the locationlistener updates when Activity is paused */
  @Override
  protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(this);
  }

  @Override
  public void onLocationChanged(Location location) {
    latitude = (double) (location.getLatitude());
    longitude = (double) (location.getLongitude());
    latitudeField.setText(String.valueOf(latitude));
    longitudeField.setText(String.valueOf(longitude));
  }

  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {

  }

  @Override
  public void onProviderEnabled(String provider) {
    Toast.makeText(this, "Enabled new provider " + provider,
        Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onProviderDisabled(String provider) {
    Toast.makeText(this, "Disabled provider " + provider,
        Toast.LENGTH_SHORT).show();
  }

Get Current location using GPS

package com.mrs.golfapp;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity{
private CommonClass mCommonClass=new CommonClass();
private NotificationManager mNotificationManager=null;
    private Intent mNotificationIntent;
private TextView txtGpsStrength = null;
private TextView txtElapsedTime = null;
public  TextView txtAntal;
private TextView txtRecording;
private Button StartButton=null,PauseButton=null;
private ImageView imgGpsStrength = null;
private LinearLayout lytAntal;
private SharedPreferences mSharedPreferences_Write = null;
private SharedPreferences mSharedPreferences_Read = null;
private final long mFrequency = 100;
    private final int TICK_WHAT = 2;
    private boolean GPS_Recording=false;
    private boolean GPS_Setting_Dialog_Not_Open=true;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.xmain_activity);
        startWakeLock();
       
        mSharedPreferences_Read=getSharedPreferences(Constant.SHAREDPREFERENCE.SHAREDPREFERENCE,MODE_WORLD_READABLE);
        mSharedPreferences_Write=getSharedPreferences(Constant.SHAREDPREFERENCE.SHAREDPREFERENCE,MODE_WORLD_WRITEABLE);
       
        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        mNotificationIntent = new Intent(this, MainActivity.class);
       
        txtGpsStrength = (TextView)findViewById(R.id.txtGpsStrength);
        imgGpsStrength =(ImageView)findViewById(R.id.ImgGpsStrength);

        txtElapsedTime = (TextView)findViewById(R.id.ElapsedTime);
        txtRecording =(TextView)findViewById(R.id.txtRecording);
        txtRecording.setText(getResources().getText(R.string.not_recording));
       
        StartButton = (Button)findViewById(R.id.StartButton);
        PauseButton = (Button)findViewById(R.id.PauseButton);
       
        txtAntal = (TextView)findViewById(R.id.txtAntal);
txtAntal.setText(String.valueOf(mSharedPreferences_Read.getInt(Constant.SHAREDPREFERENCE.NO_OF_PEOPLE, 1)));

        lytAntal = (LinearLayout)findViewById(R.id.lytAntalMensen);
        lytAntal.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Selected_Person=mSharedPreferences_Read.getInt(Constant.SHAREDPREFERENCE.NO_OF_PEOPLE, 1);
AlertDialogSelectPerson();
}
});
       
        startService(new Intent(this, StopwatchService.class));
        bindStopwatchService();
        mHandler.sendMessageDelayed(Message.obtain(mHandler, TICK_WHAT), mFrequency);      
    }

//***********************************************************************************************************************
/**
 * @author Manisha
 * @return
 * @use For update elapsed time
 */
//************************************************************************************************************************
private Handler mHandler = new Handler() {
        public void handleMessage(Message m) {
        updateElapsedTime();
        sendMessageDelayed(Message.obtain(this, TICK_WHAT), mFrequency);
        }
    };
   
//***********************************************************************************************************************
/**
 * @author Manisha
 * @return
 * @use Connection to the backgorund StopwatchService
 */
//************************************************************************************************************************
    private StopwatchService m_StopwatchService=null;
private ServiceConnection m_StopwatchServiceConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
m_StopwatchService = ((StopwatchService.LocalBinder)service).getService();
}

@Override
public void onServiceDisconnected(ComponentName name) {
m_StopwatchService = null;
}
};

private void bindStopwatchService() {
        bindService(new Intent(this, StopwatchService.class),m_StopwatchServiceConn, Context.BIND_AUTO_CREATE);
}

private void unbindStopwatchService() {
if(m_StopwatchService != null ) {
unbindService(m_StopwatchServiceConn);
}
}
   
@Override
public void onDestroy() {
if(m_StopwatchService != null ) {
    m_StopwatchService.reset();
}
         unbindStopwatchService();
         stopService(new Intent(this, StopwatchService.class));
         RemoveLocationManager();
         stopWakeLock();
super.onDestroy();
}

@Override
protected void onRestart() {
super.onRestart();
if(mNotificationManager!=null){
mNotificationManager.cancelAll();
}
}

@Override
protected void onResume() {
    GPS_Setting_Dialog_Not_Open=true;
        getLocation();
super.onResume();
}

@Override
protected void onPause() {
super.onPause();
    if(!isFinishing() && GPS_Setting_Dialog_Not_Open){
    Activity_Minimize();
    }
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param View
 * @return void
 * @use This code is used when user clik on upload button
 */
//************************************************************************************************************************
    public void onStartClicked(View v) {
    Log.d(Constant.TAG, "start button clicked");
    Start_Sending();
    }
   
    private void Start_Sending(){
if(getGPS_Status()){
    if(m_StopwatchService!=null){
    m_StopwatchService.start();
    }
    txtRecording.setText(getResources().getText(R.string.recordig));
    GPS_Recording=true;
    showPauseButtons();
     }
else{
getLocation();
}
    }
   
   
   
//***********************************************************************************************************************
/**
 * @author Manisha
 * @param View
 * @return void
 * @use This code is used when user clik on pause button
 */
//************************************************************************************************************************
   
    public void onPauseClicked(View v) {
    Log.d(Constant.TAG, "pause button clicked");
    Pause_Sending();
    }
   
    private void Pause_Sending(){
    if(m_StopwatchService!=null){
        m_StopwatchService.pause();
    }
    txtRecording.setText(getResources().getText(R.string.not_recording));
    GPS_Recording=false;
    showStartButton();
    }
   
    public void updateElapsedTime() {
    if(m_StopwatchService != null)
    txtElapsedTime.setText(m_StopwatchService.getFormattedElapsedTime());
    }
   
    private void showPauseButtons() {
    Log.d(Constant.TAG, "showPauseLapButtons");
    StartButton.setVisibility(View.GONE);
    PauseButton.setVisibility(View.VISIBLE);
    }
   
    private void showStartButton() {
    Log.d(Constant.TAG, "showStartResetButtons");
    StartButton.setVisibility(View.VISIBLE);
    PauseButton.setVisibility(View.GONE);
    }
       
//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use This method is used for minimize activity
 */
   
//************************************************************************************************************************
    private void Activity_Minimize(){
    Show_Running_Notification();
        Intent mIntent = new Intent(Intent.ACTION_MAIN);      
        mIntent.addCategory(Intent.CATEGORY_HOME);
        startActivity(mIntent);
    }
   
//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use This method is used for show notification
 */
//************************************************************************************************************************  
     private void Show_Running_Notification() {
        CharSequence strNotificationTitle = Constant.NOTIFICATION.NOTIFICATIONTITLE;
        Notification notification = new Notification(R.drawable.ic_notification, strNotificationTitle, System.currentTimeMillis());
        PendingIntent contentIntent = PendingIntent.getActivity(this,0 ,mNotificationIntent,Intent.FLAG_ACTIVITY_NEW_TASK);
        notification.setLatestEventInfo(this, Constant.NOTIFICATION.NOTIFICATIONRUNNINGMESSAGE,Constant.NOTIFICATION.NOTIFICATIONRUNNINGTEXT, contentIntent);
        notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;  
        mNotificationManager.notify(1, notification);
     }
   
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK)
           {  
        Finish_Activity_Alert();
        return true;
        }
        return super.onKeyDown(keyCode, event);
    }
   
//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use This code is for show dialog for person selection
 */
   
//************************************************************************************************************************
    int Selected_Person=0;
    private void AlertDialogSelectPerson(){
   final CharSequence[] items = {"Person 0","Person 1","Person 2","Person 3","Person 4","Person 5","Person 6","Person 7","Person 8",
"Person 9","Person 10","Person 11","Person 12","Person 13","Person 14","Person 15","Person 16","Person 17",
"Person 18","Person 19","Person 20","Person 21","Person 22","Person 23","Person 24","Person 25","Person 26",
"Person 27","Person 28","Person 29","Person 30","Person 31","Person 32","Person 33","Person 34","Person 35",
"Person 36","Person 37","Person 38","Person 39","Person 40"
};
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setTitle(Constant.SELECTPERSONDIALOG.DIALOGTITLE);
     
       builder.setNegativeButton(Constant.SELECTPERSONDIALOG.BUTTON_CANCEL, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
       });
     
       builder.setPositiveButton(Constant.SELECTPERSONDIALOG.BUTTON_OK, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
txtAntal.setText(String.valueOf(Selected_Person));

SharedPreferences.Editor mEditor  = mSharedPreferences_Write.edit();
mEditor.putInt(Constant.SHAREDPREFERENCE.NO_OF_PEOPLE, Selected_Person);
mEditor.commit();
           }
       });

       builder.setSingleChoiceItems(items, Selected_Person, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int item) {
            Selected_Person=item;
           }
       });
       AlertDialog mAlertDialog = builder.create();
       mAlertDialog.show();
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use This code is for show dialog for finish activity
 */
//************************************************************************************************************************
private void Finish_Activity_Alert() {
    AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
    mAlertDialog.setIcon(R.drawable.ic_logo);
    mAlertDialog.setTitle(Constant.FINISHACTIVITYDIALOG.DIALOGTITLE);
       mAlertDialog.setMessage(Constant.FINISHACTIVITYDIALOG.DISCARDMESSAGE);
       mAlertDialog.setCancelable(false);
       mAlertDialog.setButton(Constant.FINISHACTIVITYDIALOG.BUTTON_FINISH, new DialogInterface.OnClickListener() {          
           public void onClick(DialogInterface dialog, int which) {
        finish();
        return;
           }
       });
       mAlertDialog.setButton2(Constant.FINISHACTIVITYDIALOG.BUTTON_CANCEL, new DialogInterface.OnClickListener() {                      
           public void onClick(DialogInterface dialog, int which) {
               dialog.cancel();
               return;
           }
       });
       mAlertDialog.setButton3(Constant.FINISHACTIVITYDIALOG.BUTTON_MINIMIZE, new DialogInterface.OnClickListener() {                      
           public void onClick(DialogInterface dialog, int which) {
            Activity_Minimize();
               dialog.cancel();
               return;
           }
       });
       // Create and show the dialog
       mAlertDialog.show();
}

 //************************************************************************************************************************
 public void Show_GPS_Settings_Alert(){
       AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(this);
       mAlertDialog.setTitle(Constant.GPSSETTING.GPSSETTING_TITLE);
       mAlertDialog.setMessage(Constant.GPSSETTING.GPS_MESSAGE);
       mAlertDialog.setPositiveButton(Constant.GPSSETTING.GPS_POSITIVE_BUTTON, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog,int which) {
            GPS_Setting_Dialog_Not_Open=false;
               Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
               MainActivity.this.startActivity(intent);
               dialog.cancel();
           }
       });
       mAlertDialog.setNegativeButton(Constant.GPSSETTING.GPS_CANCEL_BUTTON, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
           }
       });
       mAlertDialog.show();
 }

  * @use Use the LocationManager class to obtain GPS locations
  */
 //************************************************************************************************************************
 private LocationManager mLocationManager=null;
 private LocationListener mLocationListener =null;
 private void getLocation(){    
        /* Use the LocationManager class to obtain GPS locations */
    if(mLocationManager==null){
  mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  if(getGPS_Status()){
txtGpsStrength.setText(getResources().getString(R.string.gps_locating));
imgGpsStrength.setBackgroundResource(R.drawable.signal_black);
  AddLocationManager();
      }
      else{
       Show_GPS_Settings_Alert();
       mLocationManager=null;
       mLocationListener=null;
      }
    }
 }

 private Boolean getGPS_Status(){
 if(mLocationManager!=null){
  return mLocationManager.isProviderEnabled(Constant.PROVIDER);
 }
 else{
 return false;
 }
 }

 private String getDeviceID(){
return Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
 }
 private void  AddLocationManager() {
if(mLocationManager!=null)
{
mLocationListener = new MyLocationListener();
mLocationManager.requestLocationUpdates(Constant.PROVIDER,Constant.minTime, Constant.minDistance, mLocationListener);
}
 }

 private void RemoveLocationManager() {
if(mLocationListener!=null && mLocationManager!=null)
{
mLocationManager.removeUpdates(mLocationListener);
mLocationListener=null;
mLocationManager=null;
}
 }

 private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc){
if(GPS_Recording){
if(mSendLocation == null){
mSendLocation=new SendLocation();
mSendLocation.execute(loc);
}
}

float accuracy = loc.getAccuracy();
if(accuracy > 30){
            txtGpsStrength.setText(Constant.GPSSETTING.GPS_SIGNAL_OK);
            imgGpsStrength.setBackgroundResource(R.drawable.signal_green);
           }
           else if(accuracy > 20 && accuracy < 30){
            txtGpsStrength.setText(Constant.GPSSETTING.GPS_SIGNAL_AVARAGE);
            imgGpsStrength.setBackgroundResource(R.drawable.signal_orange);
           }
           else if(accuracy < 20){
            txtGpsStrength.setText(Constant.GPSSETTING.GPS_SIGNAL_WEAK);
            imgGpsStrength.setBackgroundResource(R.drawable.signal_red);
           }
}
@Override
public void onProviderDisabled(String provider){
txtGpsStrength.setText(getResources().getString(R.string.gps_off));
imgGpsStrength.setBackgroundResource(R.drawable.signal_gray);
Pause_Sending();
}
@Override
public void onProviderEnabled(String provider){
txtGpsStrength.setText(getResources().getString(R.string.gps_locating));
imgGpsStrength.setBackgroundResource(R.drawable.signal_black);
Start_Sending();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
}
  }

 private SendLocation mSendLocation = null;
 private class SendLocation extends AsyncTask
   {

       protected String doInBackground(Location... location) {
        Log.d(Constant.TAG, "Location Request = " + "doInBackground");
    String strURL=MainActivity.this.getResources().getString(R.string.location_update_url);
    ArrayList alstNameValuePair = new ArrayList();
    alstNameValuePair.add(new BasicNameValuePair(MainActivity.this.getResources().getString(R.string.Action),MainActivity.this.getResources().getString(R.string.Set)));
    alstNameValuePair.add(new BasicNameValuePair(Constant.LOCATION_UPDATE_REQUEST.DEVICEID,getDeviceID().toString()));
    alstNameValuePair.add(new BasicNameValuePair(Constant.LOCATION_UPDATE_REQUEST.LATITUDE,String.valueOf(location[0].getLatitude()).toString()));
    alstNameValuePair.add(new BasicNameValuePair(Constant.LOCATION_UPDATE_REQUEST.LONGITUDE,String.valueOf(location[0].getLongitude()).toString()));
    alstNameValuePair.add(new BasicNameValuePair(Constant.LOCATION_UPDATE_REQUEST.NO_OF_PEOPLE,String.valueOf(mSharedPreferences_Read.getInt(Constant.SHAREDPREFERENCE.NO_OF_PEOPLE, 1))));
    alstNameValuePair.add(new BasicNameValuePair(Constant.LOCATION_UPDATE_REQUEST.TIMESTAMP, new SimpleDateFormat(Constant.TIME_STAMP_FORMAT).format(new Date(location[0].getTime()))));
    Log.d(Constant.TAG, "Location Request = " + alstNameValuePair.toString());
    return mCommonClass.PostConnection(strURL, alstNameValuePair);
       }          
     
       protected void onPostExecute(String result) {
       if(result!=null){
        Log.d(Constant.TAG, "Location Response = " + result.toString());
       }
       else{
       }
           super.onPostExecute(result);
           mSendLocation = null;
       }
   }
 
  private WakeLock mWakeLock=null;
private static final String WAKE_LOCK_TAG = "WAKE_LOCK_LOCATION_UPDATE_SERVICE";
private void startWakeLock() {

   if (mWakeLock == null) {
     Log.d(Constant.TAG, "wakeLock is null, getting a new WakeLock");
     PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
     Log.d(Constant.TAG, "PowerManager acquired");
     mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
     Log.d(Constant.TAG, "WakeLock set");
   }
   mWakeLock.acquire();
   Log.d(Constant.TAG, "WakeLock acquired");
}

private void stopWakeLock() {
   if (mWakeLock != null) {
    mWakeLock.release();
     Log.d(Constant.TAG, "WakeLock released");
   }
}
}