[android][sdk] Search SDK

Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
Andrei Shkrob 2025-01-22 21:06:28 +01:00 committed by Roman Tsisyk
parent d95bfeb0fd
commit cf7cce69fa
33 changed files with 168 additions and 173 deletions

View file

@ -22,11 +22,13 @@ set(SRC
app/organicmaps/vulkan/android_vulkan_context_factory.hpp
# JNI sources
app/organicmaps/sdk/search/DisplayedCategories.cpp
app/organicmaps/sdk/search/SearchEngine.cpp
app/organicmaps/sdk/search/SearchRecents.cpp
app/organicmaps/core/jni_helper.cpp
app/organicmaps/core/jni_java_methods.cpp
app/organicmaps/core/logging.cpp
app/organicmaps/bookmarks/data/BookmarkManager.cpp
app/organicmaps/DisplayedCategories.cpp
app/organicmaps/DownloadResourcesLegacyActivity.cpp
app/organicmaps/editor/Editor.cpp
app/organicmaps/editor/OpeningHours.cpp
@ -38,8 +40,6 @@ set(SRC
app/organicmaps/MapManager.cpp
app/organicmaps/MwmApplication.cpp
app/organicmaps/routing/RoutingOptions.cpp
app/organicmaps/SearchEngine.cpp
app/organicmaps/SearchRecents.cpp
app/organicmaps/settings/UnitLocale.cpp
app/organicmaps/settings/MapLanguageCode.cpp
app/organicmaps/sound/tts.cpp

View file

@ -1,40 +0,0 @@
#include "Framework.hpp"
#include "search/result.hpp"
#include "app/organicmaps/core/jni_helper.hpp"
#include "app/organicmaps/core/jni_java_methods.hpp"
using SearchRequest = search::QuerySaver::SearchRequest;
extern "C"
{
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchRecents_nativeGetList(JNIEnv * env, jclass thiz, jobject result)
{
auto const & items = g_framework->NativeFramework()->GetSearchAPI().GetLastSearchQueries();
if (items.empty())
return;
auto const listAddMethod = jni::ListBuilder::Instance(env).m_add;
for (SearchRequest const & item : items)
{
jni::TScopedLocalRef str(env, jni::ToJavaString(env, item.second));
env->CallBooleanMethod(result, listAddMethod, str.get());
}
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchRecents_nativeAdd(JNIEnv * env, jclass thiz, jstring locale, jstring query)
{
SearchRequest const sr(jni::ToNativeString(env, locale), jni::ToNativeString(env, query));
g_framework->NativeFramework()->GetSearchAPI().SaveSearchQuery(sr);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchRecents_nativeClear(JNIEnv * env, jclass thiz)
{
g_framework->NativeFramework()->GetSearchAPI().ClearSearchHistory();
}
}

View file

@ -28,7 +28,7 @@ void InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, o
//jobject CreatePopularity(JNIEnv * env, place_page::Info const & info)
//{
// static jclass const popularityClass =
// jni::GetGlobalClassRef(env, "app/organicmaps/search/Popularity");
// jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/Popularity");
// static jmethodID const popularityConstructor =
// jni::GetConstructorID(env, popularityClass, "(I)V");
// auto const popularityValue = info.GetPopularity();
@ -57,7 +57,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info, int mapObje
"Ljava/lang/String;" // appId
"Lapp/organicmaps/routing/RoutePointInfo;" // routePointInfo
"I" // openingMode
"Lapp/organicmaps/search/Popularity;" // popularity
"Lapp/organicmaps/sdk/search/Popularity;" // popularity
"Ljava/lang/String;" // description
"I" // roadWarnType
"[Ljava/lang/String;" // rawTypes
@ -105,7 +105,7 @@ jobject CreateBookmark(JNIEnv *env, const place_page::Info &info,
"(Lapp/organicmaps/bookmarks/data/FeatureId;JJLjava/lang/String;"
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
"Lapp/organicmaps/routing/RoutePointInfo;"
"ILapp/organicmaps/search/Popularity;Ljava/lang/String;"
"ILapp/organicmaps/sdk/search/Popularity;Ljava/lang/String;"
"[Ljava/lang/String;)V");
static jmethodID const featureCtorId =
jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V");

View file

@ -5,8 +5,7 @@
extern "C"
{
JNIEXPORT jobjectArray JNICALL
Java_app_organicmaps_search_DisplayedCategories_nativeGetKeys(JNIEnv * env, jclass clazz)
JNIEXPORT jobjectArray JNICALL Java_app_organicmaps_sdk_search_DisplayedCategories_nativeGetKeys(JNIEnv * env, jclass)
{
::Framework * fr = g_framework->NativeFramework();
ASSERT(fr, ());

View file

@ -39,7 +39,7 @@ Results g_results;
// Timestamp of last search query. Results with older stamps are ignored.
jlong g_queryTimestamp;
// Implements 'NativeSearchListener' java interface.
// Implements 'SearchListener' java interface.
jobject g_javaListener;
jmethodID g_updateResultsId;
jmethodID g_endResultsId;
@ -52,7 +52,7 @@ jmethodID g_descriptionConstructor;
jclass g_popularityClass;
jmethodID g_popularityConstructor;
// Implements 'NativeMapSearchListener' java interface.
// Implements 'MapSearchListener' java interface.
jmethodID g_mapResultsMethod;
jclass g_mapResultClass;
jmethodID g_mapResultCtor;
@ -232,21 +232,21 @@ void OnBookmarksSearchResults(search::BookmarksSearchParams::Results results,
extern "C"
{
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchEngine_nativeInit(JNIEnv * env, jobject thiz)
Java_app_organicmaps_sdk_search_SearchEngine_nativeInit(JNIEnv * env, jobject thiz)
{
g_javaListener = env->NewGlobalRef(thiz);
// public void onResultsUpdate(@NonNull SearchResult[] results, long timestamp)
g_updateResultsId = jni::GetMethodID(env, g_javaListener, "onResultsUpdate",
"([Lapp/organicmaps/search/SearchResult;J)V");
"([Lapp/organicmaps/sdk/search/SearchResult;J)V");
// public void onResultsEnd(long timestamp)
g_endResultsId = jni::GetMethodID(env, g_javaListener, "onResultsEnd", "(J)V");
g_resultClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/SearchResult");
g_resultClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/SearchResult");
g_resultConstructor = jni::GetConstructorID(
env, g_resultClass,
"(Ljava/lang/String;Lapp/organicmaps/search/SearchResult$Description;DD[I[I"
"Lapp/organicmaps/search/Popularity;)V");
"(Ljava/lang/String;Lapp/organicmaps/sdk/search/SearchResult$Description;DD[I[I"
"Lapp/organicmaps/sdk/search/Popularity;)V");
g_suggestConstructor = jni::GetConstructorID(env, g_resultClass, "(Ljava/lang/String;Ljava/lang/String;DD[I[I)V");
g_descriptionClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/SearchResult$Description");
g_descriptionClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/SearchResult$Description");
/*
Description(FeatureId featureId, String featureType, String region, Distance distance,
String description, int openNow, int minutesUntilOpen, int minutesUntilClosed,
@ -257,12 +257,12 @@ extern "C"
"Ljava/lang/String;Ljava/lang/String;Lapp/organicmaps/util/Distance;"
"Ljava/lang/String;IIIZ)V");
g_popularityClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/Popularity");
g_popularityClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/Popularity");
g_popularityConstructor = jni::GetConstructorID(env, g_popularityClass, "(I)V");
g_mapResultsMethod = jni::GetMethodID(env, g_javaListener, "onMapSearchResults",
"([Lapp/organicmaps/search/NativeMapSearchListener$Result;JZ)V");
g_mapResultClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/NativeMapSearchListener$Result");
"([Lapp/organicmaps/sdk/search/MapSearchListener$Result;JZ)V");
g_mapResultClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/MapSearchListener$Result");
g_mapResultCtor = jni::GetConstructorID(env, g_mapResultClass, "(Ljava/lang/String;Ljava/lang/String;)V");
g_updateBookmarksResultsId =
@ -271,7 +271,7 @@ extern "C"
jni::GetMethodID(env, g_javaListener, "onBookmarkSearchResultsEnd", "([JJ)V");
}
JNIEXPORT jboolean JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearch(
JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearch(
JNIEnv * env, jclass clazz, jbyteArray bytes, jboolean isCategory,
jstring lang, jlong timestamp, jboolean hasPosition, jdouble lat, jdouble lon)
{
@ -288,7 +288,7 @@ extern "C"
return searchStarted;
}
JNIEXPORT void JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunInteractiveSearch(
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunInteractiveSearch(
JNIEnv * env, jclass clazz, jbyteArray bytes, jboolean isCategory,
jstring lang, jlong timestamp, jboolean isMapAndTable, jboolean hasPosition, jdouble lat, jdouble lon)
{
@ -321,7 +321,7 @@ extern "C"
}
}
JNIEXPORT void JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearchMaps(
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearchMaps(
JNIEnv * env, jclass clazz, jbyteArray bytes, jstring lang, jlong timestamp)
{
storage::DownloaderSearchParams params{
@ -334,7 +334,7 @@ extern "C"
g_queryTimestamp = timestamp;
}
JNIEXPORT jboolean JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearchInBookmarks(
JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearchInBookmarks(
JNIEnv * env, jclass clazz, jbyteArray query, jlong catId, jlong timestamp)
{
search::BookmarksSearchParams params{
@ -350,25 +350,25 @@ extern "C"
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchEngine_nativeShowResult(JNIEnv * env, jclass clazz, jint index)
Java_app_organicmaps_sdk_search_SearchEngine_nativeShowResult(JNIEnv * env, jclass clazz, jint index)
{
g_framework->NativeFramework()->ShowSearchResult(g_results[index]);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchEngine_nativeCancelInteractiveSearch(JNIEnv * env, jclass clazz)
Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelInteractiveSearch(JNIEnv * env, jclass clazz)
{
g_framework->NativeFramework()->GetSearchAPI().CancelSearch(search::Mode::Viewport);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchEngine_nativeCancelEverywhereSearch(JNIEnv * env, jclass clazz)
Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelEverywhereSearch(JNIEnv * env, jclass clazz)
{
g_framework->NativeFramework()->GetSearchAPI().CancelSearch(search::Mode::Everywhere);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_search_SearchEngine_nativeCancelAllSearches(JNIEnv * env, jclass clazz)
Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelAllSearches(JNIEnv * env, jclass clazz)
{
g_framework->NativeFramework()->GetSearchAPI().CancelAllSearches();
}

View file

@ -0,0 +1,37 @@
#include "app/organicmaps/Framework.hpp"
#include "app/organicmaps/core/jni_helper.hpp"
#include "app/organicmaps/core/jni_java_methods.hpp"
#include "search/result.hpp"
using SearchRequest = search::QuerySaver::SearchRequest;
extern "C"
{
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeGetList(JNIEnv * env, jclass, jobject result)
{
auto const & items = g_framework->NativeFramework()->GetSearchAPI().GetLastSearchQueries();
if (items.empty())
return;
auto const listAddMethod = jni::ListBuilder::Instance(env).m_add;
for (SearchRequest const & item : items)
{
jni::TScopedLocalRef str(env, jni::ToJavaString(env, item.second));
env->CallBooleanMethod(result, listAddMethod, str.get());
}
}
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeAdd(JNIEnv * env, jclass, jstring locale,
jstring query)
{
SearchRequest const sr(jni::ToNativeString(env, locale), jni::ToNativeString(env, query));
g_framework->NativeFramework()->GetSearchAPI().SaveSearchQuery(sr);
}
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeClear(JNIEnv * env, jclass)
{
g_framework->NativeFramework()->GetSearchAPI().ClearSearchHistory();
}
}

View file

@ -89,7 +89,7 @@ import app.organicmaps.routing.RoutingPlanFragment;
import app.organicmaps.routing.RoutingPlanInplaceController;
import app.organicmaps.search.FloatingSearchToolbarController;
import app.organicmaps.search.SearchActivity;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.search.SearchFragment;
import app.organicmaps.settings.DrivingOptionsActivity;
import app.organicmaps.settings.RoadType;

View file

@ -34,7 +34,7 @@ import app.organicmaps.maplayer.subway.SubwayManager;
import app.organicmaps.maplayer.traffic.TrafficManager;
import app.organicmaps.routing.NavigationService;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.settings.StoragePathManager;
import app.organicmaps.sound.TtsPlayer;
import app.organicmaps.util.Config;

View file

@ -39,8 +39,8 @@ import app.organicmaps.bookmarks.data.KmlFileType;
import app.organicmaps.bookmarks.data.SortedBlock;
import app.organicmaps.bookmarks.data.Track;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.search.NativeBookmarkSearchListener;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.BookmarkSearchListener;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.SharingUtils;
import app.organicmaps.util.UiUtils;
@ -62,7 +62,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
implements BookmarkManager.BookmarksSharingListener,
BookmarkManager.BookmarksSortingListener,
BookmarkManager.BookmarksLoadingListener,
NativeBookmarkSearchListener,
BookmarkSearchListener,
ChooseBookmarksSortingTypeFragment.ChooseSortingTypeListener,
MenuBottomSheetFragment.MenuBottomSheetInterface
{

View file

@ -11,7 +11,7 @@ import androidx.core.os.ParcelCompat;
import app.organicmaps.Framework;
import app.organicmaps.routing.RoutePointInfo;
import app.organicmaps.search.Popularity;
import app.organicmaps.sdk.search.Popularity;
import app.organicmaps.util.Constants;
// TODO consider refactoring to remove hack with MapObject unmarshalling itself and Bookmark at the same time.

View file

@ -12,7 +12,7 @@ import androidx.core.os.ParcelCompat;
import app.organicmaps.Framework;
import app.organicmaps.routing.RoutePointInfo;
import app.organicmaps.search.Popularity;
import app.organicmaps.sdk.search.Popularity;
import app.organicmaps.util.Utils;
import app.organicmaps.widget.placepage.PlacePageData;

View file

@ -23,13 +23,13 @@ import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.search.NativeSearchListener;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.search.SearchRecents;
import app.organicmaps.search.SearchResult;
import app.organicmaps.sdk.search.SearchListener;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.sdk.search.SearchRecents;
import app.organicmaps.sdk.search.SearchResult;
import app.organicmaps.util.Language;
public class SearchOnMapScreen extends BaseMapScreen implements NativeSearchListener
public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
{
private final int MAX_RESULTS_SIZE;

View file

@ -21,13 +21,13 @@ import app.organicmaps.bookmarks.data.MapObject;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.search.NativeSearchListener;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.search.SearchRecents;
import app.organicmaps.search.SearchResult;
import app.organicmaps.sdk.search.SearchListener;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.sdk.search.SearchRecents;
import app.organicmaps.sdk.search.SearchResult;
import app.organicmaps.util.Language;
public class SearchScreen extends BaseMapScreen implements SearchTemplate.SearchCallback, NativeSearchListener
public class SearchScreen extends BaseMapScreen implements SearchTemplate.SearchCallback, SearchListener
{
private final int MAX_RESULTS_SIZE;

View file

@ -13,7 +13,7 @@ import androidx.car.app.model.ForegroundCarColorSpan;
import app.organicmaps.R;
import app.organicmaps.car.util.Colors;
import app.organicmaps.car.util.RoutingHelpers;
import app.organicmaps.search.SearchResult;
import app.organicmaps.sdk.search.SearchResult;
import java.util.ArrayList;
import java.util.List;

View file

@ -8,7 +8,7 @@ import androidx.car.app.suggestion.model.Suggestion;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.R;
import app.organicmaps.search.SearchRecents;
import app.organicmaps.sdk.search.SearchRecents;
import java.util.ArrayList;
import java.util.List;

View file

@ -17,8 +17,8 @@ import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.base.BaseMwmRecyclerFragment;
import app.organicmaps.base.OnBackPressListener;
import app.organicmaps.search.NativeMapSearchListener;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.MapSearchListener;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.widget.PlaceholderView;
import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
@ -52,13 +52,13 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment<DownloaderAdapte
}
};
private final NativeMapSearchListener mSearchListener = new NativeMapSearchListener()
private final MapSearchListener mSearchListener = new MapSearchListener()
{
// Called from JNI.
@Keep
@SuppressWarnings("unused")
@Override
public void onMapSearchResults(Result[] results, long timestamp, boolean isLast)
public void onMapSearchResults(@NonNull Result[] results, long timestamp, boolean isLast)
{
if (!mSearchRunning || timestamp != mCurrentSearch)
return;
@ -66,8 +66,8 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment<DownloaderAdapte
List<CountryItem> rs = new ArrayList<>();
for (Result result : results)
{
CountryItem item = CountryItem.fill(result.countryId);
item.searchResultName = result.matchedString;
CountryItem item = CountryItem.fill(result.countryId());
item.searchResultName = result.matchedString();
rs.add(item);
}

View file

@ -3,7 +3,6 @@ package app.organicmaps.intent;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.content.IntentCompat;
@ -22,7 +21,7 @@ import app.organicmaps.bookmarks.data.MapObject;
import app.organicmaps.editor.OsmLoginActivity;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.search.SearchActivity;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.util.StorageUtils;
import app.organicmaps.util.concurrency.ThreadPool;

View file

@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import app.organicmaps.R;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.search.SearchEngine;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.UiUtils;
import app.organicmaps.util.concurrency.UiThread;

View file

@ -1,4 +1,4 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import androidx.annotation.Keep;
import androidx.annotation.Nullable;
@ -6,11 +6,11 @@ import androidx.annotation.Nullable;
/**
* Native search will return results via this interface.
*/
public interface NativeBookmarkSearchListener
public interface BookmarkSearchListener
{
/**
* @param bookmarkIds Founded bookmark ids.
* @param timestamp Timestamp of search request.
* @param timestamp Timestamp of search request.
*/
// Used by JNI.
@Keep
@ -19,7 +19,7 @@ public interface NativeBookmarkSearchListener
/**
* @param bookmarkIds Founded bookmark ids.
* @param timestamp Timestamp of search request.
* @param timestamp Timestamp of search request.
*/
// Used by JNI.
@Keep

View file

@ -1,8 +1,8 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import androidx.annotation.NonNull;
class DisplayedCategories
public class DisplayedCategories
{
@NonNull
public static String[] getKeys()

View file

@ -0,0 +1,19 @@
package app.organicmaps.sdk.search;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
public interface MapSearchListener
{
// Called from JNI.
@Keep
@SuppressWarnings("unused")
record Result(String countryId, String matchedString)
{
}
// Called from JNI.
@Keep
@SuppressWarnings("unused")
void onMapSearchResults(@NonNull Result[] results, long timestamp, boolean isLast);
}

View file

@ -1,4 +1,4 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import android.os.Parcel;
import android.os.Parcelable;
@ -38,12 +38,12 @@ public class Popularity implements Parcelable
}
@Override
public void writeToParcel(Parcel dest, int flags)
public void writeToParcel(@NonNull Parcel dest, int flags)
{
dest.writeInt(this.mType.ordinal());
}
protected Popularity(Parcel in)
protected Popularity(@NonNull Parcel in)
{
int tmpMPopularity = in.readInt();
this.mType = Type.values()[tmpMPopularity];

View file

@ -1,4 +1,4 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import android.content.Context;
@ -14,9 +14,9 @@ import app.organicmaps.util.concurrency.UiThread;
import java.nio.charset.StandardCharsets;
public enum SearchEngine implements NativeSearchListener,
NativeMapSearchListener,
NativeBookmarkSearchListener
public enum SearchEngine implements SearchListener,
MapSearchListener,
BookmarkSearchListener
{
INSTANCE;
@ -30,7 +30,7 @@ public enum SearchEngine implements NativeSearchListener,
UiThread.run(
() ->
{
for (NativeSearchListener listener : mListeners)
for (SearchListener listener : mListeners)
listener.onResultsUpdate(results, timestamp);
});
}
@ -41,18 +41,18 @@ public enum SearchEngine implements NativeSearchListener,
UiThread.run(
() ->
{
for (NativeSearchListener listener : mListeners)
for (SearchListener listener : mListeners)
listener.onResultsEnd(timestamp);
});
}
@Override
public void onMapSearchResults(final NativeMapSearchListener.Result[] results, final long timestamp, final boolean isLast)
public void onMapSearchResults(@NonNull final MapSearchListener.Result[] results, final long timestamp, final boolean isLast)
{
UiThread.run(
() ->
{
for (NativeMapSearchListener listener : mMapListeners)
for (MapSearchListener listener : mMapListeners)
listener.onMapSearchResults(results, timestamp, isLast);
});
}
@ -60,55 +60,53 @@ public enum SearchEngine implements NativeSearchListener,
@Override
public void onBookmarkSearchResultsUpdate(@Nullable long[] bookmarkIds, long timestamp)
{
for (NativeBookmarkSearchListener listener : mBookmarkListeners)
for (BookmarkSearchListener listener : mBookmarkListeners)
listener.onBookmarkSearchResultsUpdate(bookmarkIds, timestamp);
}
@Override
public void onBookmarkSearchResultsEnd(@Nullable long[] bookmarkIds, long timestamp)
{
for (NativeBookmarkSearchListener listener : mBookmarkListeners)
for (BookmarkSearchListener listener : mBookmarkListeners)
listener.onBookmarkSearchResultsEnd(bookmarkIds, timestamp);
}
private final ObserverList<NativeSearchListener> mListeners = new ObserverList<>();
private final ObserverList<SearchListener> mListeners = new ObserverList<>();
private final ObserverList<NativeMapSearchListener> mMapListeners = new ObserverList<>();
private final ObserverList<MapSearchListener> mMapListeners = new ObserverList<>();
private final ObserverList<NativeBookmarkSearchListener> mBookmarkListeners = new ObserverList<>();
private final ObserverList<BookmarkSearchListener> mBookmarkListeners = new ObserverList<>();
public void addListener(NativeSearchListener listener)
public void addListener(SearchListener listener)
{
mListeners.addObserver(listener);
}
public void removeListener(NativeSearchListener listener)
public void removeListener(SearchListener listener)
{
mListeners.removeObserver(listener);
}
public void addMapListener(NativeMapSearchListener listener)
public void addMapListener(MapSearchListener listener)
{
mMapListeners.addObserver(listener);
}
public void removeMapListener(NativeMapSearchListener listener)
public void removeMapListener(MapSearchListener listener)
{
mMapListeners.removeObserver(listener);
}
public void addBookmarkListener(NativeBookmarkSearchListener listener)
public void addBookmarkListener(BookmarkSearchListener listener)
{
mBookmarkListeners.addObserver(listener);
}
public void removeBookmarkListener(NativeBookmarkSearchListener listener)
public void removeBookmarkListener(BookmarkSearchListener listener)
{
mBookmarkListeners.removeObserver(listener);
}
private native void nativeInit();
/**
*
* @param context
@ -116,7 +114,7 @@ public enum SearchEngine implements NativeSearchListener,
* @return whether search was actually started.
*/
@MainThread
public boolean search(@NonNull Context context, String query, boolean isCategory,
public boolean search(@NonNull Context context, @NonNull String query, boolean isCategory,
long timestamp, boolean hasLocation, double lat, double lon)
{
return nativeRunSearch(query.getBytes(StandardCharsets.UTF_8), isCategory,
@ -146,7 +144,7 @@ public enum SearchEngine implements NativeSearchListener,
}
@MainThread
public static void searchMaps(@NonNull Context context, String query, long timestamp)
public static void searchMaps(@NonNull Context context, @NonNull String query, long timestamp)
{
nativeRunSearchMaps(query.getBytes(StandardCharsets.UTF_8), Language.getKeyboardLocale(context),
timestamp);
@ -208,6 +206,8 @@ public enum SearchEngine implements NativeSearchListener,
nativeInit();
}
private native void nativeInit();
/**
* @param bytes utf-8 formatted bytes of query.
*/

View file

@ -1,4 +1,4 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
@ -6,10 +6,10 @@ import androidx.annotation.NonNull;
/**
* Native search will return results via this interface.
*/
public interface NativeSearchListener
public interface SearchListener
{
/**
* @param results Search results.
* @param results Search results.
* @param timestamp Timestamp of search request.
*/
// Called by JNI.

View file

@ -1,8 +1,7 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.NonNull;
@ -50,6 +49,8 @@ public final class SearchRecents
}
private static native void nativeGetList(List<String> result);
private static native void nativeAdd(String locale, String query);
private static native void nativeClear();
}

View file

@ -1,4 +1,4 @@
package app.organicmaps.search;
package app.organicmaps.sdk.search;
import android.content.Context;
import android.graphics.Typeface;
@ -32,7 +32,7 @@ public class SearchResult
public static final int OPEN_NOW_NO = 2;
public static final SearchResult EMPTY = new SearchResult("", "", 0, 0,
new int[] {}, new int[] {});
new int[]{}, new int[]{});
// Used by JNI.
@Keep

View file

@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.sdk.search.DisplayedCategories;
import app.organicmaps.util.ThemeUtils;
import java.lang.annotation.Retention;
@ -26,9 +27,10 @@ import java.lang.annotation.RetentionPolicy;
class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolder>
{
@Retention(RetentionPolicy.SOURCE)
@IntDef({ TYPE_CATEGORY })
@interface ViewType {}
private static final int TYPE_CATEGORY = 0;
@IntDef({ ViewType.CATEGORY })
@interface ViewType {
int CATEGORY = 0;
}
@StringRes
private int[] mCategoryResIds;
@ -121,15 +123,16 @@ class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolde
@ViewType
public int getItemViewType(int position)
{
return TYPE_CATEGORY;
return ViewType.CATEGORY;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, @ViewType int viewType)
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, @ViewType int viewType)
{
View view;
ViewHolder viewHolder;
if (viewType == TYPE_CATEGORY)
if (viewType == ViewType.CATEGORY)
{
view = mInflater.inflate(R.layout.item_search_category, parent, false);
viewHolder = new ViewHolder(view, (TextView) view);

View file

@ -6,7 +6,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import app.organicmaps.util.WindowInsetUtils;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.util.WindowInsetUtils.PaddingInsetsListener;
import app.organicmaps.widget.SearchToolbarController;
import app.organicmaps.util.UiUtils;

View file

@ -1,26 +0,0 @@
package app.organicmaps.search;
import androidx.annotation.Keep;
public interface NativeMapSearchListener
{
// Called from JNI.
@Keep
@SuppressWarnings("unused")
class Result
{
public final String countryId;
public final String matchedString;
public Result(String countryId, String matchedString)
{
this.countryId = countryId;
this.matchedString = matchedString;
}
}
// Called from JNI.
@Keep
@SuppressWarnings("unused")
void onMapSearchResults(Result[] results, long timestamp, boolean isLast);
}

View file

@ -2,10 +2,6 @@ package app.organicmaps.search;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -17,6 +13,7 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.sdk.search.SearchResult;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.UiUtils;

View file

@ -35,6 +35,10 @@ import app.organicmaps.downloader.MapManager;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.location.LocationListener;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.sdk.search.SearchEngine;
import app.organicmaps.sdk.search.SearchListener;
import app.organicmaps.sdk.search.SearchRecents;
import app.organicmaps.sdk.search.SearchResult;
import app.organicmaps.util.Config;
import app.organicmaps.util.SharedPropertiesUtils;
import app.organicmaps.util.UiUtils;
@ -51,7 +55,7 @@ import java.util.Arrays;
import java.util.List;
public class SearchFragment extends BaseMwmFragment
implements NativeSearchListener,
implements SearchListener,
CategoriesAdapter.CategoriesUiListener
{
private long mLastQueryTimestamp;

View file

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.location.LocationHelper;
import app.organicmaps.routing.RoutingController;
import app.organicmaps.sdk.search.SearchRecents;
import app.organicmaps.widget.SearchToolbarController;
import app.organicmaps.util.Graphics;

View file

@ -32,7 +32,7 @@ import app.organicmaps.util.SharedPropertiesUtils;
import app.organicmaps.util.ThemeSwitcher;
import app.organicmaps.util.Utils;
import app.organicmaps.util.log.LogsManager;
import app.organicmaps.search.SearchRecents;
import app.organicmaps.sdk.search.SearchRecents;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.Locale;