forked from organicmaps/organicmaps
[android] Improved location mode
This commit is contained in:
parent
1952523bd2
commit
6ba450ee9a
5 changed files with 54 additions and 27 deletions
|
@ -7,12 +7,21 @@
|
|||
extern "C"
|
||||
{
|
||||
|
||||
static void LocationStateModeChanged(location::EMyPositionMode mode, std::shared_ptr<jobject> const & listener)
|
||||
static void LocationStateModeChanged(location::EMyPositionMode mode,
|
||||
std::shared_ptr<jobject> const & listener)
|
||||
{
|
||||
g_framework->OnMyPositionModeChanged(mode);
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
env->CallVoidMethod(*listener, jni::GetMethodID(env, *listener.get(), "onMyPositionModeChanged", "(I)V"), static_cast<jint>(mode));
|
||||
env->CallVoidMethod(*listener, jni::GetMethodID(env, *listener.get(),
|
||||
"onMyPositionModeChanged", "(I)V"), static_cast<jint>(mode));
|
||||
}
|
||||
|
||||
static void LocationPendingTimeout(std::shared_ptr<jobject> const & listener)
|
||||
{
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
env->CallVoidMethod(*listener, jni::GetMethodID(env, *listener.get(),
|
||||
"onLocationPendingTimeout", "()V"));
|
||||
}
|
||||
|
||||
// public static void nativeSwitchToNextMode();
|
||||
|
@ -31,7 +40,8 @@ Java_com_mapswithme_maps_location_LocationState_nativeGetMode(JNIEnv * env, jcla
|
|||
|
||||
// public static void nativeSetListener(ModeChangeListener listener);
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationState_nativeSetListener(JNIEnv * env, jclass clazz, jobject listener)
|
||||
Java_com_mapswithme_maps_location_LocationState_nativeSetListener(JNIEnv * env, jclass clazz,
|
||||
jobject listener)
|
||||
{
|
||||
g_framework->SetMyPositionModeListener(std::bind(&LocationStateModeChanged, std::placeholders::_1,
|
||||
jni::make_global_ref(listener)));
|
||||
|
@ -44,4 +54,18 @@ Java_com_mapswithme_maps_location_LocationState_nativeRemoveListener(JNIEnv * en
|
|||
g_framework->SetMyPositionModeListener(location::TMyPositionModeChanged());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationState_nativeSetLocationPendingTimeoutListener(
|
||||
JNIEnv * env, jclass clazz, jobject listener)
|
||||
{
|
||||
g_framework->NativeFramework()->SetMyPositionPendingTimeoutListener(
|
||||
std::bind(&LocationPendingTimeout, jni::make_global_ref(listener)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationState_nativeRemoveLocationPendingTimeoutListener(
|
||||
JNIEnv * env, jclass)
|
||||
{
|
||||
g_framework->NativeFramework()->SetMyPositionPendingTimeoutListener(nullptr);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -2205,12 +2205,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
if (!LocationHelper.INSTANCE.isActive())
|
||||
LocationHelper.INSTANCE.start();
|
||||
LocationHelper.INSTANCE.switchToNextMode();
|
||||
};
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setNegativeButton(R.string.current_location_unknown_stop_button, stopClickListener)
|
||||
.setPositiveButton(R.string.current_location_unknown_continue_button, continueClickListener)
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -137,27 +137,20 @@ public enum LocationHelper
|
|||
mLogger.d(TAG, "onMyPositionModeChanged mode = " + LocationState.nameOf(newMode));
|
||||
|
||||
if (mUiCallback == null)
|
||||
{
|
||||
mLogger.d(TAG, "UI is not ready to listen my position changes, i.e. it's not attached yet.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
switch (newMode)
|
||||
{
|
||||
case LocationState.NOT_FOLLOW_NO_POSITION:
|
||||
// In the first run mode, the NOT_FOLLOW_NO_POSITION state doesn't mean that location
|
||||
// is actually not found.
|
||||
if (mInFirstRun)
|
||||
{
|
||||
mLogger.i(TAG, "It's the first run, so this state should be skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
stop();
|
||||
if (LocationUtils.areLocationServicesTurnedOn())
|
||||
notifyLocationNotFound();
|
||||
break;
|
||||
}
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final LocationState.LocationPendingTimeoutListener mLocationPendingTimeoutListener =
|
||||
new LocationState.LocationPendingTimeoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onLocationPendingTimeout()
|
||||
{
|
||||
stop();
|
||||
if (LocationUtils.areLocationServicesTurnedOn())
|
||||
notifyLocationNotFound();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -166,6 +159,7 @@ public enum LocationHelper
|
|||
{
|
||||
initProvider();
|
||||
LocationState.nativeSetListener(mMyPositionModeListener);
|
||||
LocationState.nativeSetLocationPendingTimeoutListener(mLocationPendingTimeoutListener);
|
||||
MwmApplication.backgroundTracker().addListener(mOnTransition);
|
||||
}
|
||||
|
||||
|
@ -528,11 +522,7 @@ public enum LocationHelper
|
|||
mLogger.d(TAG, mLocationProvider.isActive() ? "SUCCESS" : "FAILURE");
|
||||
|
||||
if (mLocationProvider.isActive())
|
||||
{
|
||||
PushwooshHelper.startLocationTracking();
|
||||
if (!mInFirstRun && getMyPositionMode() == LocationState.NOT_FOLLOW_NO_POSITION)
|
||||
switchToNextMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkProviderInitialization()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -13,6 +14,12 @@ public final class LocationState
|
|||
void onMyPositionModeChanged(int newMode);
|
||||
}
|
||||
|
||||
interface LocationPendingTimeoutListener
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
void onLocationPendingTimeout();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ PENDING_POSITION, NOT_FOLLOW_NO_POSITION, NOT_FOLLOW, FOLLOW, FOLLOW_AND_ROTATE})
|
||||
@interface Value {}
|
||||
|
@ -31,6 +38,10 @@ public final class LocationState
|
|||
static native void nativeSetListener(ModeChangeListener listener);
|
||||
static native void nativeRemoveListener();
|
||||
|
||||
static native void nativeSetLocationPendingTimeoutListener(
|
||||
@NonNull LocationPendingTimeoutListener listener);
|
||||
static native void nativeRemoveLocationPendingTimeoutListener();
|
||||
|
||||
private LocationState() {}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class ResultCodesHelper
|
|||
switch (errorCode)
|
||||
{
|
||||
case NO_POSITION:
|
||||
if (LocationHelper.INSTANCE.getMyPositionMode() == LocationState.NOT_FOLLOW_NO_POSITION)
|
||||
if (!LocationHelper.INSTANCE.isActive())
|
||||
{
|
||||
titleRes = R.string.dialog_routing_location_turn_on;
|
||||
messages.add(resources.getString(R.string.dialog_routing_location_unknown_turn_on));
|
||||
|
|
Loading…
Add table
Reference in a new issue