POI management changes

This commit is contained in:
Jens 2021-06-10 23:22:38 +02:00
parent 7b88e7a612
commit ab51eb3655
2 changed files with 51 additions and 74 deletions

View File

@ -21,6 +21,8 @@ import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.Toast; import android.widget.Toast;
import java.util.Calendar;
public class ActivityManagePoi extends Activity public class ActivityManagePoi extends Activity
{ {
public LocationManager myLocationManager; public LocationManager myLocationManager;
@ -31,6 +33,10 @@ public class ActivityManagePoi extends Activity
Button bGetPosition, bSavePoi; Button bGetPosition, bSavePoi;
ImageButton ibShowOnMap; ImageButton ibShowOnMap;
EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius; EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius;
Calendar locationSearchStart = null;
final static int defaultRadius = 300;
final static int searchTimeout = 120;
private static ProgressDialog progressDialog; private static ProgressDialog progressDialog;
@ -150,17 +156,20 @@ public class ActivityManagePoi extends Activity
} }
else else
{ {
locationSearchStart = Calendar.getInstance();
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider1, 3); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider1, 3);
myLocationManager.requestLocationUpdates(provider1, 500, Settings.satisfactoryAccuracyNetwork, myLocationListenerNetwork); myLocationManager.requestLocationUpdates(provider1, 500, Settings.satisfactoryAccuracyNetwork, myLocationListenerNetwork);
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider2, 3); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider2, 3);
myLocationManager.requestLocationUpdates(provider2, 500, Settings.satisfactoryAccuracyGps, myLocationListenerGps); myLocationManager.requestLocationUpdates(provider2, 500, Settings.satisfactoryAccuracyGps, myLocationListenerGps);
} }
} }
private void compareLocations() private void compareLocations()
{ {
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.comparing), 4);
if(locationGps != null) if(locationGps != null)
{ {
guiPoiLatitude.setText(String.valueOf(locationGps.getLatitude())); guiPoiLatitude.setText(String.valueOf(locationGps.getLatitude()));
@ -168,20 +177,11 @@ public class ActivityManagePoi extends Activity
if(locationNetwork != null) if(locationNetwork != null)
{ {
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.comparing), 4);
double variance = locationGps.distanceTo(locationNetwork); double variance = locationGps.distanceTo(locationNetwork);
String text = String.format(getResources().getString(R.string.distanceBetween), Math.round(variance)); String text = String.format(getResources().getString(R.string.distanceBetween), Math.round(variance));
// Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG).show();
Miscellaneous.logEvent("i", "POI Manager", text, 4); Miscellaneous.logEvent("i", "POI Manager", text, 4);
// if(variance > 50 && guiPoiRadius.getText().toString().length()>0 && Integer.parseInt(guiPoiRadius.getText().toString())<variance)
// {
// String text = "Positioning via network is off by " + variance + " meters. The radius you specify shouldn't be smaller than that.";
getDialog(text, Math.round(variance) + 1).show(); getDialog(text, Math.round(variance) + 1).show();
// Toast.makeText(getBaseContext(), "Positioning via network is off by " + variance + " meters. The radius you specify shouldn't be smaller than that.", Toast.LENGTH_LONG).show();
// }
} }
else else
{ {
@ -190,6 +190,31 @@ public class ActivityManagePoi extends Activity
guiPoiRadius.setText("250"); guiPoiRadius.setText("250");
} }
} }
else if(locationNetwork != null && locationNetwork.getAccuracy() <= Settings.satisfactoryAccuracyGps && locationNetwork.getAccuracy() <= defaultRadius)
{
/*
We do not yet have a GPS result. But we have a network result that is good enough
to accept it a sole result. In that case we suggest a default radius, no variance.
*/
String text = String.format(getResources().getString(R.string.locationFound), defaultRadius);
Miscellaneous.logEvent("i", "POI Manager", text, 4);
getDialog(text, defaultRadius).show();
}
else if(
locationNetwork != null
&&
Calendar.getInstance().getTimeInMillis()
>
(locationSearchStart.getTimeInMillis() + ((long)searchTimeout * 1000))
)
{
// Only a network location was found that is also not very accurate.
String text = String.format(getResources().getString(R.string.locationFoundInaccurate), defaultRadius);
Miscellaneous.logEvent("i", "POI Manager", text, 4);
}
else else
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logNotAllMeasurings), 4); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logNotAllMeasurings), 4);
} }
@ -203,15 +228,6 @@ public class ActivityManagePoi extends Activity
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
// switch(which)
// {
// case DialogInterface.BUTTON_POSITIVE:
// guiPoiRadius.setText(String.valueOf(value));
// break;
// case DialogInterface.BUTTON_NEGATIVE:
// break;
// }
progressDialog = ProgressDialog.show(ActivityManagePoi.this, "", getResources().getString(R.string.gettingPosition), true, true); progressDialog = ProgressDialog.show(ActivityManagePoi.this, "", getResources().getString(R.string.gettingPosition), true, true);
getLocation(); getLocation();
} }
@ -251,7 +267,6 @@ public class ActivityManagePoi extends Activity
public class MyLocationListenerGps implements LocationListener public class MyLocationListenerGps implements LocationListener
{ {
@Override @Override
public void onLocationChanged(Location location) public void onLocationChanged(Location location)
{ {
@ -288,66 +303,27 @@ public class ActivityManagePoi extends Activity
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }
// public class MyLocationListenerWifi implements LocationListener
// {
//
// @Override
// public void onLocationChanged(Location location)
// {
// Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.gotGpsUpdate) + " " + String.valueOf(location.getAccuracy()));
// // Deactivate when accuracy reached
//// if(location.getAccuracy() < Settings.SATISFACTORY_ACCURACY_GPS)
//// {
//// Miscellaneous.logEvent("i", "POI Manager", "satisfactoryNetworkAccuracy of " + String.valueOf(Settings.SATISFACTORY_ACCURACY_GPS) + "m reached. Removing location updates...");
//
// myLocationManager.removeUpdates(this);
// locationGps = location;
//
// compareLocations();
//// }
// }
//
// @Override
// public void onProviderDisabled(String provider)
// {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void onProviderEnabled(String provider)
// {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void onStatusChanged(String provider, int status, Bundle extras)
// {
// // TODO Auto-generated method stub
//
// }
//
// }
public class MyLocationListenerNetwork implements LocationListener public class MyLocationListenerNetwork implements LocationListener
{ {
@Override @Override
public void onLocationChanged(Location location) public void onLocationChanged(Location location)
{ {
Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGotNetworkUpdate) + " " + String.valueOf(location.getAccuracy()), 3); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGotNetworkUpdate) + " " + String.valueOf(location.getAccuracy()), 3);
String text = "Network position found. satisfactoryNetworkAccuracy of " + String.valueOf(Settings.satisfactoryAccuracyNetwork) + "m reached. Removing location updates...";
Miscellaneous.logEvent("i", "POI Manager", text, 5);
myLocationManager.removeUpdates(this);
locationNetwork = location;
// Deactivate when accuracy reached // Deactivate when accuracy reached
// if(location.getAccuracy() < Settings.SATISFACTORY_ACCURACY_GPS) if(location.getAccuracy() <= Settings.satisfactoryAccuracyGps)
// { {
// String text = "Network position found. satisfactoryNetworkAccuracy of " + String.valueOf(Settings.SATISFACTORY_ACCURACY_NETWORK) + "m reached. Removing location updates..."; // Accuracy is so good that we don't need to wait for GPS result
// Miscellaneous.logEvent("i", "POI Manager", text); myLocationManager.removeUpdates(myLocationListenerGps);
myLocationManager.removeUpdates(this); }
locationNetwork = location;
compareLocations();
compareLocations();
// }
} }
@Override @Override
@ -370,7 +346,6 @@ public class ActivityManagePoi extends Activity
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }
public void editPoi(PointOfInterest poi) public void editPoi(PointOfInterest poi)

View File

@ -678,4 +678,6 @@
<string name="automaticUpdateCheck">Check for updates</string> <string name="automaticUpdateCheck">Check for updates</string>
<string name="automaticUpdateCheckSummary">Only applies to APK version.</string> <string name="automaticUpdateCheckSummary">Only applies to APK version.</string>
<string name="updateAvailable">There\'s a new update available. Would you like opening the browser to download it?</string> <string name="updateAvailable">There\'s a new update available. Would you like opening the browser to download it?</string>
<string name="locationFound">Location found. The suggested minimum radius for locations is %1$d."</string>
<string name="locationFoundInaccurate">Only a location with a limited accuracy could be found. It might not work reliably. The suggested minimum radius for locations is %1$d."</string>
</resources> </resources>