Showing
2 changed files
with
54 additions
and
29 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); | ... | ... |
... | @@ -39,6 +39,11 @@ | ... | @@ -39,6 +39,11 @@ |
39 | app:layout_constraintTop_toTopOf="parent" /> | 39 | app:layout_constraintTop_toTopOf="parent" /> |
40 | </androidx.constraintlayout.widget.ConstraintLayout> | 40 | </androidx.constraintlayout.widget.ConstraintLayout> |
41 | 41 | ||
42 | + <ScrollView | ||
43 | + android:fillViewport="true" | ||
44 | + android:layout_width="wrap_content" | ||
45 | + android:layout_height="match_parent"> | ||
46 | + | ||
42 | <RelativeLayout | 47 | <RelativeLayout |
43 | android:layout_width="match_parent" | 48 | android:layout_width="match_parent" |
44 | android:layout_height="match_parent" | 49 | android:layout_height="match_parent" |
... | @@ -72,10 +77,10 @@ | ... | @@ -72,10 +77,10 @@ |
72 | fontPath="fonts/PeridotPE-Regular.ttf" | 77 | fontPath="fonts/PeridotPE-Regular.ttf" |
73 | android:layout_width="wrap_content" | 78 | android:layout_width="wrap_content" |
74 | android:layout_height="wrap_content" | 79 | android:layout_height="wrap_content" |
80 | + android:layout_below="@+id/tv_sensor_data" | ||
75 | android:layout_centerHorizontal="true" | 81 | android:layout_centerHorizontal="true" |
76 | android:layout_marginTop="24dp" | 82 | android:layout_marginTop="24dp" |
77 | android:text="Acceleration" | 83 | android:text="Acceleration" |
78 | - android:layout_below="@+id/tv_sensor_data" | ||
79 | android:textColor="@color/blue_dark" | 84 | android:textColor="@color/blue_dark" |
80 | android:textSize="16sp" /> | 85 | android:textSize="16sp" /> |
81 | 86 | ||
... | @@ -88,17 +93,17 @@ | ... | @@ -88,17 +93,17 @@ |
88 | android:layout_centerHorizontal="true" | 93 | android:layout_centerHorizontal="true" |
89 | android:layout_marginTop="24dp" | 94 | android:layout_marginTop="24dp" |
90 | android:textColor="@color/blue_dark" | 95 | android:textColor="@color/blue_dark" |
91 | - android:textSize="16sp" /> | 96 | + android:textSize="20sp" /> |
92 | 97 | ||
93 | <TextView | 98 | <TextView |
94 | android:id="@+id/tv_avg_label" | 99 | android:id="@+id/tv_avg_label" |
95 | fontPath="fonts/PeridotPE-Regular.ttf" | 100 | fontPath="fonts/PeridotPE-Regular.ttf" |
96 | android:layout_width="wrap_content" | 101 | android:layout_width="wrap_content" |
97 | android:layout_height="wrap_content" | 102 | android:layout_height="wrap_content" |
103 | + android:layout_below="@+id/tv_velocity" | ||
98 | android:layout_centerHorizontal="true" | 104 | android:layout_centerHorizontal="true" |
99 | android:layout_marginTop="24dp" | 105 | android:layout_marginTop="24dp" |
100 | android:text="Velocity" | 106 | android:text="Velocity" |
101 | - android:layout_below="@+id/tv_velocity" | ||
102 | android:textColor="@color/blue_dark" | 107 | android:textColor="@color/blue_dark" |
103 | android:textSize="16sp" /> | 108 | android:textSize="16sp" /> |
104 | 109 | ||
... | @@ -111,18 +116,18 @@ | ... | @@ -111,18 +116,18 @@ |
111 | android:layout_centerHorizontal="true" | 116 | android:layout_centerHorizontal="true" |
112 | android:layout_marginTop="24dp" | 117 | android:layout_marginTop="24dp" |
113 | android:textColor="@color/blue_dark" | 118 | android:textColor="@color/blue_dark" |
114 | - android:textSize="16sp" /> | 119 | + android:textSize="20sp" /> |
115 | 120 | ||
116 | <TextView | 121 | <TextView |
117 | android:id="@+id/tv_orientation_label" | 122 | android:id="@+id/tv_orientation_label" |
118 | fontPath="fonts/PeridotPE-Regular.ttf" | 123 | fontPath="fonts/PeridotPE-Regular.ttf" |
119 | android:layout_width="wrap_content" | 124 | android:layout_width="wrap_content" |
120 | android:layout_height="wrap_content" | 125 | android:layout_height="wrap_content" |
126 | + android:layout_below="@+id/tv_avg" | ||
121 | android:layout_alignParentStart="true" | 127 | android:layout_alignParentStart="true" |
122 | - android:layout_marginTop="24dp" | ||
123 | android:layout_marginStart="24dp" | 128 | android:layout_marginStart="24dp" |
129 | + android:layout_marginTop="24dp" | ||
124 | android:text="Orientation Count" | 130 | android:text="Orientation Count" |
125 | - android:layout_below="@+id/tv_avg" | ||
126 | android:textColor="@color/blue_dark" | 131 | android:textColor="@color/blue_dark" |
127 | android:textSize="16sp" /> | 132 | android:textSize="16sp" /> |
128 | 133 | ||
... | @@ -144,12 +149,12 @@ | ... | @@ -144,12 +149,12 @@ |
144 | fontPath="fonts/PeridotPE-Regular.ttf" | 149 | fontPath="fonts/PeridotPE-Regular.ttf" |
145 | android:layout_width="wrap_content" | 150 | android:layout_width="wrap_content" |
146 | android:layout_height="wrap_content" | 151 | android:layout_height="wrap_content" |
152 | + android:layout_below="@+id/tv_avg" | ||
153 | + android:layout_alignParentEnd="true" | ||
147 | android:layout_marginTop="24dp" | 154 | android:layout_marginTop="24dp" |
155 | + android:paddingEnd="24dp" | ||
148 | android:layout_marginEnd="24dp" | 156 | android:layout_marginEnd="24dp" |
149 | - android:layout_alignParentEnd="true" | ||
150 | android:text="Touch Count" | 157 | android:text="Touch Count" |
151 | - android:layout_below="@+id/tv_avg" | ||
152 | - android:layout_alignEnd="@+id/tv_orientation_label" | ||
153 | android:textColor="@color/blue_dark" | 158 | android:textColor="@color/blue_dark" |
154 | android:textSize="16sp" /> | 159 | android:textSize="16sp" /> |
155 | 160 | ||
... | @@ -171,10 +176,10 @@ | ... | @@ -171,10 +176,10 @@ |
171 | fontPath="fonts/PeridotPE-Regular.ttf" | 176 | fontPath="fonts/PeridotPE-Regular.ttf" |
172 | android:layout_width="wrap_content" | 177 | android:layout_width="wrap_content" |
173 | android:layout_height="wrap_content" | 178 | android:layout_height="wrap_content" |
179 | + android:layout_below="@+id/tv_orientation" | ||
174 | android:layout_centerHorizontal="true" | 180 | android:layout_centerHorizontal="true" |
175 | android:layout_marginTop="24dp" | 181 | android:layout_marginTop="24dp" |
176 | android:text="Records Saved" | 182 | android:text="Records Saved" |
177 | - android:layout_below="@+id/tv_orientation" | ||
178 | android:textColor="@color/blue_dark" | 183 | android:textColor="@color/blue_dark" |
179 | android:textSize="16sp" /> | 184 | android:textSize="16sp" /> |
180 | 185 | ||
... | @@ -194,21 +199,36 @@ | ... | @@ -194,21 +199,36 @@ |
194 | fontPath="fonts/PeridotPE-Bold.ttf" | 199 | fontPath="fonts/PeridotPE-Bold.ttf" |
195 | android:layout_width="wrap_content" | 200 | android:layout_width="wrap_content" |
196 | android:layout_height="wrap_content" | 201 | android:layout_height="wrap_content" |
197 | - android:layout_centerHorizontal="true" | 202 | + android:layout_below="@+id/tv_records" |
198 | - android:textColor="@color/blue_dark" | 203 | + android:layout_alignParentStart="true" |
199 | - android:textSize="16sp" | 204 | + android:layout_marginTop="24dp" |
205 | + android:layout_marginStart="24dp" | ||
206 | + android:hint="Cut off in m/s^2" | ||
200 | android:inputType="phone" | 207 | android:inputType="phone" |
208 | + android:textColor="@color/blue_dark" | ||
209 | + android:textSize="16sp" /> | ||
210 | + | ||
211 | + <EditText | ||
212 | + android:id="@+id/et_save" | ||
213 | + fontPath="fonts/PeridotPE-Bold.ttf" | ||
214 | + android:layout_width="wrap_content" | ||
215 | + android:layout_height="wrap_content" | ||
216 | + android:layout_below="@+id/tv_records" | ||
217 | + android:layout_alignParentEnd="true" | ||
218 | + android:paddingEnd="24dp" | ||
201 | android:layout_marginTop="24dp" | 219 | android:layout_marginTop="24dp" |
202 | - android:hint="Cut off in km/h" | 220 | + android:hint="Sample Interval in ms" |
203 | - android:layout_below="@+id/tv_records"/> | 221 | + android:inputType="phone" |
222 | + android:textColor="@color/blue_dark" | ||
223 | + android:textSize="16sp" /> | ||
204 | 224 | ||
205 | <LinearLayout | 225 | <LinearLayout |
206 | android:id="@+id/ll_activate_button" | 226 | android:id="@+id/ll_activate_button" |
207 | android:layout_width="match_parent" | 227 | android:layout_width="match_parent" |
208 | android:layout_height="55dp" | 228 | android:layout_height="55dp" |
209 | - android:layout_alignParentBottom="true" | 229 | + android:layout_below="@+id/et_acceleration" |
210 | android:layout_marginHorizontal="24dp" | 230 | android:layout_marginHorizontal="24dp" |
211 | - android:layout_marginBottom="56dp" | 231 | + android:layout_marginVertical="56dp" |
212 | android:background="@drawable/selector_button_green_border" | 232 | android:background="@drawable/selector_button_green_border" |
213 | android:gravity="center" | 233 | android:gravity="center" |
214 | android:orientation="horizontal"> | 234 | android:orientation="horizontal"> |
... | @@ -225,4 +245,5 @@ | ... | @@ -225,4 +245,5 @@ |
225 | android:textSize="16sp" /> | 245 | android:textSize="16sp" /> |
226 | </LinearLayout> | 246 | </LinearLayout> |
227 | </RelativeLayout> | 247 | </RelativeLayout> |
248 | + </ScrollView> | ||
228 | </LinearLayout> | 249 | </LinearLayout> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment