fix stupid errors for android htc 2.1 (there were not reproducible in 1.5)
git-svn-id: https://osmand.googlecode.com/svn/trunk@313 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
3d2692afd9
commit
7089997b81
2 changed files with 1061 additions and 1015 deletions
|
@ -77,12 +77,13 @@ import com.osmand.views.PointNavigationLayer;
|
||||||
import com.osmand.views.RouteLayer;
|
import com.osmand.views.RouteLayer;
|
||||||
import com.osmand.views.TransportStopsLayer;
|
import com.osmand.views.TransportStopsLayer;
|
||||||
|
|
||||||
public class MapActivity extends Activity implements LocationListener, IMapLocationListener, SensorEventListener {
|
public class MapActivity extends Activity implements IMapLocationListener, SensorEventListener {
|
||||||
|
|
||||||
private static final String GPS_STATUS_ACTIVITY = "com.eclipsim.gpsstatus2.GPSStatus"; //$NON-NLS-1$
|
private static final String GPS_STATUS_ACTIVITY = "com.eclipsim.gpsstatus2.GPSStatus"; //$NON-NLS-1$
|
||||||
private static final String GPS_STATUS_COMPONENT = "com.eclipsim.gpsstatus2"; //$NON-NLS-1$
|
private static final String GPS_STATUS_COMPONENT = "com.eclipsim.gpsstatus2"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final int GPS_TIMEOUT_REQUEST = 2000;
|
// stupid error but anyway hero 2.1 : always lost gps signal (temporarily unavailable) for timeout = 2000
|
||||||
|
private static final int GPS_TIMEOUT_REQUEST = 1000;
|
||||||
private static final int GPS_DIST_REQUEST = 5;
|
private static final int GPS_DIST_REQUEST = 5;
|
||||||
|
|
||||||
private boolean providerSupportsBearing = false;
|
private boolean providerSupportsBearing = false;
|
||||||
|
@ -395,6 +396,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
|
if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
|
||||||
Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
|
Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
if(location != null && OsmandSettings.isSavingTrackToGpx(this)){
|
||||||
|
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(),
|
||||||
|
location.getAltitude(), location.getSpeed(), location.getTime());
|
||||||
|
}
|
||||||
registerUnregisterSensor(location);
|
registerUnregisterSensor(location);
|
||||||
updateSpeedBearing(location);
|
updateSpeedBearing(location);
|
||||||
|
|
||||||
|
@ -472,26 +477,6 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
return routingHelper;
|
return routingHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(Location location) {
|
|
||||||
if(location != null && OsmandSettings.isSavingTrackToGpx(this)){
|
|
||||||
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(),
|
|
||||||
location.getAltitude(), location.getSpeed(), location.getTime());
|
|
||||||
}
|
|
||||||
setLocation(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderDisabled(String provider) {
|
|
||||||
setLocation(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderEnabled(String provider) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isRunningOnEmulator(){
|
private boolean isRunningOnEmulator(){
|
||||||
if (Build.DEVICE.equals("generic")) { //$NON-NLS-1$
|
if (Build.DEVICE.equals("generic")) { //$NON-NLS-1$
|
||||||
return true;
|
return true;
|
||||||
|
@ -499,17 +484,56 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
// Working with location listeners
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
private LocationListener networkListener = new LocationListener(){
|
||||||
if (LocationManager.GPS_PROVIDER.equals(provider)) {
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
setLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
|
if(LocationProvider.OUT_OF_SERVICE == status){
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private LocationListener gpsListener = new LocationListener(){
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
setLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
LocationProvider prov = service.getProvider(LocationManager.NETWORK_PROVIDER);
|
LocationProvider prov = service.getProvider(LocationManager.NETWORK_PROVIDER);
|
||||||
if (LocationProvider.OUT_OF_SERVICE == status || LocationProvider.TEMPORARILY_UNAVAILABLE == status) {
|
// do not change provider for temporarily unavailable (possible bug for htc hero 2.1 ?)
|
||||||
|
if (LocationProvider.OUT_OF_SERVICE == status /*|| LocationProvider.TEMPORARILY_UNAVAILABLE == status*/) {
|
||||||
if(LocationProvider.OUT_OF_SERVICE == status){
|
if(LocationProvider.OUT_OF_SERVICE == status){
|
||||||
setLocation(null);
|
setLocation(null);
|
||||||
}
|
}
|
||||||
if(!isRunningOnEmulator() && service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
|
if (!isRunningOnEmulator() && service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||||
if(!Algoritms.objectEquals(currentLocationProvider, LocationManager.NETWORK_PROVIDER)){
|
if (!Algoritms.objectEquals(currentLocationProvider, LocationManager.NETWORK_PROVIDER)) {
|
||||||
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
||||||
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
||||||
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
||||||
|
@ -517,25 +541,26 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (LocationProvider.AVAILABLE == status) {
|
} else if (LocationProvider.AVAILABLE == status) {
|
||||||
if(!Algoritms.objectEquals(currentLocationProvider, LocationManager.GPS_PROVIDER)){
|
if (!Algoritms.objectEquals(currentLocationProvider, LocationManager.GPS_PROVIDER)) {
|
||||||
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
||||||
service.removeUpdates(this);
|
service.removeUpdates(networkListener);
|
||||||
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
|
||||||
prov = service.getProvider(LocationManager.GPS_PROVIDER);
|
prov = service.getProvider(LocationManager.GPS_PROVIDER);
|
||||||
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
||||||
providerSupportsSpeed = prov == null ? false : prov.supportsSpeed() && !isRunningOnEmulator();
|
providerSupportsSpeed = prov == null ? false : prov.supportsSpeed() && !isRunningOnEmulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
service.removeUpdates(this);
|
service.removeUpdates(gpsListener);
|
||||||
|
service.removeUpdates(networkListener);
|
||||||
|
|
||||||
SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
|
SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
sensorMgr.unregisterListener(this);
|
sensorMgr.unregisterListener(this);
|
||||||
|
@ -607,17 +632,15 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
|
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, gpsListener);
|
||||||
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
||||||
if(!isRunningOnEmulator()){
|
if(!isRunningOnEmulator()){
|
||||||
// try to always ask for network provide it is faster way to find location
|
// try to always ask for network provide : it is faster way to find location
|
||||||
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, networkListener);
|
||||||
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
||||||
} else {
|
|
||||||
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
|
||||||
}
|
}
|
||||||
LocationProvider prov = service.getProvider(currentLocationProvider);
|
|
||||||
|
|
||||||
|
LocationProvider prov = service.getProvider(currentLocationProvider);
|
||||||
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator();
|
||||||
providerSupportsSpeed = prov == null ? false : prov.supportsSpeed() && !isRunningOnEmulator();
|
providerSupportsSpeed = prov == null ? false : prov.supportsSpeed() && !isRunningOnEmulator();
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,12 @@ import com.osmand.osm.OpeningHoursParser.OpeningHoursRule;
|
||||||
* @author Maxim Frolov
|
* @author Maxim Frolov
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SearchPOIActivity extends ListActivity implements LocationListener, SensorEventListener {
|
public class SearchPOIActivity extends ListActivity implements SensorEventListener {
|
||||||
|
|
||||||
public static final String AMENITY_FILTER = "com.osmand.amenity_filter"; //$NON-NLS-1$
|
public static final String AMENITY_FILTER = "com.osmand.amenity_filter"; //$NON-NLS-1$
|
||||||
public static final String SEARCH_LAT = "com.osmand.am_search_lat"; //$NON-NLS-1$
|
public static final String SEARCH_LAT = "com.osmand.am_search_lat"; //$NON-NLS-1$
|
||||||
public static final String SEARCH_LON = "com.osmand.am_search_lon"; //$NON-NLS-1$
|
public static final String SEARCH_LON = "com.osmand.am_search_lon"; //$NON-NLS-1$
|
||||||
private static final int GPS_TIMEOUT_REQUEST = 2000;
|
private static final int GPS_TIMEOUT_REQUEST = 1000;
|
||||||
private static final int GPS_DIST_REQUEST = 5;
|
private static final int GPS_DIST_REQUEST = 5;
|
||||||
private static final int MIN_DISTANCE_TO_RESEARCH = 70;
|
private static final int MIN_DISTANCE_TO_RESEARCH = 70;
|
||||||
private static final int MIN_DISTANCE_TO_UPDATE = 6;
|
private static final int MIN_DISTANCE_TO_UPDATE = 6;
|
||||||
|
@ -192,12 +192,51 @@ public class SearchPOIActivity extends ListActivity implements LocationListener,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
// Working with location listeners
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
private LocationListener networkListener = new LocationListener(){
|
||||||
if (LocationManager.GPS_PROVIDER.equals(provider)) {
|
@Override
|
||||||
if (LocationProvider.OUT_OF_SERVICE == status || LocationProvider.TEMPORARILY_UNAVAILABLE == status) {
|
public void onLocationChanged(Location location) {
|
||||||
if (LocationProvider.OUT_OF_SERVICE == status) {
|
setLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
|
if(LocationProvider.OUT_OF_SERVICE == status){
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private LocationListener gpsListener = new LocationListener(){
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
setLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
|
setLocation(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
|
// do not change provider for temporarily unavailable (possible bug for htc hero 2.1 ?)
|
||||||
|
if (LocationProvider.OUT_OF_SERVICE == status /*|| LocationProvider.TEMPORARILY_UNAVAILABLE == status*/) {
|
||||||
|
if(LocationProvider.OUT_OF_SERVICE == status){
|
||||||
setLocation(null);
|
setLocation(null);
|
||||||
}
|
}
|
||||||
if (!isRunningOnEmulator() && service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
if (!isRunningOnEmulator() && service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||||
|
@ -209,22 +248,11 @@ public class SearchPOIActivity extends ListActivity implements LocationListener,
|
||||||
} else if (LocationProvider.AVAILABLE == status) {
|
} else if (LocationProvider.AVAILABLE == status) {
|
||||||
if (!Algoritms.objectEquals(currentLocationProvider, LocationManager.GPS_PROVIDER)) {
|
if (!Algoritms.objectEquals(currentLocationProvider, LocationManager.GPS_PROVIDER)) {
|
||||||
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
||||||
service.removeUpdates(this);
|
service.removeUpdates(networkListener);
|
||||||
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(Location location) {
|
|
||||||
setLocation(location);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onProviderDisabled(String provider) {
|
|
||||||
setLocation(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
|
@ -247,11 +275,6 @@ public class SearchPOIActivity extends ListActivity implements LocationListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderEnabled(String provider) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
}
|
}
|
||||||
|
@ -280,13 +303,12 @@ public class SearchPOIActivity extends ListActivity implements LocationListener,
|
||||||
showOnMap.setEnabled(filter != null);
|
showOnMap.setEnabled(filter != null);
|
||||||
if (searchNearBy) {
|
if (searchNearBy) {
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, gpsListener);
|
||||||
|
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
||||||
if(!isRunningOnEmulator()){
|
if(!isRunningOnEmulator()){
|
||||||
// try to always ask for network provide it is faster way to find location
|
// try to always ask for network provide it is faster way to find location
|
||||||
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, this);
|
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, networkListener);
|
||||||
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
|
||||||
} else {
|
|
||||||
currentLocationProvider = LocationManager.GPS_PROVIDER;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,7 +340,8 @@ public class SearchPOIActivity extends ListActivity implements LocationListener,
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (searchNearBy) {
|
if (searchNearBy) {
|
||||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
service.removeUpdates(this);
|
service.removeUpdates(gpsListener);
|
||||||
|
service.removeUpdates(networkListener);
|
||||||
|
|
||||||
SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
|
SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
sensorMgr.unregisterListener(this);
|
sensorMgr.unregisterListener(this);
|
||||||
|
|
Loading…
Reference in a new issue