From b3c6fede747bf9ceeddd1c53088dfe0f3d85fca1 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Thu, 13 Oct 2011 00:25:50 +0200 Subject: [PATCH 1/4] Fixed issue 494. Do not draw new map when it is already drawing and there is only rotation change. --- .../net/osmand/plus/AsyncLoadingThread.java | 13 ++-- .../src/net/osmand/plus/RotatedTileBox.java | 63 ++++++++++++++++++- .../plus/render/MapRenderRepositories.java | 20 ++++-- .../osmand/plus/render/MapVectorLayer.java | 3 +- 4 files changed, 84 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java index 91779e8e7c..d5be9ce42c 100644 --- a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java @@ -4,22 +4,21 @@ import java.io.File; import java.util.List; import java.util.Stack; -import org.apache.commons.logging.Log; - -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Looper; - import net.osmand.Algoritms; import net.osmand.LogUtil; import net.osmand.ResultMatcher; import net.osmand.data.Amenity; import net.osmand.data.MapTileDownloader; -import net.osmand.data.TransportStop; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; +import net.osmand.data.TransportStop; import net.osmand.map.ITileSource; +import org.apache.commons.logging.Log; + +import android.os.Handler; +import android.os.HandlerThread; + /** * Thread to load map objects (POI, transport stops )async */ diff --git a/OsmAnd/src/net/osmand/plus/RotatedTileBox.java b/OsmAnd/src/net/osmand/plus/RotatedTileBox.java index bb22dfa330..5bf6ea82e9 100644 --- a/OsmAnd/src/net/osmand/plus/RotatedTileBox.java +++ b/OsmAnd/src/net/osmand/plus/RotatedTileBox.java @@ -13,6 +13,9 @@ public class RotatedTileBox { private int zoom; private float rotateCos; private float rotateSin; + private RectF latLon; + private boolean rendering; + private RotatedTileBox parent; public RotatedTileBox(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) { set(leftTileX, topTileY, tileWidth, tileHeight, rotate, zoom); @@ -20,6 +23,9 @@ public class RotatedTileBox { public RotatedTileBox(RotatedTileBox r){ set(r.leftTileX, r.topTileY, r.tileWidth, r.tileHeight, r.rotate, r.zoom); + this.latLon = r.latLon; + this.rendering = r.rendering; + this.parent = r; } private void init() { @@ -166,6 +172,61 @@ public class RotatedTileBox { return calcPointTileY(tileWidth, tileHeight); } - + /** + * the lat lon bounds + * @param latLonBounds + */ + public void setLatLon(RectF latLonBounds) { + //on new latLonBounds reset rendering info and latLonBounds.... + if (!latLonBounds.equals(this.latLon)) { + this.rendering = false; + this.latLon = latLonBounds; + } + } + + /** + * @return true if rendering is in progress + */ + public boolean isRendering() { + return rendering; + } + + /** + * Say we are rendering this box + */ + public void rendering() { + rendering = true; + if (parent != null) { + parent.rendering(latLon); + } + } + + /** + * Say we are rendering this box for this coordinates + * + * @param aLatLon + */ + private void rendering(RectF aLatLon) { + if (aLatLon.equals(latLon)) { + rendering = true; + } + } + + /** + * all if rendering was interrupted + */ + public void renderingInterrupted() { + rendered(); + } + + /** + * Call if rendering is finished + */ + public void rendered() { + rendering = false; + if (parent != null) { + parent.rendered(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 7edba9a3cd..5ccf009419 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -196,6 +196,9 @@ public class MapRenderRepositories { } public void interruptLoadingMap(){ + if (requestedBox != null) { + requestedBox.renderingInterrupted(); + } interrupted = true; if(currentRenderingContext != null){ currentRenderingContext.interrupted = true; @@ -207,6 +210,9 @@ public class MapRenderRepositories { private boolean checkWhetherInterrupted(){ if(interrupted || (currentRenderingContext != null && currentRenderingContext.interrupted)){ + if (requestedBox != null) { + requestedBox.renderingInterrupted(); + } requestedBox = bmpLocation; return true; } @@ -356,6 +362,10 @@ public class MapRenderRepositories { currentRenderingContext = null; } try { + // prevent editing + requestedBox = new RotatedTileBox(tileRect); + requestedBox.rendering(); + // find selected rendering type OsmandApplication app = ((OsmandApplication)context.getApplicationContext()); Boolean renderDay = app.getDaynightHelper().getDayNightRenderer(); @@ -363,9 +373,6 @@ public class MapRenderRepositories { // boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get(); BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer(); - // prevent editing - requestedBox = new RotatedTileBox(tileRect); - // calculate data box RectF dataBox = requestedBox.calculateLatLonBox(new RectF()); long now = System.currentTimeMillis(); @@ -419,7 +426,6 @@ public class MapRenderRepositories { } - renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingType, stepByStep ? notifyList : null); String renderingDebugInfo = currentRenderingContext.renderingDebugInfo; @@ -468,9 +474,11 @@ public class MapRenderRepositories { Toast.makeText(context, R.string.rendering_out_of_memory, Toast.LENGTH_SHORT).show(); } }); - + } finally { + if (requestedBox != null) { + requestedBox.rendered(); + } } - } public Bitmap getBitmap() { diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index 7d5bf1596a..14f1e2974e 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -93,10 +93,11 @@ public class MapVectorLayer extends BaseMapLayer { tileLayer.drawTileMap(canvas, tilesRect); resourceManager.getRenderer().interruptLoadingMap(); } else { + rotatedTileBox.setLatLon(latLonBounds); if (!view.isZooming()) { pixRect.set(0, 0, view.getWidth(), view.getHeight()); updateRotatedTileBox(); - if (resourceManager.updateRenderedMapNeeded(rotatedTileBox)) { + if (!rotatedTileBox.isRendering() && resourceManager.updateRenderedMapNeeded(rotatedTileBox)) { // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * view.getHeight() / 2); pixRect.set(-view.getWidth() / 3, -view.getHeight() / 4, 4 * view.getWidth() / 3, 5 * view.getHeight() / 4); updateRotatedTileBox(); From 2bf311d7d02b325927ddf1819ddd5982c3518471 Mon Sep 17 00:00:00 2001 From: zibik Date: Thu, 13 Oct 2011 23:21:08 +0300 Subject: [PATCH 2/4] Updating and translating new strings of v0.6.8, minor fixes --- OsmAnd/res/values-pl/strings.xml | 94 ++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index c40330e3cf..f3a9668b73 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3,7 +3,7 @@ Brak danych lokalnych do wyszukania POI Szukaj wg nazwy -Plik \'%1$s\' z danymi POI jest przestarzały i należy go usunąć. +Plik \'%1$s\' z danymi POI jest nadmiarowy i można go usunąć. Nie znaleziono lokalnego pliku z POI i nie może on zostać utworzony. Zmiana POI w aplikacji nie powoduje zmian w mapie, a jedynie jest zapisywana w pliku lokalnym. Uaktualnij Osmand+ @@ -15,9 +15,9 @@ Autostart nawigatora Ustaw czas, po którym nastąpi automatyczne uruchomienie nawigatora Wybierz -Pobierz nowe, zarchiwizuj lub usuń istniejące dane. \nIstniejące dane offline na urządzeniu (%1$s jest dostępny): +Pobierz nowe, zarchiwizuj lub usuń istniejące dane. \nIstniejące dane offline na urządzeniu (%1$s jest dostępne): Ustal pozycję GPS... -Pozycja [Ustalono] +Pozycja [ustalona] Adres... Ulubione... Niezdefiniowane @@ -181,8 +181,8 @@ \n\tNastępnie wybierz sposób udostępnienia. Do wyboru jest e-mail, SMS lub zwykłe skopiowanie koordynat do schowka. Ulubione punkty -\tCzęsto używane punkty mogą zostać zapisane jako Ulubione. -\n\tAby zapisać punkt jako Ulubiony przejdź do menu kontekstowego, wybierz \'Opcje punktu\' -> \'Dodaj do ulubionych\' i wprowadź jego nazwę. Po zapisaniu, punkt będzie można znaleźć w głównym menu -> \'Ulubione\'. +\tCzęsto używane punkty mogą zostać zapisane jako ulubione. +\n\tAby zapisać punkt jako ulubiony przejdź do menu kontekstowego, wybierz \'Opcje punktu\' -> \'Dodaj do ulubionych\' i wprowadź jego nazwę. Po zapisaniu, punkt będzie można znaleźć w głównym menu -> \'Ulubione\'. \n\tDłuższe naciśnięcie pozycji w \'Ulubionych\' pokaże opcje dotyczące tego punktu. \n\tAby wyświetlić wszystkie ulubione punkty bezpośrednio na mapie, włącz warstwę \'Ulubione\' w \'Zdefiniuj widok\'. @@ -306,7 +306,7 @@ GPS Status application not installed. Search in Market? -Voice guidance is not available. Please go to settings, choose preferred voice data package, and download it. +Głos nawigatora nie jest dostępny. Przejdź do ustawień, wybierz ulubiony zestaw i zainstaluj go. Nie wybrano głosu nawigatora Dzień Noc @@ -373,7 +373,7 @@ Mapy wektorowe offline Search transport at stop -Punkt na mapie:\n Lat {0,number,#.####}\n Lon {1,number,#.####} +Punkt na mapie:\n Szer. {0,number,#.####}\n Dł. {1,number,#.####} Błąd Modyfikuj POI Usuń POI @@ -405,7 +405,7 @@ POI... Źródło mapy... Zdefiniuj widok -Previous route was unfinished. Continue following it? +Poprzednia trasa nie została ukończona. Czy chcesz kontynuować? Szukaj POI Trasa z Użyj trackballa do przesuwania mapy @@ -426,13 +426,13 @@ Enable background service to track position over long time periods Użyj usługi w tle The background routing service requires a location source to be turned on. -Specify routing options +Skonfiguruj opcje routingu Nawigacja Ukryj filtr Pokaż filtr Filtr -Dźwięk włączony -Dźwięk wyłączony +Wył. dźwięk +Wł. dźwięk Wybierz głos nawigatora Głos nawigatora Inicjalizacja danych głosowych... @@ -478,8 +478,8 @@ Długość trasy Transport OK -Show public transport stops on map -Show transport stops +Pokaż na mapie przystanki transportu publicznego +Pokaż przystanki Program do nawigacji satelitarnej OsmAnd POI data was updated successfully ({0} were loaded) Error updating local POI list @@ -495,7 +495,7 @@ Naviguj do szer. = {0}, dł. = {1} Ulubione Wyczyść wszystko -History +Historia Wysyłanie danych... Wysyłanie... Nic nie znaleziono @@ -505,7 +505,7 @@ Numer domu, ulica, miejscowość Offline Internet -Max. online zoom +Maks. zoom online Choose maximum zoom level to download for online map tiles O trasie Dystans całkowity {0}, czas podróży {1} h {2} m. @@ -540,7 +540,7 @@ Wczytywanie POI... Autoryzacja nie powiodła się nie powiodło się -Konwertowanie Converting native/English names... +Konwertowanie natywnych/angielskich nazw... Wczytywanie ulic/budynków... Wczytywanie kodów pocztowych... Wczytywanie ulic... @@ -569,16 +569,16 @@ Użyj routingu online Twoje hasło do konta OSM Hasło do konta OSM -Specify Openstreetmap.org (OSM) settings needed for OSM submissions -Specify tracking settings +Skonfiguruj ustawienia dotyczące potrzebne do wysyłania danych do Openstreetmap.org (OSM) +Skonfiguruj zapisywanie śladów GPX Ustaw język, pobierz/przeładuj dane Dane -Specify map settings: map source, rotation, marker position, screen orientation +Zmień ustawienia mapy: źródło mapy, obracanie, pozycję markera, orientację ekranu OSM Dostosuj zoom mapy do Twojej prędkości Autozoom mapy Ustawienia dodatkowe -Wybierz profil. (Ustawienia każdego profilu mogą być zmieniane poniżej.) +Wybierz profil nawigacji (ustawienia każdego profilu mogą być zmieniane poniżej). Tryb programu Ustawienia Zapisz bieżący ślad do karty SD @@ -596,10 +596,10 @@ Cel Pokaż OpenStreetBugs na mapie Pokaż OpenStreetBugs -List of favorite points -Add to Favorites -Select between native and English names -Use english names +Lista ulubionych punktów +Dodaj do ulubionych +Zaznacz, jeśli chcesz używać angielskich nazw zamiast natywnych +Używaj angielskich nazw Ustawienia programu Szukaj adresu Wybierz nr domu @@ -616,7 +616,7 @@ Włącz widok 3D mapy Widok 3D mapy -Show POI over map (use last chosen filter) +Pokaż POI na mapie (używa ostatnio wybranego filtru) Pokaż POI Wybierz źródło mapy kafelkowej (online lub offline): Źródło mapy kafelkowej @@ -672,7 +672,7 @@ Budynek Przecinająca ulica (przecznica) -Pozycja +Pozycja GPS Nawiguj do punktu Dodaj do ulubionych @@ -695,26 +695,26 @@ Usuń Zmień nazwę -Are you sure to remove favorite point? -Favorite point {0} was succesfully deleted. +Czy na pewno chcesz usunąć ulubiony punkt? +Ulubiony punkt {0} został usunięty. Wprowadź opis błędu -Błąd złoszony +Błąd został zgłoszony Wystąpił błąd, zgłoszenie nie zostało utworzone Dodaj komentarz Wiadomość Author name -Adding comment to bug +Dodaj komentarz do błędu Dodaj komentarz Dodano komentarz Wystąpił błąd, komentarz nie został dodany -Close bug -Closing bug -Close bug -Bug was successfully closed -Exception occured: bug was not closed +Zamknij błąd +Zamykanie błędu +Zamknij błąd +Błąd został zamknięty +Wystąpił problem, błąd nie został zamknięty Edytuj POI Dodaj POI @@ -746,4 +746,26 @@ Filtr {0} został utworzony Zaznacz wszystko - \ No newline at end of file +Etykiety POI +Włącz autostart nawigatora tylko w trybie nawigacji. +Autostart nawigatora +Autostart nawigatora jest włączony. +Wył. animacje +Wł. animacje + +Zmiany w wersji 0.6.8: +\n\t- całkowicie przeprojektowano wyszukiwanie (POI, adresy) - teraz jest szysbsze i bardziej responsywne +\n\t- zaimplementowano wyszukiwanie POI po nazwie na dużych obszarach (krajach) +\n\t- naprawiono migotanie ekranu na tabletach (zgłoszenie nr 641) +\n\t- dodano opcję autostartu nawigacji (zgłoszenie nr 356) +\n\t- nawigacja wg śladu GPX przeniesiona została do menu \'Nawigacja\' +\n\t- dane POI teraz są w plikach .obf +\n\t- poprawiono błedy komunikatów głosowych (ustalenie pozycji GPS, pomijanie pierwszej komendy) +\n\t- naprawiono inne, drobne błędy + + +Nazwa pliku nie może zostać zmieniona. +Plik o takiej nazwie już istnieje. +Trasa GPX + + From 10a50b651416066b4835283ce5f5ec0f50fb0b77 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 15 Oct 2011 12:20:04 +0200 Subject: [PATCH 3/4] Implement tool box on click 'show on map' --- .../src/net/osmand/plus/OsmandSettings.java | 34 ++++++++----- .../plus/activities/FavouritesActivity.java | 12 +++-- .../activities/FavouritesListActivity.java | 14 +++-- .../plus/activities/LocalIndexesActivity.java | 3 +- .../osmand/plus/activities/MapActivity.java | 16 ++++-- .../activities/NavigatePointActivity.java | 4 +- .../activities/ShowRouteInfoActivity.java | 4 +- .../activities/search/GeoIntentActivity.java | 10 ++-- .../search/SearchAddressOnlineActivity.java | 4 +- .../search/SearchHistoryActivity.java | 51 +++++++++---------- .../osmand/plus/views/ContextMenuLayer.java | 7 ++- 11 files changed, 98 insertions(+), 61 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 2a7c1ed87f..ee79a8cfcb 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -751,7 +751,8 @@ public class OsmandSettings { public static final String LAST_KNOWN_MAP_LAT = "last_known_map_lat"; //$NON-NLS-1$ public static final String LAST_KNOWN_MAP_LON = "last_known_map_lon"; //$NON-NLS-1$ public static final String LAST_KNOWN_MAP_ZOOM = "last_known_map_zoom"; //$NON-NLS-1$ - + + public static final String MAP_LABEL_TO_SHOW = "map_label_to_show"; //$NON-NLS-1$ public static final String MAP_LAT_TO_SHOW = "map_lat_to_show"; //$NON-NLS-1$ public static final String MAP_LON_TO_SHOW = "map_lon_to_show"; //$NON-NLS-1$ public static final String MAP_ZOOM_TO_SHOW = "map_zoom_to_show"; //$NON-NLS-1$ @@ -766,14 +767,7 @@ public class OsmandSettings { return globalPreferences.contains(LAST_KNOWN_MAP_LAT); } - public void setMapLocationToShow(double latitude, double longitude) { - setMapLocationToShow(latitude, longitude, getLastKnownMapZoom(), null); - } - - public void setMapLocationToShow(double latitude, double longitude, int zoom) { - setMapLocationToShow(latitude, longitude, null); - } - + public LatLon getAndClearMapLocationToShow(){ if(!globalPreferences.contains(MAP_LAT_TO_SHOW)){ return null; @@ -784,14 +778,26 @@ public class OsmandSettings { return new LatLon(lat, lon); } + public String getAndClearMapLabelToShow(){ + String label = globalPreferences.getString(MAP_LABEL_TO_SHOW, null); + globalPreferences.edit().remove(MAP_LABEL_TO_SHOW).commit(); + return label; + } + public int getMapZoomToShow() { return globalPreferences.getInt(MAP_ZOOM_TO_SHOW, 5); } - public void setMapLocationToShow(double latitude, double longitude, int zoom, String historyDescription) { + public void setMapLocationToShow(double latitude, double longitude, int zoom, String historyDescription, + String labelToShow) { Editor edit = globalPreferences.edit(); edit.putFloat(MAP_LAT_TO_SHOW, (float) latitude); edit.putFloat(MAP_LON_TO_SHOW, (float) longitude); + if (labelToShow != null) { + edit.putString(MAP_LABEL_TO_SHOW, labelToShow); + } else { + edit.remove(MAP_LABEL_TO_SHOW); + } edit.putInt(MAP_ZOOM_TO_SHOW, zoom); edit.commit(); if(historyDescription != null){ @@ -799,8 +805,12 @@ public class OsmandSettings { } } - public void setMapLocationToShow(double latitude, double longitude, String historyDescription) { - setMapLocationToShow(latitude, longitude, getLastKnownMapZoom(), historyDescription); + public void setMapLocationToShow(double latitude, double longitude, int zoom) { + setMapLocationToShow(latitude, longitude, zoom, null, null); + } + + public void setMapLocationToShow(double latitude, double longitude, int zoom, String historyDescription){ + setMapLocationToShow(latitude, longitude, zoom, historyDescription, historyDescription); } // Do not use that method if you want to show point on map. Use setMapLocationToShow diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java index 68398e03a9..243fa825b5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java @@ -229,8 +229,10 @@ public class FavouritesActivity extends ExpandableListActivity { } } else { FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition); - OsmandSettings.getOsmandSettings(this).SHOW_FAVORITES.set( true); - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); + settings.SHOW_FAVORITES.set(true); + settings.setMapLocationToShow(point.getLatitude(), point.getLongitude(), + Math.max(12, settings.getLastKnownMapZoom()), null, getString(R.string.favorite)+" : " + point.getName()); MapActivity.launchMapActivityMoveToTop(FavouritesActivity.this); } return true; @@ -244,8 +246,10 @@ public class FavouritesActivity extends ExpandableListActivity { int group = ExpandableListView.getPackedPositionGroup(((ExpandableListContextMenuInfo)menuInfo).packedPosition); final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(group, child); if (aItem.getItemId() == SHOW_ON_MAP) { - OsmandSettings.getOsmandSettings(this).SHOW_FAVORITES.set( true); - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); + settings.SHOW_FAVORITES.set(true); + settings.setMapLocationToShow(point.getLatitude(), point.getLongitude(), + Math.max(12, settings.getLastKnownMapZoom()), null, getString(R.string.favorite)+" : " + point.getName()); MapActivity.launchMapActivityMoveToTop(this); } else if (aItem.getItemId() == NAVIGATE_TO) { OsmandSettings.getOsmandSettings(this).setPointToNavigate(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java index b28e8cda9f..220419361a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java @@ -124,8 +124,9 @@ public class FavouritesListActivity extends ListActivity implements SearchActivi @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { - OsmandSettings.getOsmandSettings(FavouritesListActivity.this).setMapLocationToShow(entry.getLatitude(), - entry.getLongitude()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(FavouritesListActivity.this); + settings.setMapLocationToShow(entry.getLatitude(), entry.getLongitude(), settings.getLastKnownMapZoom(), + null, getString(R.string.favorite)+" : " + entry.getName()); //$NON-NLS-1$ } else if (which == 1) { OsmandSettings.getOsmandSettings(FavouritesListActivity.this).setPointToNavigate(entry.getLatitude(), entry.getLongitude(), getString(R.string.favorite) + " : " + entry.getName()); @@ -140,10 +141,13 @@ public class FavouritesListActivity extends ListActivity implements SearchActivi @Override protected void onListItemClick(ListView l, View v, int position, long id) { - if(!isSelectFavoriteMode()) { + + if (!isSelectFavoriteMode()) { + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); FavouritePoint point = favouritesAdapter.getItem(position); - OsmandSettings.getOsmandSettings(this).SHOW_FAVORITES.set( true); - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ + settings.SHOW_FAVORITES.set(true); + settings.setMapLocationToShow(point.getLatitude(), point.getLongitude(), settings.getLastKnownMapZoom(), null, + getString(R.string.favorite) + " : " + point.getName()); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(FavouritesListActivity.this); } else { Intent intent = getIntent(); diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index d9f06ad176..1b01c0ac20 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -154,7 +154,8 @@ public class LocalIndexesActivity extends ExpandableListActivity { if (info != null && info.getGpxFile() != null) { WptPt loc = info.getGpxFile().findPointToShow(); if (loc != null) { - OsmandSettings.getOsmandSettings(LocalIndexesActivity.this).setMapLocationToShow(loc.lat, loc.lon); + OsmandSettings settings = OsmandSettings.getOsmandSettings(LocalIndexesActivity.this); + settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom()); } ((OsmandApplication) getApplication()).setGpxFileToDisplay(info.getGpxFile()); MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 36b3582b8a..da7154d379 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -292,9 +292,19 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso showAndHideMapPosition(); LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude()); - LatLon latLon = settings.getAndClearMapLocationToShow(); - if (latLon != null && !latLon.equals(cur)) { - mapView.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), settings.getMapZoomToShow(), true); + LatLon latLonToShow = settings.getAndClearMapLocationToShow(); + String mapLabelToShow = settings.getAndClearMapLabelToShow(); + if(mapLabelToShow != null && latLonToShow != null){ + if(mapLabelToShow.length() == 0){ + mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow); + } else { + mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow); + } + } + if (latLonToShow != null && !latLonToShow.equals(cur)) { + mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), + settings.getMapZoomToShow(), true); + } View progress = findViewById(R.id.ProgressBar); diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java index 16a79e0298..f4dc6121f8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java @@ -169,7 +169,9 @@ public class NavigatePointActivity extends Activity implements SearchActivityChi OsmandMapTileView v = activity.getMapView(); v.getAnimatedDraggingThread().startMoving(lat, lon, v.getZoom(), true); } else { - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(lat, lon, MessageFormat.format(getString(R.string.search_history_navigate_to), lat, lon)); + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); + settings.setMapLocationToShow(lat, lon, Math.max(12, settings.getLastKnownMapZoom()), + MessageFormat.format(getString(R.string.search_history_navigate_to), lat, lon)); } } close(); diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 1fa95ce510..945ef1b044 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -78,7 +78,9 @@ public class ShowRouteInfoActivity extends ListActivity { RouteDirectionInfo item = ((RouteInfoAdapter)getListAdapter()).getItem(position - 1); Location loc = helper.getLocationFromRouteDirection(item); if(loc != null){ - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(loc.getLatitude(),loc.getLongitude()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); + settings.setMapLocationToShow(loc.getLatitude(),loc.getLongitude(), + Math.max(13, settings.getLastKnownMapZoom())); MapActivity.launchMapActivityMoveToTop(this); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 9d1199f0a7..036007f249 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -18,6 +18,7 @@ import net.osmand.data.Street; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; import net.osmand.osm.Node; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.RegionAddressRepository; import net.osmand.plus.ResourceManager; @@ -154,11 +155,10 @@ public class GeoIntentActivity extends ListActivity { @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - MapObject item = ((MapObjectAdapter) getListAdapter()) - .getItem(position); - getMyApplication().getSettings().setMapLocationToShow(item.getLocation() - .getLatitude(), item.getLocation().getLongitude(), - getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$ + MapObject item = ((MapObjectAdapter) getListAdapter()).getItem(position); + OsmandSettings settings = getMyApplication().getSettings(); + settings.setMapLocationToShow(item.getLocation().getLatitude(), item.getLocation().getLongitude(), + settings.getLastKnownMapZoom(), getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(this); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java index 4e6fb6d152..6dc5875255 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java @@ -209,7 +209,9 @@ public class SearchAddressOnlineActivity extends ListActivity implements SearchA protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Place item = ((PlacesAdapter) getListAdapter()).getItem(position); - OsmandSettings.getOsmandSettings(this).setMapLocationToShow(item.lat, item.lon, getString(R.string.address)+ " : " + item.displayName); //$NON-NLS-1$ + OsmandSettings settings = OsmandSettings.getOsmandSettings(this); + settings.setMapLocationToShow(item.lat, item.lon, + Math.max(15, settings.getLastKnownMapZoom()), getString(R.string.address)+ " : " + item.displayName); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(this); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java index 62c1c3d82a..1cbb4d08c8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java @@ -1,6 +1,5 @@ package net.osmand.plus.activities.search; - import java.util.List; import net.osmand.OsmAndFormatter; @@ -38,12 +37,11 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit super.onCreate(savedInstanceState); ListView lv = new ListView(this); lv.setId(android.R.id.list); - + setContentView(lv); - + helper = SearchHistoryHelper.getInstance(); - - + clearButton = new Button(this); clearButton.setText(R.string.clear_all); clearButton.setOnClickListener(new View.OnClickListener() { @@ -61,39 +59,40 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit }); } + @Override protected void onResume() { super.onResume(); Intent intent = getIntent(); - if(intent != null){ + if (intent != null) { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SEARCH_LON, 0); - if(lat != 0 || lon != 0){ + if (lat != 0 || lon != 0) { location = new LatLon(lat, lon); } } - if(location == null && getParent() instanceof SearchActivity){ + if (location == null && getParent() instanceof SearchActivity) { location = ((SearchActivity) getParent()).getSearchPoint(); } if (location == null) { location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); } - + List historyEntries = helper.getHistoryEntries(this); - + getListView().removeFooterView(clearButton); if (!historyEntries.isEmpty()) { getListView().addFooterView(clearButton); } setListAdapter(new HistoryAdapter(historyEntries)); } - + @Override public void locationUpdate(LatLon l) { location = l; ((HistoryAdapter) getListAdapter()).notifyDataSetChanged(); } - + private boolean onItemLongClick(int pos) { final HistoryEntry entry = ((HistoryAdapter) getListAdapter()).getItem(pos); AlertDialog.Builder builder = new AlertDialog.Builder(SearchHistoryActivity.this); @@ -104,8 +103,9 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { - OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(entry.getLat(), - entry.getLon()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(SearchHistoryActivity.this); + settings.setMapLocationToShow(entry.getLat(), entry.getLon(), settings.getLastKnownMapZoom(), null, entry + .getName()); } else if (which == 1) { OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setPointToNavigate(entry.getLat(), entry.getLon(), null); @@ -117,27 +117,26 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit builder.show(); return true; } - - + @Override protected void onListItemClick(ListView l, View v, int position, long id) { - HistoryEntry model = ((HistoryAdapter)getListAdapter()).getItem(position); + HistoryEntry model = ((HistoryAdapter) getListAdapter()).getItem(position); selectModel(model); } private void selectModel(HistoryEntry model) { helper.selectEntry(model, this); - OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(model.getLat(), model.getLon()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(SearchHistoryActivity.this); + settings.setMapLocationToShow(model.getLat(), model.getLon(), settings.getLastKnownMapZoom(), null, model.getName()); MapActivity.launchMapActivityMoveToTop(this); } - - + class HistoryAdapter extends ArrayAdapter { public HistoryAdapter(List list) { super(SearchHistoryActivity.this, R.layout.search_history_list_item, list); } - + @Override public View getView(final int position, View convertView, ViewGroup parent) { View row = convertView; @@ -149,28 +148,28 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit TextView distanceLabel = (TextView) row.findViewById(R.id.distance_label); ImageButton icon = (ImageButton) row.findViewById(R.id.remove); final HistoryEntry model = getItem(position); - if(location != null){ + if (location != null) { int dist = (int) (MapUtils.getDistance(location, model.lat, model.lon)); distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist, SearchHistoryActivity.this)); } else { distanceLabel.setText(""); //$NON-NLS-1$ } label.setText(model.name); - icon.setOnClickListener(new View.OnClickListener(){ + icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { helper.remove(model, SearchHistoryActivity.this); setListAdapter(new HistoryAdapter(helper.getHistoryEntries(SearchHistoryActivity.this))); } - + }); - View.OnClickListener clickListener = new View.OnClickListener(){ + View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View v) { selectModel(model); } }; - + View.OnLongClickListener longClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index f1d3857568..df075cc698 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -123,6 +123,10 @@ public class ContextMenuLayer implements OsmandMapLayer { public void setLocation(LatLon loc, String description){ latLon = loc; if(latLon != null){ + if(description == null || description.length() == 0){ + description = MessageFormat.format(view.getContext().getString(R.string.point_on_map), + latLon.getLatitude(), latLon.getLongitude()); + } textView.setText(description); } else { textView.setText(""); //$NON-NLS-1$ @@ -151,8 +155,7 @@ public class ContextMenuLayer implements OsmandMapLayer { } LatLon latLon = view.getLatLonFromScreenPoint(point.x, point.y); - String description = MessageFormat.format(view.getContext().getString(R.string.point_on_map), - latLon.getLatitude(), latLon.getLongitude()); + String description = ""; if(selectedObject != null){ description = selectedContextProvider.getObjectDescription(selectedObject); From 17d4467ec402417bcfecab1d0a51e51296b1be67 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 15 Oct 2011 12:44:39 +0200 Subject: [PATCH 4/4] Fix issue with osm bugs functionality --- .../net/osmand/plus/views/OsmBugsLayer.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java index 552a94a205..40af23e31e 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java @@ -183,7 +183,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe cRightLongitude = nRightLongitude; cBottomLatitude = nBottomLatitude; czoom = zoom; - view.refreshMap(); + refreshMap(); } } } @@ -200,7 +200,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe public OpenStreetBug getBugFromPoint(PointF point){ OpenStreetBug result = null; - if (objects != null) { + if (objects != null && view != null) { int ex = (int) point.x; int ey = (int) point.y; int radius = getRadiusBug(view.getZoom()) * 3 / 2; @@ -225,8 +225,8 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe public boolean onTouchEvent(PointF point) { OpenStreetBug bug = getBugFromPoint(point); if(bug != null){ - String format = view.getContext().getString(R.string.osb_bug_name)+ " : " + bug.getName(); //$NON-NLS-1$ - Toast.makeText(view.getContext(), format, Toast.LENGTH_LONG).show(); + String format = activity.getString(R.string.osb_bug_name)+ " : " + bug.getName(); //$NON-NLS-1$ + Toast.makeText(activity, format, Toast.LENGTH_LONG).show(); return true; } return false; @@ -360,9 +360,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe if (bug) { Toast.makeText(activity, activity.getResources().getString(R.string.osb_add_dialog_success), Toast.LENGTH_LONG).show(); clearCache(); - if (view.getLayers().contains(OsmBugsLayer.this)) { - view.refreshMap(); - } + refreshMap(); } else { Toast.makeText(activity, activity.getResources().getString(R.string.osb_add_dialog_error), Toast.LENGTH_LONG).show(); openBugAlertDialog(latitude, longitude, text, author); @@ -374,7 +372,8 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe public void openBug(final double latitude, final double longitude){ - openBugAlertDialog(latitude, longitude, "", view.getSettings().USER_OSM_BUG_NAME.get()); + OsmandSettings settings = OsmandSettings.getOsmandSettings(activity); + openBugAlertDialog(latitude, longitude, "", settings.USER_OSM_BUG_NAME.get()); } public void commentBug(final OpenStreetBug bug){ @@ -400,9 +399,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe if (added) { Toast.makeText(activity, activity.getResources().getString(R.string.osb_comment_dialog_success), Toast.LENGTH_LONG).show(); clearCache(); - if (OsmBugsLayer.this.view.getLayers().contains(OsmBugsLayer.this)) { - OsmBugsLayer.this.view.refreshMap(); - } + } else { Toast.makeText(activity, activity.getResources().getString(R.string.osb_comment_dialog_error), Toast.LENGTH_LONG).show(); } @@ -411,6 +408,12 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe return builder.create(); } + public void refreshMap(){ + if (view != null && view.getLayers().contains(OsmBugsLayer.this)) { + view.refreshMap(); + } + } + public void closeBug(final OpenStreetBug bug){ dialogBundle.putSerializable(KEY_BUG, bug); activity.showDialog(DIALOG_CLOSE_BUG); @@ -428,9 +431,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe if (closed) { Toast.makeText(activity, activity.getString(R.string.osb_close_dialog_success), Toast.LENGTH_LONG).show(); clearCache(); - if (OsmBugsLayer.this.view.getLayers().contains(OsmBugsLayer.this)) { - OsmBugsLayer.this.view.refreshMap(); - } + refreshMap(); } else { Toast.makeText(activity, activity.getString(R.string.osb_close_dialog_error), Toast.LENGTH_LONG).show(); } @@ -443,8 +444,8 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe @Override public OnClickListener getActionListener(List actionsList, Object o) { final OpenStreetBug bug = (OpenStreetBug) o; - actionsList.add(view.getContext().getString(R.string.osb_comment_menu_item)); - actionsList.add(view.getContext().getString(R.string.osb_close_menu_item)); + actionsList.add(activity.getString(R.string.osb_comment_menu_item)); + actionsList.add(activity.getString(R.string.osb_close_menu_item)); return new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -461,7 +462,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe @Override public String getObjectDescription(Object o) { if(o instanceof OpenStreetBug){ - return view.getContext().getString(R.string.osb_bug_name) + " : " + ((OpenStreetBug)o).getName(); //$NON-NLS-1$ + return activity.getString(R.string.osb_bug_name) + " : " + ((OpenStreetBug)o).getName(); //$NON-NLS-1$ } return null; }