Panagiotis Triantafyllou

telematics fix

...@@ -256,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener ...@@ -256,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
256 //TODO: comment the first block and uncomment the second block if needs revert to handler implementation 256 //TODO: comment the first block and uncomment the second block if needs revert to handler implementation
257 if (mLatitude != 0 && mLongitude != 0) { 257 if (mLatitude != 0 && mLongitude != 0) {
258 mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); 258 mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
259 - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " m/s^2"); 259 + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h");
260 } 260 }
261 261
262 262
...@@ -321,7 +321,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener ...@@ -321,7 +321,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
321 321
322 private void initViews() { 322 private void initViews() {
323 mTvVelocity.setText("0.0 m/s^2"); 323 mTvVelocity.setText("0.0 m/s^2");
324 - mTvAvgVelocity.setText("0.0 m/s^2"); 324 + mTvAvgVelocity.setText("0.0 km/h");
325 } 325 }
326 326
327 private void requestLocationUpdates() { 327 private void requestLocationUpdates() {
...@@ -352,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener ...@@ -352,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
352 @Override 352 @Override
353 public void run() { 353 public void run() {
354 double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); 354 double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
355 - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " m/s^2"); 355 + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h");
356 mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL); 356 mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL);
357 } 357 }
358 }; 358 };
...@@ -368,8 +368,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener ...@@ -368,8 +368,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
368 // Function to calculate speed in meters per second 368 // Function to calculate speed in meters per second
369 private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) { 369 private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) {
370 double distance = calculateDistance(lat1, lon1, lat2, lon2); 370 double distance = calculateDistance(lat1, lon1, lat2, lon2);
371 -// return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h; 371 + return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
372 - return (distance / timeDifferenceInSeconds); // Convert to km/h;
373 } 372 }
374 373
375 private void requestSingleLocationUpdate() { 374 private void requestSingleLocationUpdate() {
...@@ -446,7 +445,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener ...@@ -446,7 +445,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
446 touchCount = 0; 445 touchCount = 0;
447 mSensorManager.unregisterListener(this); 446 mSensorManager.unregisterListener(this);
448 mTvVelocity.setText("0.0 m/s^2"); 447 mTvVelocity.setText("0.0 m/s^2");
449 - mTvAvgVelocity.setText("0.0 m/s^2"); 448 + mTvAvgVelocity.setText("0.0 km/h");
450 Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show(); 449 Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show();
451 if (mHandler != null) 450 if (mHandler != null)
452 mHandler.removeCallbacks(mRunnable); 451 mHandler.removeCallbacks(mRunnable);
......