Showing
2 changed files
with
138 additions
and
137 deletions
... | @@ -2,8 +2,10 @@ package ly.warp.sdk.activities; | ... | @@ -2,8 +2,10 @@ package ly.warp.sdk.activities; |
2 | 2 | ||
3 | import android.Manifest; | 3 | import android.Manifest; |
4 | import android.app.Activity; | 4 | import android.app.Activity; |
5 | +import android.app.AlertDialog; | ||
5 | import android.content.Context; | 6 | import android.content.Context; |
6 | import android.content.Intent; | 7 | import android.content.Intent; |
8 | +import android.content.IntentSender; | ||
7 | import android.content.pm.PackageManager; | 9 | import android.content.pm.PackageManager; |
8 | import android.content.res.Configuration; | 10 | import android.content.res.Configuration; |
9 | import android.hardware.Sensor; | 11 | import android.hardware.Sensor; |
... | @@ -14,9 +16,9 @@ import android.location.Location; | ... | @@ -14,9 +16,9 @@ import android.location.Location; |
14 | import android.location.LocationListener; | 16 | import android.location.LocationListener; |
15 | import android.location.LocationManager; | 17 | import android.location.LocationManager; |
16 | import android.os.Bundle; | 18 | import android.os.Bundle; |
17 | -import android.os.Environment; | ||
18 | import android.os.Handler; | 19 | import android.os.Handler; |
19 | import android.text.TextUtils; | 20 | import android.text.TextUtils; |
21 | +import android.util.Log; | ||
20 | import android.view.MotionEvent; | 22 | import android.view.MotionEvent; |
21 | import android.view.View; | 23 | import android.view.View; |
22 | import android.view.WindowManager; | 24 | import android.view.WindowManager; |
... | @@ -30,6 +32,14 @@ import androidx.annotation.NonNull; | ... | @@ -30,6 +32,14 @@ import androidx.annotation.NonNull; |
30 | import androidx.core.app.ActivityCompat; | 32 | import androidx.core.app.ActivityCompat; |
31 | import androidx.core.content.ContextCompat; | 33 | import androidx.core.content.ContextCompat; |
32 | 34 | ||
35 | +import com.google.android.gms.common.api.ApiException; | ||
36 | +import com.google.android.gms.common.api.ResolvableApiException; | ||
37 | +import com.google.android.gms.location.LocationRequest; | ||
38 | +import com.google.android.gms.location.LocationServices; | ||
39 | +import com.google.android.gms.location.LocationSettingsRequest; | ||
40 | +import com.google.android.gms.location.LocationSettingsResponse; | ||
41 | +import com.google.android.gms.location.LocationSettingsStatusCodes; | ||
42 | +import com.google.android.gms.tasks.Task; | ||
33 | import com.google.android.material.snackbar.Snackbar; | 43 | import com.google.android.material.snackbar.Snackbar; |
34 | 44 | ||
35 | import org.jetbrains.annotations.NotNull; | 45 | import org.jetbrains.annotations.NotNull; |
... | @@ -37,9 +47,6 @@ import org.json.JSONArray; | ... | @@ -37,9 +47,6 @@ import org.json.JSONArray; |
37 | import org.json.JSONException; | 47 | import org.json.JSONException; |
38 | import org.json.JSONObject; | 48 | import org.json.JSONObject; |
39 | 49 | ||
40 | -import java.io.File; | ||
41 | -import java.io.FileOutputStream; | ||
42 | -import java.io.IOException; | ||
43 | import java.util.ArrayList; | 50 | import java.util.ArrayList; |
44 | import java.util.Arrays; | 51 | import java.util.Arrays; |
45 | 52 | ||
... | @@ -69,8 +76,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -69,8 +76,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
69 | mTvOrientationCount, mTvTouchCount; | 76 | mTvOrientationCount, mTvTouchCount; |
70 | private SensorManager mSensorManager; | 77 | private SensorManager mSensorManager; |
71 | private Sensor mSensor; | 78 | private Sensor mSensor; |
72 | - private Handler mHandler, mLocationHandler, mTouchHandler; | 79 | + private Handler mHandler, mTouchHandler; |
73 | - private Runnable mRunnable, mLocationRunnable, mTouchRunnable; | 80 | + private Runnable mRunnable, mTouchRunnable; |
74 | private long lastUpdate = 0; | 81 | private long lastUpdate = 0; |
75 | private float lastX, lastY, lastZ; | 82 | private float lastX, lastY, lastZ; |
76 | private float velocity = 0; | 83 | private float velocity = 0; |
... | @@ -95,6 +102,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -95,6 +102,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
95 | private final int RECORDS_INTERVAL = 5000; | 102 | private final int RECORDS_INTERVAL = 5000; |
96 | private EditText mEtLimit, mEtSampleTime; | 103 | private EditText mEtLimit, mEtSampleTime; |
97 | private RelativeLayout mRlMainScroll; | 104 | private RelativeLayout mRlMainScroll; |
105 | + private int REQUEST_LOCATION_SETTINGS = 4000; | ||
98 | 106 | ||
99 | 107 | ||
100 | // =========================================================== | 108 | // =========================================================== |
... | @@ -148,8 +156,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -148,8 +156,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
148 | public void onBackPressed() { | 156 | public void onBackPressed() { |
149 | super.onBackPressed(); | 157 | super.onBackPressed(); |
150 | if (mIsTripStarted) { | 158 | if (mIsTripStarted) { |
151 | - unregisterSensor(); | ||
152 | stopLocationUpdates(); | 159 | stopLocationUpdates(); |
160 | + unregisterSensor(); | ||
153 | } | 161 | } |
154 | } | 162 | } |
155 | 163 | ||
... | @@ -215,13 +223,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -215,13 +223,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
215 | } | 223 | } |
216 | if (view.getId() == R.id.ll_activate_button) { | 224 | if (view.getId() == R.id.ll_activate_button) { |
217 | if (mIsTripStarted) { | 225 | if (mIsTripStarted) { |
226 | + mIsTripStarted = false; | ||
227 | + mTvTripButton.setText(R.string.cos_dlg_start_trip); | ||
218 | mEtLimit.setEnabled(true); | 228 | mEtLimit.setEnabled(true); |
219 | mEtSampleTime.setEnabled(true); | 229 | mEtSampleTime.setEnabled(true); |
220 | - unregisterSensor(); | ||
221 | stopLocationUpdates(); | 230 | stopLocationUpdates(); |
231 | + unregisterSensor(); | ||
222 | initViews(); | 232 | initViews(); |
223 | - mIsTripStarted = false; | ||
224 | - mTvTripButton.setText(R.string.cos_dlg_start_trip); | ||
225 | } else { | 233 | } else { |
226 | if (mEtLimit.getText().length() == 0) { | 234 | if (mEtLimit.getText().length() == 0) { |
227 | Snackbar.make(mLlTelematicsMain, "Please fill the Cut off field", Snackbar.LENGTH_SHORT).show(); | 235 | Snackbar.make(mLlTelematicsMain, "Please fill the Cut off field", Snackbar.LENGTH_SHORT).show(); |
... | @@ -237,9 +245,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -237,9 +245,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
237 | } | 245 | } |
238 | }; | 246 | }; |
239 | requestLocationUpdates(); | 247 | requestLocationUpdates(); |
240 | - registerSensor(); | ||
241 | - mIsTripStarted = true; | ||
242 | - mTvTripButton.setText(R.string.cos_dlg_stop_trip); | ||
243 | } | 248 | } |
244 | } | 249 | } |
245 | } | 250 | } |
... | @@ -253,18 +258,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -253,18 +258,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
253 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | 258 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
254 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); | 259 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
255 | 260 | ||
256 | - if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) { | ||
257 | - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
258 | -// saveAccelerationDataToExternalStorage(jsonArray); | ||
259 | - sendAccelerationDataToServer(jsonArray); | ||
260 | - } else { | ||
261 | - Snackbar.make(mLlTelematicsMain, "Storage Permission Denied", Snackbar.LENGTH_SHORT).show(); | ||
262 | - } | ||
263 | - return; | ||
264 | - } | ||
265 | if (requestCode == PERMISSION_REQUEST_ACCESS_FINE_LOCATION) { | 261 | if (requestCode == PERMISSION_REQUEST_ACCESS_FINE_LOCATION) { |
266 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | 262 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
267 | - startLocationUpdates(); | 263 | + enableLocationSettings(); |
268 | } else { | 264 | } else { |
269 | Snackbar.make(mLlTelematicsMain, "Location Permission Denied", Snackbar.LENGTH_SHORT).show(); | 265 | Snackbar.make(mLlTelematicsMain, "Location Permission Denied", Snackbar.LENGTH_SHORT).show(); |
270 | } | 266 | } |
... | @@ -273,17 +269,15 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -273,17 +269,15 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
273 | 269 | ||
274 | @Override | 270 | @Override |
275 | public void onLocationChanged(Location location) { | 271 | public void onLocationChanged(Location location) { |
276 | - //TODO: comment the first block and uncomment the second block if needs revert to handler implementation | 272 | + if (mIsTripStarted) { |
277 | - if (mLatitude != 0 && mLongitude != 0) { | 273 | + if (mLatitude != 0 && mLongitude != 0) { |
278 | - mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); | 274 | + mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); |
279 | - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h"); | 275 | + mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h"); |
280 | - } | 276 | + } |
281 | - | ||
282 | 277 | ||
283 | -// if (mLatitude != 0 && mLongitude != 0) | 278 | + mLatitude = location.getLatitude(); |
284 | -// requestLocationUpdatePeriodically(location); | 279 | + mLongitude = location.getLongitude(); |
285 | - mLatitude = location.getLatitude(); | 280 | + } |
286 | - mLongitude = location.getLongitude(); | ||
287 | } | 281 | } |
288 | 282 | ||
289 | @Override | 283 | @Override |
... | @@ -312,45 +306,33 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -312,45 +306,33 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
312 | } | 306 | } |
313 | } | 307 | } |
314 | 308 | ||
315 | -// @Override | 309 | + @Override |
316 | -// public boolean dispatchTouchEvent(MotionEvent event) { | 310 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
317 | -// if (mIsTripStarted) { | 311 | + if (requestCode == REQUEST_LOCATION_SETTINGS) { |
318 | -// switch (event.getAction()) { | 312 | + switch (resultCode) { |
319 | -// case MotionEvent.ACTION_DOWN: | 313 | + case Activity.RESULT_OK: |
320 | -// touchCount++; | 314 | + mIsTripStarted = true; |
321 | -// mTvTouchCount.setText(String.valueOf(touchCount)); | 315 | + mTvTripButton.setText(R.string.cos_dlg_stop_trip); |
322 | -// mTouchHandler.post(mTouchRunnable); | 316 | + startLocationUpdates(); |
323 | -// return true; | 317 | + registerSensor(); |
324 | -// case MotionEvent.ACTION_UP: | 318 | + break; |
325 | -// mTouchHandler.removeCallbacks(mTouchRunnable); | 319 | + case Activity.RESULT_CANCELED: |
326 | -// return true; | 320 | + if (!isFinishing()) { |
327 | -// } | 321 | + AlertDialog.Builder builder = new AlertDialog.Builder(this); |
328 | -// } | 322 | + builder.setTitle(getString(R.string.cos_telematics)); |
329 | -// return super.dispatchTouchEvent(event); | 323 | + builder.setMessage(getString(R.string.lbl_telematics_no_location)) |
330 | -// } | 324 | + .setCancelable(false) |
331 | - | 325 | + .setNegativeButton(getString(R.string.cos_dlg_positive_button2), (dialog, id) -> { |
332 | -// @Override | 326 | + }); |
333 | -// public boolean onTouchEvent(MotionEvent event) { | 327 | + AlertDialog alert = builder.create(); |
334 | -//// return super.onTouchEvent(event); | 328 | + alert.show(); |
335 | -// if (mIsTripStarted) { | 329 | + } |
336 | -//// touchCount++; | 330 | + break; |
337 | -//// mTvTouchCount.setText(String.valueOf(touchCount)); | 331 | + default: |
338 | -//// return true; | 332 | + break; |
339 | -// | 333 | + } |
340 | -// switch (event.getAction()) { | 334 | + } |
341 | -// case MotionEvent.ACTION_DOWN: | 335 | + } |
342 | -// touchCount++; | ||
343 | -// mTvTouchCount.setText(String.valueOf(touchCount)); | ||
344 | -// mTouchHandler.post(mTouchRunnable); | ||
345 | -// return true; | ||
346 | -// case MotionEvent.ACTION_UP: | ||
347 | -// mTouchHandler.removeCallbacks(mTouchRunnable); | ||
348 | -// return true; | ||
349 | -// } | ||
350 | -// return false; | ||
351 | -// } | ||
352 | -// return false; | ||
353 | -// } | ||
354 | 336 | ||
355 | // =========================================================== | 337 | // =========================================================== |
356 | // Methods | 338 | // Methods |
... | @@ -359,6 +341,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -359,6 +341,9 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
359 | private void initViews() { | 341 | private void initViews() { |
360 | mTvVelocity.setText("0.0 m/s^2"); | 342 | mTvVelocity.setText("0.0 m/s^2"); |
361 | mTvAvgVelocity.setText("0.0 km/h"); | 343 | mTvAvgVelocity.setText("0.0 km/h"); |
344 | + mTvOrientationCount.setText(String.valueOf(orientationCount)); | ||
345 | + mTvTouchCount.setText(String.valueOf(touchCount)); | ||
346 | + mTvRecordsSaved.setText(String.valueOf(touchCount)); | ||
362 | } | 347 | } |
363 | 348 | ||
364 | private void requestLocationUpdates() { | 349 | private void requestLocationUpdates() { |
... | @@ -368,7 +353,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -368,7 +353,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
368 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, | 353 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, |
369 | PERMISSION_REQUEST_ACCESS_FINE_LOCATION); | 354 | PERMISSION_REQUEST_ACCESS_FINE_LOCATION); |
370 | } else { | 355 | } else { |
371 | - startLocationUpdates(); | 356 | + enableLocationSettings(); |
372 | } | 357 | } |
373 | } | 358 | } |
374 | 359 | ||
... | @@ -383,19 +368,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -383,19 +368,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
383 | } | 368 | } |
384 | } | 369 | } |
385 | 370 | ||
386 | - private void requestLocationUpdatePeriodically(Location location) { | ||
387 | - mLocationHandler = new Handler(); | ||
388 | - mLocationRunnable = new Runnable() { | ||
389 | - @Override | ||
390 | - public void run() { | ||
391 | - double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000)); | ||
392 | - mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h"); | ||
393 | - mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL); | ||
394 | - } | ||
395 | - }; | ||
396 | - mLocationHandler.postDelayed(mLocationRunnable, LOCATION_UPDATE_INTERVAL); | ||
397 | - } | ||
398 | - | ||
399 | private double calculateDistance(double lat1, double lon1, double lat2, double lon2) { | 371 | private double calculateDistance(double lat1, double lon1, double lat2, double lon2) { |
400 | double x = Math.toRadians(lon2 - lon1) * Math.cos(Math.toRadians((lat1 + lat2) / 2)); | 372 | double x = Math.toRadians(lon2 - lon1) * Math.cos(Math.toRadians((lat1 + lat2) / 2)); |
401 | double y = Math.toRadians(lat2 - lat1); | 373 | double y = Math.toRadians(lat2 - lat1); |
... | @@ -403,24 +375,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -403,24 +375,13 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
403 | } | 375 | } |
404 | 376 | ||
405 | // Function to calculate speed in meters per second | 377 | // Function to calculate speed in meters per second |
406 | - private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) { | 378 | + private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, int timeDifferenceInSeconds) { |
407 | double distance = calculateDistance(lat1, lon1, lat2, lon2); | 379 | double distance = calculateDistance(lat1, lon1, lat2, lon2); |
408 | return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h; | 380 | return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h; |
409 | } | 381 | } |
410 | 382 | ||
411 | - private void requestSingleLocationUpdate() { | ||
412 | - try { | ||
413 | - locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null); | ||
414 | - } catch (SecurityException e) { | ||
415 | - e.printStackTrace(); | ||
416 | - Snackbar.make(mLlTelematicsMain, "requestSingleLocationUpdate Exception", Snackbar.LENGTH_SHORT).show(); | ||
417 | - } | ||
418 | - } | ||
419 | - | ||
420 | private void stopLocationUpdates() { | 383 | private void stopLocationUpdates() { |
421 | locationManager.removeUpdates(this); | 384 | locationManager.removeUpdates(this); |
422 | - if (mLocationHandler != null) | ||
423 | - mLocationHandler.removeCallbacks(mLocationRunnable); | ||
424 | } | 385 | } |
425 | 386 | ||
426 | private String getCutOffLimit() { | 387 | private String getCutOffLimit() { |
... | @@ -509,40 +470,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -509,40 +470,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
509 | } | 470 | } |
510 | jsonArray.put(jsonObject); | 471 | jsonArray.put(jsonObject); |
511 | } | 472 | } |
512 | - | ||
513 | - //TODO: uncomment if needed to write to file | ||
514 | -// if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
515 | -// != PackageManager.PERMISSION_GRANTED) { | ||
516 | -// ActivityCompat.requestPermissions(this, | ||
517 | -// new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, | ||
518 | -// PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); | ||
519 | -// } else { | ||
520 | -// saveAccelerationDataToExternalStorage(jsonArray); //TODO: uncomment if needed to write to file | ||
521 | sendAccelerationDataToServer(jsonArray); | 473 | sendAccelerationDataToServer(jsonArray); |
522 | -// } | ||
523 | - } | ||
524 | - | ||
525 | - private void saveAccelerationDataToExternalStorage(JSONArray jsonArray) { | ||
526 | - //TODO: comment if needed to write to file | ||
527 | -// WarplyDBHelper.getInstance(this).saveTelematics(jsonArray); | ||
528 | - | ||
529 | - //TODO: uncomment if needed to write to file | ||
530 | - String state = Environment.getExternalStorageState(); | ||
531 | - if (Environment.MEDIA_MOUNTED.equals(state)) { | ||
532 | - File documentsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS); | ||
533 | - File file = new File(documentsDir, "telematics_data" + String.valueOf(System.currentTimeMillis()) + ".json"); | ||
534 | - try { | ||
535 | - FileOutputStream fileOutputStream = new FileOutputStream(file); | ||
536 | - fileOutputStream.write(jsonArray.toString().getBytes()); | ||
537 | - fileOutputStream.close(); | ||
538 | - Snackbar.make(mLlTelematicsMain, "Success saving data to file", Snackbar.LENGTH_SHORT).show(); | ||
539 | - } catch (IOException e) { | ||
540 | - e.printStackTrace(); | ||
541 | - Snackbar.make(mLlTelematicsMain, "Error saving acceleration data to file", Snackbar.LENGTH_SHORT).show(); | ||
542 | - } | ||
543 | - } else { | ||
544 | - Snackbar.make(mLlTelematicsMain, "External storage is not accessible", Snackbar.LENGTH_SHORT).show(); | ||
545 | - } | ||
546 | } | 474 | } |
547 | 475 | ||
548 | private void sendAccelerationDataToServer(JSONArray jsonArray) { | 476 | private void sendAccelerationDataToServer(JSONArray jsonArray) { |
... | @@ -594,12 +522,83 @@ public class TelematicsActivity extends Activity implements View.OnClickListener | ... | @@ -594,12 +522,83 @@ public class TelematicsActivity extends Activity implements View.OnClickListener |
594 | } | 522 | } |
595 | }; | 523 | }; |
596 | 524 | ||
597 | -// // Low-pass filter function using Exponential Moving Average (EMA) | 525 | + private void enableLocationSettings() { |
598 | -// private float lowPassFilter(float currentValue) { | 526 | + LocationRequest locationRequest = LocationRequest.create(); |
599 | -// float filteredValue = alpha * currentValue + (1 - alpha) * previousFilteredValue; | 527 | + locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); |
600 | -// previousFilteredValue = filteredValue; | 528 | + |
601 | -// return filteredValue; | 529 | + LocationSettingsRequest.Builder locationBuilder = new LocationSettingsRequest.Builder() |
602 | -// } | 530 | + .addLocationRequest(locationRequest); |
531 | + | ||
532 | + Task<LocationSettingsResponse> result = | ||
533 | + LocationServices.getSettingsClient(this).checkLocationSettings(locationBuilder.build()); | ||
534 | + | ||
535 | + result.addOnCompleteListener(task -> { | ||
536 | + try { | ||
537 | + LocationSettingsResponse response = task.getResult(ApiException.class); | ||
538 | + // All location settings are satisfied. The client can initialize location | ||
539 | + // requests here. | ||
540 | + mIsTripStarted = true; | ||
541 | + mTvTripButton.setText(R.string.cos_dlg_stop_trip); | ||
542 | + startLocationUpdates(); | ||
543 | + registerSensor(); | ||
544 | + } catch (ApiException exception) { | ||
545 | + switch (exception.getStatusCode()) { | ||
546 | + case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: | ||
547 | + // Location settings are not satisfied. But could be fixed by showing the | ||
548 | + // user a dialog. | ||
549 | + try { | ||
550 | + // Cast to a resolvable exception. | ||
551 | + ResolvableApiException resolvable = (ResolvableApiException) exception; | ||
552 | + // Show the dialog by calling startResolutionForResult(), | ||
553 | + // and check the result in onActivityResult(). | ||
554 | + resolvable.startResolutionForResult(TelematicsActivity.this, REQUEST_LOCATION_SETTINGS); | ||
555 | + } catch (IntentSender.SendIntentException e) { | ||
556 | + // Ignore the error. | ||
557 | + Log.v("SendIntentException", e.getMessage()); | ||
558 | + if (!isFinishing()) { | ||
559 | + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); | ||
560 | + alertBuilder.setTitle(getString(R.string.cos_telematics)); | ||
561 | + alertBuilder.setMessage(getString(R.string.lbl_telematics_generic_error)) | ||
562 | + .setCancelable(false) | ||
563 | + .setNegativeButton(getString(R.string.cos_dlg_positive_button2), (dialog, id) -> { | ||
564 | + }); | ||
565 | + AlertDialog alert = alertBuilder.create(); | ||
566 | + alert.show(); | ||
567 | + } | ||
568 | + } catch (ClassCastException e) { | ||
569 | + // Ignore, should be an impossible error. | ||
570 | + Log.v("ClassCastException", e.getMessage()); | ||
571 | + if (!isFinishing()) { | ||
572 | + AlertDialog.Builder alertBuilder2 = new AlertDialog.Builder(this); | ||
573 | + alertBuilder2.setTitle(getString(R.string.cos_telematics)); | ||
574 | + alertBuilder2.setMessage(getString(R.string.lbl_telematics_generic_error)) | ||
575 | + .setCancelable(false) | ||
576 | + .setNegativeButton(getString(R.string.cos_dlg_positive_button2), (dialog, id) -> { | ||
577 | + }); | ||
578 | + AlertDialog alert = alertBuilder2.create(); | ||
579 | + alert.show(); | ||
580 | + } | ||
581 | + } | ||
582 | + break; | ||
583 | + case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: | ||
584 | + // Location settings are not satisfied. However, we have no way to fix the | ||
585 | + // settings so we won't show the dialog. | ||
586 | + Log.v("SETTINGS_CHANGE_UNAVAILABLE", "SETTINGS_CHANGE_UNAVAILABLE"); | ||
587 | + if (!isFinishing()) { | ||
588 | + AlertDialog.Builder alertBuilder3 = new AlertDialog.Builder(this); | ||
589 | + alertBuilder3.setTitle(getString(R.string.cos_telematics)); | ||
590 | + alertBuilder3.setMessage(getString(R.string.lbl_telematics_generic_error)) | ||
591 | + .setCancelable(false) | ||
592 | + .setNegativeButton(getString(R.string.cos_dlg_positive_button2), (dialog, id) -> { | ||
593 | + }); | ||
594 | + AlertDialog alert = alertBuilder3.create(); | ||
595 | + alert.show(); | ||
596 | + } | ||
597 | + break; | ||
598 | + } | ||
599 | + } | ||
600 | + }); | ||
601 | + } | ||
603 | 602 | ||
604 | // =========================================================== | 603 | // =========================================================== |
605 | // Inner and Anonymous Classes | 604 | // Inner and Anonymous Classes | ... | ... |
... | @@ -187,6 +187,8 @@ | ... | @@ -187,6 +187,8 @@ |
187 | <string name="cos_telematics_history">Ιστορικό</string> | 187 | <string name="cos_telematics_history">Ιστορικό</string> |
188 | <string name="cos_telematics_history_analysis_title">Ανάλυση παραμέτρων ασφαλούς οδήγησης</string> | 188 | <string name="cos_telematics_history_analysis_title">Ανάλυση παραμέτρων ασφαλούς οδήγησης</string> |
189 | <string name="cos_telematics_history_analysis_rate">Αξιολογήστε την ανάλυση</string> | 189 | <string name="cos_telematics_history_analysis_rate">Αξιολογήστε την ανάλυση</string> |
190 | + <string name="lbl_telematics_no_location">Για να ξεκινήσετε θα πρέπει να ενεργοποιήσετε την τοποθεσία σας</string> | ||
191 | + <string name="lbl_telematics_generic_error">Άγνωστο σφάλμα</string> | ||
190 | 192 | ||
191 | <string-array name="coupons_array"> | 193 | <string-array name="coupons_array"> |
192 | <item>Κουπόνια</item> | 194 | <item>Κουπόνια</item> | ... | ... |
-
Please register or login to post a comment