Showing
2 changed files
with
16 additions
and
12 deletions
... | @@ -15,6 +15,7 @@ import android.location.LocationManager; | ... | @@ -15,6 +15,7 @@ import android.location.LocationManager; |
15 | import android.os.Bundle; | 15 | import android.os.Bundle; |
16 | import android.os.Environment; | 16 | import android.os.Environment; |
17 | import android.os.Handler; | 17 | import android.os.Handler; |
18 | +import android.text.TextUtils; | ||
18 | import android.view.MotionEvent; | 19 | import android.view.MotionEvent; |
19 | import android.view.View; | 20 | import android.view.View; |
20 | import android.view.WindowManager; | 21 | import android.view.WindowManager; |
... | @@ -88,7 +89,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -88,7 +89,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
88 | final long REFRESH_TIME = 100; // miliseconds | 89 | final long REFRESH_TIME = 100; // miliseconds |
89 | private String mStartTimestamp = "", mStopTimestamp = ""; | 90 | private String mStartTimestamp = "", mStopTimestamp = ""; |
90 | private final int RECORDS_INTERVAL = 5000; | 91 | private final int RECORDS_INTERVAL = 5000; |
91 | - private EditText mEtLimit; | 92 | + private EditText mEtLimit, mEtSampleTime; |
92 | 93 | ||
93 | 94 | ||
94 | // =========================================================== | 95 | // =========================================================== |
... | @@ -114,6 +115,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -114,6 +115,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
114 | mTvOrientationCount = findViewById(R.id.tv_orientation); | 115 | mTvOrientationCount = findViewById(R.id.tv_orientation); |
115 | mTvTouchCount = findViewById(R.id.tv_touch); | 116 | mTvTouchCount = findViewById(R.id.tv_touch); |
116 | mEtLimit = findViewById(R.id.et_acceleration); | 117 | mEtLimit = findViewById(R.id.et_acceleration); |
118 | + mEtSampleTime = findViewById(R.id.et_save); | ||
117 | 119 | ||
118 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); | 120 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
119 | previousLocation = null; | 121 | previousLocation = null; |
... | @@ -176,8 +178,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -176,8 +178,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
176 | velocity = acceleration * time; | 178 | velocity = acceleration * time; |
177 | } | 179 | } |
178 | // Convert velocity to km/h | 180 | // Convert velocity to km/h |
179 | - mAcceleration = velocity * 3.6f; // Convert to km/h | 181 | +// mAcceleration = velocity * 3.6f; // Convert to km/h |
180 | - mTvVelocity.setText(String.format("%.1f", mAcceleration) + " km/h"); | 182 | + mAcceleration = velocity; // Convert to km/h |
183 | + mTvVelocity.setText(String.format("%.1f", velocity) + " m/s^2"); | ||
181 | // Update last values | 184 | // Update last values |
182 | lastX = filteredX; | 185 | lastX = filteredX; |
183 | lastY = filteredY; | 186 | lastY = filteredY; |
... | @@ -253,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -253,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
253 | //TODO: comment the first block and uncomment the second block if needs revert to handler implementation | 256 | //TODO: comment the first block and uncomment the second block if needs revert to handler implementation |
254 | if (mLatitude != 0 && mLongitude != 0) { | 257 | if (mLatitude != 0 && mLongitude != 0) { |
255 | mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); | 258 | mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); |
256 | - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h"); | 259 | + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " m/s^2"); |
257 | } | 260 | } |
258 | 261 | ||
259 | 262 | ||
... | @@ -317,8 +320,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -317,8 +320,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
317 | // =========================================================== | 320 | // =========================================================== |
318 | 321 | ||
319 | private void initViews() { | 322 | private void initViews() { |
320 | - mTvVelocity.setText("0.0 km/h"); | 323 | + mTvVelocity.setText("0.0 m/s^2"); |
321 | - mTvAvgVelocity.setText("0.0 km/h"); | 324 | + mTvAvgVelocity.setText("0.0 m/s^2"); |
322 | } | 325 | } |
323 | 326 | ||
324 | private void requestLocationUpdates() { | 327 | private void requestLocationUpdates() { |
... | @@ -349,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -349,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
349 | @Override | 352 | @Override |
350 | public void run() { | 353 | public void run() { |
351 | double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); | 354 | double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); |
352 | - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h"); | 355 | + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " m/s^2"); |
353 | mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL); | 356 | mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL); |
354 | } | 357 | } |
355 | }; | 358 | }; |
... | @@ -365,7 +368,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -365,7 +368,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
365 | // Function to calculate speed in meters per second | 368 | // Function to calculate speed in meters per second |
366 | private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) { | 369 | private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) { |
367 | double distance = calculateDistance(lat1, lon1, lat2, lon2); | 370 | double distance = calculateDistance(lat1, lon1, lat2, lon2); |
368 | - return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h; | 371 | +// return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h; |
372 | + return (distance / timeDifferenceInSeconds); // Convert to km/h; | ||
369 | } | 373 | } |
370 | 374 | ||
371 | private void requestSingleLocationUpdate() { | 375 | private void requestSingleLocationUpdate() { |
... | @@ -430,10 +434,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -430,10 +434,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
430 | e.printStackTrace(); | 434 | e.printStackTrace(); |
431 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); | 435 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); |
432 | } | 436 | } |
433 | - mHandler.postDelayed(this, RECORDS_INTERVAL); | 437 | + mHandler.postDelayed(this, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString())); |
434 | } | 438 | } |
435 | }; | 439 | }; |
436 | - mHandler.postDelayed(mRunnable, RECORDS_INTERVAL); | 440 | + mHandler.postDelayed(mRunnable, TextUtils.isEmpty(mEtSampleTime.getText()) ? RECORDS_INTERVAL : Integer.valueOf(mEtSampleTime.getText().toString())); |
437 | } | 441 | } |
438 | 442 | ||
439 | private void unregisterSensor() { | 443 | private void unregisterSensor() { |
... | @@ -441,8 +445,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -441,8 +445,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
441 | orientationCount = 0; | 445 | orientationCount = 0; |
442 | touchCount = 0; | 446 | touchCount = 0; |
443 | mSensorManager.unregisterListener(this); | 447 | mSensorManager.unregisterListener(this); |
444 | - mTvVelocity.setText("0.0 km/h"); | 448 | + mTvVelocity.setText("0.0 m/s^2"); |
445 | - mTvAvgVelocity.setText("0.0 km/h"); | 449 | + mTvAvgVelocity.setText("0.0 m/s^2"); |
446 | Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show(); | 450 | Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show(); |
447 | if (mHandler != null) | 451 | if (mHandler != null) |
448 | mHandler.removeCallbacks(mRunnable); | 452 | mHandler.removeCallbacks(mRunnable); | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment