From 85d9ad665c59253aa0dd9e974bc560871e0d90c6 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 6 Feb 2013 13:11:46 +0300 Subject: [PATCH] [search] Add warning message to download absent countries if no search results found. --- android/jni/com/mapswithme/maps/Framework.cpp | 23 +++++++++- android/jni/com/mapswithme/maps/Framework.hpp | 3 ++ .../com/mapswithme/maps/SearchActivity.cpp | 17 ++++++++ android/res/values-de/strings.xml | 6 +++ android/res/values-es/strings.xml | 6 +++ android/res/values-fr/strings.xml | 6 +++ android/res/values-it/strings.xml | 6 +++ android/res/values-ja/strings.xml | 6 +++ android/res/values-ko/strings.xml | 6 +++ android/res/values-nl/strings.xml | 6 +++ android/res/values-ru/strings.xml | 8 +++- android/res/values-uk/strings.xml | 6 +++ android/res/values/strings.xml | 8 +++- .../com/mapswithme/maps/SearchActivity.java | 38 +++++++++++++--- map/framework.cpp | 5 +++ map/framework.hpp | 1 + strings.txt | 43 +++++++++++++++++-- 17 files changed, 180 insertions(+), 14 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index f9c407a69b..54f1b6ed72 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -491,12 +491,31 @@ namespace android storage::TIndex Framework::GetCountryIndex(double lat, double lon) const { - return m_work.GetCountryIndex(m2::PointD(MercatorBounds::LonToX(lon), MercatorBounds::LatToY(lat))); + return m_work.GetCountryIndex(m2::PointD(MercatorBounds::LonToX(lon), + MercatorBounds::LatToY(lat))); } string Framework::GetCountryCode(double lat, double lon) const { - return m_work.GetCountryCode(m2::PointD(MercatorBounds::LonToX(lon), MercatorBounds::LatToY(lat))); + return m_work.GetCountryCode(m2::PointD(MercatorBounds::LonToX(lon), + MercatorBounds::LatToY(lat))); + } + + string Framework::GetCountryNameIfAbsent(m2::PointD const & pt) const + { + using namespace storage; + + TIndex const idx = m_work.GetCountryIndex(pt); + TStatus const status = m_work.GetCountryStatus(idx); + if (status != EOnDisk && status != EOnDiskOutOfDate) + return m_work.GetCountryName(idx); + else + return string(); + } + + m2::PointD Framework::GetViewportCenter() const + { + return m_work.GetViewportCenter(); } void Framework::AddString(string const & name, string const & value) diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 7cc22b5f59..9a18a5cf39 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -105,6 +105,9 @@ namespace android storage::TIndex GetCountryIndex(double lat, double lon) const; string GetCountryCode(double lat, double lon) const; + string GetCountryNameIfAbsent(m2::PointD const & pt) const; + m2::PointD GetViewportCenter() const; + void AddString(string const & name, string const & value); void Scale(double k); diff --git a/android/jni/com/mapswithme/maps/SearchActivity.cpp b/android/jni/com/mapswithme/maps/SearchActivity.cpp index 4a2ac2ffe2..3b662ca7c1 100644 --- a/android/jni/com/mapswithme/maps/SearchActivity.cpp +++ b/android/jni/com/mapswithme/maps/SearchActivity.cpp @@ -255,4 +255,21 @@ Java_com_mapswithme_maps_SearchActivity_nativeGetResult( } } +JNIEXPORT jstring JNICALL +Java_com_mapswithme_maps_SearchActivity_getCountryNameIfAbsent(JNIEnv * env, jobject thiz, + jdouble lat, jdouble lon) +{ + string const name = g_framework->GetCountryNameIfAbsent(m2::PointD( + MercatorBounds::LonToX(lon), MercatorBounds::LatToY(lat))); + + return (name.empty() ? 0 : jni::ToJavaString(env, name)); +} + +JNIEXPORT jstring JNICALL +Java_com_mapswithme_maps_SearchActivity_getViewportCountryNameIfAbsent(JNIEnv * env, jobject thiz) +{ + string const name = g_framework->GetCountryNameIfAbsent(g_framework->GetViewportCenter()); + return (name.empty() ? 0 : jni::ToJavaString(env, name)); +} + } diff --git a/android/res/values-de/strings.xml b/android/res/values-de/strings.xml index 1183f8a554..93cd7dd6be 100644 --- a/android/res/values-de/strings.xml +++ b/android/res/values-de/strings.xml @@ -245,4 +245,10 @@ Lesezeichen erfolgreich geladen! Sie können diese nun auf Ihrer Karte oder im Lesezeichen-Manager sehen. Hochladen der Lesezeichen fehlgeschlagen. Die Datei könnte beschädigt oder defekt sein. + + Ihr Standort wurde bisher noch nicht bestimmt + + Land (%s) Ihres derzeitigen Standorts herunterladen + + Land (%s) herunterladen, von dem aus Sie suchen diff --git a/android/res/values-es/strings.xml b/android/res/values-es/strings.xml index 95585d7b4b..ce6c658dd1 100644 --- a/android/res/values-es/strings.xml +++ b/android/res/values-es/strings.xml @@ -241,4 +241,10 @@ ¡Los favoritos se han cargado con éxito! Puedes encontrarlos en el mapa o en la pantalla de Gestión de favoritos. La carga de favoritos ha fallado. El archivo puede estar corrupto o ser defectuoso. + + Tu ubicación aún no ha sido determinada + + Descargar país (%s) de tu ubicación actual + + Descargar país (%s) en el que estás buscando diff --git a/android/res/values-fr/strings.xml b/android/res/values-fr/strings.xml index bfb96d54f7..bbf66d11cb 100644 --- a/android/res/values-fr/strings.xml +++ b/android/res/values-fr/strings.xml @@ -237,4 +237,10 @@ Favoris chargés avec succès ! Vous pouvez les trouver sur la carte ou sur l\'écran de gestion des favoris. Chargement des favoris échoué. Le dossier peut être corrompu ou défectueux. + + Votre position n\'a pas encore été déterminée + + Téléchargez le pays (%s) de votre position actuelle + + Téléchargez le pays (%s) que vous recherchez sur diff --git a/android/res/values-it/strings.xml b/android/res/values-it/strings.xml index 179123e41d..ff06b0f084 100644 --- a/android/res/values-it/strings.xml +++ b/android/res/values-it/strings.xml @@ -39,4 +39,10 @@ Segnalibri caricati con successo! Puoi trovare i segnalibri direttamente sulla mappa, oppure aprendo la schermata dedicata alla Gestione dei segnalibri. Caricamento dei segnalibri non riuscito. Il file potrebbe essere corrotto o difettoso. + + La tua posizione non è stata ancora stabilita + + Scarica il paese (%s) della tua posizione attuale + + Scarica il paese (%s) che stai cercando diff --git a/android/res/values-ja/strings.xml b/android/res/values-ja/strings.xml index 690b2f5c30..5e00fcba02 100644 --- a/android/res/values-ja/strings.xml +++ b/android/res/values-ja/strings.xml @@ -243,4 +243,10 @@ ブックマークが無事読み込まれました! ブックマークはマップ上またはブックマークマネージャー画面上にあります。 ブックマークのアップロードに失敗しました。ファイルが破損していた、または問題があった可能性があります。 + + 現在地がまだ決定されていません + + 現在地である国(%s)をダウンロード + + 現在マップで検索している国(%s)をダウンロード diff --git a/android/res/values-ko/strings.xml b/android/res/values-ko/strings.xml index cc05a5faab..ad64a3a02c 100644 --- a/android/res/values-ko/strings.xml +++ b/android/res/values-ko/strings.xml @@ -239,4 +239,10 @@ 즐겨찾기가 성공적으로 로드되었습니다! 지도 또는 즐겨찾기 관리자 화면에서 찾으실 수 있습니다. 즐겨찾기 업로드가 실패했습니다. 파일이 훼손되었거나 결함이 있을지도 모릅니다. + + 귀하의 위치를 아직 알아내지 못 했습니다 + + 귀하께서 현재 계신 국가인 (%s)을(를) 다운로드 + + 귀하께서 검색 중인 국가인 (%s)을(를) 다운로드 diff --git a/android/res/values-nl/strings.xml b/android/res/values-nl/strings.xml index 719d96e255..bc0d08304d 100644 --- a/android/res/values-nl/strings.xml +++ b/android/res/values-nl/strings.xml @@ -249,4 +249,10 @@ Bladwijzers met succes geüpload! U vindt ze op de kaart of op het scherm van de Bladwijzer Manager. Bladwijzers uploaden mislukt. Het bestand is mogelijk beschadigd of defect. + + Je plaats werd nog niet vastgesteld + + Download land (%s) waar je nu bent + + Download land (%s) waar je op wilt zoeken diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index 2d7a6344e6..e99e48d4da 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -253,6 +253,10 @@ Редактировать Вы уверены? - - Текущая позиция недоступна + + Ваше местоположение еще не определено + + Скачайте страну (%s) вашего текущего местоположения + + Скачайте страну (%s), на которой вы ищете diff --git a/android/res/values-uk/strings.xml b/android/res/values-uk/strings.xml index 56ba1da67b..19b55eff34 100644 --- a/android/res/values-uk/strings.xml +++ b/android/res/values-uk/strings.xml @@ -220,4 +220,10 @@ Закладки успішно завантажено! Ви можете знайти їх на карті або у меню Менеджер закладок. Не вдалося завантажити закладки. Файл може бути пошкодженим або несправним. + + Ваше місце розташування не визначено + + Завантажити країну (%s) вашого поточного місця розташування + + Завантажити країну (% @), в якій ви шукаєте diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index d93f5c4b3b..71131b5fb8 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -257,6 +257,10 @@ Edit Are you sure? - - Current postion is not available + + Your location hasn\'t been determined yet + + Download the country (%s) of your current location + + Download the country (%s) you are searching on diff --git a/android/src/com/mapswithme/maps/SearchActivity.java b/android/src/com/mapswithme/maps/SearchActivity.java index a2e27254a2..160ac133f6 100644 --- a/android/src/com/mapswithme/maps/SearchActivity.java +++ b/android/src/com/mapswithme/maps/SearchActivity.java @@ -5,6 +5,7 @@ import java.util.Locale; import android.app.ListActivity; import android.content.Context; import android.content.res.Resources; +import android.location.Location; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; @@ -77,11 +78,34 @@ public class SearchActivity extends ListActivity implements LocationService.List return m_context.isShowCategories(); } - private boolean isShowPositionWarning() + private String getWarningForEmptyResults() { - return (m_context.m_location.getLastKnown() == null && m_context.m_searchMode == AROUND_POSITION); - } + // First try to show warning if no country downloaded for viewport. + if (m_context.m_searchMode != AROUND_POSITION) + { + final String name = m_context.getViewportCountryNameIfAbsent(); + if (name != null) + return String.format(m_context.getString(R.string.download_viewport_country_to_search), name); + } + // If now position detected or no country downloaded for position. + if (m_context.m_searchMode != IN_VIEWPORT) + { + final Location loc = m_context.m_location.getLastKnown(); + if (loc == null) + { + return m_context.getString(R.string.unknown_current_position); + } + else + { + final String name = m_context.getCountryNameIfAbsent(loc.getLatitude(), loc.getLongitude()); + if (name != null) + return String.format(m_context.getString(R.string.download_location_country), name); + } + } + + return null; + } @Override public boolean isEnabled(int position) @@ -259,10 +283,11 @@ public class SearchActivity extends ListActivity implements LocationService.List holder.m_name.setText(m_context.getString(R.string.no_search_results_found)); - if (isShowPositionWarning()) + final String msg = getWarningForEmptyResults(); + if (msg != null) { holder.m_country.setVisibility(View.VISIBLE); - holder.m_country.setText(R.string.unknown_current_position); + holder.m_country.setText(msg); } else holder.m_country.setVisibility(View.GONE); @@ -690,4 +715,7 @@ public class SearchActivity extends ListActivity implements LocationService.List double lat, double lon, int flags, int searchMode, int queryID); private static native void nativeShowItem(int position); + + private native String getCountryNameIfAbsent(double lat, double lon); + private native String getViewportCountryNameIfAbsent(); } diff --git a/map/framework.cpp b/map/framework.cpp index 53ed46ad4b..6d3e952111 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -310,6 +310,11 @@ TStatus Framework::GetCountryStatus(TIndex const & index) const return res; } +string Framework::GetCountryName(storage::TIndex const & index) const +{ + return m_storage.CountryName(index); +} + m2::RectD Framework::GetCountryBounds(string const & file) const { m2::RectD const r = GetSearchEngine()->GetCountryBounds(file); diff --git a/map/framework.hpp b/map/framework.hpp index 5c731eb0a4..e924381ed0 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -175,6 +175,7 @@ public: void DeleteCountry(storage::TIndex const & index); storage::TStatus GetCountryStatus(storage::TIndex const & index) const; + string GetCountryName(storage::TIndex const & index) const; /// Get country rect from borders (not from mwm file). /// @param[in] file Pass country file name without extension as an id. diff --git a/strings.txt b/strings.txt index 0c3daf63da..53e551f3d1 100644 --- a/strings.txt +++ b/strings.txt @@ -1639,7 +1639,44 @@ comment = Title for Confirm dialog ru = Вы уверены? [unknown_current_position] - en = Current postion is not available + en = Your location hasn't been determined yet tags = ios, android - comment = Warning message when searching around current position - ru = Текущая позиция недоступна + comment = Warning message when doing search around current position + ru = Ваше местоположение еще не определено + uk = Ваше місце розташування не визначено + ko = 귀하의 위치를 아직 알아내지 못 했습니다 + es = Tu ubicación aún no ha sido determinada + it = La tua posizione non è stata ancora stabilita + ja = 現在地がまだ決定されていません + fr = Votre position n'a pas encore été déterminée + cz = Vaše poloha zatím nebyla určena + nl = Je plaats werd nog niet vastgesteld + de = Ihr Standort wurde bisher noch nicht bestimmt + [download_location_country] + en = Download the country (%@) of your current location + tags = ios, android + comment = Warning message when location country isn't downloaded during search (see also download_location_map_proposal). + ru = Скачайте страну (%@) вашего текущего местоположения + uk = Завантажити країну (%@) вашого поточного місця розташування + ko = 귀하께서 현재 계신 국가인 (%@)을(를) 다운로드 + es = Descargar país (%@) de tu ubicación actual + it = Scarica il paese (%@) della tua posizione attuale + ja = 現在地である国(%@)をダウンロード + fr = Téléchargez le pays (%@) de votre position actuelle + cz = Země stahování (%@) Vašeho současného místa + nl = Download land (%@) waar je nu bent + de = Land (%@) Ihres derzeitigen Standorts herunterladen + [download_viewport_country_to_search] + en = Download the country (%@) you are searching on + tags = ios, android + comment = Warning message when viewport country isn't downloaded during search + ru = Скачайте страну (%@), на которой вы ищете + uk = Завантажити країну (% @), в якій ви шукаєте + ko = 귀하께서 검색 중인 국가인 (%@)을(를) 다운로드 + es = Descargar país (%@) en el que estás buscando + it = Scarica il paese (%@) che stai cercando + ja = 現在マップで検索している国(%@)をダウンロード + fr = Téléchargez le pays (%@) que vous recherchez sur + cz = Země stahování (%@), o níž hledáte + nl = Download land (%@) waar je op wilt zoeken + de = Land (%@) herunterladen, von dem aus Sie suchen