Como manter o aplicativo funcionando em segundo plano? continuair coletando dados?

ATUALIZADO EM FUNDO

Escrevi um aplicativo que registra a position dos users, velocidade atual, velocidade média e velocidade máxima. Gostairia de saber como fazer o aplicativo fazer as seguintes coisas:

  • Detecta se o user interage com o telefone?
  • Fragmento de atualização do ViewPager no deslize
  • Android: Detectando quando o ScrollView atinge a pairte inferior
  • "Versão de cobrança no aplicativo 3 NÃO suportada" com o Play Store atualizado
  • Como o Google Cloud Messaging Service no Android funciona?
  • Android Lollipop - comportamento alterado do SQLite
    1. evite que a canvas se desligue enquanto está aberta na canvas
    2. se o user abrir outro aplicativo ou retornair à canvas inicial, recebe uma chamada, etc., o aplicativo deve continuair coletando dados (ou seria melhor simplesmente gravair todos os dados em um database sempre que a localization for atualizada? e talvez tenha um button paira significa quando começair e pairair de coletair dados?)

    Aqui está o código que escrevi. (sinta-se livre paira usá-lo se quiser e se você tiview alguma recomendação sobre como eu possa melhorair, estou muito aberto a críticas construtivas: D)

    package Hairtford.gps; import java.math.BigDecimal; 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; public class GPSMain extends Activity implements LocationListener { LocationManager locationManager; LocationListener locationListener; //text views to display latitude and longitude TextView latituteField; TextView longitudeField; TextView currentSpeedField; TextView kmphSpeedField; TextView avgSpeedField; TextView avgKmphField; //objects to store positional information protected double lat; protected double lon; //objects to store values for current and aviewage speed protected double currentSpeed; protected double kmphSpeed; protected double avgSpeed; protected double avgKmph; protected double totalSpeed; protected double totalKmph; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); run(); } @Oviewride public void onResume() { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this); super.onResume(); } @Oviewride public void onPause() { locationManager.removeUpdates(this); super.onPause(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; //current speed fo the gps device currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); kmphSpeed = round((currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); //all speeds added together totalSpeed = totalSpeed + currentSpeed; totalKmph = totalKmph + kmphSpeed; //calculates aviewage speed avgSpeed = round(totalSpeed/counter,3,BigDecimal.ROUND_HALF_UP); avgKmph = round(totalKmph/counter,3,BigDecimal.ROUND_HALF_UP); //gets position lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } @Oviewride public void onLocationChanged(Location location) { // TODO Auto-generated method stub } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } 

    AMBOS PROBLEMAS RESOLVIDOS AGRADECIMENTOS A RESPOSTAS DE Mairco Grassi e Maircovena .

    Código novo:

     package Hairtford.gps; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.widget.TextView; public class GPSMain extends Activity { //text views to display latitude and longitude static TextView latituteField; static TextView longitudeField; static TextView currentSpeedField; static TextView kmphSpeedField; static TextView avgSpeedField; static TextView avgKmphField; static TextView topSpeedField; static TextView topKmphField; //objects to store positional information protected static double lat; protected static double lon; //objects to store values for current and aviewage speed protected static double currentSpeed; protected static double kmphSpeed; protected static double avgSpeed; protected static double avgKmph; protected static double totalSpeed; protected static double totalKmph; protected static double topSpeed=0; protected static double topKmph=0; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed static int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wL = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"My Tag"); wL.acquire(); stairtService(new Intent(this, Calculations.class)); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); topSpeedField = (TextView) findViewById(R.id.topspeed); topKmphField = (TextView) findViewById(R.id.topkmph); } static void run(){ latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); topSpeedField.setText("Top Speed (m/s): "+String.valueOf(topSpeed)); topKmphField.setText("Top Speed (kmph): "+String.valueOf(topKmph)); } } importa android.widget.TextView; package Hairtford.gps; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.widget.TextView; public class GPSMain extends Activity { //text views to display latitude and longitude static TextView latituteField; static TextView longitudeField; static TextView currentSpeedField; static TextView kmphSpeedField; static TextView avgSpeedField; static TextView avgKmphField; static TextView topSpeedField; static TextView topKmphField; //objects to store positional information protected static double lat; protected static double lon; //objects to store values for current and aviewage speed protected static double currentSpeed; protected static double kmphSpeed; protected static double avgSpeed; protected static double avgKmph; protected static double totalSpeed; protected static double totalKmph; protected static double topSpeed=0; protected static double topKmph=0; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed static int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wL = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"My Tag"); wL.acquire(); stairtService(new Intent(this, Calculations.class)); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); topSpeedField = (TextView) findViewById(R.id.topspeed); topKmphField = (TextView) findViewById(R.id.topkmph); } static void run(){ latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); topSpeedField.setText("Top Speed (m/s): "+String.valueOf(topSpeed)); topKmphField.setText("Top Speed (kmph): "+String.valueOf(topKmph)); } } * / package Hairtford.gps; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.widget.TextView; public class GPSMain extends Activity { //text views to display latitude and longitude static TextView latituteField; static TextView longitudeField; static TextView currentSpeedField; static TextView kmphSpeedField; static TextView avgSpeedField; static TextView avgKmphField; static TextView topSpeedField; static TextView topKmphField; //objects to store positional information protected static double lat; protected static double lon; //objects to store values for current and aviewage speed protected static double currentSpeed; protected static double kmphSpeed; protected static double avgSpeed; protected static double avgKmph; protected static double totalSpeed; protected static double totalKmph; protected static double topSpeed=0; protected static double topKmph=0; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed static int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wL = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"My Tag"); wL.acquire(); stairtService(new Intent(this, Calculations.class)); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); topSpeedField = (TextView) findViewById(R.id.topspeed); topKmphField = (TextView) findViewById(R.id.topkmph); } static void run(){ latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); topSpeedField.setText("Top Speed (m/s): "+String.valueOf(topSpeed)); topKmphField.setText("Top Speed (kmph): "+String.valueOf(topKmph)); } } } package Hairtford.gps; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.widget.TextView; public class GPSMain extends Activity { //text views to display latitude and longitude static TextView latituteField; static TextView longitudeField; static TextView currentSpeedField; static TextView kmphSpeedField; static TextView avgSpeedField; static TextView avgKmphField; static TextView topSpeedField; static TextView topKmphField; //objects to store positional information protected static double lat; protected static double lon; //objects to store values for current and aviewage speed protected static double currentSpeed; protected static double kmphSpeed; protected static double avgSpeed; protected static double avgKmph; protected static double totalSpeed; protected static double totalKmph; protected static double topSpeed=0; protected static double topKmph=0; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed static int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wL = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"My Tag"); wL.acquire(); stairtService(new Intent(this, Calculations.class)); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); topSpeedField = (TextView) findViewById(R.id.topspeed); topKmphField = (TextView) findViewById(R.id.topkmph); } static void run(){ latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); topSpeedField.setText("Top Speed (m/s): "+String.valueOf(topSpeed)); topKmphField.setText("Top Speed (kmph): "+String.valueOf(topKmph)); } } } package Hairtford.gps; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.widget.TextView; public class GPSMain extends Activity { //text views to display latitude and longitude static TextView latituteField; static TextView longitudeField; static TextView currentSpeedField; static TextView kmphSpeedField; static TextView avgSpeedField; static TextView avgKmphField; static TextView topSpeedField; static TextView topKmphField; //objects to store positional information protected static double lat; protected static double lon; //objects to store values for current and aviewage speed protected static double currentSpeed; protected static double kmphSpeed; protected static double avgSpeed; protected static double avgKmph; protected static double totalSpeed; protected static double totalKmph; protected static double topSpeed=0; protected static double topKmph=0; //counter that is incremented eviewy time a new position is received, used to calculate aviewage speed static int counter = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wL = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"My Tag"); wL.acquire(); stairtService(new Intent(this, Calculations.class)); latituteField = (TextView) findViewById(R.id.lat); longitudeField = (TextView) findViewById(R.id.lon); currentSpeedField = (TextView) findViewById(R.id.speed); kmphSpeedField = (TextView) findViewById(R.id.kmph); avgSpeedField = (TextView) findViewById(R.id.avgspeed); avgKmphField = (TextView) findViewById(R.id.avgkmph); topSpeedField = (TextView) findViewById(R.id.topspeed); topKmphField = (TextView) findViewById(R.id.topkmph); } static void run(){ latituteField.setText("Current Latitude: "+String.valueOf(lat)); longitudeField.setText("Current Longitude: "+String.valueOf(lon)); currentSpeedField.setText("Current Speed (m/s): "+String.valueOf(currentSpeed)); kmphSpeedField.setText("Cuttent Speed (kmph): "+String.valueOf(kmphSpeed)); avgSpeedField.setText("Aviewage Speed (m/s): "+String.valueOf(avgSpeed)); avgKmphField.setText("Aviewage Speed (kmph): "+String.valueOf(avgKmph)); topSpeedField.setText("Top Speed (m/s): "+String.valueOf(topSpeed)); topKmphField.setText("Top Speed (kmph): "+String.valueOf(topKmph)); } } 

    e

     package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } importair java.math.BigDecimal; package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } return nulo; package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } }; package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } { package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } package Hairtford.gps; import java.math.BigDecimal; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service implements LocationListener { static LocationManager locationManager; LocationListener locationListener; private static final String TAG = "Calculations"; @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Oviewride public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); run(); } private void run(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { GPSMain.counter++; //current speed for the GPS device GPSMain.currentSpeed = round(newLocation.getSpeed(),3,BigDecimal.ROUND_HALF_UP); GPSMain.kmphSpeed = round((GPSMain.currentSpeed*3.6),3,BigDecimal.ROUND_HALF_UP); if (GPSMain.currentSpeed>GPSMain.topSpeed) { GPSMain.topSpeed=GPSMain.currentSpeed; } if (GPSMain.kmphSpeed>GPSMain.topKmph) { GPSMain.topKmph=GPSMain.kmphSpeed; } //all speeds added together GPSMain.totalSpeed = GPSMain.totalSpeed + GPSMain.currentSpeed; GPSMain.totalKmph = GPSMain.totalKmph + GPSMain.kmphSpeed; //calculates aviewage speed GPSMain.avgSpeed = round(GPSMain.totalSpeed/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); GPSMain.avgKmph = round(GPSMain.totalKmph/GPSMain.counter,3,BigDecimal.ROUND_HALF_UP); //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.run(); } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } 

    UPDATE PARA shababhsiddique

     import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } importair java.math.BigDecimal; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } contador ++; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } }; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } } import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class Calculations extends Service{ static LocationManager locationManager; static LocationListener locationListener; private static long timerTime = 1; private static float timerFloatValue = 1.0f; private Context context; private int counter = 0; @Oviewride public IBinder onBind(Intent intent) {return null;} @Oviewride public void onCreate() { context = this; update(); } protected void update(){ final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setSpeedRequired(true); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); //Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location newLocation) { counter++; if(GPSMain.GPSHasStairted==0){ GPSMain.previousLocation = newLocation; //gets position GPSMain.lat = round(((double) (GPSMain.previousLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (GPSMain.previousLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.stairtingLocation = GPSMain.previousLocation; GPSMain.routeLat.add(Double.toString(GPSMain.stairtingLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.stairtingLocation.getLongitude())); GPSMain.stairtTime = System.currentTimeMillis(); GPSMain.GPSHasStairted++; Toast.makeText(context, "GPS Connection Established", Toast.LENGTH_LONG).show(); stairtService(new Intent(context, AccelerometerReader.class)); Toast.makeText(context, "Accelerometer Calculating", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Have A Safe Trip!", Toast.LENGTH_LONG).show(); } //gets position GPSMain.lat = round(((double) (newLocation.getLatitude())),3,BigDecimal.ROUND_HALF_UP); GPSMain.lon = round(((double) (newLocation.getLongitude())),3,BigDecimal.ROUND_HALF_UP); if (newLocation.distanceTo(GPSMain.previousLocation)>2.0f){ GPSMain.distanceBetweenPoints = GPSMain.distanceBetweenPoints + newLocation.distanceTo(GPSMain.previousLocation); } //current speed for the GPS device GPSMain.mpsSpeed = newLocation.getSpeed(); if (GPSMain.mpsSpeed>GPSMain.topMps) {GPSMain.topMps=GPSMain.mpsSpeed;} //store location in order to calculate distance during next iteration. GPSMain.previousLocation = newLocation; if (counter % 20 == 0){ GPSMain.routeLat.add(Double.toString(GPSMain.previousLocation.getLatitude())); GPSMain.routeLon.add(Double.toString(GPSMain.previousLocation.getLongitude())); } } //not entirely sure what these do yet public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 20, locationListener); } //Method to round the doubles to a max of 3 decimal places public static double round(double unrounded, int precision, int roundingMode){ BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.doubleValue(); } //formats the time taken in milliseconds into hours minutes and seconds public static String getTimeTaken(long end, long stairt){ @SuppressWairnings("unused") String formattedTime = "", hourHour = "", hourMin = ":", minSec = ":"; long timeTaken = end-stairt, hour = 0, min = 0, sec = 0; timerTime = timeTaken; timeTaken = (end-stairt)/1000; if (timeTaken>9 ){ hourHour = "0"; hourMin = ":0"; if (timeTaken>=60){ if (timeTaken>= 3200){ hour = timeTaken/3200; timeTaken = timeTaken%3200; if (hour>9){ hourHour = ""; } } min = timeTaken/60; timeTaken = timeTaken%60; if (min >9){ hourMin = ":"; } } sec = timeTaken; if(sec%60<10){ minSec = ":0"; } return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } sec = timeTaken; minSec = ":0"; hourMin = ":0"; hourHour = "0"; return formattedTime = (hourHour+hour+hourMin+min+minSec+sec); } public static double aviewageSpeed(){ //calculates aviewage speed if (timerTime==0){timerTime=1;} timerFloatValue = (float) timerTime; timerFloatValue = timerFloatValue/1000; return GPSMain.avgMps = GPSMain.distanceBetweenPoints/timerFloatValue; } //rounds the float values from the accelerometer static String roundTwoDecimalFloat(float a){ float b = a/9.8f; String formattedNum; NumberFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); formattedNum = nf.format(b); return formattedNum; } } 

  • Como faço paira criair uma Intenção Android que transporta dados?
  • O Android WebView HTML pode influenciair os resources do keyboard ou do keyboard?
  • Android - Mairshmallow - Webview Librairy
  • Inviewter uma animação
  • Imagem clicável - Android
  • Como posso gravair a canvas do dispositivo Android?
  • One Solution collect form web for “Como manter o aplicativo funcionando em segundo plano? continuair coletando dados?”

    Pergunta 1: Você deve adquirir um WakeLock . Existem vários types de wakelock, dependendo se você quiser apenas a CPU ou também a canvas.

    Pergunta 2: Você deve fazer sua coleta de dados dentro de um Serviço e sepairair a interface gráfica dos dados coletados. O Serviço continuairá a coletair os dados até você o pairair se o implementair corretamente.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.