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);
......
......@@ -39,6 +39,11 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ScrollView
android:fillViewport="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
......@@ -72,10 +77,10 @@
fontPath="fonts/PeridotPE-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_sensor_data"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Acceleration"
android:layout_below="@+id/tv_sensor_data"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
......@@ -88,17 +93,17 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
android:textSize="20sp" />
<TextView
android:id="@+id/tv_avg_label"
fontPath="fonts/PeridotPE-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_velocity"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Velocity"
android:layout_below="@+id/tv_velocity"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
......@@ -111,18 +116,18 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
android:textSize="20sp" />
<TextView
android:id="@+id/tv_orientation_label"
fontPath="fonts/PeridotPE-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_avg"
android:layout_alignParentStart="true"
android:layout_marginTop="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="Orientation Count"
android:layout_below="@+id/tv_avg"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
......@@ -144,12 +149,12 @@
fontPath="fonts/PeridotPE-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_avg"
android:layout_alignParentEnd="true"
android:layout_marginTop="24dp"
android:paddingEnd="24dp"
android:layout_marginEnd="24dp"
android:layout_alignParentEnd="true"
android:text="Touch Count"
android:layout_below="@+id/tv_avg"
android:layout_alignEnd="@+id/tv_orientation_label"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
......@@ -171,10 +176,10 @@
fontPath="fonts/PeridotPE-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_orientation"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Records Saved"
android:layout_below="@+id/tv_orientation"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
......@@ -194,21 +199,36 @@
fontPath="fonts/PeridotPE-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="@color/blue_dark"
android:textSize="16sp"
android:layout_below="@+id/tv_records"
android:layout_alignParentStart="true"
android:layout_marginTop="24dp"
android:layout_marginStart="24dp"
android:hint="Cut off in m/s^2"
android:inputType="phone"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
<EditText
android:id="@+id/et_save"
fontPath="fonts/PeridotPE-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_records"
android:layout_alignParentEnd="true"
android:paddingEnd="24dp"
android:layout_marginTop="24dp"
android:hint="Cut off in km/h"
android:layout_below="@+id/tv_records"/>
android:hint="Sample Interval in ms"
android:inputType="phone"
android:textColor="@color/blue_dark"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/ll_activate_button"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/et_acceleration"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="56dp"
android:layout_marginVertical="56dp"
android:background="@drawable/selector_button_green_border"
android:gravity="center"
android:orientation="horizontal">
......@@ -225,4 +245,5 @@
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
\ No newline at end of file
......