Tuesday 28 April 2015

Gps Signal strength

1)MainActivity.java
===============
package com.mrs.golfapp;

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();
}

//***********************************************************************************************************************
 /**
  * @author Manisha
  * @param none
  * @return void
  * @use This code is for show dialog for show dialog if gps is not turn on.
  */
 //************************************************************************************************************************
 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();
 }

//***********************************************************************************************************************
 /**
  * @author Manisha
  * @param none
  * @return void
  * @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<Location, String, String>
   {
       protected String doInBackground(Location... location) {
        Log.d(Constant.TAG, "Location Request = " + "doInBackground");
    String strURL=MainActivity.this.getResources().getString(R.string.location_update_url);
    ArrayList<NameValuePair> alstNameValuePair = new ArrayList<NameValuePair>();
    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");
   }
}
}

2)CommonClass.java
================
package com.mrs.golfapp;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

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.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 CommonClass {
private ConnectivityManager connectivity=null;
private NetworkInfo netinfo=null;
public static String LoginMessage="";
// private static final String TAG="ServerConnection";

/**This method is used 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, "Not Network Connectivity Available", Toast.LENGTH_SHORT).show();
        Log.e("Let Recycle", "Not Network Connectivity Avialable");
        return false;      
        }
}
/**This method is used for check Network Connectivity
*/
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
   {
    LoginMessage="Not Network Connectivity Avilable";
    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<NameValuePair> 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;
}
}

3)Constant.java
=============
package com.mrs.golfapp;

import android.location.LocationManager;

public class Constant {
public static final String TAG="GOLF_APP";
/**This is for Location */
public static final String PROVIDER = LocationManager.GPS_PROVIDER;
public static final int minTime = 1000;
public static final int minDistance = 1;

public static final String LOCATION_MESSAGE = "Please wait for location.";
    public static final String PROVIDER_NOT="Location Provider not available, please turn on GPS";
    public static final String LOCATION_NOT_FOUND = "Location Not Found";
    public static final String NotificationMessage = "GolfclubZeewolde minimize";
    
    public static final String TIME_STAMP_FORMAT="yyyy-MM-dd HH:mm:ss";
    
    /** this constant is for store no. of people in shared preference*/
    public static final class SHAREDPREFERENCE {
    public static final String SHAREDPREFERENCE = "SP";
    public static final String NO_OF_PEOPLE = "NoOfPeople ";
    }
    
    /**it use for check service*/
    public static final String LOCATION_UPDATE_SERVICE="com.mrs.golfapp.Location_Update_Service";
    
    /**This is for location update request*/
    public static final class LOCATION_UPDATE_REQUEST {
   public static final String DEVICEID="id";
   public static final String LATITUDE="latitude";
   public static final String LONGITUDE="longitude";
   public static final String NO_OF_PEOPLE = "no_of_ppl";
   public static final String TIMESTAMP="timestamp";
    }
    
    /**This is for finish activity dialog*/
    public static final class FINISHACTIVITYDIALOG {
   public static final String DIALOGTITLE = "Golftrack";
   public static final String DISCARDMESSAGE = "Which action do you want to perform?";
   public static final String BUTTON_MINIMIZE = "Minimize";
   public static final String BUTTON_FINISH = "Exit";
   public static final String BUTTON_CANCEL = "Cancel";
    }
    
    /**This is for select person dialog*/
    public static final class SELECTPERSONDIALOG{
   public static final String DIALOGTITLE ="Select Person";
   public static final String BUTTON_OK = "OK";
   public static final String BUTTON_CANCEL = "Cancel";
    }
    
    /**This is for notification text*/
    public static final class NOTIFICATION{
   public static final String NOTIFICATIONTITLE ="Golftrack";
   public static final String NOTIFICATIONRUNNINGMESSAGE ="Golftrack Running...";
   public static final String NOTIFICATIONRUNNINGTEXT ="Tap here to open application.";
//    public static final String NOTIFICATIONMESSAGE ="Golftrack not running";
//    public static final String NOTIFICATIONTEXT ="Not Running";
    }
    
    /**This is for notification text*/
    public static final class GPSSETTING{
   public static final String GPSSETTING_TITLE ="GPS settings";
   public static final String GPS_MESSAGE ="GPS is not enabled. Do you want to go to settings menu?";
   public static final String GPS_POSITIVE_BUTTON = "Settings";
   public static final String GPS_CANCEL_BUTTON = "Cancel";
   public static final String GPS_SIGNAL_OK = "GPS Signal OK";
   public static final String GPS_SIGNAL_AVARAGE = "GPS Signal Average";
   public static final String GPS_SIGNAL_WEAK = "GPS Signal Weak";
    }
}
4)splashscreen.java
==============package com.mrs.golfapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen 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.xsplashscreen);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
//        DisplayMetrics metrics = new DisplayMetrics();
//        getWindowManager().getDefaultDisplay().getMetrics(metrics);
    }
    
    @Override
    protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    Thread th = new Thread(){
    public void run(){
    try{
    sleep(2500);
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    Intent in = new Intent(getBaseContext(), MainActivity.class);
    startActivity(in);
    finish();
    }
    };
    };
    th.start();
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME){
    return true;
    }
    return super.onKeyDown(keyCode, event);
    }
}

5)xmain_activity.xml
================
<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="fill_parent"
    android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/top_tab" >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="5dip"
                    android:src="@drawable/golf_icon" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="6dip"
                    android:gravity="left"
                    android:padding="@dimen/padding_medium"
                    android:text="@string/navigation_title"
                    android:textColor="@color/BLACK"
                    android:textSize="14sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center|center_vertical"
                android:orientation="horizontal" 
                android:layout_marginTop="10dip">

                <ImageView
                    android:id="@+id/ImgGpsStrength"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/signal_gray" />

                <TextView
                    android:id="@+id/txtGpsStrength"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dip"
                    android:gravity="center"
                    android:padding="@dimen/padding_medium"
                    android:text="@string/gps_off"
                    android:textColor="@color/SilverDark"
                    android:textSize="16sp"
                    android:textStyle="bold" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="0.2dip"
                android:background="@color/SilverBest" />

            <TextView
                android:id="@+id/ElapsedTime"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:layout_marginTop="2dip"
                android:gravity="center"
                android:text="00:00:00"
                android:textColor="@color/Gray"
                android:textSize="55sp"
                android:textStyle="bold" />
            <LinearLayout
                android:id="@+id/lytAntalMensen"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:gravity="center" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="10dip"
                    android:gravity="center"
                    android:text="@string/antal_mensen"
                    android:textColor="@color/SilverDark"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/txtAntal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="1dip"
                    android:gravity="center"
                    android:text="@string/no_of_person"
                    android:textColor="@color/SilverDark"
                    android:textSize="16sp" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="7dip"
                android:layout_weight="1"
                android:gravity="center" >

                <Button
                    android:id="@+id/StartButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_timer_play"
                    android:gravity="center"
                    android:onClick="onStartClicked" />

                <Button
                    android:id="@+id/PauseButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_timer_pause"
                    android:gravity="center"
                    android:onClick="onPauseClicked"
                    android:visibility="gone" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dip"
                android:layout_gravity="center"
                android:layout_marginLeft="20dip"
                android:layout_marginRight="20dip"
                android:layout_marginBottom="10dip"
                android:gravity="center" >

                <TextView
                    android:id="@+id/txtRecording"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:text="@string/recordig"
                    android:textColor="@color/SilverDark"
                    android:textSize="16sp" />
            </LinearLayout>
        </LinearLayout>
</LinearLayout>
6)xsplashscree.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
  android:layout_width = "fill_parent"
  android:layout_height = "fill_parent"
  android:layout_gravity = "center"
  android:background = "@drawable/splash_screen"/>
</LinearLayout>

7)string.xml
==========
<resources>
    <string name="app_name">Golftrack</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">GolfTrack</string>

<string name="navigation_title">Golftrack</string>
<string name="gps_locating">GPS Locating...</string>
<string name="gps_off">GPS OFF</string>
<string name="antal_mensen">"Aantal mensen:"</string>
<string name="no_of_person">"1"</string>
<string name="recordig">Door op bovenstaande knop te drukken wordt uw locatie  anoniem gedeeld met Golfclub Zeewolde</string>
<string name="not_recording">Uw locatie wordt nu constant doorgegeven aan Golfclub Zeewolde</string>
<!-- Local Webservice Url -->
<!-- <string name="location_update_url">http://192.168.0.103/php-projects/golftrack/</string> -->
<!-- <string name="location_update_url">http://180.211.110.196/php-projects/golftrack/</string> -->

<!-- Live Webservice Url -->
<string name="location_update_url">http://view.golftrack.eu/service/index.php</string>
<string name="Action">action</string>
<string name="Set">set</string>
</resources>

8)manifest.xml
===========
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mrs.golfapp"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    
    <application
        android:icon="@drawable/ic_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:debuggable="false">
        <activity
            android:name="com.mrs.golfapp.SplashScreen"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <service android:name=".StopwatchService"
            android:icon="@drawable/ic_logo"
            android:label="@string/app_name" />
    </application>

</manifest>


9)Stopwatch.java
=============
package com.mrs.golfapp;

import java.util.ArrayList;
import java.util.List;

public class Stopwatch {

//***********************************************************************************************************************
/**
 * @author Manisha
 * @use Implements a method that returns the current time, in milliseconds.
 */
//************************************************************************************************************************

public interface GetTime {
public long now();
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return long
 * @use Default way to get time. Just use the system clock.
 */
//************************************************************************************************************************

private GetTime SystemTime = new GetTime() {
@Override
public long now() { return System.currentTimeMillis(); }
};

public enum State { PAUSED, RUNNING };
private GetTime m_time;
private long m_startTime;
private long m_stopTime;
private long m_pauseOffset;
private List<Long> m_laps = new ArrayList<Long>();
private State m_state;

public Stopwatch() {
m_time = SystemTime;
reset();
}
public Stopwatch(GetTime time) {
m_time = time;
reset();
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use Start the stopwatch running. If the stopwatch is already running, this does nothing.
 */
//************************************************************************************************************************

public void start() {
if ( m_state == State.PAUSED ) {
m_pauseOffset = getElapsedTime();
m_stopTime = 0;
m_startTime = m_time.now();
m_state = State.RUNNING;
}
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use Pause the stopwatch. If the stopwatch is already running, do nothing.
 */
//***********************************************************************************************************************
public void pause() {
if ( m_state == State.RUNNING ) {
m_stopTime = m_time.now();
m_state = State.PAUSED;
}
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use  Reset the stopwatch to the initial state, clearing all stored times.
 */
//***********************************************************************************************************************
public void reset() {
m_state = State.PAUSED;
m_startTime = 0;
m_stopTime = 0;
m_pauseOffset = 0;
m_laps.clear();
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return void
 * @use  Record a lap at the current time.
 */
public void lap() {
m_laps.add(getElapsedTime());
}

//********************************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return The amount of time recorded by the stopwatch, in milliseconds
 */
//********************************************************************************************************************************

public long getElapsedTime() {
if ( m_state == State.PAUSED ) {
return (m_stopTime - m_startTime) + m_pauseOffset;
} else {
return (m_time.now() - m_startTime) + m_pauseOffset;
}
}

//********************************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return A list of the laps recorded. Each lap is given as a millisecond
 *   value from when the stopwatch began running.
 */
//********************************************************************************************************************************

public List<Long> getLaps() {
return m_laps;
}

//********************************************************************************************************************************
/**
 * @author Manisha
 * @param none
 * @return true if the stopwatch is currently running and recording
 *   time, false otherwise.
 */
//********************************************************************************************************************************

public boolean isRunning() {
return (m_state == State.RUNNING);
}
}
10)StopwatchService.java
===================
package com.mrs.golfapp;


import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class StopwatchService extends Service {
private final String TAG = "StopwatchService";
public class LocalBinder extends Binder {
StopwatchService getService() {
return StopwatchService.this;
}
}
private static Stopwatch m_stopwatch;
private LocalBinder m_binder = new LocalBinder();
@Override
public IBinder onBind(Intent intent) {
Log.d(TAG, "bound");
return m_binder;
}

@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "created");
m_stopwatch = new Stopwatch();
}
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("LocalService", "Received start id " + startId + ": " + intent);
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        return START_STICKY;
    }

    
public void start() {
Log.d(TAG, "start");
m_stopwatch.start();
}
public void pause() {
Log.d(TAG, "pause");
m_stopwatch.pause();
}
public void lap() {
Log.d(TAG, "lap");
m_stopwatch.lap();
}
public void reset() {
Log.d(TAG, "reset");
m_stopwatch.reset();
}
public static long getElapsedTime() {
return m_stopwatch.getElapsedTime();
}
public static String getFormattedElapsedTime() {
return formatElapsedTime(getElapsedTime());
}
public boolean isStopwatchRunning() {
return m_stopwatch.isRunning();
}

//***********************************************************************************************************************
/**
 * @author Manisha
 * @param now, the current time in tenths of seconds
 * @return String with the current time in the format MM:SS.T or 
HH:MM:SS.T, depending on elapsed time.
 * @use Given the time elapsed in tenths of seconds, returns the string
  representation of that time. 
 */
//************************************************************************************************************************
private static String formatElapsedTime(long now) {
long hours=0, minutes=0, seconds=0, tenths=0;
StringBuilder sb = new StringBuilder();
if (now < 1000) {
tenths = now / 100;
} else if (now < 60000) {
seconds = now / 1000;
now -= seconds * 1000;
tenths = (now / 100);
} else if (now < 3600000) {
hours = now / 3600000;
now -= hours * 3600000;
minutes = now / 60000;
now -= minutes * 60000;
seconds = now / 1000;
now -= seconds * 1000;
tenths = (now / 100);
}
if (hours > 0) {
sb.append(hours).append(":")
.append(formatDigits(hours)).append(":")
.append(formatDigits(minutes)).append(":")
.append(formatDigits(seconds));
} else {
sb.append(formatDigits(hours)).append(":")
.append(formatDigits(minutes)).append(":")
.append(formatDigits(seconds));
}
return sb.toString();
}
private static String formatDigits(long num) {
return (num < 10) ? "0" + num : new Long(num).toString();
}
}