Fix customized settings update

This commit is contained in:
Vitaliy 2020-01-10 18:59:13 +02:00
parent d9900126a7
commit 5759601738
15 changed files with 152 additions and 115 deletions

View file

@ -9,6 +9,8 @@ import android.support.v4.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
@ -16,8 +18,6 @@ import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
@ -64,7 +64,6 @@ public class MapMarkersHelper {
} }
private OsmandApplication ctx; private OsmandApplication ctx;
private OsmandSettings settings;
private MapMarkersDbHelper markersDbHelper; private MapMarkersDbHelper markersDbHelper;
private ExecutorService executorService = Executors.newSingleThreadExecutor(); private ExecutorService executorService = Executors.newSingleThreadExecutor();
@ -76,8 +75,6 @@ public class MapMarkersHelper {
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>(); private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
private boolean startFromMyLocation;
private MarkersPlanRouteContext planRouteContext; private MarkersPlanRouteContext planRouteContext;
public List<MapMarker> getMapMarkers() { public List<MapMarker> getMapMarkers() {
@ -93,12 +90,11 @@ public class MapMarkersHelper {
} }
public boolean isStartFromMyLocation() { public boolean isStartFromMyLocation() {
return startFromMyLocation; return ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get();
} }
public void setStartFromMyLocation(boolean startFromMyLocation) { public void setStartFromMyLocation(boolean startFromMyLocation) {
this.startFromMyLocation = startFromMyLocation; ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
settings.ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
} }
public MarkersPlanRouteContext getPlanRouteContext() { public MarkersPlanRouteContext getPlanRouteContext() {
@ -107,10 +103,8 @@ public class MapMarkersHelper {
public MapMarkersHelper(OsmandApplication ctx) { public MapMarkersHelper(OsmandApplication ctx) {
this.ctx = ctx; this.ctx = ctx;
settings = ctx.getSettings();
markersDbHelper = ctx.getMapMarkersDbHelper(); markersDbHelper = ctx.getMapMarkersDbHelper();
planRouteContext = new MarkersPlanRouteContext(ctx); planRouteContext = new MarkersPlanRouteContext(ctx);
startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
markersDbHelper.removeDisabledGroups(); markersDbHelper.removeDisabledGroups();
loadMarkers(); loadMarkers();
loadGroups(); loadGroups();
@ -616,7 +610,7 @@ public class MapMarkersHelper {
private List<MapMarker> getMarkers() { private List<MapMarker> getMarkers() {
List<MapMarker> res = new ArrayList<>(mapMarkers); List<MapMarker> res = new ArrayList<>(mapMarkers);
if (settings.KEEP_PASSED_MARKERS_ON_MAP.get()) { if (ctx.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
res.addAll(mapMarkersHistory); res.addAll(mapMarkersHistory);
} }
return res; return res;
@ -883,7 +877,7 @@ public class MapMarkersHelper {
@Nullable List<WptPt> wptPts, @Nullable List<WptPt> wptPts,
@Nullable List<String> mapObjNames) { @Nullable List<String> mapObjNames) {
if (points.size() > 0) { if (points.size() > 0) {
settings.SHOW_MAP_MARKERS.set(true); ctx.getSettings().SHOW_MAP_MARKERS.set(true);
int colorIndex = -1; int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>(); List<MapMarker> addedMarkers = new ArrayList<>();
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {

View file

@ -76,6 +76,8 @@ public class OsmAndLocationProvider implements SensorEventListener {
private static final long LOCATION_TIMEOUT_TO_BE_STALE = 1000 * 60 * 2; // 2 minutes private static final long LOCATION_TIMEOUT_TO_BE_STALE = 1000 * 60 * 2; // 2 minutes
private static final long STALE_LOCATION_TIMEOUT_TO_BE_GONE = 1000 * 60 * 20; // 20 minutes private static final long STALE_LOCATION_TIMEOUT_TO_BE_GONE = 1000 * 60 * 20; // 20 minutes
private static final long AGPS_TO_REDOWNLOAD = 16 * 60 * 60 * 1000; // 16 hours
private static final int REQUESTS_BEFORE_CHECK_LOCATION = 100; private static final int REQUESTS_BEFORE_CHECK_LOCATION = 100;
private AtomicInteger locationRequestsCounter = new AtomicInteger(); private AtomicInteger locationRequestsCounter = new AtomicInteger();
private AtomicInteger staleLocationRequestsCounter = new AtomicInteger(); private AtomicInteger staleLocationRequestsCounter = new AtomicInteger();
@ -114,7 +116,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
private int currentScreenOrientation; private int currentScreenOrientation;
private OsmandApplication app; private OsmandApplication app;
private OsmandSettings settings;
private NavigationInfo navigationInfo; private NavigationInfo navigationInfo;
private CurrentPositionHelper currentPositionHelper; private CurrentPositionHelper currentPositionHelper;
@ -128,9 +129,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
private List<OsmAndCompassListener> compassListeners = new ArrayList<OsmAndLocationProvider.OsmAndCompassListener>(); private List<OsmAndCompassListener> compassListeners = new ArrayList<OsmAndLocationProvider.OsmAndCompassListener>();
private Listener gpsStatusListener; private Listener gpsStatusListener;
private float[] mRotationM = new float[9]; private float[] mRotationM = new float[9];
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS;
private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS;
private static final long AGPS_TO_REDOWNLOAD = 16 * 60 * 60 * 1000; // 16 hours
public class SimulationProvider { public class SimulationProvider {
@ -234,9 +232,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
public OsmAndLocationProvider(OsmandApplication app) { public OsmAndLocationProvider(OsmandApplication app) {
this.app = app; this.app = app;
navigationInfo = new NavigationInfo(app); navigationInfo = new NavigationInfo(app);
settings = app.getSettings();
USE_MAGNETIC_FIELD_SENSOR_COMPASS = settings.USE_MAGNETIC_FIELD_SENSOR_COMPASS;
USE_FILTER_FOR_COMPASS = settings.USE_KALMAN_FILTER_FOR_COMPASS;
currentPositionHelper = new CurrentPositionHelper(app); currentPositionHelper = new CurrentPositionHelper(app);
locationSimulation = new OsmAndLocationSimulation(app, this); locationSimulation = new OsmAndLocationSimulation(app, this);
addLocationListener(navigationInfo); addLocationListener(navigationInfo);
@ -393,7 +388,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
} else if (!sensorRegistered && register) { } else if (!sensorRegistered && register) {
Log.d(PlatformUtil.TAG, "Enable sensor"); //$NON-NLS-1$ Log.d(PlatformUtil.TAG, "Enable sensor"); //$NON-NLS-1$
SensorManager sensorMgr = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE); SensorManager sensorMgr = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
if (USE_MAGNETIC_FIELD_SENSOR_COMPASS.get()) { if (app.getSettings().USE_MAGNETIC_FIELD_SENSOR_COMPASS.get()) {
Sensor s = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Sensor s = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (s == null || !sensorMgr.registerListener(this, s, SensorManager.SENSOR_DELAY_UI)) { if (s == null || !sensorMgr.registerListener(this, s, SensorManager.SENSOR_DELAY_UI)) {
Log.e(PlatformUtil.TAG, "Sensor accelerometer could not be enabled"); Log.e(PlatformUtil.TAG, "Sensor accelerometer could not be enabled");
@ -476,7 +471,8 @@ public class OsmAndLocationProvider implements SensorEventListener {
default: default:
return; return;
} }
if (USE_MAGNETIC_FIELD_SENSOR_COMPASS.get()) { OsmandSettings settings = app.getSettings();
if (settings.USE_MAGNETIC_FIELD_SENSOR_COMPASS.get()) {
if (mGravs != null && mGeoMags != null) { if (mGravs != null && mGeoMags != null) {
boolean success = SensorManager.getRotationMatrix(mRotationM, null, mGravs, mGeoMags); boolean success = SensorManager.getRotationMatrix(mRotationM, null, mGravs, mGeoMags);
if (!success) { if (!success) {
@ -495,7 +491,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
lastValSin = (float) Math.sin(valRad); lastValSin = (float) Math.sin(valRad);
lastValCos = (float) Math.cos(valRad); lastValCos = (float) Math.cos(valRad);
// lastHeadingCalcTime = System.currentTimeMillis(); // lastHeadingCalcTime = System.currentTimeMillis();
boolean filter = USE_FILTER_FOR_COMPASS.get(); //USE_MAGNETIC_FIELD_SENSOR_COMPASS.get(); boolean filter = settings.USE_KALMAN_FILTER_FOR_COMPASS.get(); //USE_MAGNETIC_FIELD_SENSOR_COMPASS.get();
if (filter) { if (filter) {
filterCompassValue(); filterCompassValue();
} else { } else {
@ -806,9 +802,9 @@ public class OsmAndLocationProvider implements SensorEventListener {
if (routingHelper.isFollowingMode()) { if (routingHelper.isFollowingMode()) {
if (location == null || isPointAccurateForRouting(location)) { if (location == null || isPointAccurateForRouting(location)) {
// Update routing position and get location for sticking mode // Update routing position and get location for sticking mode
updatedLocation = routingHelper.setCurrentLocation(location, settings.SNAP_TO_ROAD.get()); updatedLocation = routingHelper.setCurrentLocation(location, app.getSettings().SNAP_TO_ROAD.get());
} }
} else if(routingHelper.isRoutePlanningMode() && settings.getPointToStart() == null) { } else if(routingHelper.isRoutePlanningMode() && app.getSettings().getPointToStart() == null) {
routingHelper.setCurrentLocation(location, false); routingHelper.setCurrentLocation(location, false);
} else if(getLocationSimulation().isRouteAnimating()) { } else if(getLocationSimulation().isRouteAnimating()) {
routingHelper.setCurrentLocation(location, false); routingHelper.setCurrentLocation(location, false);

View file

@ -291,7 +291,6 @@ public class OsmandApplication extends MultiDexApplication {
public void setOsmandSettings(OsmandSettings osmandSettings) { public void setOsmandSettings(OsmandSettings osmandSettings) {
//android.os.Process.killProcess(android.os.Process.myPid()); //android.os.Process.killProcess(android.os.Process.myPid());
this.osmandSettings = osmandSettings; this.osmandSettings = osmandSettings;
resourceManager.getRenderer().updateSettings();
OsmandPlugin.initPlugins(this); OsmandPlugin.initPlugins(this);
} }

View file

@ -1470,8 +1470,6 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> PREFERRED_LOCALE = new StringPreference("preferred_locale", "").makeGlobal(); public final OsmandPreference<String> PREFERRED_LOCALE = new StringPreference("preferred_locale", "").makeGlobal();
public static final String TRANSPORT_STOPS_OVER_MAP = "transportStops";
public final OsmandPreference<String> MAP_PREFERRED_LOCALE = new StringPreference("map_preferred_locale", "").makeGlobal().cache(); public final OsmandPreference<String> MAP_PREFERRED_LOCALE = new StringPreference("map_preferred_locale", "").makeGlobal().cache();
public final OsmandPreference<Boolean> MAP_TRANSLITERATE_NAMES = new BooleanPreference("map_transliterate_names", false).makeGlobal().cache(); public final OsmandPreference<Boolean> MAP_TRANSLITERATE_NAMES = new BooleanPreference("map_transliterate_names", false).makeGlobal().cache();

View file

@ -12,6 +12,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -147,6 +148,16 @@ public class TargetPointsHelper {
this.settings = ctx.getSettings(); this.settings = ctx.getSettings();
this.routingHelper = ctx.getRoutingHelper(); this.routingHelper = ctx.getRoutingHelper();
readFromSettings(); readFromSettings();
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
settings = TargetPointsHelper.this.ctx.getSettings();
readFromSettings();
updateRouteAndRefresh(true);
}
};
ctx.getAppCustomization().addListener(customizationListener);
} }
public void lookupAddessAll() { public void lookupAddessAll() {

View file

@ -10,7 +10,6 @@ import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.DayNightMode; import net.osmand.plus.OsmandSettings.DayNightMode;
import net.osmand.util.SunriseSunset; import net.osmand.util.SunriseSunset;
@ -41,15 +40,13 @@ import android.location.LocationManager;
* @author pavol.zibrita * @author pavol.zibrita
*/ */
public class DayNightHelper implements SensorEventListener { public class DayNightHelper implements SensorEventListener {
private static final Log log = PlatformUtil.getLog(DayNightHelper.class); private static final Log log = PlatformUtil.getLog(DayNightHelper.class);
private final OsmandApplication osmandApplication; private final OsmandApplication osmandApplication;
private CommonPreference<DayNightMode> pref;
public DayNightHelper(OsmandApplication osmandApplication) { public DayNightHelper(OsmandApplication osmandApplication) {
this.osmandApplication = osmandApplication; this.osmandApplication = osmandApplication;
pref = osmandApplication.getSettings().DAYNIGHT_MODE;
} }
private DayNightHelper listener; private DayNightHelper listener;
@ -79,7 +76,7 @@ public class DayNightHelper implements SensorEventListener {
} }
public boolean isNightModeForProfile(ApplicationMode mode) { public boolean isNightModeForProfile(ApplicationMode mode) {
DayNightMode dayNightMode = pref.getModeValue(mode); DayNightMode dayNightMode = osmandApplication.getSettings().DAYNIGHT_MODE.getModeValue(mode);
if (dayNightMode.isDay()) { if (dayNightMode.isDay()) {
return false; return false;
} else if (dayNightMode.isNight()) { } else if (dayNightMode.isNight()) {
@ -138,7 +135,7 @@ public class DayNightHelper implements SensorEventListener {
public void startSensorIfNeeded(StateChangedListener<Boolean> sensorStateListener) { public void startSensorIfNeeded(StateChangedListener<Boolean> sensorStateListener) {
this.sensorStateListener = sensorStateListener; this.sensorStateListener = sensorStateListener;
DayNightMode dayNightMode = pref.get(); DayNightMode dayNightMode = osmandApplication.getSettings().DAYNIGHT_MODE.get();
if (listener == null && dayNightMode.isSensor()) { if (listener == null && dayNightMode.isSensor()) {
SensorManager mSensorManager = (SensorManager) osmandApplication.getSystemService(Context.SENSOR_SERVICE); SensorManager mSensorManager = (SensorManager) osmandApplication.getSystemService(Context.SENSOR_SERVICE);
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

View file

@ -208,8 +208,6 @@ public class MapActivityLayers {
public void updateLayers(OsmandMapTileView mapView) { public void updateLayers(OsmandMapTileView mapView) {
OsmandSettings settings = getApplication().getSettings(); OsmandSettings settings = getApplication().getSettings();
updateMapSource(mapView, settings.MAP_TILE_SOURCES); updateMapSource(mapView, settings.MAP_TILE_SOURCES);
boolean showStops = settings.getCustomRenderBooleanProperty(OsmandSettings.TRANSPORT_STOPS_OVER_MAP).get();
transportStopsLayer.setShowTransportStops(showStops);
OsmandPlugin.refreshLayers(mapView, activity); OsmandPlugin.refreshLayers(mapView, activity);
} }

View file

@ -13,6 +13,7 @@ import android.os.PowerManager.WakeLock;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
@ -65,6 +66,16 @@ public class LockHelper implements SensorEventListener {
unlockEvent(); unlockEvent();
} }
}; };
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
OsmandSettings settings = app.getSettings();
turnScreenOnEnabled = settings.TURN_SCREEN_ON_ENABLED;
turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT;
turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR;
}
};
app.getAppCustomization().addListener(customizationListener);
app.getRoutingHelper().getVoiceRouter().addVoiceMessageListener(voiceMessageListener); app.getRoutingHelper().getVoiceRouter().addVoiceMessageListener(voiceMessageListener);
} }

View file

@ -292,7 +292,7 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat
} }
Object item = adapter.getItem(pos); Object item = adapter.getItem(pos);
if (item instanceof Location) { if (item instanceof Location) {
markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get()); markersHelper.setStartFromMyLocation(!markersHelper.isStartFromMyLocation());
} else if (item instanceof MapMarker) { } else if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item; MapMarker marker = (MapMarker) item;
selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1; selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;

View file

@ -1,6 +1,5 @@
package net.osmand.plus.monitoring; package net.osmand.plus.monitoring;
import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -26,21 +25,23 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class LiveMonitoringHelper { public class LiveMonitoringHelper {
protected Context ctx;
private OsmandSettings settings;
private long lastTimeUpdated;
private LatLon lastPoint;
private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class); private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class);
private OsmandApplication app;
private ConcurrentLinkedQueue<LiveMonitoringData> queue; private ConcurrentLinkedQueue<LiveMonitoringData> queue;
private LatLon lastPoint;
private long lastTimeUpdated;
private boolean started = false; private boolean started = false;
public LiveMonitoringHelper(Context ctx){ public LiveMonitoringHelper(OsmandApplication app) {
this.ctx = ctx; this.app = app;
settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
queue = new ConcurrentLinkedQueue<>(); queue = new ConcurrentLinkedQueue<>();
} }
public boolean isLiveMonitoringEnabled(){ public boolean isLiveMonitoringEnabled() {
OsmandSettings settings = app.getSettings();
return settings.LIVE_MONITORING.get() && (settings.SAVE_TRACK_TO_GPX.get() || settings.SAVE_GLOBAL_TRACK_TO_GPX.get()); return settings.LIVE_MONITORING.get() && (settings.SAVE_TRACK_TO_GPX.get() || settings.SAVE_GLOBAL_TRACK_TO_GPX.get());
} }
@ -50,6 +51,7 @@ public class LiveMonitoringHelper {
if (location != null && isLiveMonitoringEnabled() if (location != null && isLiveMonitoringEnabled()
&& OsmAndLocationProvider.isNotSimulatedLocation(location) && OsmAndLocationProvider.isNotSimulatedLocation(location)
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
OsmandSettings settings = app.getSettings();
if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) { if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) {
record = true; record = true;
} }
@ -112,10 +114,11 @@ public class LiveMonitoringHelper {
@Override @Override
protected Void doInBackground(ConcurrentLinkedQueue<LiveMonitoringData>... concurrentLinkedQueues) { protected Void doInBackground(ConcurrentLinkedQueue<LiveMonitoringData>... concurrentLinkedQueues) {
while (isLiveMonitoringEnabled()) { while (isLiveMonitoringEnabled()) {
int maxSendInterval = app.getSettings().LIVE_MONITORING_MAX_INTERVAL_TO_SEND.get();
for (ConcurrentLinkedQueue queue : concurrentLinkedQueues) { for (ConcurrentLinkedQueue queue : concurrentLinkedQueues) {
if (!queue.isEmpty()) { if (!queue.isEmpty()) {
LiveMonitoringData data = (LiveMonitoringData) queue.peek(); LiveMonitoringData data = (LiveMonitoringData) queue.peek();
if (!(System.currentTimeMillis() - data.time > settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND.get())) { if (!(System.currentTimeMillis() - data.time > maxSendInterval)) {
sendData(data); sendData(data);
} else { } else {
queue.poll(); queue.poll();
@ -128,10 +131,52 @@ public class LiveMonitoringHelper {
} }
public void sendData(LiveMonitoringData data) { public void sendData(LiveMonitoringData data) {
String st = settings.LIVE_MONITORING_URL.get(); String urlStr = getLiveUrl(data);
try {
// Parse the URL and let the URI constructor handle proper encoding of special characters such as spaces
URL url = new URL(urlStr);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(),
url.getPath(), url.getQuery(), url.getRef());
urlConnection.setConnectTimeout(15000);
urlConnection.setReadTimeout(15000);
log.info("Monitor " + uri);
if (urlConnection.getResponseCode() / 100 != 2) {
String msg = urlConnection.getResponseCode() + " : " + //$NON-NLS-1$//$NON-NLS-2$
urlConnection.getResponseMessage();
log.error("Error sending monitor request: " + msg);
} else {
queue.poll();
InputStream is = urlConnection.getInputStream();
StringBuilder responseBody = new StringBuilder();
if (is != null) {
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); //$NON-NLS-1$
String s;
while ((s = in.readLine()) != null) {
responseBody.append(s);
responseBody.append("\n"); //$NON-NLS-1$
}
is.close();
}
log.info("Monitor response (" + urlConnection.getHeaderField("Content-Type") + "): " + responseBody.toString());
}
urlConnection.disconnect();
} catch (Exception e) {
log.error("Failed connect to " + urlStr + ": " + e.getMessage(), e);
}
}
private String getLiveUrl(LiveMonitoringData data) {
String st = app.getSettings().LIVE_MONITORING_URL.get();
List<String> prm = new ArrayList<String>(); List<String> prm = new ArrayList<String>();
int maxLen = 0; int maxLen = 0;
for(int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
boolean b = st.contains("{"+i+"}"); boolean b = st.contains("{"+i+"}");
if(b) { if(b) {
maxLen = i; maxLen = i;
@ -165,45 +210,6 @@ public class LiveMonitoringHelper {
break; break;
} }
} }
String urlStr = MessageFormat.format(st, prm.toArray()); return MessageFormat.format(st, prm.toArray());
try {
// Parse the URL and let the URI constructor handle proper encoding of special characters such as spaces
URL url = new URL(urlStr);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(),
url.getPath(), url.getQuery(), url.getRef());
urlConnection.setConnectTimeout(15000);
urlConnection.setReadTimeout(15000);
log.info("Monitor " + uri);
if (urlConnection.getResponseCode()/100 != 2) {
String msg = urlConnection.getResponseCode() + " : " + //$NON-NLS-1$//$NON-NLS-2$
urlConnection.getResponseMessage();
log.error("Error sending monitor request: " + msg);
} else {
queue.poll();
InputStream is = urlConnection.getInputStream();
StringBuilder responseBody = new StringBuilder();
if (is != null) {
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); //$NON-NLS-1$
String s;
while ((s = in.readLine()) != null) {
responseBody.append(s);
responseBody.append("\n"); //$NON-NLS-1$
}
is.close();
}
log.info("Monitor response (" + urlConnection.getHeaderField("Content-Type") + "): " + responseBody.toString());
}
urlConnection.disconnect();
} catch (Exception e) {
log.error("Failed connect to " + urlStr + ": " + e.getMessage(), e);
}
} }
} }

View file

@ -39,6 +39,7 @@ import net.osmand.data.QuadPointDouble;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader; import net.osmand.map.MapTileDownloader;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -121,6 +122,15 @@ public class MapRenderRepositories {
this.renderer = new OsmandRenderer(context); this.renderer = new OsmandRenderer(context);
handler = new Handler(Looper.getMainLooper()); handler = new Handler(Looper.getMainLooper());
prefs = context.getSettings(); prefs = context.getSettings();
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
prefs = MapRenderRepositories.this.context.getSettings();
clearCache();
}
};
context.getAppCustomization().addListener(customizationListener);
} }
public Context getContext() { public Context getContext() {
@ -153,11 +163,6 @@ public class MapRenderRepositories {
return prevBmpLocation; return prevBmpLocation;
} }
public void updateSettings() {
prefs = context.getSettings();
clearCache();
}
public synchronized void closeConnection(String file) { public synchronized void closeConnection(String file) {
LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files); LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files);
BinaryMapIndexReader bmir = cpfiles.remove(file); BinaryMapIndexReader bmir = cpfiles.remove(file);

View file

@ -63,13 +63,11 @@ public class RoutingOptionsHelper {
public static final String DRIVING_STYLE = "driving_style"; public static final String DRIVING_STYLE = "driving_style";
private OsmandApplication app; private OsmandApplication app;
private OsmandSettings settings;
private Map<ApplicationMode, RouteMenuAppModes> modes = new HashMap<>(); private Map<ApplicationMode, RouteMenuAppModes> modes = new HashMap<>();
public RoutingOptionsHelper(OsmandApplication application) { public RoutingOptionsHelper(OsmandApplication application) {
app = application; app = application;
settings = app.getSettings();
} }
private void addRouteMenuAppModes(ApplicationMode am, List<String> routingParameters) { private void addRouteMenuAppModes(ApplicationMode am, List<String> routingParameters) {
@ -104,6 +102,7 @@ public class RoutingOptionsHelper {
} }
public void switchMusic() { public void switchMusic() {
OsmandSettings settings = app.getSettings();
boolean mt = !settings.INTERRUPT_MUSIC.get(); boolean mt = !settings.INTERRUPT_MUSIC.get();
settings.INTERRUPT_MUSIC.set(mt); settings.INTERRUPT_MUSIC.set(mt);
} }
@ -311,6 +310,7 @@ public class RoutingOptionsHelper {
} }
public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) { public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) {
OsmandSettings settings = app.getSettings();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0; int i = 0;
int selectedIndex = -1; int selectedIndex = -1;
@ -364,6 +364,7 @@ public class RoutingOptionsHelper {
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
OsmandSettings settings = app.getSettings();
int position = selectedPosition[0]; int position = selectedPosition[0];
if (position >= 0 && position < group.getRoutingParameters().size()) { if (position >= 0 && position < group.getRoutingParameters().size()) {
for (int i = 0; i < group.getRoutingParameters().size(); i++) { for (int i = 0; i < group.getRoutingParameters().size(); i++) {

View file

@ -8,6 +8,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.NavigationService; import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -95,11 +96,19 @@ public class RoutingHelper {
public RoutingHelper(OsmandApplication context){ public RoutingHelper(OsmandApplication context){
this.app = context; this.app = context;
settings = context.getSettings(); settings = context.getSettings();
voiceRouter = new VoiceRouter(this, settings); voiceRouter = new VoiceRouter(this);
provider = new RouteProvider(); provider = new RouteProvider();
transportRoutingHelper = context.getTransportRoutingHelper(); transportRoutingHelper = context.getTransportRoutingHelper();
transportRoutingHelper.setRoutingHelper(this); transportRoutingHelper.setRoutingHelper(this);
setAppMode(settings.APPLICATION_MODE.get()); setAppMode(settings.APPLICATION_MODE.get());
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
settings = app.getSettings();
}
};
app.getAppCustomization().addListener(customizationListener);
} }
public TransportRoutingHelper getTransportRoutingHelper() { public TransportRoutingHelper getTransportRoutingHelper() {

View file

@ -8,6 +8,8 @@ import net.osmand.Location;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
@ -45,9 +47,11 @@ public class VoiceRouter {
public static final String FROM_STREET_NAME = "fromStreetName"; public static final String FROM_STREET_NAME = "fromStreetName";
public static final String FROM_DEST = "fromDest"; public static final String FROM_DEST = "fromDest";
protected final RoutingHelper router;
protected static CommandPlayer player; protected static CommandPlayer player;
protected final OsmandSettings settings;
protected final OsmandApplication app;
protected final RoutingHelper router;
protected OsmandSettings settings;
private static int currentStatus = STATUS_UNKNOWN; private static int currentStatus = STATUS_UNKNOWN;
private static boolean playedAndArriveAtTarget = false; private static boolean playedAndArriveAtTarget = false;
@ -83,9 +87,18 @@ public class VoiceRouter {
private List<WeakReference<VoiceMessageListener>> voiceMessageListeners = new ArrayList<>(); private List<WeakReference<VoiceMessageListener>> voiceMessageListeners = new ArrayList<>();
VoiceRouter(RoutingHelper router, final OsmandSettings settings) { VoiceRouter(RoutingHelper router) {
this.router = router; this.router = router;
this.settings = settings; this.app = router.getApplication();
this.settings = app.getSettings();
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
settings = app.getSettings();
}
};
app.getAppCustomization().addListener(customizationListener);
} }
public void setPlayer(CommandPlayer player) { public void setPlayer(CommandPlayer player) {

View file

@ -22,6 +22,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way; import net.osmand.osm.edit.Way;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
@ -36,6 +37,9 @@ import java.util.List;
import java.util.TreeSet; import java.util.TreeSet;
public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
public static final String TRANSPORT_STOPS_OVER_MAP = "transportStops";
private static final int startZoom = 12; private static final int startZoom = 12;
private static final int startZoomRoute = 10; private static final int startZoomRoute = 10;
@ -53,13 +57,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private MapLayerData<List<TransportStop>> data; private MapLayerData<List<TransportStop>> data;
private TransportStopRoute stopRoute = null; private TransportStopRoute stopRoute = null;
private boolean showTransportStops; private OsmandSettings.CommonPreference<Boolean> showTransportStops;
private Path path; private Path path;
private float backgroundIconHalfWidth; private float backgroundIconHalfWidth;
private float backgroundIconHalfHeight; private float backgroundIconHalfHeight;
public TransportStopsLayer(MapActivity mapActivity) { public TransportStopsLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
showTransportStops = settings.getCustomRenderBooleanProperty(TRANSPORT_STOPS_OVER_MAP).cache();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -168,14 +175,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
this.stopRoute = route; this.stopRoute = route;
} }
public boolean isShowTransportStops() {
return showTransportStops;
}
public void setShowTransportStops(boolean showTransportStops) {
this.showTransportStops = showTransportStops;
}
private int getRadiusPoi(RotatedTileBox tb){ private int getRadiusPoi(RotatedTileBox tb){
final double zoom = tb.getZoom(); final double zoom = tb.getZoom();
int r; int r;
@ -227,7 +226,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
} }
} }
if (showTransportStops && tb.getZoom() >= startZoom && objects == null) { if (showTransportStops.get() && tb.getZoom() >= startZoom && objects == null) {
data.queryNewData(tb); data.queryNewData(tb);
objects = data.getResults(); objects = data.getResults();
} }