Skip to content

Commit

Permalink
Fix map update for #7408
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Feb 26, 2025
1 parent a3c65ac commit afe4633
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
36 changes: 14 additions & 22 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.exploreplaces.ExplorePlacesFragment;
import net.osmand.plus.feedback.CrashBottomSheetDialogFragment;
import net.osmand.plus.feedback.RateUsHelper;
import net.osmand.plus.feedback.RenderInitErrorBottomSheet;
import net.osmand.plus.feedback.SendAnalyticsBottomSheetDialogFragment;
import net.osmand.plus.firstusage.FirstUsageWizardFragment;
import net.osmand.plus.helpers.*;
import net.osmand.plus.helpers.LockHelper.LockUIAdapter;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.importfiles.ImportHelper;
import net.osmand.plus.importfiles.ui.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.keyevent.KeyEventHelper;
Expand All @@ -88,12 +88,10 @@
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.exploreplaces.ExplorePlacesFragment;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
import net.osmand.plus.plugins.OsmandPlugin;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.accessibility.MapAccessibilityActions;
import net.osmand.plus.render.UpdateVectorRendererAsyncTask;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RouteCalculationProgressListener;
Expand Down Expand Up @@ -139,8 +137,6 @@
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
IRouteInformationListener, AMapPointUpdateListener, MapMarkerChangedListener,
Expand Down Expand Up @@ -196,7 +192,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean activityRestartNeeded;
private boolean stopped = true;

private final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();

private final StateChangedListener<Integer> mapScreenOrientationSettingListener = new StateChangedListener<Integer>() {
@Override
Expand Down Expand Up @@ -519,7 +514,7 @@ public void onBackPressed() {
return;
}
ExplorePlacesFragment nearbyPlacesFragment = fragmentsHelper.getNearbyPlacesFragment();
if(nearbyPlacesFragment != null && nearbyPlacesFragment.onBackPress()) {
if (nearbyPlacesFragment != null && nearbyPlacesFragment.onBackPress()) {
return;
}
QuickSearchDialogFragment quickSearchFragment = fragmentsHelper.getQuickSearchDialogFragment();
Expand Down Expand Up @@ -1123,18 +1118,15 @@ public void updateNavigationBarColor() {
}

public void updateMapSettings(boolean updateMapRenderer) {
if (!app.isApplicationInitializing()) {
UpdateVectorRendererAsyncTask task = new UpdateVectorRendererAsyncTask(app, updateMapRenderer, changed -> {
if (changed) {
ConfigureMapFragment fragment = ConfigureMapFragment.getVisibleInstance(this);
if (fragment != null) {
fragment.onRefreshItem(MAP_STYLE_ID);
}
getMapView().updateMapSettings(updateMapRenderer, changed -> {
if (changed) {
ConfigureMapFragment fragment = ConfigureMapFragment.getVisibleInstance(this);
if (fragment != null) {
fragment.onRefreshItem(MAP_STYLE_ID);
}
return true;
});
task.executeOnExecutor(singleThreadExecutor);
}
}
return true;
});
}

public MapScrollHelper getMapScrollHelper() {
Expand Down Expand Up @@ -1294,9 +1286,7 @@ public void updateLayers() {
}

public void refreshMapComplete() {
getMyApplication().getResourceManager().getRenderer().clearCache();
updateMapSettings(true);
getMapView().refreshMap(true);
getMapView().refreshMapComplete();
}

public View getLayout() {
Expand Down Expand Up @@ -1324,7 +1314,9 @@ public MapContextMenu getContextMenu() {
}

@NonNull
public MapRouteInfoMenu getMapRouteInfoMenu() { return mapRouteInfoMenu; }
public MapRouteInfoMenu getMapRouteInfoMenu() {
return mapRouteInfoMenu;
}

@NonNull
public TrackDetailsMenu getTrackDetailsMenu() {
Expand Down
6 changes: 5 additions & 1 deletion OsmAnd/src/net/osmand/plus/plugins/srtm/SRTMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.osmand.plus.widgets.ctxmenu.callback.OnRowItemClick;
import net.osmand.plus.widgets.ctxmenu.data.ContextMenuItem;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.shared.settings.enums.MetricsConstants;
import net.osmand.util.Algorithms;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -94,6 +95,7 @@ public class SRTMPlugin extends OsmandPlugin {
private final StateChangedListener<Boolean> terrainListener;
private final StateChangedListener<String> terrainModeListener;
private final StateChangedListener<Float> verticalExaggerationListener;
private final StateChangedListener<MetricsConstants> metricSystemListener;

private TerrainLayer terrainLayer;

Expand All @@ -105,7 +107,6 @@ public String getId() {
public SRTMPlugin(OsmandApplication app) {
super(app);


TERRAIN = registerBooleanPreference("terrain_layer", true).makeProfile();
TerrainMode[] tms = TerrainMode.values(app);
TERRAIN_MODE = registerStringPreference("terrain_mode", tms.length == 0 ? "" : tms[0].getKeyName()).makeProfile();
Expand Down Expand Up @@ -142,6 +143,9 @@ public SRTMPlugin(OsmandApplication app) {
}
};
app.getSettings().VERTICAL_EXAGGERATION_SCALE.addListener(verticalExaggerationListener);

metricSystemListener = constants -> app.getOsmandMap().getMapView().refreshMapComplete();
app.getSettings().METRIC_SYSTEM.addListener(metricSystemListener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.AsyncTask;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import net.osmand.CallbackWithObject;
import net.osmand.core.android.MapRendererContext;
Expand All @@ -13,15 +14,15 @@
import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.render.RenderingRulesStorage;

public class UpdateVectorRendererAsyncTask extends AsyncTask<Void, Void, Boolean> {
public class UpdateRendererAsyncTask extends AsyncTask<Void, Void, Boolean> {

private final OsmandApplication app;

private final boolean updateMapRenderer;
private final CallbackWithObject<Boolean> callback;

public UpdateVectorRendererAsyncTask(@NonNull OsmandApplication app, boolean updateMapRenderer,
@NonNull CallbackWithObject<Boolean> callback) {
public UpdateRendererAsyncTask(@NonNull OsmandApplication app, boolean updateMapRenderer,
@Nullable CallbackWithObject<Boolean> callback) {
this.app = app;
this.callback = callback;
this.updateMapRenderer = updateMapRenderer;
Expand Down
20 changes: 19 additions & 1 deletion OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import android.util.DisplayMetrics;
import android.view.*;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.core.android.MapRendererView;
Expand Down Expand Up @@ -61,12 +61,14 @@
import net.osmand.plus.auto.SurfaceRenderer;
import net.osmand.plus.auto.views.CarSurfaceView;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.card.color.palette.migration.ColorsMigrationAlgorithmV2;
import net.osmand.plus.helpers.MapDisplayPositionManager;
import net.osmand.plus.helpers.TwoFingerTapDetector;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.accessibility.AccessibilityActionsProvider;
import net.osmand.plus.plugins.development.OsmandDevelopmentPlugin;
import net.osmand.plus.render.UpdateRendererAsyncTask;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.enums.CompassMode;
import net.osmand.plus.utils.AndroidUtils;
Expand All @@ -92,6 +94,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class OsmandMapTileView implements IMapDownloaderCallback {

Expand Down Expand Up @@ -119,6 +123,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
private final FPSMeasurement main = new FPSMeasurement();
private final FPSMeasurement additional = new FPSMeasurement();
private final MapRenderFPSMeasurement renderFPSMeasurement = new MapRenderFPSMeasurement();
private final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();

private boolean DISABLE_MAP_LAYERS;
private StateChangedListener<Boolean> disableMapLayersListener;
Expand Down Expand Up @@ -1324,6 +1329,19 @@ public void refreshMap(boolean updateVectorRendering) {
}
}

public void refreshMapComplete() {
app.getResourceManager().getRenderer().clearCache();
updateMapSettings(true, null);
refreshMap(true);
}

public void updateMapSettings(boolean updateMapRenderer, @Nullable CallbackWithObject<Boolean> callback) {
app.getAppInitializer().addOnFinishListener(init -> {
UpdateRendererAsyncTask task = new UpdateRendererAsyncTask(app, updateMapRenderer, callback);
task.executeOnExecutor(singleThreadExecutor);
});
}

private void sendRefreshMapMsg(@NonNull DrawSettings drawSettings, int delay) {
if (!handler.hasMessages(MAP_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(handler, () -> {
Expand Down

0 comments on commit afe4633

Please sign in to comment.