Panagiotis Triantafyllou

telematics additions

......@@ -18,6 +18,7 @@ import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
......@@ -70,13 +71,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private float velocity = 0;
private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>();
private float mAcceleration = 0;
private static final float ALPHA = 0.8f; // Filter factor
private static final float STOP_THRESHOLD = 8.0f; // Stop threshold in m/s²
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4000;
private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001;
private final float ALPHA = 0.8f; // Filter factor
private final float STOP_THRESHOLD = 8.0f; // Stop threshold in m/s²
private final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4000;
private final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001;
private JSONArray jsonArray = new JSONArray();
private LocationManager locationManager;
private static final int LOCATION_UPDATE_INTERVAL = 1000;
private final int LOCATION_UPDATE_INTERVAL = 1000;
private double mLatitude = 0;
private double mLongitude = 0;
// Radius of the Earth in meters
......@@ -86,6 +87,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private int orientationCount = 0, touchCount = 0;
final long REFRESH_TIME = 100; // miliseconds
private String mStartTimestamp = "", mStopTimestamp = "";
private final int RECORDS_INTERVAL = 5000;
private EditText mEtLimit;
// ===========================================================
......@@ -110,6 +113,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mIvBack.setOnClickListener(this);
mTvOrientationCount = findViewById(R.id.tv_orientation);
mTvTouchCount = findViewById(R.id.tv_touch);
mEtLimit = findViewById(R.id.et_acceleration);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
previousLocation = null;
......@@ -199,6 +203,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mIsTripStarted = false;
mTvTripButton.setText(R.string.cos_dlg_start_trip);
} else {
if (mEtLimit.getText().length() == 0) {
Snackbar.make(mLlTelematicsMain, "Please fill the Cut off field", Snackbar.LENGTH_SHORT).show();
return;
}
mTouchHandler = new Handler();
mTouchRunnable = new Runnable() {
@Override
......@@ -375,6 +383,18 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mLocationHandler.removeCallbacks(mLocationRunnable);
}
private String getCutOffLimit() {
if (mEtLimit.getText().length() != 0) {
if (Float.valueOf(mEtLimit.getText().toString()) > mAcceleration) {
return "red";
} else {
return "green";
}
}
return "";
}
private void registerSensor() {
mStartTimestamp = String.valueOf(System.currentTimeMillis());
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
......@@ -382,7 +402,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
Snackbar.make(mLlTelematicsMain, "Sensor Registered", Snackbar.LENGTH_SHORT).show();
final int delay = 1000;
final int[] recordsCount = {0};
mTvRecordsSaved.setText(String.valueOf(recordsCount[0]));
mHandler = new Handler();
......@@ -400,8 +419,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
jobjData.putOpt("timestamp", timestamp);
jobjData.putOpt("start_time", mStartTimestamp);
jobjData.putOpt("stop_time", mStopTimestamp);
jobjData.putOpt("latitude",mLatitude);
jobjData.putOpt("latitude", mLatitude);
jobjData.putOpt("longitude", mLongitude);
jobjData.putOpt("limit", getCutOffLimit());
jobj.putOpt(timestamp, jobjData);
mAccelerationTimestamps.add(jobj);
recordsCount[0]++;
......@@ -410,10 +430,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
e.printStackTrace();
Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show();
}
mHandler.postDelayed(this, delay);
mHandler.postDelayed(this, RECORDS_INTERVAL);
}
};
mHandler.postDelayed(mRunnable, delay);
mHandler.postDelayed(mRunnable, RECORDS_INTERVAL);
}
private void unregisterSensor() {
......
......@@ -189,6 +189,19 @@
android:textColor="@color/blue_dark"
android:textSize="16sp" />
<EditText
android:id="@+id/et_acceleration"
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:inputType="phone"
android:layout_marginTop="24dp"
android:hint="Cut off in km/h"
android:layout_below="@+id/tv_records"/>
<LinearLayout
android:id="@+id/ll_activate_button"
android:layout_width="match_parent"
......