Showing
1 changed file
with
12 additions
and
11 deletions
... | @@ -83,9 +83,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -83,9 +83,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
83 | private float velocity = 0; | 83 | private float velocity = 0; |
84 | private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>(); | 84 | private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>(); |
85 | private float mAcceleration = 0; | 85 | private float mAcceleration = 0; |
86 | - private final float ALPHA = 0.8f; // Filter factor | 86 | + private final float ALPHA = 0.5f; // Filter factor 0.8f |
87 | - private final float STOP_THRESHOLD = 8.0f; // Stop threshold in m/s² | 87 | + private final float STOP_THRESHOLD = 10.0f; // Stop threshold in m/s² 8.0f |
88 | - private final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4000; | 88 | + private final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4003; |
89 | + private final int PERMISSION_REQUEST_LOCATION_SETTINGS = 4000; | ||
89 | private final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; | 90 | private final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; |
90 | private JSONArray jsonArray = new JSONArray(); | 91 | private JSONArray jsonArray = new JSONArray(); |
91 | private LocationManager locationManager; | 92 | private LocationManager locationManager; |
... | @@ -94,7 +95,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -94,7 +95,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
94 | private double mLongitude = 0; | 95 | private double mLongitude = 0; |
95 | // Radius of the Earth in meters | 96 | // Radius of the Earth in meters |
96 | private final double EARTH_RADIUS = 6371000.0; | 97 | private final double EARTH_RADIUS = 6371000.0; |
97 | - private Location previousLocation; | ||
98 | private double mSpeed = 0; | 98 | private double mSpeed = 0; |
99 | private int orientationCount = 0, touchCount = 0; | 99 | private int orientationCount = 0, touchCount = 0; |
100 | final long REFRESH_TIME = 100; // miliseconds | 100 | final long REFRESH_TIME = 100; // miliseconds |
... | @@ -102,7 +102,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -102,7 +102,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
102 | private final int RECORDS_INTERVAL = 5000; | 102 | private final int RECORDS_INTERVAL = 5000; |
103 | private EditText mEtLimit, mEtSampleTime; | 103 | private EditText mEtLimit, mEtSampleTime; |
104 | private RelativeLayout mRlMainScroll; | 104 | private RelativeLayout mRlMainScroll; |
105 | - private int REQUEST_LOCATION_SETTINGS = 4000; | ||
106 | 105 | ||
107 | 106 | ||
108 | // =========================================================== | 107 | // =========================================================== |
... | @@ -136,7 +135,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -136,7 +135,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
136 | mLlTelematicsHistory.setOnClickListener(this); | 135 | mLlTelematicsHistory.setOnClickListener(this); |
137 | 136 | ||
138 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); | 137 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
139 | - previousLocation = null; | ||
140 | 138 | ||
141 | initViews(); | 139 | initViews(); |
142 | } | 140 | } |
... | @@ -308,7 +306,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -308,7 +306,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
308 | 306 | ||
309 | @Override | 307 | @Override |
310 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 308 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
311 | - if (requestCode == REQUEST_LOCATION_SETTINGS) { | 309 | + if (requestCode == PERMISSION_REQUEST_LOCATION_SETTINGS) { |
312 | switch (resultCode) { | 310 | switch (resultCode) { |
313 | case Activity.RESULT_OK: | 311 | case Activity.RESULT_OK: |
314 | mIsTripStarted = true; | 312 | mIsTripStarted = true; |
... | @@ -423,7 +421,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -423,7 +421,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
423 | jobjData.putOpt("latitude", mLatitude); | 421 | jobjData.putOpt("latitude", mLatitude); |
424 | jobjData.putOpt("longitude", mLongitude); | 422 | jobjData.putOpt("longitude", mLongitude); |
425 | jobjData.putOpt("limit", getCutOffLimit()); | 423 | jobjData.putOpt("limit", getCutOffLimit()); |
426 | - jobjData.putOpt("samples", TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString())); | 424 | + jobjData.putOpt("samples", TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.parseInt(mEtSampleTime.getText().toString())); |
427 | jobj.putOpt(timestamp, jobjData); | 425 | jobj.putOpt(timestamp, jobjData); |
428 | mAccelerationTimestamps.add(jobj); | 426 | mAccelerationTimestamps.add(jobj); |
429 | recordsCount[0]++; | 427 | recordsCount[0]++; |
... | @@ -431,11 +429,14 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -431,11 +429,14 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
431 | } catch (JSONException e) { | 429 | } catch (JSONException e) { |
432 | e.printStackTrace(); | 430 | e.printStackTrace(); |
433 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); | 431 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); |
432 | + } finally { | ||
433 | + mHandler.removeCallbacks(mRunnable); | ||
434 | + mHandler = new Handler(); | ||
435 | + mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.parseInt(mEtSampleTime.getText().toString())); | ||
434 | } | 436 | } |
435 | - mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString())); | ||
436 | } | 437 | } |
437 | }; | 438 | }; |
438 | - mHandler.postDelayed(mRunnable, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString())); | 439 | + mHandler.post(mRunnable); |
439 | } | 440 | } |
440 | 441 | ||
441 | private void unregisterSensor() { | 442 | private void unregisterSensor() { |
... | @@ -551,7 +552,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -551,7 +552,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
551 | ResolvableApiException resolvable = (ResolvableApiException) exception; | 552 | ResolvableApiException resolvable = (ResolvableApiException) exception; |
552 | // Show the dialog by calling startResolutionForResult(), | 553 | // Show the dialog by calling startResolutionForResult(), |
553 | // and check the result in onActivityResult(). | 554 | // and check the result in onActivityResult(). |
554 | - resolvable.startResolutionForResult(TelematicsActivity.this, REQUEST_LOCATION_SETTINGS); | 555 | + resolvable.startResolutionForResult(TelematicsActivity.this, PERMISSION_REQUEST_LOCATION_SETTINGS); |
555 | } catch (IntentSender.SendIntentException e) { | 556 | } catch (IntentSender.SendIntentException e) { |
556 | // Ignore the error. | 557 | // Ignore the error. |
557 | Log.v("SendIntentException", e.getMessage()); | 558 | Log.v("SendIntentException", e.getMessage()); | ... | ... |
-
Please register or login to post a comment