|
@@ -18,6 +18,7 @@ import android.support.v4.content.ContextCompat;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import app.brest.testmin3d.ARActivity;
|
|
|
+import app.brest.testmin3d.R;
|
|
|
import app.brest.utils.geometry.GPSPoint;
|
|
|
|
|
|
/**
|
|
@@ -25,6 +26,7 @@ import app.brest.utils.geometry.GPSPoint;
|
|
|
*/
|
|
|
public class SensorsManager implements SensorEventListener, LocationListener {
|
|
|
|
|
|
+ public final boolean USE_GPS_STUB=true;
|
|
|
private SensorManager mSensorManager;
|
|
|
private Sensor mAccelerometer;
|
|
|
private Sensor mMagnetometer;
|
|
@@ -47,6 +49,7 @@ public class SensorsManager implements SensorEventListener, LocationListener {
|
|
|
private float mAccuracy;
|
|
|
private boolean mIsLocalised = false;
|
|
|
private Activity mParent;
|
|
|
+ private GpsStub mStub=null;
|
|
|
|
|
|
public float getAzimuth() {
|
|
|
return mBufferX.average();
|
|
@@ -90,14 +93,21 @@ public class SensorsManager implements SensorEventListener, LocationListener {
|
|
|
ActivityCompat.checkSelfPermission(mParent, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
}
|
|
|
- if (ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
|
|
|
- PackageManager.PERMISSION_GRANTED &&
|
|
|
- ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
|
|
- PackageManager.PERMISSION_GRANTED) {
|
|
|
- mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
|
|
- } else {
|
|
|
- Toast.makeText(parent,"Error", Toast.LENGTH_LONG).show();
|
|
|
- mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
|
|
+ if(!USE_GPS_STUB) {
|
|
|
+ if (ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
|
|
|
+ PackageManager.PERMISSION_GRANTED &&
|
|
|
+ ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
|
|
+ PackageManager.PERMISSION_GRANTED) {
|
|
|
+ mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
|
|
+ } else {
|
|
|
+ Toast.makeText(parent, "Error", Toast.LENGTH_LONG).show();
|
|
|
+ mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(USE_GPS_STUB) {
|
|
|
+ mIsLocalised=true;
|
|
|
+ mStub=new GpsStub(parent.getResources().getString(R.string.gps_stub));
|
|
|
+ nextStub();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -177,9 +187,11 @@ public class SensorsManager implements SensorEventListener, LocationListener {
|
|
|
@Override
|
|
|
public void onLocationChanged(Location location) {
|
|
|
mIsLocalised=true;
|
|
|
- mLongitude=location.getLongitude();
|
|
|
- mLatitude=location.getLatitude();
|
|
|
- mAccuracy=location.getAccuracy();
|
|
|
+ if(!USE_GPS_STUB) {
|
|
|
+ mLongitude = location.getLongitude();
|
|
|
+ mLatitude = location.getLatitude();
|
|
|
+ mAccuracy = location.getAccuracy();
|
|
|
+ }
|
|
|
|
|
|
ARActivity.setLocation(new GPSPoint(mLatitude, mLongitude, mAccuracy));
|
|
|
//Toast.makeText(mParent, "Longitude: "+location.getLongitude()+ " Latitude: "+location.getLatitude(), Toast.LENGTH_LONG).show();
|
|
@@ -195,4 +207,17 @@ public class SensorsManager implements SensorEventListener, LocationListener {
|
|
|
|
|
|
@Override
|
|
|
public void onProviderDisabled(String s) {}
|
|
|
+
|
|
|
+ public void nextStub()
|
|
|
+ {
|
|
|
+ if(USE_GPS_STUB)
|
|
|
+ {
|
|
|
+ GPSPoint stub = mStub.next();
|
|
|
+ if(stub==null) return;
|
|
|
+ mLongitude=stub.getX();
|
|
|
+ mLatitude=stub.getY();
|
|
|
+ mAccuracy=stub.getAccuracy();
|
|
|
+ ARActivity.setLocation(new GPSPoint(mLatitude, mLongitude, mAccuracy));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|