Panagiotis Triantafyllou

telematics fixes

......@@ -65,11 +65,11 @@
android:screenOrientation="portrait"
android:theme="@style/SDKAppTheme" />
<!-- <activity-->
<!-- android:name="ly.warp.sdk.activities.TelematicsActivity"-->
<!-- android:exported="false"-->
<!-- android:screenOrientation="portrait"-->
<!-- android:theme="@style/SDKAppTheme" />-->
<activity
android:name="ly.warp.sdk.activities.TelematicsActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/SDKAppTheme" />
<activity
android:name="ly.warp.sdk.activities.GiftsForYouActivity"
......
......@@ -74,7 +74,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 4001;
JSONArray jsonArray = new JSONArray();
private LocationManager locationManager;
private static final int LOCATION_UPDATE_INTERVAL = 5000;
private static final int LOCATION_UPDATE_INTERVAL = 1000;
double mLatitude = 0;
double mLongitude = 0;
// Radius of the Earth in meters
......@@ -109,7 +109,6 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
public void onResume() {
super.onResume();
requestLocationUpdates();
// WarplyAnalyticsManager.logTrackersEvent(this, "screen", "TelematicsActivity");
}
......@@ -183,6 +182,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
mIsTripStarted = false;
mTvTripButton.setText(R.string.cos_dlg_start_trip);
} else {
requestLocationUpdates();
registerStepSensor();
mIsTripStarted = true;
mTvTripButton.setText(R.string.cos_dlg_stop_trip);
......@@ -197,6 +197,8 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
saveAccelerationDataToExternalStorage(jsonArray);
......@@ -218,10 +220,16 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
public void onLocationChanged(Location location) {
//TODO: uncomment and remove setText if needs revert to handler implementation
//TODO: LOCATION_UPDATE_INTERVAL = 300 when using location.getSpeed()
// float speedKmph = (location.getSpeed() * 3600) / 1000;
// float speedKmph = location.getSpeed() * 3.6f;
// mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speedKmph)) + " km/h");
if (mLatitude != 0 && mLongitude != 0)
requestLocationUpdatePeriodically(location);
if (mLatitude != 0 && mLongitude != 0) {
double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h");
}
// if (mLatitude != 0 && mLongitude != 0)
// requestLocationUpdatePeriodically(location);
mLatitude = location.getLatitude();
mLongitude = location.getLongitude();
}
......@@ -251,15 +259,12 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
}
private void requestLocationUpdates() {
// Check if the ACCESS_FINE_LOCATION permission is granted
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted, request it
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSION_REQUEST_ACCESS_FINE_LOCATION);
} else {
// Permission is granted, start requesting location updates
startLocationUpdates();
}
}
......