Panagiotis Triantafyllou

telematics fixes

......@@ -83,9 +83,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private float velocity = 0;
private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>();
private float mAcceleration = 0;
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 float ALPHA = 0.5f; // Filter factor 0.8f
private final float STOP_THRESHOLD = 10.0f; // Stop threshold in m/s² 8.0f
private final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4003;
private final int PERMISSION_REQUEST_LOCATION_SETTINGS = 4000;
private final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001;
private JSONArray jsonArray = new JSONArray();
private LocationManager locationManager;
......@@ -94,7 +95,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private double mLongitude = 0;
// Radius of the Earth in meters
private final double EARTH_RADIUS = 6371000.0;
private Location previousLocation;
private double mSpeed = 0;
private int orientationCount = 0, touchCount = 0;
final long REFRESH_TIME = 100; // miliseconds
......@@ -102,7 +102,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private final int RECORDS_INTERVAL = 5000;
private EditText mEtLimit, mEtSampleTime;
private RelativeLayout mRlMainScroll;
private int REQUEST_LOCATION_SETTINGS = 4000;
// ===========================================================
......@@ -136,7 +135,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mLlTelematicsHistory.setOnClickListener(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
previousLocation = null;
initViews();
}
......@@ -308,7 +306,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LOCATION_SETTINGS) {
if (requestCode == PERMISSION_REQUEST_LOCATION_SETTINGS) {
switch (resultCode) {
case Activity.RESULT_OK:
mIsTripStarted = true;
......@@ -423,7 +421,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
jobjData.putOpt("latitude", mLatitude);
jobjData.putOpt("longitude", mLongitude);
jobjData.putOpt("limit", getCutOffLimit());
jobjData.putOpt("samples", TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString()));
jobjData.putOpt("samples", TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.parseInt(mEtSampleTime.getText().toString()));
jobj.putOpt(timestamp, jobjData);
mAccelerationTimestamps.add(jobj);
recordsCount[0]++;
......@@ -431,11 +429,14 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
} catch (JSONException e) {
e.printStackTrace();
Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show();
} finally {
mHandler.removeCallbacks(mRunnable);
mHandler = new Handler();
mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.parseInt(mEtSampleTime.getText().toString()));
}
mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString()));
}
};
mHandler.postDelayed(mRunnable, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString()));
mHandler.post(mRunnable);
}
private void unregisterSensor() {
......@@ -551,7 +552,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
ResolvableApiException resolvable = (ResolvableApiException) exception;
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
resolvable.startResolutionForResult(TelematicsActivity.this, REQUEST_LOCATION_SETTINGS);
resolvable.startResolutionForResult(TelematicsActivity.this, PERMISSION_REQUEST_LOCATION_SETTINGS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
Log.v("SendIntentException", e.getMessage());
......