Showing
2 changed files
with
18 additions
and
13 deletions
... | @@ -65,11 +65,11 @@ | ... | @@ -65,11 +65,11 @@ |
65 | android:screenOrientation="portrait" | 65 | android:screenOrientation="portrait" |
66 | android:theme="@style/SDKAppTheme" /> | 66 | android:theme="@style/SDKAppTheme" /> |
67 | 67 | ||
68 | -<!-- <activity--> | 68 | + <activity |
69 | -<!-- android:name="ly.warp.sdk.activities.TelematicsActivity"--> | 69 | + android:name="ly.warp.sdk.activities.TelematicsActivity" |
70 | -<!-- android:exported="false"--> | 70 | + android:exported="false" |
71 | -<!-- android:screenOrientation="portrait"--> | 71 | + android:screenOrientation="portrait" |
72 | -<!-- android:theme="@style/SDKAppTheme" />--> | 72 | + android:theme="@style/SDKAppTheme" /> |
73 | 73 | ||
74 | <activity | 74 | <activity |
75 | android:name="ly.warp.sdk.activities.GiftsForYouActivity" | 75 | android:name="ly.warp.sdk.activities.GiftsForYouActivity" | ... | ... |
... | @@ -74,7 +74,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -74,7 +74,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
74 | private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; | 74 | private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001; |
75 | JSONArray jsonArray = new JSONArray(); | 75 | JSONArray jsonArray = new JSONArray(); |
76 | private LocationManager locationManager; | 76 | private LocationManager locationManager; |
77 | - private static final int LOCATION_UPDATE_INTERVAL = 5000; | 77 | + private static final int LOCATION_UPDATE_INTERVAL = 1000; |
78 | double mLatitude = 0; | 78 | double mLatitude = 0; |
79 | double mLongitude = 0; | 79 | double mLongitude = 0; |
80 | // Radius of the Earth in meters | 80 | // Radius of the Earth in meters |
... | @@ -109,7 +109,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -109,7 +109,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
109 | @Override | 109 | @Override |
110 | public void onResume() { | 110 | public void onResume() { |
111 | super.onResume(); | 111 | super.onResume(); |
112 | - requestLocationUpdates(); | ||
113 | // WarplyAnalyticsManager.logTrackersEvent(this, "screen", "TelematicsActivity"); | 112 | // WarplyAnalyticsManager.logTrackersEvent(this, "screen", "TelematicsActivity"); |
114 | } | 113 | } |
115 | 114 | ||
... | @@ -183,6 +182,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -183,6 +182,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
183 | mIsTripStarted = false; | 182 | mIsTripStarted = false; |
184 | mTvTripButton.setText(R.string.cos_dlg_start_trip); | 183 | mTvTripButton.setText(R.string.cos_dlg_start_trip); |
185 | } else { | 184 | } else { |
185 | + requestLocationUpdates(); | ||
186 | registerStepSensor(); | 186 | registerStepSensor(); |
187 | mIsTripStarted = true; | 187 | mIsTripStarted = true; |
188 | mTvTripButton.setText(R.string.cos_dlg_stop_trip); | 188 | mTvTripButton.setText(R.string.cos_dlg_stop_trip); |
... | @@ -197,6 +197,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -197,6 +197,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
197 | 197 | ||
198 | @Override | 198 | @Override |
199 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | 199 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
200 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
201 | + | ||
200 | if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) { | 202 | if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) { |
201 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | 203 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
202 | saveAccelerationDataToExternalStorage(jsonArray); | 204 | saveAccelerationDataToExternalStorage(jsonArray); |
... | @@ -218,10 +220,16 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -218,10 +220,16 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
218 | public void onLocationChanged(Location location) { | 220 | public void onLocationChanged(Location location) { |
219 | //TODO: uncomment and remove setText if needs revert to handler implementation | 221 | //TODO: uncomment and remove setText if needs revert to handler implementation |
220 | //TODO: LOCATION_UPDATE_INTERVAL = 300 when using location.getSpeed() | 222 | //TODO: LOCATION_UPDATE_INTERVAL = 300 when using location.getSpeed() |
221 | -// float speedKmph = (location.getSpeed() * 3600) / 1000; | 223 | +// float speedKmph = location.getSpeed() * 3.6f; |
222 | // mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speedKmph)) + " km/h"); | 224 | // mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speedKmph)) + " km/h"); |
223 | - if (mLatitude != 0 && mLongitude != 0) | 225 | + if (mLatitude != 0 && mLongitude != 0) { |
224 | - requestLocationUpdatePeriodically(location); | 226 | + double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); |
227 | + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h"); | ||
228 | + } | ||
229 | + | ||
230 | + | ||
231 | +// if (mLatitude != 0 && mLongitude != 0) | ||
232 | +// requestLocationUpdatePeriodically(location); | ||
225 | mLatitude = location.getLatitude(); | 233 | mLatitude = location.getLatitude(); |
226 | mLongitude = location.getLongitude(); | 234 | mLongitude = location.getLongitude(); |
227 | } | 235 | } |
... | @@ -251,15 +259,12 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -251,15 +259,12 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
251 | } | 259 | } |
252 | 260 | ||
253 | private void requestLocationUpdates() { | 261 | private void requestLocationUpdates() { |
254 | - // Check if the ACCESS_FINE_LOCATION permission is granted | ||
255 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) | 262 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) |
256 | != PackageManager.PERMISSION_GRANTED) { | 263 | != PackageManager.PERMISSION_GRANTED) { |
257 | - // Permission is not granted, request it | ||
258 | ActivityCompat.requestPermissions(this, | 264 | ActivityCompat.requestPermissions(this, |
259 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, | 265 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, |
260 | PERMISSION_REQUEST_ACCESS_FINE_LOCATION); | 266 | PERMISSION_REQUEST_ACCESS_FINE_LOCATION); |
261 | } else { | 267 | } else { |
262 | - // Permission is granted, start requesting location updates | ||
263 | startLocationUpdates(); | 268 | startLocationUpdates(); |
264 | } | 269 | } |
265 | } | 270 | } | ... | ... |
-
Please register or login to post a comment