From 9b520597f74189f7d7e76b47c02cdb86f316b940 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 17 Jul 2014 18:46:12 +0300 Subject: [PATCH] [android] Implement interactive search. --- android/jni/com/mapswithme/maps/Framework.cpp | 4 +++- android/jni/com/mapswithme/maps/Framework.hpp | 2 +- android/jni/com/mapswithme/maps/Lifecycle.cpp | 9 +++++++++ .../jni/com/mapswithme/maps/SearchActivity.cpp | 11 +++++++++++ android/jni/com/mapswithme/platform/Platform.cpp | 12 ++++++++++++ android/jni/com/mapswithme/platform/Platform.hpp | 3 +++ android/jni/nv_event/nv_event.cpp | 12 +++++++++++- android/jni/nv_event/nv_event.hpp | 11 ++++++++++- .../src/com/mapswithme/maps/SearchActivity.java | 16 +++++++++++++--- .../mapswithme/maps/search/SearchController.java | 2 +- platform/platform_android.cpp | 6 ------ 11 files changed, 74 insertions(+), 14 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 46dfb2089f..3988b2fdd8 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -440,6 +440,7 @@ namespace android m_work.ShowAllSearchResults(); } + /* void Framework::CleanSearchLayerOnMap() { ::Framework * f = NativeFramework(); @@ -450,6 +451,7 @@ namespace android f->GetBalloonManager().Dismiss(); f->Invalidate(); } + */ bool Framework::Search(search::SearchParams const & params) { @@ -1005,7 +1007,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_cleanSearchLayerOnMap(JNIEnv * env, jclass clazz) { - g_framework->CleanSearchLayerOnMap(); + g_framework->NativeFramework()->CancelInteractiveSearch(); } JNIEXPORT void JNICALL diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index e6ff94cfdd..4825d52a93 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -95,7 +95,7 @@ namespace android bool Search(search::SearchParams const & params); string GetLastSearchQuery() { return m_searchQuery; } void ClearLastSearchQuery() { m_searchQuery.clear(); } - void CleanSearchLayerOnMap(); + //void CleanSearchLayerOnMap(); void LoadState(); void SaveState(); diff --git a/android/jni/com/mapswithme/maps/Lifecycle.cpp b/android/jni/com/mapswithme/maps/Lifecycle.cpp index 18d89f577d..df6f3d43d4 100644 --- a/android/jni/com/mapswithme/maps/Lifecycle.cpp +++ b/android/jni/com/mapswithme/maps/Lifecycle.cpp @@ -284,6 +284,15 @@ int32_t NVEventAppMain(int32_t argc, char** argv) NVDEBUG("%s event: no specific app action", NVEventGetEventStr(ev->m_type)); break; + case NV_EVENT_MWM: + { + typedef function FnT; + FnT * pFn = reinterpret_cast(ev->m_data.m_mwm.m_pFn); + (*pFn)(); + delete pFn; + break; + } + default: NVDEBUG("UNKNOWN event"); break; diff --git a/android/jni/com/mapswithme/maps/SearchActivity.cpp b/android/jni/com/mapswithme/maps/SearchActivity.cpp index 0ffa20aaf1..0f3c560baa 100644 --- a/android/jni/com/mapswithme/maps/SearchActivity.cpp +++ b/android/jni/com/mapswithme/maps/SearchActivity.cpp @@ -321,4 +321,15 @@ Java_com_mapswithme_maps_SearchActivity_clearLastQuery(JNIEnv * env, jobject thi g_framework->ClearLastSearchQuery(); } +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_SearchActivity_runInteractiveSearch(JNIEnv * env, jobject thiz, + jstring query, jstring lang) +{ + search::SearchParams params; + params.m_query = jni::ToNativeString(env, query); + params.SetInputLanguage(jni::ToNativeString(env, lang)); + + g_framework->NativeFramework()->StartInteractiveSearch(params); +} + } diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index 5ae85704a4..2e2eafe1c9 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -2,6 +2,8 @@ #include "../core/jni_helper.hpp" +#include "../../../nv_event/nv_event.hpp" + #include "../../../../../platform/settings.hpp" #include "../../../../../base/logging.hpp" @@ -53,6 +55,11 @@ string Platform::UniqueClientId() const return res; } +void Platform::RunOnGuiThread(TFunctor const & fn) +{ + static_cast(this)->RunOnGuiThreadImpl(fn); +} + namespace android { void Platform::Initialize(JNIEnv * env, @@ -128,6 +135,11 @@ namespace android static Platform platform; return platform; } + + void Platform::RunOnGuiThreadImpl(TFunctor const & fn) + { + postMWMEvent(new TFunctor(fn)); + } } Platform & GetPlatform() diff --git a/android/jni/com/mapswithme/platform/Platform.hpp b/android/jni/com/mapswithme/platform/Platform.hpp index 38344c02ac..17ae20d49b 100644 --- a/android/jni/com/mapswithme/platform/Platform.hpp +++ b/android/jni/com/mapswithme/platform/Platform.hpp @@ -4,6 +4,7 @@ #include "../../../../../platform/platform.hpp" + namespace android { class Platform : public ::Platform @@ -23,6 +24,8 @@ namespace android bool HasAvailableSpaceForWriting(uint64_t size) const; + void RunOnGuiThreadImpl(TFunctor const & fn); + static Platform & Instance(); }; } diff --git a/android/jni/nv_event/nv_event.cpp b/android/jni/nv_event/nv_event.cpp index dbc741bdbc..bc4ad2e97f 100644 --- a/android/jni/nv_event/nv_event.cpp +++ b/android/jni/nv_event/nv_event.cpp @@ -340,10 +340,11 @@ const char* NVEventGetEventStr(NVEventType eventType) case NV_EVENT_QUIT: return "NV_EVENT_QUIT"; case NV_EVENT_USER: return "NV_EVENT_USER"; case NV_EVENT_LONG_CLICK: return "NV_EVENT_LONG_CLICK"; + case NV_EVENT_MWM: return "NV_EVENT_MWM"; } // update this if you end up having to edit something. - CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 18); + CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 19); return "unknown event type!"; } @@ -804,6 +805,15 @@ static jboolean postUserEvent(JNIEnv* env, jobject thiz, } } +void postMWMEvent(void * pFn) +{ + NVEvent ev; + ev.m_type = NV_EVENT_MWM; + ev.m_data.m_mwm.m_pFn = pFn; + + NVEventInsertBlocking(&ev); +} + /////////////////////////////////////////////////////////////////////////////// // File and APK handling functions diff --git a/android/jni/nv_event/nv_event.hpp b/android/jni/nv_event/nv_event.hpp index 5111e7289c..3ed4c2aaa7 100644 --- a/android/jni/nv_event/nv_event.hpp +++ b/android/jni/nv_event/nv_event.hpp @@ -4,7 +4,7 @@ // Email: tegradev@nvidia.com // Web: http://developer.nvidia.com/category/zone/mobile-development // -// Copyright 2009-2011 NVIDIA® Corporation +// Copyright 2009-2011 NVIDIA® Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -103,6 +103,7 @@ typedef enum NVEventType NV_EVENT_QUIT, /** App-specific events */ NV_EVENT_USER, + NV_EVENT_MWM, /* a dummy enum value used to compute num_events */ NV_EVENT_NUM_EVENT_DUMMY_DONTUSEME, /* total number of events */ @@ -330,6 +331,11 @@ typedef struct NVEventUser int32_t m_u3; } NVEventUser; +typedef struct NVEventMWM +{ + void * m_pFn; +} NVEventMWM; + /** All-encompassing event structure */ typedef struct NVEvent @@ -353,6 +359,7 @@ typedef struct NVEvent NVEventSurfaceSize m_size; /** Data for user/app events */ NVEventUser m_user; + NVEventMWM m_mwm; } m_data; } NVEvent; @@ -537,4 +544,6 @@ NVEventPlatformAppHandle NVEventGetPlatformAppHandle(); void InitNVEvent(JavaVM * jvm); +void postMWMEvent(void * pFn); + #endif diff --git a/android/src/com/mapswithme/maps/SearchActivity.java b/android/src/com/mapswithme/maps/SearchActivity.java index e6e886bbdf..60eb2dbc8d 100644 --- a/android/src/com/mapswithme/maps/SearchActivity.java +++ b/android/src/com/mapswithme/maps/SearchActivity.java @@ -716,10 +716,18 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati finish(); // Put query string for "View on map" or feature name for search result. - SearchController.getInstance().setQuery(position == 0 ? - mSearchEt.getText().toString() : ""); + final boolean allResults = (position == 0); + final String query = getSearchString(); - MWMActivity.startWithSearchResult(this, position != 0); + SearchController.getInstance().setQuery(allResults ? query : ""); + + if (allResults) + { + final String lang = Language.getKeyboardInput(this); + runInteractiveSearch(query, lang); + } + + MWMActivity.startWithSearchResult(this, !allResults); } else { @@ -920,6 +928,8 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati private native void clearLastQuery(); + private native void runInteractiveSearch(String query, String lang); + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/android/src/com/mapswithme/maps/search/SearchController.java b/android/src/com/mapswithme/maps/search/SearchController.java index 2747c741ce..12ce4daccf 100644 --- a/android/src/com/mapswithme/maps/search/SearchController.java +++ b/android/src/com/mapswithme/maps/search/SearchController.java @@ -107,7 +107,7 @@ public class SearchController implements OnClickListener public void setQuery(String query) { - mQuery = query == null ? "" : query; + mQuery = (query == null) ? "" : query; } public String getQuery() diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 362f0c79e7..ad458824fd 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -217,12 +217,6 @@ bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const } } -void Platform::RunOnGuiThread(TFunctor const & fn) -{ - /// @todo - fn(); -} - namespace { class SelfDeleteRoutine : public threads::IRoutine