Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
ab77320eb7 [android] Add assertion into nativeGetMode() 2023-09-22 17:49:37 +03:00
5 changed files with 25 additions and 10 deletions

View file

@ -1054,7 +1054,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
IsolinesManager.from(getApplicationContext()).attach(this::onIsolinesStateChanged);
LocationState.nativeSetListener(this);
LocationHelper.from(this).addListener(this);
onMyPositionModeChanged(LocationState.nativeGetMode());
onMyPositionModeChanged(LocationState.getMode(this));
mSearchController.attach(this);
if (!Config.isScreenSleepEnabled())
Utils.keepScreenOn(true, getWindow());
@ -1778,7 +1778,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
*/
private void autostartLocation()
{
if (LocationState.nativeGetMode() == LocationState.NOT_FOLLOW_NO_POSITION)
if (LocationState.getMode(this) == LocationState.NOT_FOLLOW_NO_POSITION)
{
Logger.i(LOCATION_TAG, "Location updates are stopped by the user manually.");
LocationState.nativeOnLocationError(LocationState.ERROR_GPS_OFF);

View file

@ -233,10 +233,12 @@ public class MwmApplication extends Application implements Application.ActivityL
TrafficManager.INSTANCE.initialize(null);
SubwayManager.from(this).initialize(null);
IsolinesManager.from(this).initialize(null);
ProcessLifecycleOwner.get().getLifecycle().addObserver(mProcessLifecycleObserver);
Logger.i(TAG, "Framework initialized");
mFrameworkInitialized = true;
ProcessLifecycleOwner.get().getLifecycle().addObserver(mProcessLifecycleObserver);
return true;
}

View file

@ -75,7 +75,7 @@ public class LocationHelper implements BaseLocationProvider.Listener
@Nullable
public MapObject getMyPosition()
{
if (!LocationState.isTurnedOn())
if (!LocationState.isTurnedOn(mContext))
{
mMyPosition = null;
return null;
@ -263,7 +263,7 @@ public class LocationHelper implements BaseLocationProvider.Listener
return;
}
int mode = LocationState.nativeGetMode();
int mode = LocationState.getMode(mContext);
switch (mode)
{
case LocationState.FOLLOW:
@ -348,7 +348,7 @@ public class LocationHelper implements BaseLocationProvider.Listener
{
if (isActive())
return;
else if (LocationState.nativeGetMode() == LocationState.NOT_FOLLOW_NO_POSITION)
else if (LocationState.getMode(mContext) == LocationState.NOT_FOLLOW_NO_POSITION)
{
Logger.i(TAG, "Location updates are stopped by the user manually.");
return;

View file

@ -1,8 +1,12 @@
package app.organicmaps.location;
import android.content.Context;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import app.organicmaps.MwmApplication;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -41,7 +45,7 @@ public final class LocationState
public static native void nativeSwitchToNextMode();
@Value
public static native int nativeGetMode();
private static native int nativeGetMode();
public static native void nativeSetListener(@NonNull ModeChangeListener listener);
public static native void nativeRemoveListener();
@ -56,12 +60,20 @@ public final class LocationState
private LocationState() {}
@Value
static public int getMode(@NonNull Context context)
{
if (!MwmApplication.from(context).arePlatformAndCoreInitialized())
throw new AssertionError("!arePlatformAndCoreInitialized");
return nativeGetMode();
}
/**
* Checks if location state on the map is active (so its not turned off or pending).
*/
static boolean isTurnedOn()
static boolean isTurnedOn(@NonNull Context context)
{
return hasLocation(nativeGetMode());
return hasLocation(getMode(context));
}
static boolean hasLocation(int mode)
@ -69,6 +81,7 @@ public final class LocationState
return (mode > NOT_FOLLOW_NO_POSITION);
}
static String nameOf(@Value int mode)
{
switch (mode)

View file

@ -36,7 +36,7 @@ public class MyPositionButton
mButton.setOnClickListener(listener);
mIcons.clear();
mFollowPaddingShift = (int) (FOLLOW_SHIFT * button.getResources().getDisplayMetrics().density);
update(LocationState.nativeGetMode());
update(LocationState.getMode(mButton.getContext()));
}
public void update(int mode)