[android][sdk] Refactor Framework class

Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
Andrei Shkrob
2025-01-17 17:36:10 +01:00
committed by Konstantin Pastbin
parent fe766e50ac
commit 3d7d754785
26 changed files with 467 additions and 306 deletions

View File

@@ -25,7 +25,11 @@ set(SRC
app/organicmaps/sdk/search/DisplayedCategories.cpp
app/organicmaps/sdk/search/SearchEngine.cpp
app/organicmaps/sdk/search/SearchRecents.cpp
app/organicmaps/sdk/routing/RouteRecommendationType.hpp
app/organicmaps/sdk/ChoosePositionMode.cpp
app/organicmaps/sdk/MapStyle.cpp
app/organicmaps/sdk/OrganicMaps.cpp
app/organicmaps/sdk/Router.cpp
app/organicmaps/core/jni_helper.cpp
app/organicmaps/core/jni_java_methods.cpp
app/organicmaps/core/logging.cpp

View File

@@ -4,6 +4,7 @@
#include "app/organicmaps/UserMarkHelper.hpp"
#include "app/organicmaps/opengl/androidoglcontextfactory.hpp"
#include "app/organicmaps/platform/AndroidPlatform.hpp"
#include "app/organicmaps/sdk/routing/RouteRecommendationType.hpp"
#include "app/organicmaps/util/Distance.hpp"
#include "app/organicmaps/util/FeatureIdBuilder.hpp"
#include "app/organicmaps/util/NetworkPolicy.hpp"
@@ -803,8 +804,8 @@ void CallRouteRecommendationListener(shared_ptr<jobject> listener,
RoutingManager::Recommendation recommendation)
{
JNIEnv * env = jni::GetEnv();
jmethodID const methodId = jni::GetMethodID(env, *listener, "onRecommend", "(I)V");
env->CallVoidMethod(*listener, methodId, static_cast<int>(recommendation));
jmethodID const methodId = jni::GetMethodID(env, *listener, "onRecommend", "(Lapp/organicmaps/sdk/routing/RouteRecommendationType;)V");
env->CallVoidMethod(*listener, methodId, GetRouteRecommendationType(env, recommendation));
}
void CallSetRoutingLoadPointsListener(shared_ptr<jobject> listener, bool success)
@@ -1499,66 +1500,6 @@ Java_app_organicmaps_Framework_nativeDeactivateMapSelectionCircle(JNIEnv * env,
return g_framework->DeactivateMapSelectionCircle();
}
JNIEXPORT void JNICALL
Java_app_organicmaps_Framework_nativeSetMapStyle(JNIEnv * env, jclass, jint mapStyle)
{
MapStyle const val = static_cast<MapStyle>(mapStyle);
if (val != g_framework->GetMapStyle())
g_framework->SetMapStyle(val);
}
JNIEXPORT jint JNICALL
Java_app_organicmaps_Framework_nativeGetMapStyle(JNIEnv * env, jclass)
{
return g_framework->GetMapStyle();
}
JNIEXPORT void JNICALL
Java_app_organicmaps_Framework_nativeMarkMapStyle(JNIEnv * env, jclass, jint mapStyle)
{
MapStyle const val = static_cast<MapStyle>(mapStyle);
if (val != g_framework->GetMapStyle())
g_framework->MarkMapStyle(val);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_Framework_nativeSetRouter(JNIEnv * env, jclass, jint routerType)
{
using Type = routing::RouterType;
Type type = Type::Vehicle;
switch (routerType)
{
case 0: break;
case 1: type = Type::Pedestrian; break;
case 2: type = Type::Bicycle; break;
case 3: type = Type::Transit; break;
case 4: type = Type::Ruler; break;
default: assert(false); break;
}
g_framework->GetRoutingManager().SetRouter(type);
}
JNIEXPORT jint JNICALL
Java_app_organicmaps_Framework_nativeGetRouter(JNIEnv * env, jclass)
{
return static_cast<jint>(g_framework->GetRoutingManager().GetRouter());
}
JNIEXPORT jint JNICALL
Java_app_organicmaps_Framework_nativeGetLastUsedRouter(JNIEnv * env, jclass)
{
return static_cast<jint>(g_framework->GetRoutingManager().GetLastUsedRouter());
}
JNIEXPORT jint JNICALL
Java_app_organicmaps_Framework_nativeGetBestRouter(JNIEnv * env, jclass,
jdouble srcLat, jdouble srcLon,
jdouble dstLat, jdouble dstLon)
{
return static_cast<jint>(frm()->GetRoutingManager().GetBestRouter(
mercator::FromLatLon(srcLat, srcLon), mercator::FromLatLon(dstLat, dstLon)));
}
JNIEXPORT void JNICALL
Java_app_organicmaps_Framework_nativeAddRoutePoint(JNIEnv * env, jclass, jstring title,
jstring subtitle, jint markType,
@@ -1820,25 +1761,6 @@ Java_app_organicmaps_Framework_nativeGetPoiContactUrl(JNIEnv *env, jclass, jint
return jni::ToJavaString(env, value);
}
JNIEXPORT void JNICALL
Java_app_organicmaps_Framework_nativeSetChoosePositionMode(JNIEnv *, jclass, jint mode, jboolean isBusiness,
jboolean applyPosition)
{
// TODO(AB): Move this code into the Framework to share with iOS and other platforms.
auto const f = frm();
if (applyPosition && f->HasPlacePageInfo())
g_framework->SetChoosePositionMode(static_cast<android::ChoosePositionMode>(mode), isBusiness,
&f->GetCurrentPlacePageInfo().GetMercator());
else
g_framework->SetChoosePositionMode(static_cast<android::ChoosePositionMode>(mode), isBusiness, nullptr);
}
JNIEXPORT jint JNICALL
Java_app_organicmaps_Framework_nativeGetChoosePositionMode(JNIEnv *, jclass)
{
return static_cast<jint>(g_framework->GetChoosePositionMode());
}
JNIEXPORT jboolean JNICALL
Java_app_organicmaps_Framework_nativeIsDownloadedMapAtScreenCenter(JNIEnv *, jclass)
{

View File

@@ -0,0 +1,26 @@
#include "app/organicmaps/core/jni_helper.hpp"
#include "app/organicmaps/Framework.hpp"
#include "indexer/map_style.hpp"
extern "C"
{
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_ChoosePositionMode_nativeSet(JNIEnv *, jclass, jint mode,
jboolean isBusiness,
jboolean applyPosition)
{
// TODO(AB): Move this code into the Framework to share with iOS and other platforms.
auto const f = frm();
if (applyPosition && f->HasPlacePageInfo())
g_framework->SetChoosePositionMode(static_cast<android::ChoosePositionMode>(mode), isBusiness,
&f->GetCurrentPlacePageInfo().GetMercator());
else
g_framework->SetChoosePositionMode(static_cast<android::ChoosePositionMode>(mode), isBusiness, nullptr);
}
JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_ChoosePositionMode_nativeGet(JNIEnv *, jclass)
{
return static_cast<jint>(g_framework->GetChoosePositionMode());
}
}

View File

@@ -0,0 +1,27 @@
#include "app/organicmaps/core/jni_helper.hpp"
#include "app/organicmaps/Framework.hpp"
#include "indexer/map_style.hpp"
extern "C"
{
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_MapStyle_nativeSet(JNIEnv *, jclass, jint mapStyle)
{
auto const val = static_cast<MapStyle>(mapStyle);
if (val != g_framework->GetMapStyle())
g_framework->SetMapStyle(val);
}
JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_MapStyle_nativeGet(JNIEnv *, jclass)
{
return g_framework->GetMapStyle();
}
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_MapStyle_nativeMark(JNIEnv *, jclass, jint mapStyle)
{
auto const val = static_cast<MapStyle>(mapStyle);
if (val != g_framework->GetMapStyle())
g_framework->MarkMapStyle(val);
}
}

View File

@@ -0,0 +1,41 @@
#include "app/organicmaps/core/jni_helper.hpp"
#include "app/organicmaps/Framework.hpp"
#include "indexer/map_style.hpp"
extern "C"
{
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_Router_nativeSet(JNIEnv *, jclass, jint routerType)
{
using Type = routing::RouterType;
Type type;
switch (routerType)
{
case 0: type = Type::Vehicle; break;
case 1: type = Type::Pedestrian; break;
case 2: type = Type::Bicycle; break;
case 3: type = Type::Transit; break;
case 4: type = Type::Ruler; break;
default: assert(false); break;
}
frm()->GetRoutingManager().SetRouter(type);
}
JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_Router_nativeGet(JNIEnv *, jclass)
{
return static_cast<jint>(frm()->GetRoutingManager().GetRouter());
}
JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_Router_nativeGetLastUsed(JNIEnv *, jclass)
{
return static_cast<jint>(frm()->GetRoutingManager().GetLastUsedRouter());
}
JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_Router_nativeGetBest(JNIEnv *, jclass, jdouble srcLat, jdouble srcLon,
jdouble dstLat, jdouble dstLon)
{
return static_cast<jint>(frm()->GetRoutingManager().GetBestRouter(mercator::FromLatLon(srcLat, srcLon),
mercator::FromLatLon(dstLat, dstLon)));
}
}

View File

@@ -0,0 +1,36 @@
#include "app/organicmaps/core/jni_helper.hpp"
jobject GetRebuildAfterPointsLoading(JNIEnv * env)
{
static jobject rebuildAfterPointsLoading = nullptr;
if (rebuildAfterPointsLoading)
return rebuildAfterPointsLoading;
// Find the RouteRecommendationType class
jclass routeRecommendationTypeClass = env->FindClass("app/organicmaps/sdk/routing/RouteRecommendationType");
ASSERT(routeRecommendationTypeClass, ());
// Get the values() method of RouteRecommendationType
jmethodID valuesMethod = env->GetStaticMethodID(routeRecommendationTypeClass, "values",
"()[Lapp/organicmaps/sdk/routing/RouteRecommendationType;");
ASSERT(valuesMethod, ());
// Call values() to get all enum constants
jobjectArray enumConstants = (jobjectArray)env->CallStaticObjectMethod(routeRecommendationTypeClass, valuesMethod);
ASSERT(enumConstants, ());
// Retrieve the first (and only) constant, RebuildAfterPointsLoading
rebuildAfterPointsLoading = env->NewGlobalRef(env->GetObjectArrayElement(enumConstants, 0));
ASSERT(rebuildAfterPointsLoading, ());
return rebuildAfterPointsLoading;
}
jobject GetRouteRecommendationType(JNIEnv * env, RoutingManager::Recommendation recommendation)
{
switch (recommendation)
{
case RoutingManager::Recommendation::RebuildAfterPointsLoading: return GetRebuildAfterPointsLoading(env);
default: ASSERT_FAIL("Unknown recommendation type");
}
}