Showing
2 changed files
with
42 additions
and
9 deletions
... | @@ -18,6 +18,7 @@ import android.os.Handler; | ... | @@ -18,6 +18,7 @@ import android.os.Handler; |
18 | import android.view.MotionEvent; | 18 | import android.view.MotionEvent; |
19 | import android.view.View; | 19 | import android.view.View; |
20 | import android.view.WindowManager; | 20 | import android.view.WindowManager; |
21 | +import android.widget.EditText; | ||
21 | import android.widget.ImageView; | 22 | import android.widget.ImageView; |
22 | import android.widget.LinearLayout; | 23 | import android.widget.LinearLayout; |
23 | import android.widget.TextView; | 24 | import android.widget.TextView; |
... | @@ -70,13 +71,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -70,13 +71,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
70 | private float velocity = 0; | 71 | private float velocity = 0; |
71 | private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>(); | 72 | private ArrayList<JSONObject> mAccelerationTimestamps = new ArrayList<>(); |
72 | private float mAcceleration = 0; | 73 | private float mAcceleration = 0; |
73 | - private static final float ALPHA = 0.8f; // Filter factor | 74 | + private final float ALPHA = 0.8f; // Filter factor |
74 | - private static final float STOP_THRESHOLD = 8.0f; // Stop threshold in m/s² | 75 | + private final float STOP_THRESHOLD = 8.0f; // Stop threshold in m/s² |
75 | - private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4000; | 76 | + private final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 4000; |
76 | - private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; | 77 | + private final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; |
77 | private JSONArray jsonArray = new JSONArray(); | 78 | private JSONArray jsonArray = new JSONArray(); |
78 | private LocationManager locationManager; | 79 | private LocationManager locationManager; |
79 | - private static final int LOCATION_UPDATE_INTERVAL = 1000; | 80 | + private final int LOCATION_UPDATE_INTERVAL = 1000; |
80 | private double mLatitude = 0; | 81 | private double mLatitude = 0; |
81 | private double mLongitude = 0; | 82 | private double mLongitude = 0; |
82 | // Radius of the Earth in meters | 83 | // Radius of the Earth in meters |
... | @@ -86,6 +87,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -86,6 +87,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
86 | private int orientationCount = 0, touchCount = 0; | 87 | private int orientationCount = 0, touchCount = 0; |
87 | final long REFRESH_TIME = 100; // miliseconds | 88 | final long REFRESH_TIME = 100; // miliseconds |
88 | private String mStartTimestamp = "", mStopTimestamp = ""; | 89 | private String mStartTimestamp = "", mStopTimestamp = ""; |
90 | + private final int RECORDS_INTERVAL = 5000; | ||
91 | + private EditText mEtLimit; | ||
89 | 92 | ||
90 | 93 | ||
91 | // =========================================================== | 94 | // =========================================================== |
... | @@ -110,6 +113,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -110,6 +113,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
110 | mIvBack.setOnClickListener(this); | 113 | mIvBack.setOnClickListener(this); |
111 | mTvOrientationCount = findViewById(R.id.tv_orientation); | 114 | mTvOrientationCount = findViewById(R.id.tv_orientation); |
112 | mTvTouchCount = findViewById(R.id.tv_touch); | 115 | mTvTouchCount = findViewById(R.id.tv_touch); |
116 | + mEtLimit = findViewById(R.id.et_acceleration); | ||
113 | 117 | ||
114 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); | 118 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
115 | previousLocation = null; | 119 | previousLocation = null; |
... | @@ -199,6 +203,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -199,6 +203,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
199 | mIsTripStarted = false; | 203 | mIsTripStarted = false; |
200 | mTvTripButton.setText(R.string.cos_dlg_start_trip); | 204 | mTvTripButton.setText(R.string.cos_dlg_start_trip); |
201 | } else { | 205 | } else { |
206 | + if (mEtLimit.getText().length() == 0) { | ||
207 | + Snackbar.make(mLlTelematicsMain, "Please fill the Cut off field", Snackbar.LENGTH_SHORT).show(); | ||
208 | + return; | ||
209 | + } | ||
202 | mTouchHandler = new Handler(); | 210 | mTouchHandler = new Handler(); |
203 | mTouchRunnable = new Runnable() { | 211 | mTouchRunnable = new Runnable() { |
204 | @Override | 212 | @Override |
... | @@ -375,6 +383,18 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -375,6 +383,18 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
375 | mLocationHandler.removeCallbacks(mLocationRunnable); | 383 | mLocationHandler.removeCallbacks(mLocationRunnable); |
376 | } | 384 | } |
377 | 385 | ||
386 | + private String getCutOffLimit() { | ||
387 | + if (mEtLimit.getText().length() != 0) { | ||
388 | + if (Float.valueOf(mEtLimit.getText().toString()) > mAcceleration) { | ||
389 | + return "red"; | ||
390 | + } else { | ||
391 | + return "green"; | ||
392 | + } | ||
393 | + } | ||
394 | + | ||
395 | + return ""; | ||
396 | + } | ||
397 | + | ||
378 | private void registerSensor() { | 398 | private void registerSensor() { |
379 | mStartTimestamp = String.valueOf(System.currentTimeMillis()); | 399 | mStartTimestamp = String.valueOf(System.currentTimeMillis()); |
380 | mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); | 400 | mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); |
... | @@ -382,7 +402,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -382,7 +402,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
382 | mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); | 402 | mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); |
383 | Snackbar.make(mLlTelematicsMain, "Sensor Registered", Snackbar.LENGTH_SHORT).show(); | 403 | Snackbar.make(mLlTelematicsMain, "Sensor Registered", Snackbar.LENGTH_SHORT).show(); |
384 | 404 | ||
385 | - final int delay = 1000; | ||
386 | final int[] recordsCount = {0}; | 405 | final int[] recordsCount = {0}; |
387 | mTvRecordsSaved.setText(String.valueOf(recordsCount[0])); | 406 | mTvRecordsSaved.setText(String.valueOf(recordsCount[0])); |
388 | mHandler = new Handler(); | 407 | mHandler = new Handler(); |
... | @@ -400,8 +419,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -400,8 +419,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
400 | jobjData.putOpt("timestamp", timestamp); | 419 | jobjData.putOpt("timestamp", timestamp); |
401 | jobjData.putOpt("start_time", mStartTimestamp); | 420 | jobjData.putOpt("start_time", mStartTimestamp); |
402 | jobjData.putOpt("stop_time", mStopTimestamp); | 421 | jobjData.putOpt("stop_time", mStopTimestamp); |
403 | - jobjData.putOpt("latitude",mLatitude); | 422 | + jobjData.putOpt("latitude", mLatitude); |
404 | jobjData.putOpt("longitude", mLongitude); | 423 | jobjData.putOpt("longitude", mLongitude); |
424 | + jobjData.putOpt("limit", getCutOffLimit()); | ||
405 | jobj.putOpt(timestamp, jobjData); | 425 | jobj.putOpt(timestamp, jobjData); |
406 | mAccelerationTimestamps.add(jobj); | 426 | mAccelerationTimestamps.add(jobj); |
407 | recordsCount[0]++; | 427 | recordsCount[0]++; |
... | @@ -410,10 +430,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -410,10 +430,10 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
410 | e.printStackTrace(); | 430 | e.printStackTrace(); |
411 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); | 431 | Snackbar.make(mLlTelematicsMain, "Runnable Failed", Snackbar.LENGTH_SHORT).show(); |
412 | } | 432 | } |
413 | - mHandler.postDelayed(this, delay); | 433 | + mHandler.postDelayed(this, RECORDS_INTERVAL); |
414 | } | 434 | } |
415 | }; | 435 | }; |
416 | - mHandler.postDelayed(mRunnable, delay); | 436 | + mHandler.postDelayed(mRunnable, RECORDS_INTERVAL); |
417 | } | 437 | } |
418 | 438 | ||
419 | private void unregisterSensor() { | 439 | private void unregisterSensor() { | ... | ... |
... | @@ -189,6 +189,19 @@ | ... | @@ -189,6 +189,19 @@ |
189 | android:textColor="@color/blue_dark" | 189 | android:textColor="@color/blue_dark" |
190 | android:textSize="16sp" /> | 190 | android:textSize="16sp" /> |
191 | 191 | ||
192 | + <EditText | ||
193 | + android:id="@+id/et_acceleration" | ||
194 | + fontPath="fonts/PeridotPE-Bold.ttf" | ||
195 | + android:layout_width="wrap_content" | ||
196 | + android:layout_height="wrap_content" | ||
197 | + android:layout_centerHorizontal="true" | ||
198 | + android:textColor="@color/blue_dark" | ||
199 | + android:textSize="16sp" | ||
200 | + android:inputType="phone" | ||
201 | + android:layout_marginTop="24dp" | ||
202 | + android:hint="Cut off in km/h" | ||
203 | + android:layout_below="@+id/tv_records"/> | ||
204 | + | ||
192 | <LinearLayout | 205 | <LinearLayout |
193 | android:id="@+id/ll_activate_button" | 206 | android:id="@+id/ll_activate_button" |
194 | android:layout_width="match_parent" | 207 | android:layout_width="match_parent" | ... | ... |
-
Please register or login to post a comment