Search in sources :

Example 91 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class MapMarkersLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
    OsmandApplication app = getApplication();
    OsmandSettings settings = app.getSettings();
    if (!settings.SHOW_MAP_MARKERS.get()) {
        return;
    }
    Location myLoc;
    if (useFingerLocation && fingerLocation != null) {
        myLoc = new Location("");
        myLoc.setLatitude(fingerLocation.getLatitude());
        myLoc.setLongitude(fingerLocation.getLongitude());
    } else {
        myLoc = app.getLocationProvider().getLastStaleKnownLocation();
    }
    MapMarkersHelper markersHelper = app.getMapMarkersHelper();
    List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
    int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    if (route != null && route.points.size() > 0) {
        planRouteAttrs.updatePaints(app, nightMode, tileBox);
        new Renderable.StandardTrack(new ArrayList<>(route.points), 17.2).drawSegment(view.getZoom(), defaultAppMode ? planRouteAttrs.paint : planRouteAttrs.paint2, canvas, tileBox);
    }
    if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) {
        textAttrs.paint.setTextSize(textSize);
        textAttrs.paint2.setTextSize(textSize);
        lineAttrs.updatePaints(app, nightMode, tileBox);
        textAttrs.updatePaints(app, nightMode, tileBox);
        textAttrs.paint.setStyle(Paint.Style.FILL);
        textPaint.set(textAttrs.paint);
        boolean drawMarkerName = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1;
        float locX;
        float locY;
        MapViewTrackingUtilities mapViewTrackingUtilities = app.getMapViewTrackingUtilities();
        if (mapViewTrackingUtilities.isMapLinkedToLocation() && !MapViewTrackingUtilities.isSmallSpeedForAnimation(myLoc) && !mapViewTrackingUtilities.isMovingToMyLocation()) {
            locX = tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
            locY = tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
        } else {
            locX = tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
            locY = tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
        }
        int[] colors = MapMarker.getColors(getContext());
        for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) {
            MapMarker marker = activeMapMarkers.get(i);
            float markerX = tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
            float markerY = tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
            linePath.reset();
            tx.clear();
            ty.clear();
            tx.add(locX);
            ty.add(locY);
            tx.add(markerX);
            ty.add(markerY);
            GeometryWay.calculatePath(tileBox, tx, ty, linePath);
            PathMeasure pm = new PathMeasure(linePath, false);
            float[] pos = new float[2];
            pm.getPosTan(pm.getLength() / 2, pos, null);
            float dist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude());
            String distSt = OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
            String text = distSt + (drawMarkerName ? " • " + marker.getName(getContext()) : "");
            text = TextUtils.ellipsize(text, textPaint, pm.getLength(), TextUtils.TruncateAt.END).toString();
            Rect bounds = new Rect();
            textAttrs.paint.getTextBounds(text, 0, text.length(), bounds);
            float hOffset = pm.getLength() / 2 - bounds.width() / 2f;
            lineAttrs.paint.setColor(colors[marker.colorIndex]);
            canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
            canvas.drawPath(linePath, lineAttrs.paint);
            if (locX >= markerX) {
                canvas.rotate(180, pos[0], pos[1]);
                canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint2);
                canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint);
                canvas.rotate(-180, pos[0], pos[1]);
            } else {
                canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint2);
                canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint);
            }
            canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
        }
    }
}
Also used : Rect(android.graphics.Rect) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) ArrayList(java.util.ArrayList) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) QuadPoint(net.osmand.data.QuadPoint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) Renderable(net.osmand.plus.views.Renderable) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) PathMeasure(android.graphics.PathMeasure) Location(net.osmand.Location)

Example 92 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class OsmandAidlApi method registerHideSqliteDbFileReceiver.

private void registerHideSqliteDbFileReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver hideSqliteDbFileReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            OsmandSettings settings = app.getSettings();
            String fileName = intent.getStringExtra(AIDL_FILE_NAME);
            if (!Algorithms.isEmpty(fileName) && fileName.equals(settings.MAP_OVERLAY.get())) {
                settings.MAP_OVERLAY.set(null);
                settings.MAP_OVERLAY_PREVIOUS.set(null);
                MapActivity mapActivity = mapActivityRef.get();
                if (mapActivity != null) {
                    OsmandRasterMapsPlugin plugin = OsmandPlugin.getActivePlugin(OsmandRasterMapsPlugin.class);
                    if (plugin != null) {
                        plugin.updateMapLayers(mapActivity, mapActivity, settings.MAP_OVERLAY);
                    }
                }
            }
        }
    };
    registerReceiver(hideSqliteDbFileReceiver, mapActivity, AIDL_HIDE_SQLITEDB_FILE);
}
Also used : Context(android.content.Context) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapActivity(net.osmand.plus.activities.MapActivity)

Example 93 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class MapRendererContext method getMapStyleSettings.

protected QStringStringHash getMapStyleSettings() {
    // Apply map style settings
    OsmandSettings prefs = app.getSettings();
    RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
    Map<String, String> props = new HashMap<String, String>();
    for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
        if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
            continue;
        } else if (customProp.isBoolean()) {
            CommonPreference<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
            props.put(customProp.getAttrName(), pref.get() + "");
        } else {
            CommonPreference<String> settings = prefs.getCustomRenderProperty(customProp.getAttrName());
            String res = settings.get();
            if (!Algorithms.isEmpty(res)) {
                props.put(customProp.getAttrName(), res);
            }
        }
    }
    QStringStringHash convertedStyleSettings = new QStringStringHash();
    for (Map.Entry<String, String> setting : props.entrySet()) {
        convertedStyleSettings.set(setting.getKey(), setting.getValue());
    }
    if (nightMode) {
        convertedStyleSettings.set("nightMode", "true");
    }
    return convertedStyleSettings;
}
Also used : CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) HashMap(java.util.HashMap) QStringStringHash(net.osmand.core.jni.QStringStringHash) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) HashMap(java.util.HashMap) Map(java.util.Map) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 94 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class PointDescription method getLocationData.

public static Map<Integer, String> getLocationData(MapActivity ctx, double lat, double lon, boolean sh) {
    OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
    Map<Integer, String> results = new LinkedHashMap<>();
    String latLonString;
    String latLonDeg;
    String latLonMin;
    String latLonSec;
    String utm = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.UTM_FORMAT);
    String olc = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.OLC_FORMAT);
    String mgrs = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.MGRS_FORMAT);
    String swissGrid = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.SWISS_GRID_FORMAT);
    String swissGridPlus = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.SWISS_GRID_PLUS_FORMAT);
    try {
        latLonString = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES_SHORT);
        latLonDeg = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES);
        latLonMin = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_MINUTES);
        latLonSec = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_SECONDS);
    } catch (RuntimeException e) {
        latLonString = "0, 0";
        latLonDeg = "0°, 0°";
        latLonMin = "0° 0′, 0° 0′";
        latLonSec = "0° 0′ 0″, 0° 0′ 0″";
    }
    results.put(OsmAndFormatter.FORMAT_DEGREES_SHORT, latLonString);
    results.put(OsmAndFormatter.FORMAT_DEGREES, latLonDeg);
    results.put(OsmAndFormatter.FORMAT_MINUTES, latLonMin);
    results.put(OsmAndFormatter.FORMAT_SECONDS, latLonSec);
    results.put(OsmAndFormatter.UTM_FORMAT, utm);
    results.put(OsmAndFormatter.OLC_FORMAT, olc);
    results.put(OsmAndFormatter.MGRS_FORMAT, mgrs);
    results.put(OsmAndFormatter.SWISS_GRID_FORMAT, swissGrid);
    results.put(OsmAndFormatter.SWISS_GRID_PLUS_FORMAT, swissGridPlus);
    int zoom = 17;
    if (ctx.getMapView() != null) {
        zoom = ctx.getMapView().getZoom();
    }
    final String httpUrl = "https://osmand.net/go?lat=" + (lat) + "&lon=" + (lon) + "&z=" + zoom;
    results.put(LOCATION_URL, httpUrl);
    int f = settings.COORDINATES_FORMAT.get();
    if (f == PointDescription.UTM_FORMAT) {
        results.put(LOCATION_LIST_HEADER, utm);
    } else if (f == PointDescription.OLC_FORMAT) {
        results.put(LOCATION_LIST_HEADER, olc);
    } else if (f == PointDescription.MGRS_FORMAT) {
        results.put(LOCATION_LIST_HEADER, mgrs);
    } else if (f == PointDescription.SWISS_GRID_FORMAT) {
        results.put(LOCATION_LIST_HEADER, swissGrid);
    } else if (f == PointDescription.SWISS_GRID_PLUS_FORMAT) {
        results.put(LOCATION_LIST_HEADER, swissGridPlus);
    } else if (f == PointDescription.FORMAT_DEGREES) {
        results.put(LOCATION_LIST_HEADER, latLonDeg);
    } else if (f == PointDescription.FORMAT_MINUTES) {
        results.put(LOCATION_LIST_HEADER, latLonMin);
    } else if (f == PointDescription.FORMAT_SECONDS) {
        results.put(LOCATION_LIST_HEADER, latLonSec);
    }
    return results;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) LinkedHashMap(java.util.LinkedHashMap)

Example 95 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class AppVersionUpgradeOnInit method migrateHomeWorkParkingToFavorites.

public void migrateHomeWorkParkingToFavorites() {
    OsmandSettings settings = app.getSettings();
    FavouritesHelper favorites = app.getFavoritesHelper();
    SettingsAPI settingsAPI = settings.getSettingsAPI();
    Object globalPreferences = settings.getGlobalPreferences();
    LatLon homePoint = null;
    float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0);
    float lon = settingsAPI.getFloat(globalPreferences, "home_point_lon", 0);
    if (lat != 0 || lon != 0) {
        homePoint = new LatLon(lat, lon);
    }
    LatLon workPoint = null;
    lat = settingsAPI.getFloat(globalPreferences, "work_point_lat", 0);
    lon = settingsAPI.getFloat(globalPreferences, "work_point_lon", 0);
    if (lat != 0 || lon != 0) {
        workPoint = new LatLon(lat, lon);
    }
    if (homePoint != null) {
        favorites.setSpecialPoint(homePoint, SpecialPointType.HOME, null);
    }
    if (workPoint != null) {
        favorites.setSpecialPoint(workPoint, SpecialPointType.WORK, null);
    }
}
Also used : LatLon(net.osmand.data.LatLon) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) SettingsAPI(net.osmand.plus.api.SettingsAPI) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Aggregations

OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)154 OsmandApplication (net.osmand.plus.OsmandApplication)52 View (android.view.View)25 ArrayList (java.util.ArrayList)23 LatLon (net.osmand.data.LatLon)17 MapActivity (net.osmand.plus.activities.MapActivity)17 TextView (android.widget.TextView)16 NonNull (androidx.annotation.NonNull)16 AlertDialog (androidx.appcompat.app.AlertDialog)15 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)15 ArrayAdapter (android.widget.ArrayAdapter)13 ContextMenuItem (net.osmand.plus.ContextMenuItem)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)12 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)12 Context (android.content.Context)11 ImageView (android.widget.ImageView)11 Intent (android.content.Intent)8 List (java.util.List)8 PointDescription (net.osmand.data.PointDescription)8 DialogInterface (android.content.DialogInterface)7