forked from organicmaps/organicmaps
[android] refactor: JNI reorganized.
This commit is contained in:
parent
e1c79cc0db
commit
6043e081ec
5 changed files with 76 additions and 59 deletions
|
@ -83,6 +83,8 @@ LOCAL_SRC_FILES := \
|
|||
com/mapswithme/maps/MapFragment.cpp \
|
||||
com/mapswithme/maps/MwmApplication.cpp \
|
||||
com/mapswithme/maps/LocationState.cpp \
|
||||
com/mapswithme/maps/LocationHelper.cpp \
|
||||
com/mapswithme/maps/TrackRecorder.cpp \
|
||||
com/mapswithme/maps/MapStorage.cpp \
|
||||
com/mapswithme/maps/DownloadResourcesActivity.cpp \
|
||||
com/mapswithme/maps/PrivateVariables.cpp \
|
||||
|
|
58
android/jni/com/mapswithme/maps/LocationHelper.cpp
Normal file
58
android/jni/com/mapswithme/maps/LocationHelper.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "Framework.hpp"
|
||||
#include "platform/file_logging.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationHelper_nativeOnLocationError(JNIEnv * env, jclass clazz, int errorCode)
|
||||
{
|
||||
g_framework->OnLocationError(errorCode);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationHelper_nativeLocationUpdated(JNIEnv * env, jclass clazz, jlong time,
|
||||
jdouble lat, jdouble lon, jfloat accuracy,
|
||||
jdouble altitude, jfloat speed, jfloat bearing)
|
||||
{
|
||||
location::GpsInfo info;
|
||||
info.m_source = location::EAndroidNative;
|
||||
|
||||
info.m_timestamp = static_cast<double>(time) / 1000.0;
|
||||
info.m_latitude = lat;
|
||||
info.m_longitude = lon;
|
||||
|
||||
if (accuracy > 0.0)
|
||||
info.m_horizontalAccuracy = accuracy;
|
||||
|
||||
if (altitude != 0.0)
|
||||
{
|
||||
info.m_altitude = altitude;
|
||||
info.m_verticalAccuracy = accuracy;
|
||||
}
|
||||
|
||||
if (bearing > 0.0)
|
||||
info.m_bearing = bearing;
|
||||
|
||||
if (speed > 0.0)
|
||||
info.m_speed = speed;
|
||||
|
||||
LOG_MEMORY_INFO();
|
||||
g_framework->OnLocationUpdated(info);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloatArray JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationHelper_nativeUpdateCompassSensor(JNIEnv * env, jclass clazz, jint ind, jfloatArray arr)
|
||||
{
|
||||
int const kCoordsCount = 3;
|
||||
|
||||
// Extract coords
|
||||
jfloat coords[kCoordsCount];
|
||||
env->GetFloatArrayRegion(arr, 0, kCoordsCount, coords);
|
||||
g_framework->UpdateCompassSensor(ind, coords);
|
||||
|
||||
// Put coords back to java result array
|
||||
jfloatArray ret = (jfloatArray)env->NewFloatArray(kCoordsCount);
|
||||
env->SetFloatArrayRegion(ret, 0, kCoordsCount, coords);
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -16,44 +16,6 @@
|
|||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeOnLocationError(JNIEnv * env, jobject thiz,
|
||||
int errorCode)
|
||||
{
|
||||
g_framework->OnLocationError(errorCode);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MapFragment_nativeLocationUpdated(JNIEnv * env, jobject thiz,
|
||||
jlong time, jdouble lat, jdouble lon,
|
||||
jfloat accuracy, jdouble altitude, jfloat speed, jfloat bearing)
|
||||
{
|
||||
location::GpsInfo info;
|
||||
info.m_source = location::EAndroidNative;
|
||||
|
||||
info.m_timestamp = static_cast<double>(time) / 1000.0;
|
||||
info.m_latitude = lat;
|
||||
info.m_longitude = lon;
|
||||
|
||||
if (accuracy > 0.0)
|
||||
info.m_horizontalAccuracy = accuracy;
|
||||
|
||||
if (altitude != 0.0)
|
||||
{
|
||||
info.m_altitude = altitude;
|
||||
info.m_verticalAccuracy = accuracy;
|
||||
}
|
||||
|
||||
if (bearing > 0.0)
|
||||
info.m_bearing = bearing;
|
||||
|
||||
if (speed > 0.0)
|
||||
info.m_speed = speed;
|
||||
|
||||
LOG_MEMORY_INFO();
|
||||
g_framework->OnLocationUpdated(info);
|
||||
}
|
||||
|
||||
// Fixed optimization bug for x86 (reproduced on Asus ME302C).
|
||||
#pragma clang push_options
|
||||
#pragma clang optimize off
|
||||
|
@ -69,22 +31,6 @@ extern "C"
|
|||
|
||||
#pragma clang pop_options
|
||||
|
||||
JNIEXPORT jfloatArray JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationHelper_nativeUpdateCompassSensor(JNIEnv * env, jclass clazz, jint ind, jfloatArray arr)
|
||||
{
|
||||
int const kCoordsCount = 3;
|
||||
|
||||
// Extract coords
|
||||
jfloat coords[kCoordsCount];
|
||||
env->GetFloatArrayRegion(arr, 0, kCoordsCount, coords);
|
||||
g_framework->UpdateCompassSensor(ind, coords);
|
||||
|
||||
// Put coords back to java result array
|
||||
jfloatArray ret = (jfloatArray)env->NewFloatArray(kCoordsCount);
|
||||
env->SetFloatArrayRegion(ret, 0, kCoordsCount, coords);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void CallOnDownloadCountryClicked(shared_ptr<jobject> const & obj, storage::TIndex const & idx, int options, jmethodID methodID)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
|
|
@ -1,4 +1,17 @@
|
|||
#include "Framework.hpp"
|
||||
#include "../platform/Platform.hpp"
|
||||
|
||||
#include "std/chrono.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
::Framework * frm()
|
||||
{
|
||||
return g_framework->NativeFramework();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -15,14 +28,14 @@ extern "C"
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_TrackRecorder_nativeSetDuration(JNIEnv * env, jclass clazz, jint hours)
|
||||
Java_com_mapswithme_maps_location_TrackRecorder_nativeSetDuration(JNIEnv * env, jclass clazz, jint durationHours)
|
||||
{
|
||||
frm()->SetGpsTrackingDuration(hours(hours));
|
||||
frm()->SetGpsTrackingDuration(hours(durationHours));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_location_TrackRecorder_nativeGetDuration(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
return frm()->GetGpsTrackingDuration();
|
||||
return frm()->GetGpsTrackingDuration().count();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,8 +290,6 @@ public class MapFragment extends BaseMwmFragment
|
|||
|
||||
private native void nativeConnectDownloadButton();
|
||||
private static native void nativeDownloadCountry(MapStorage.Index index, int options);
|
||||
static native void nativeOnLocationError(int errorCode);
|
||||
static native void nativeLocationUpdated(long time, double lat, double lon, float accuracy, double altitude, float speed, float bearing);
|
||||
static native void nativeCompassUpdated(double magneticNorth, double trueNorth, boolean forceRedraw);
|
||||
static native void nativeScalePlus();
|
||||
static native void nativeScaleMinus();
|
||||
|
|
Loading…
Add table
Reference in a new issue