Suppress gpsLocationLost() in one place, causes bogus prompt

This commit is contained in:
sonora 2012-02-16 21:43:11 +01:00
parent 04179fba54
commit 3807c0f2e4

View file

@ -143,13 +143,13 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
return notification; return notification;
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
settings = getMyApplication().getSettings(); settings = getMyApplication().getSettings();
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
// Full screen is not used here // Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main); setContentView(R.layout.main);
startProgressDialog = new ProgressDialog(this); startProgressDialog = new ProgressDialog(this);
startProgressDialog.setCancelable(true); startProgressDialog.setCancelable(true);
@ -230,8 +230,8 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
addDialogProvider(poiActions); addDialogProvider(poiActions);
addDialogProvider(mapLayers.getOsmBugsLayer()); addDialogProvider(mapLayers.getOsmBugsLayer());
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) { if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
@ -309,13 +309,13 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
getMyApplication().getDaynightHelper().onMapResume(); getMyApplication().getDaynightHelper().onMapResume();
mapView.refreshMap(true); mapView.refreshMap(true);
} }
private void notRestoreRoutingMode(){ private void notRestoreRoutingMode(){
boolean changed = settings.APPLICATION_MODE.set(ApplicationMode.DEFAULT); boolean changed = settings.APPLICATION_MODE.set(ApplicationMode.DEFAULT);
updateApplicationModeSettings(); updateApplicationModeSettings();
routingHelper.clearCurrentRoute(null); routingHelper.clearCurrentRoute(null);
mapView.refreshMap(changed); mapView.refreshMap(changed);
} }
private void restoreRoutingMode(final LatLon pointToNavigate) { private void restoreRoutingMode(final LatLon pointToNavigate) {
final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get(); final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
@ -374,43 +374,41 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
OsmandApplication getMyApplication() { OsmandApplication getMyApplication() {
return ((OsmandApplication) getApplication()); return ((OsmandApplication) getApplication());
} }
private void addDialogProvider(DialogProvider dp) { private void addDialogProvider(DialogProvider dp) {
dialogProviders.add(dp); dialogProviders.add(dp);
} }
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
Dialog dialog = null; Dialog dialog = null;
for (DialogProvider dp : dialogProviders) { for (DialogProvider dp : dialogProviders) {
dialog = dp.onCreateDialog(id); dialog = dp.onCreateDialog(id);
if (dialog != null) { if (dialog != null) {
return dialog; return dialog;
} }
} }
if (id == OsmandApplication.PROGRESS_DIALOG) { if (id == OsmandApplication.PROGRESS_DIALOG) {
return startProgressDialog; return startProgressDialog;
} }
return null; return null;
} }
@Override @Override
protected void onPrepareDialog(int id, Dialog dialog) { protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog); super.onPrepareDialog(id, dialog);
for (DialogProvider dp : dialogProviders) { for (DialogProvider dp : dialogProviders) {
dp.onPrepareDialog(id, dialog); dp.onPrepareDialog(id, dialog);
} }
} }
public void changeZoom(int newZoom){ public void changeZoom(int newZoom){
boolean changeLocation = settings.AUTO_ZOOM_MAP.get(); boolean changeLocation = settings.AUTO_ZOOM_MAP.get();
mapView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation); mapView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation);
showAndHideMapPosition(); showAndHideMapPosition();
} }
public void backToMainMenu() { public void backToMainMenu() {
final Dialog dlg = new Dialog(this, R.style.Dialog_Fullscreen); final Dialog dlg = new Dialog(this, R.style.Dialog_Fullscreen);
final View menuView = (View) getLayoutInflater().inflate(R.layout.menu, null); final View menuView = (View) getLayoutInflater().inflate(R.layout.menu, null);
@ -505,13 +503,13 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
// startActivity(newIntent); // startActivity(newIntent);
} }
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
//some application/hardware needs that back button reacts on key up, so //some application/hardware needs that back button reacts on key up, so
//that they could do some key combinations with it... //that they could do some key combinations with it...
// Victor : doing in that way doesn't close dialog properly! // Victor : doing in that way doesn't close dialog properly!
// return true; //return true;
} else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
Intent newIntent = new Intent(MapActivity.this, SearchActivity.class); Intent newIntent = new Intent(MapActivity.this, SearchActivity.class);
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -520,7 +518,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
startActivity(newIntent); startActivity(newIntent);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return true; return true;
} else if (!routingHelper.isFollowingMode()) { } else if (!routingHelper.isFollowingMode()) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) {
if (mapView.isZooming()) { if (mapView.isZooming()) {
@ -534,70 +532,70 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
return true; return true;
} }
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void setMapLocation(double lat, double lon){ public void setMapLocation(double lat, double lon){
mapView.setLatLon(lat, lon); mapView.setLatLon(lat, lon);
locationChanged(lat, lon, this); locationChanged(lat, lon, this);
} }
@Override @Override
public boolean onTrackballEvent(MotionEvent event) { public boolean onTrackballEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()){ if(event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()){
float x = event.getX(); float x = event.getX();
float y = event.getY(); float y = event.getY();
LatLon l = mapView.getLatLonFromScreenPoint(mapView.getCenterPointX() + x * 15, mapView.getCenterPointY() + y * 15); LatLon l = mapView.getLatLonFromScreenPoint(mapView.getCenterPointX() + x * 15, mapView.getCenterPointY() + y * 15);
setMapLocation(l.getLatitude(), l.getLongitude()); setMapLocation(l.getLatitude(), l.getLongitude());
return true; return true;
} }
return super.onTrackballEvent(event); return super.onTrackballEvent(event);
} }
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
} }
protected void setProgressDlg(Dialog progressDlg) { protected void setProgressDlg(Dialog progressDlg) {
this.progressDlg = progressDlg; this.progressDlg = progressDlg;
} }
protected Dialog getProgressDlg() { protected Dialog getProgressDlg() {
return progressDlg; return progressDlg;
} }
@Override @Override
protected void onStop() { protected void onStop() {
if(routingHelper.isFollowingMode()){ if(routingHelper.isFollowingMode()){
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(APP_NOTIFICATION_ID, getNotification()); mNotificationManager.notify(APP_NOTIFICATION_ID, getNotification());
} }
if(progressDlg != null){ if(progressDlg != null){
progressDlg.dismiss(); progressDlg.dismiss();
progressDlg = null; progressDlg = null;
} }
super.onStop(); super.onStop();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
savingTrackHelper.close(); savingTrackHelper.close();
routeAnimation.close(); routeAnimation.close();
if(mNotificationManager != null){ if(mNotificationManager != null){
mNotificationManager.cancel(APP_NOTIFICATION_ID); mNotificationManager.cancel(APP_NOTIFICATION_ID);
} }
getMyApplication().getResourceManager().getMapTileDownloader().removeDownloaderCallback(mapView); getMyApplication().getResourceManager().getMapTileDownloader().removeDownloaderCallback(mapView);
} }
private void registerUnregisterSensor(Location location){ private void registerUnregisterSensor(Location location){
boolean currentShowingAngle = settings.SHOW_VIEW_ANGLE.get(); boolean currentShowingAngle = settings.SHOW_VIEW_ANGLE.get();
int currentMapRotation = settings.ROTATE_MAP.get(); int currentMapRotation = settings.ROTATE_MAP.get();
boolean show = (currentShowingAngle && location != null) || currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS; boolean show = (currentShowingAngle && location != null) || currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS;
// show point view only if gps enabled // show point view only if gps enabled
if (sensorRegistered && !show) { if (sensorRegistered && !show) {
Log.d(LogUtil.TAG, "Disable sensor"); //$NON-NLS-1$ Log.d(LogUtil.TAG, "Disable sensor"); //$NON-NLS-1$
((SensorManager) getSystemService(SENSOR_SERVICE)).unregisterListener(this); ((SensorManager) getSystemService(SENSOR_SERVICE)).unregisterListener(this);
@ -612,10 +610,10 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
} }
sensorRegistered = true; sensorRegistered = true;
} }
} }
public void backToLocationImpl() { public void backToLocationImpl() {
mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(false); mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(false);
PointLocationLayer locationLayer = mapLayers.getLocationLayer(); PointLocationLayer locationLayer = mapLayers.getLocationLayer();
if(!isMapLinkedToLocation()){ if(!isMapLinkedToLocation()){
setMapLinkedToLocation(true); setMapLinkedToLocation(true);
@ -630,13 +628,13 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
Toast.makeText(this, R.string.unknown_location, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.unknown_location, Toast.LENGTH_LONG).show();
} }
} }
private void updateSpeedBearing(Location location) { private void updateSpeedBearing(Location location) {
// For network/gps it's bad way (not accurate). It's widely used for testing purposes // For network/gps it's bad way (not accurate). It's widely used for testing purposes
// possibly keep using only for emulator case // possibly keep using only for emulator case
PointLocationLayer locationLayer = mapLayers.getLocationLayer(); PointLocationLayer locationLayer = mapLayers.getLocationLayer();
if (isRunningOnEmulator() if (isRunningOnEmulator()
&& locationLayer.getLastKnownLocation() != null && location != null) { && locationLayer.getLastKnownLocation() != null && location != null) {
if (locationLayer.getLastKnownLocation().distanceTo(location) > 3) { if (locationLayer.getLastKnownLocation().distanceTo(location) > 3) {
float d = location.distanceTo(locationLayer.getLastKnownLocation()); float d = location.distanceTo(locationLayer.getLastKnownLocation());
long time = location.getTime() - locationLayer.getLastKnownLocation().getTime(); long time = location.getTime() - locationLayer.getLastKnownLocation().getTime();
@ -652,109 +650,108 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
} }
location.setSpeed(speed); location.setSpeed(speed);
} }
}
if(locationLayer.getLastKnownLocation() != null && location != null && location.hasBearing()){
if(locationLayer.getLastKnownLocation().distanceTo(location) > 10 && !isRunningOnEmulator()){
location.setBearing(locationLayer.getLastKnownLocation().bearingTo(location));
}
}
}
public void setLocation(Location location){
if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
}
if(location != null ){
// write only with 50 meters accuracy
if (!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
if (settings.SAVE_TRACK_TO_GPX.get()) {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), location.getTime(),
location.getAltitude(), location.getSpeed(), location.getAccuracy());
mapLayers.getGpxLayer().addTrackPoint(pt);
}
}
} }
if(settings.LIVE_MONITORING.get()){ if(locationLayer.getLastKnownLocation() != null && location != null && location.hasBearing()){
liveMonitoringHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), if(locationLayer.getLastKnownLocation().distanceTo(location) > 10 && !isRunningOnEmulator()){
location.getSpeed(), location.getAccuracy(), location.getTime(), settings); location.setBearing(locationLayer.getLastKnownLocation().bearingTo(location));
}
} }
} }
public void setLocation(Location location){
registerUnregisterSensor(location); if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
updateSpeedBearing(location); Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
mapLayers.getLocationLayer().setLastKnownLocation(location); }
if(routingHelper.isFollowingMode()){ if(location != null ){
if(location == null || !location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) { // write only with 50 meters accuracy
// Update routing position if (!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
routingHelper.setCurrentLocation(location); if (settings.SAVE_TRACK_TO_GPX.get()) {
// Check with delay that gps location is not lost savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
if(location != null && routingHelper.getLeftDistance() > 0){ location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
Message msg = Message.obtain(uiHandler, new Runnable() { if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
@Override WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), location.getTime(),
public void run() { location.getAltitude(), location.getSpeed(), location.getAccuracy());
mapLayers.getGpxLayer().addTrackPoint(pt);
}
}
}
if(settings.LIVE_MONITORING.get()){
liveMonitoringHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
}
}
registerUnregisterSensor(location);
updateSpeedBearing(location);
mapLayers.getLocationLayer().setLastKnownLocation(location);
if(routingHelper.isFollowingMode()){
if(location == null || !location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
// Update routing position
routingHelper.setCurrentLocation(location);
// Check with delay that gps location is not lost
if(location != null && routingHelper.getLeftDistance() > 0){
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override public void run() {
if (routingHelper.getLeftDistance() > 0 && settings.MAP_ACTIVITY_ENABLED.get()) { if (routingHelper.getLeftDistance() > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
routingHelper.getVoiceRouter().gpsLocationLost(); routingHelper.getVoiceRouter().gpsLocationLost();
} }
} }
}); });
msg.what = LOST_LOCATION_MSG_ID; msg.what = LOST_LOCATION_MSG_ID;
uiHandler.removeMessages(LOST_LOCATION_MSG_ID); uiHandler.removeMessages(LOST_LOCATION_MSG_ID);
uiHandler.sendMessageDelayed(msg, LOST_LOCATION_CHECK_DELAY); uiHandler.sendMessageDelayed(msg, LOST_LOCATION_CHECK_DELAY);
} }
} }
} }
if (location != null) { if (location != null) {
if (isMapLinkedToLocation()) { if (isMapLinkedToLocation()) {
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){ if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom()); int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
if(mapView.getZoom() != z && !mapView.mapIsAnimating()){ if(mapView.getZoom() != z && !mapView.mapIsAnimating()){
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// prevent ui hysterisis (check time interval for autozoom) // prevent ui hysterisis (check time interval for autozoom)
if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){ if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){
lastTimeAutoZooming = now; lastTimeAutoZooming = now;
mapView.setZoom(z); mapView.setZoom(z);
} }
} }
} }
int currentMapRotation = settings.ROTATE_MAP.get(); int currentMapRotation = settings.ROTATE_MAP.get();
if (location.hasBearing() && currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) { if (location.hasBearing() && currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) {
mapView.setRotate(-location.getBearing()); mapView.setRotate(-location.getBearing());
}
mapView.setLatLon(location.getLatitude(), location.getLongitude());
} else {
if(!mapLayers.getMapInfoLayer().getBackToLocation().isEnabled()){
mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(true);
}
} }
mapView.setLatLon(location.getLatitude(), location.getLongitude());
} else { } else {
if(!mapLayers.getMapInfoLayer().getBackToLocation().isEnabled()){ if(mapLayers.getMapInfoLayer().getBackToLocation().isEnabled()){
mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(true); mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(false);
} }
} }
} else { // When location is changed we need to refresh map in order to show movement!
if(mapLayers.getMapInfoLayer().getBackToLocation().isEnabled()){ mapView.refreshMap();
mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(false); }
}
public int defineZoomFromSpeed(float speed, int currentZoom){
speed *= 3.6;
if(speed < 4){
return currentZoom;
} else if(speed < 33){
// less than 33 - show 17
return 17;
} else if(speed < 53){
return 16;
} else if(speed < 83){
return 15;
}
// more than 80 - show 14 (it is slow)
return 14;
} }
// When location is changed we need to refresh map in order to show movement!
mapView.refreshMap();
}
public int defineZoomFromSpeed(float speed, int currentZoom){
speed *= 3.6;
if(speed < 4){
return currentZoom;
} else if(speed < 33){
// less than 33 - show 17
return 17;
} else if(speed < 53){
return 16;
} else if(speed < 83){
return 15;
}
// more than 80 - show 14 (it is slow)
return 14;
}
public void navigateToPoint(LatLon point){ public void navigateToPoint(LatLon point){
if(point != null){ if(point != null){
@ -793,7 +790,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
return (routingHelper != null && routingHelper.isFollowingMode()) return (routingHelper != null && routingHelper.isFollowingMode())
|| (System.currentTimeMillis() - lastTimeGPSLocationFixed) < USE_ONLY_GPS_INTERVAL || isRunningOnEmulator(); || (System.currentTimeMillis() - lastTimeGPSLocationFixed) < USE_ONLY_GPS_INTERVAL || isRunningOnEmulator();
} }
// Working with location listeners // Working with location listeners
private LocationListener networkListener = new LocationListener(){ private LocationListener networkListener = new LocationListener(){
@ -857,7 +854,8 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
if (LocationProvider.TEMPORARILY_UNAVAILABLE == status) { if (LocationProvider.TEMPORARILY_UNAVAILABLE == status) {
if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){ if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){
routingHelper.getVoiceRouter().gpsLocationLost(); // Suppress gpsLocationLost() prompt here for now, as it causes duplicate announcement and then also prompts when signal is found again
//routingHelper.getVoiceRouter().gpsLocationLost();
} }
} else if (LocationProvider.OUT_OF_SERVICE == status) { } else if (LocationProvider.OUT_OF_SERVICE == status) {
if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){ if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){
@ -899,7 +897,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
public void updateApplicationModeSettings(){ public void updateApplicationModeSettings(){
boolean currentShowingAngle = settings.SHOW_VIEW_ANGLE.get(); boolean currentShowingAngle = settings.SHOW_VIEW_ANGLE.get();
int currentMapRotation = settings.ROTATE_MAP.get(); int currentMapRotation = settings.ROTATE_MAP.get();
if(currentMapRotation == OsmandSettings.ROTATE_MAP_NONE){ if(currentMapRotation == OsmandSettings.ROTATE_MAP_NONE){
mapView.setRotate(0); mapView.setRotate(0);
} }
@ -934,23 +932,23 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
@Override @Override
public boolean onKeyUp(int keyCode, KeyEvent event) { public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
//some application/hardware needs that back button reacts on key up, so //some application/hardware needs that back button reacts on key up, so
//that they could do some key combinations with it... //that they could do some key combinations with it...
// Android 1.6 doesn't have onBackPressed() method it should be finish instead! // Android 1.6 doesn't have onBackPressed() method it should be finish instead!
// onBackPressed(); //onBackPressed();
// return true; //return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true; return true;
} else } else
// Parrot device has only dpad left and right // Parrot device has only dpad left and right
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
changeZoom(mapView.getZoom() - 1); changeZoom(mapView.getZoom() - 1);
return true; return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
changeZoom(mapView.getZoom() + 1); changeZoom(mapView.getZoom() + 1);
return true; return true;
} }
return super.onKeyUp(keyCode,event); return super.onKeyUp(keyCode,event);
} }
@ -1077,7 +1075,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
return val; return val;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.map_show_settings: case R.id.map_show_settings:
@ -1130,8 +1128,8 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
navigateToPoint(null); navigateToPoint(null);
} }
} else { } else {
navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude())); navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude()));
} }
mapView.refreshMap(); mapView.refreshMap();
return true; return true;
case R.id.map_show_point_options: case R.id.map_show_point_options:
@ -1178,16 +1176,16 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
} }
} }
protected void parseLaunchIntentLocation(){ protected void parseLaunchIntentLocation(){
Intent intent = getIntent(); Intent intent = getIntent();
if(intent != null && intent.getData() != null){ if(intent != null && intent.getData() != null){
Uri data = intent.getData(); Uri data = intent.getData();
if("http".equalsIgnoreCase(data.getScheme()) && "download.osmand.net".equals(data.getHost()) && if("http".equalsIgnoreCase(data.getScheme()) && "download.osmand.net".equals(data.getHost()) &&
"/go".equals( data.getPath())) { "/go".equals( data.getPath())) {
String lat = data.getQueryParameter("lat"); String lat = data.getQueryParameter("lat");
String lon = data.getQueryParameter("lon"); String lon = data.getQueryParameter("lon");
if (lat != null && lon != null) { if (lat != null && lon != null) {
try { try {
double lt = Double.parseDouble(lat); double lt = Double.parseDouble(lat);
double ln = Double.parseDouble(lon); double ln = Double.parseDouble(lon);
@ -1199,9 +1197,9 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
} }
} }
} }
} }
public FavouritesDbHelper getFavoritesHelper() { public FavouritesDbHelper getFavoritesHelper() {
return getMyApplication().getFavorites(); return getMyApplication().getFavorites();
@ -1212,89 +1210,89 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
contextMenuPoint(latitude, longitude, null, null); contextMenuPoint(latitude, longitude, null, null);
} }
public void contextMenuPoint(final double latitude, final double longitude, List<String> additionalItems, public void contextMenuPoint(final double latitude, final double longitude, List<String> additionalItems,
final DialogInterface.OnClickListener additionalActions){ final DialogInterface.OnClickListener additionalActions){
Builder builder = new AlertDialog.Builder(this); Builder builder = new AlertDialog.Builder(this);
final int sizeAdditional = additionalActions == null || additionalItems == null ? 0 : additionalItems.size(); final int sizeAdditional = additionalActions == null || additionalItems == null ? 0 : additionalItems.size();
List<String> actions = new ArrayList<String>(); List<String> actions = new ArrayList<String>();
if(sizeAdditional > 0){ if(sizeAdditional > 0){
actions.addAll(additionalItems); actions.addAll(additionalItems);
} }
final int[] contextMenuStandardActions = new int[]{ final int[] contextMenuStandardActions = new int[]{
R.string.context_menu_item_navigate_point, R.string.context_menu_item_navigate_point,
R.string.context_menu_item_show_route, R.string.context_menu_item_show_route,
R.string.context_menu_item_search, R.string.context_menu_item_search,
R.string.context_menu_item_add_favorite, R.string.context_menu_item_add_favorite,
R.string.context_menu_item_share_location, R.string.context_menu_item_share_location,
R.string.context_menu_item_create_poi, R.string.context_menu_item_create_poi,
R.string.context_menu_item_add_waypoint, R.string.context_menu_item_add_waypoint,
R.string.context_menu_item_open_bug, R.string.context_menu_item_open_bug,
//MapTileLayer menu actions //MapTileLayer menu actions
R.string.context_menu_item_update_map, R.string.context_menu_item_update_map,
R.string.context_menu_item_download_map R.string.context_menu_item_download_map
}; };
int actionsToUse = (mapView.getMainLayer() instanceof MapTileLayer) ? contextMenuStandardActions.length : contextMenuStandardActions.length - 2; int actionsToUse = (mapView.getMainLayer() instanceof MapTileLayer) ? contextMenuStandardActions.length : contextMenuStandardActions.length - 2;
for(int j = 0; j<actionsToUse; j++){ for(int j = 0; j<actionsToUse; j++){
actions.add(getResources().getString(contextMenuStandardActions[j])); actions.add(getResources().getString(contextMenuStandardActions[j]));
} }
builder.setItems(actions.toArray(new String[actions.size()]), new DialogInterface.OnClickListener(){ builder.setItems(actions.toArray(new String[actions.size()]), new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(which < sizeAdditional){ if(which < sizeAdditional){
additionalActions.onClick(dialog, which); additionalActions.onClick(dialog, which);
return; return;
}
int standardId = contextMenuStandardActions[which - sizeAdditional];
if(standardId == R.string.context_menu_item_navigate_point){
navigateToPoint(new LatLon(latitude, longitude));
} else if(standardId == R.string.context_menu_item_show_route){
mapActions.getDirections(latitude, longitude, false);
} else if(standardId == R.string.context_menu_item_search){
Intent intent = new Intent(MapActivity.this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH_LAT, latitude);
intent.putExtra(SearchActivity.SEARCH_LON, longitude);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if(standardId == R.string.context_menu_item_add_favorite){
mapActions.addFavouritePoint(latitude, longitude);
} else if(standardId == R.string.context_menu_item_share_location){
mapActions.shareLocation(latitude, longitude, mapView.getZoom());
} else if(standardId == R.string.context_menu_item_create_poi){
getPoiActions().showCreateDialog(latitude, longitude);
} else if(standardId == R.string.context_menu_item_add_waypoint){
mapActions.addWaypoint(latitude, longitude);
} else if(standardId == R.string.context_menu_item_open_bug){
mapLayers.getOsmBugsLayer().openBug(latitude, longitude);
} else if(standardId == R.string.context_menu_item_update_map){
mapActions.reloadTile(mapView.getZoom(), latitude, longitude);
} else if(standardId == R.string.context_menu_item_download_map){
DownloadTilesDialog dlg = new DownloadTilesDialog(MapActivity.this,
(OsmandApplication) getApplication(), mapView);
dlg.openDialog();
}
} }
}); int standardId = contextMenuStandardActions[which - sizeAdditional];
builder.create().show(); if(standardId == R.string.context_menu_item_navigate_point){
} navigateToPoint(new LatLon(latitude, longitude));
} else if(standardId == R.string.context_menu_item_show_route){
public MapActivityActions getMapActions() { mapActions.getDirections(latitude, longitude, false);
} else if(standardId == R.string.context_menu_item_search){
Intent intent = new Intent(MapActivity.this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH_LAT, latitude);
intent.putExtra(SearchActivity.SEARCH_LON, longitude);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if(standardId == R.string.context_menu_item_add_favorite){
mapActions.addFavouritePoint(latitude, longitude);
} else if(standardId == R.string.context_menu_item_share_location){
mapActions.shareLocation(latitude, longitude, mapView.getZoom());
} else if(standardId == R.string.context_menu_item_create_poi){
getPoiActions().showCreateDialog(latitude, longitude);
} else if(standardId == R.string.context_menu_item_add_waypoint){
mapActions.addWaypoint(latitude, longitude);
} else if(standardId == R.string.context_menu_item_open_bug){
mapLayers.getOsmBugsLayer().openBug(latitude, longitude);
} else if(standardId == R.string.context_menu_item_update_map){
mapActions.reloadTile(mapView.getZoom(), latitude, longitude);
} else if(standardId == R.string.context_menu_item_download_map){
DownloadTilesDialog dlg = new DownloadTilesDialog(MapActivity.this,
(OsmandApplication) getApplication(), mapView);
dlg.openDialog();
}
}
});
builder.create().show();
}
public MapActivityActions getMapActions() {
return mapActions; return mapActions;
} }
public EditingPOIActivity getPoiActions() { public EditingPOIActivity getPoiActions() {
return poiActions; return poiActions;
} }
public MapActivityLayers getMapLayers() { public MapActivityLayers getMapLayers() {
return mapLayers; return mapLayers;
} }
public SavingTrackHelper getSavingTrackHelper() { public SavingTrackHelper getSavingTrackHelper() {
return savingTrackHelper; return savingTrackHelper;
} }
@Override @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) { public void onAccuracyChanged(Sensor sensor, int accuracy) {
} }