[android] Implement interactive search.

This commit is contained in:
vng 2014-07-17 18:46:12 +03:00 committed by Alex Zolotarev
parent addb026787
commit 9b520597f7
11 changed files with 74 additions and 14 deletions

View file

@ -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

View file

@ -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();

View file

@ -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<void ()> FnT;
FnT * pFn = reinterpret_cast<FnT *>(ev->m_data.m_mwm.m_pFn);
(*pFn)();
delete pFn;
break;
}
default:
NVDEBUG("UNKNOWN event");
break;

View file

@ -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);
}
}

View file

@ -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<android::Platform *>(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()

View file

@ -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();
};
}

View file

@ -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

View file

@ -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

View file

@ -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)
{

View file

@ -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()

View file

@ -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