Panagiotis Triantafyllou

telematics changes

......@@ -15,6 +15,7 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
......@@ -88,7 +89,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
final long REFRESH_TIME = 100; // miliseconds
private String mStartTimestamp = "", mStopTimestamp = "";
private final int RECORDS_INTERVAL = 5000;
private EditText mEtLimit;
private EditText mEtLimit, mEtSampleTime;
// ===========================================================
......@@ -114,6 +115,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mTvOrientationCount = findViewById(R.id.tv_orientation);
mTvTouchCount = findViewById(R.id.tv_touch);
mEtLimit = findViewById(R.id.et_acceleration);
mEtSampleTime = findViewById(R.id.et_save);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
previousLocation = null;
......@@ -176,8 +178,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
velocity = acceleration * time;
}
// Convert velocity to km/h
mAcceleration = velocity * 3.6f; // Convert to km/h
mTvVelocity.setText(String.format("%.1f", mAcceleration) + " km/h");
// mAcceleration = velocity * 3.6f; // Convert to km/h
mAcceleration = velocity; // Convert to km/h
mTvVelocity.setText(String.format("%.1f", velocity) + " m/s^2");
// Update last values
lastX = filteredX;
lastY = filteredY;
......@@ -253,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
//TODO: comment the first block and uncomment the second block if needs revert to handler implementation
if (mLatitude != 0 && mLongitude != 0) {
mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h");
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " m/s^2");
}
......@@ -317,8 +320,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
// ===========================================================
private void initViews() {
mTvVelocity.setText("0.0 km/h");
mTvAvgVelocity.setText("0.0 km/h");
mTvVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 m/s^2");
}
private void requestLocationUpdates() {
......@@ -349,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
public void run() {
double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h");
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " m/s^2");
mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL);
}
};
......@@ -365,7 +368,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
// Function to calculate speed in meters per second
private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) {
double distance = calculateDistance(lat1, lon1, lat2, lon2);
return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
// return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
return (distance / timeDifferenceInSeconds); // Convert to km/h;
}
private void requestSingleLocationUpdate() {
......@@ -430,10 +434,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
e.printStackTrace();
Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show();
}
mHandler.postDelayed(this, RECORDS_INTERVAL);
mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString()));
}
};
mHandler.postDelayed(mRunnable, RECORDS_INTERVAL);
mHandler.postDelayed(mRunnable, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString()));
}
private void unregisterSensor() {
......@@ -441,8 +445,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
orientationCount = 0;
touchCount = 0;
mSensorManager.unregisterListener(this);
mTvVelocity.setText("0.0 km/h");
mTvAvgVelocity.setText("0.0 km/h");
mTvVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 m/s^2");
Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show();
if (mHandler != null)
mHandler.removeCallbacks(mRunnable);
......