[android] Move JNI from LocationHelper to LocationState
Move all JNI methods related to location into one place. LocationHeloper.java will be refactored further. This is pure refactoring. JNI code is not changed. Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
parent
72a38a8478
commit
3a9a118562
6 changed files with 64 additions and 73 deletions
|
@ -30,7 +30,6 @@ set(SRC
|
|||
app/organicmaps/editor/OsmOAuth.cpp
|
||||
app/organicmaps/Framework.cpp
|
||||
app/organicmaps/isolines/IsolinesManager.cpp
|
||||
app/organicmaps/LocationHelper.cpp
|
||||
app/organicmaps/LocationState.cpp
|
||||
app/organicmaps/Map.cpp
|
||||
app/organicmaps/MapManager.cpp
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#include "Framework.hpp"
|
||||
#include "map/gps_tracker.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL
|
||||
Java_app_organicmaps_location_LocationHelper_nativeOnLocationError(JNIEnv * env, jclass clazz, int errorCode)
|
||||
{
|
||||
ASSERT(g_framework, ());
|
||||
g_framework->OnLocationError(errorCode);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_app_organicmaps_location_LocationHelper_nativeLocationUpdated(JNIEnv * env, jclass clazz, jlong time,
|
||||
jdouble lat, jdouble lon, jfloat accuracy,
|
||||
jdouble altitude, jfloat speed, jfloat bearing)
|
||||
{
|
||||
ASSERT(g_framework, ());
|
||||
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_speedMpS = speed;
|
||||
|
||||
g_framework->OnLocationUpdated(info);
|
||||
GpsTracker::Instance().OnLocationUpdated(info);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "Framework.hpp"
|
||||
#include "map/gps_tracker.hpp"
|
||||
|
||||
#include "app/organicmaps/core/jni_helper.hpp"
|
||||
|
||||
|
@ -72,4 +73,43 @@ Java_app_organicmaps_location_LocationState_nativeRemoveLocationPendingTimeoutLi
|
|||
ASSERT(g_framework, ());
|
||||
g_framework->NativeFramework()->SetMyPositionPendingTimeoutListener(nullptr);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_app_organicmaps_location_LocationState_nativeOnLocationError(JNIEnv * env, jclass clazz, int errorCode)
|
||||
{
|
||||
ASSERT(g_framework, ());
|
||||
g_framework->OnLocationError(errorCode);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_app_organicmaps_location_LocationState_nativeLocationUpdated(JNIEnv * env, jclass clazz, jlong time,
|
||||
jdouble lat, jdouble lon, jfloat accuracy,
|
||||
jdouble altitude, jfloat speed, jfloat bearing)
|
||||
{
|
||||
ASSERT(g_framework, ());
|
||||
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_speedMpS = speed;
|
||||
|
||||
g_framework->OnLocationUpdated(info);
|
||||
GpsTracker::Instance().OnLocationUpdated(info);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -625,7 +625,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mMapButtonsController = new MapButtonsController();
|
||||
mMapButtonsController.init(
|
||||
layoutMode,
|
||||
LocationHelper.INSTANCE.getMyPositionMode(),
|
||||
LocationState.nativeGetMode(),
|
||||
this::onMapButtonClick,
|
||||
(v) -> closeSearchToolbar(true, true),
|
||||
mPlacePageController,
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.app.Dialog;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
|
||||
|
@ -40,13 +39,6 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
{
|
||||
INSTANCE;
|
||||
|
||||
// These constants should correspond to values defined in platform/location.hpp
|
||||
// Leave 0-value as no any error.
|
||||
//private static final int ERROR_UNKNOWN = 0;
|
||||
//private static final int ERROR_NOT_SUPPORTED = 1;
|
||||
private static final int ERROR_DENIED = 2;
|
||||
private static final int ERROR_GPS_OFF = 3;
|
||||
|
||||
private static final long INTERVAL_FOLLOW_AND_ROTATE_MS = 3000;
|
||||
private static final long INTERVAL_FOLLOW_MS = 1000;
|
||||
private static final long INTERVAL_NOT_FOLLOW_MS = 3000;
|
||||
|
@ -203,7 +195,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
return;
|
||||
}
|
||||
|
||||
nativeLocationUpdated(mSavedLocation.getTime(),
|
||||
LocationState.nativeLocationUpdated(mSavedLocation.getTime(),
|
||||
mSavedLocation.getLatitude(),
|
||||
mSavedLocation.getLongitude(),
|
||||
mSavedLocation.getAccuracy(),
|
||||
|
@ -253,7 +245,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
{
|
||||
Logger.d(TAG, "Can't resolve location permissions because UI is not attached");
|
||||
stop();
|
||||
nativeOnLocationError(ERROR_GPS_OFF);
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -287,7 +279,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
" settings = " + LocationUtils.areLocationServicesTurnedOn(mContext));
|
||||
|
||||
stop();
|
||||
nativeOnLocationError(ERROR_GPS_OFF);
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);
|
||||
|
||||
if (mActivity == null)
|
||||
{
|
||||
|
@ -325,7 +317,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
" settings = " + LocationUtils.areLocationServicesTurnedOn(mContext));
|
||||
|
||||
stop();
|
||||
nativeOnLocationError(ERROR_DENIED);
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_DENIED);
|
||||
|
||||
if (mActivity == null)
|
||||
{
|
||||
|
@ -383,7 +375,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
.setNegativeButton(R.string.current_location_unknown_stop_button, (dialog, which) ->
|
||||
{
|
||||
Logger.w(TAG, "Disabled by user");
|
||||
nativeOnLocationError(ERROR_GPS_OFF);
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);
|
||||
stop();
|
||||
})
|
||||
.setPositiveButton(R.string.current_location_unknown_continue_button, (dialog, which) ->
|
||||
|
@ -453,7 +445,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
return;
|
||||
}
|
||||
|
||||
int mode = getMyPositionMode();
|
||||
int mode = LocationState.nativeGetMode();
|
||||
switch (mode)
|
||||
{
|
||||
case LocationState.FOLLOW:
|
||||
|
@ -500,8 +492,8 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
if (!LocationUtils.isLocationGranted(mContext))
|
||||
{
|
||||
Logger.w(TAG, "Dynamic permissions ACCESS_COARSE_LOCATION and/or ACCESS_FINE_LOCATION are not granted");
|
||||
Logger.d(TAG, "error mode = " + getMyPositionMode());
|
||||
nativeOnLocationError(ERROR_DENIED);
|
||||
Logger.d(TAG, "error mode = " + LocationState.nativeGetMode());
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_DENIED);
|
||||
|
||||
if (mPermissionRequest == null)
|
||||
{
|
||||
|
@ -629,7 +621,7 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
{
|
||||
Logger.w(TAG, "Resolution has not been granted");
|
||||
stop();
|
||||
nativeOnLocationError(ERROR_GPS_OFF);
|
||||
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -677,14 +669,4 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
|
|||
{
|
||||
return mSavedNorth;
|
||||
}
|
||||
|
||||
@LocationState.Value
|
||||
public int getMyPositionMode()
|
||||
{
|
||||
return LocationState.nativeGetMode();
|
||||
}
|
||||
|
||||
private static native void nativeOnLocationError(int errorCode);
|
||||
private static native void nativeLocationUpdated(long time, double lat, double lon, float accuracy,
|
||||
double altitude, float speed, float bearing);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.lang.annotation.RetentionPolicy;
|
|||
|
||||
public final class LocationState
|
||||
{
|
||||
public static final String LOCATION_TAG = LocationState.class.getPackage().getName();
|
||||
|
||||
public interface ModeChangeListener
|
||||
{
|
||||
void onMyPositionModeChanged(int newMode);
|
||||
|
@ -29,6 +31,13 @@ public final class LocationState
|
|||
public static final int FOLLOW = 3;
|
||||
public static final int FOLLOW_AND_ROTATE = 4;
|
||||
|
||||
// These constants should correspond to values defined in platform/location.hpp
|
||||
// Leave 0-value as no any error.
|
||||
//private static final int ERROR_UNKNOWN = 0;
|
||||
//private static final int ERROR_NOT_SUPPORTED = 1;
|
||||
public static final int ERROR_DENIED = 2;
|
||||
public static final int ERROR_GPS_OFF = 3;
|
||||
|
||||
public static native void nativeSwitchToNextMode();
|
||||
@Value
|
||||
public static native int nativeGetMode();
|
||||
|
@ -39,6 +48,11 @@ public final class LocationState
|
|||
static native void nativeSetLocationPendingTimeoutListener(@NonNull PendingTimeoutListener listener);
|
||||
static native void nativeRemoveLocationPendingTimeoutListener();
|
||||
|
||||
static native void nativeOnLocationError(int errorCode);
|
||||
|
||||
static native void nativeLocationUpdated(long time, double lat, double lon, float accuracy,
|
||||
double altitude, float speed, float bearing);
|
||||
|
||||
private LocationState() {}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue