Search in sources :

Example 86 with OsmandSettings

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

the class ProfileSettingsItem method getReader.

@Nullable
@Override
public SettingsItemReader<? extends SettingsItem> getReader() {
    return new OsmandSettingsItemReader<ProfileSettingsItem>(this, getSettings()) {

        @Override
        protected void readPreferenceFromJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
            if (!appModeBeanPrefsIds.contains(preference.getId())) {
                preference.readFromJson(json, appMode);
            }
        }

        @Override
        public void readPreferencesFromJson(final JSONObject json) {
            getSettings().getContext().runInUIThread(() -> {
                OsmandSettings settings = getSettings();
                Map<String, OsmandPreference<?>> prefs = settings.getRegisteredPreferences();
                Iterator<String> iterator = json.keys();
                while (iterator.hasNext()) {
                    String key = iterator.next();
                    OsmandPreference<?> p = prefs.get(key);
                    if (p == null) {
                        if (OsmandSettings.isRoutingPreference(key)) {
                            p = settings.registerStringPreference(key, "");
                        }
                    }
                    if (p != null) {
                        try {
                            readPreferenceFromJson(p, json);
                            if (OsmandSettings.isRoutingPreference(p.getId())) {
                                if (p.getId().endsWith(GeneralRouter.USE_SHORTEST_WAY)) {
                                    settings.FAST_ROUTE_MODE.setModeValue(appMode, !settings.getCustomRoutingBooleanProperty(GeneralRouter.USE_SHORTEST_WAY, false).getModeValue(appMode));
                                }
                            }
                        } catch (Exception e) {
                            SettingsHelper.LOG.error("Failed to read preference: " + key, e);
                        }
                    } else {
                        SettingsHelper.LOG.warn("No preference while importing settings: " + key);
                    }
                }
            });
        }
    };
}
Also used : JSONObject(org.json.JSONObject) NonNull(androidx.annotation.NonNull) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) OsmandSettingsItemReader(net.osmand.plus.settings.backend.backup.OsmandSettingsItemReader) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) JSONException(org.json.JSONException) Nullable(androidx.annotation.Nullable)

Example 87 with OsmandSettings

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

the class RouteLineAppearanceFragment method saveRouteLineAppearance.

private void saveRouteLineAppearance() {
    if (getMyApplication() != null) {
        OsmandSettings settings = getMyApplication().getSettings();
        settings.CUSTOM_ROUTE_COLOR_DAY.setModeValue(appMode, previewRouteLineInfo.getCustomColor(false));
        settings.CUSTOM_ROUTE_COLOR_NIGHT.setModeValue(appMode, previewRouteLineInfo.getCustomColor(true));
        settings.ROUTE_COLORING_TYPE.setModeValue(appMode, previewRouteLineInfo.getRouteColoringType());
        settings.ROUTE_INFO_ATTRIBUTE.setModeValue(appMode, previewRouteLineInfo.getRouteInfoAttribute());
        settings.ROUTE_LINE_WIDTH.setModeValue(appMode, previewRouteLineInfo.getWidth());
        settings.ROUTE_SHOW_TURN_ARROWS.setModeValue(appMode, previewRouteLineInfo.shouldShowTurnArrows());
    }
}
Also used : OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 88 with OsmandSettings

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

the class RouteLineAppearanceFragment method createPreviewRouteLineInfo.

private PreviewRouteLineInfo createPreviewRouteLineInfo() {
    OsmandSettings settings = requireSettings();
    int colorDay = settings.CUSTOM_ROUTE_COLOR_DAY.getModeValue(appMode);
    int colorNight = settings.CUSTOM_ROUTE_COLOR_NIGHT.getModeValue(appMode);
    ColoringType coloringType = settings.ROUTE_COLORING_TYPE.getModeValue(appMode);
    String routeInfoAttribute = settings.ROUTE_INFO_ATTRIBUTE.getModeValue(appMode);
    String widthKey = settings.ROUTE_LINE_WIDTH.getModeValue(appMode);
    boolean showTurnArrows = settings.ROUTE_SHOW_TURN_ARROWS.getModeValue(appMode);
    PreviewRouteLineInfo previewRouteLineInfo = new PreviewRouteLineInfo(colorDay, colorNight, coloringType, routeInfoAttribute, widthKey, showTurnArrows);
    previewRouteLineInfo.setIconId(appMode.getNavigationIcon().getIconId());
    previewRouteLineInfo.setIconColor(appMode.getProfileColor(isNightMode()));
    return previewRouteLineInfo;
}
Also used : ColoringType(net.osmand.plus.routing.ColoringType) PreviewRouteLineInfo(net.osmand.plus.routing.PreviewRouteLineInfo) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 89 with OsmandSettings

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

the class TrackDrawInfo method initCurrentTrackParams.

private void initCurrentTrackParams(@NonNull OsmandApplication app) {
    OsmandSettings settings = app.getSettings();
    width = settings.CURRENT_TRACK_WIDTH.get();
    color = settings.CURRENT_TRACK_COLOR.get();
    coloringType = settings.CURRENT_TRACK_COLORING_TYPE.get();
    routeInfoAttribute = settings.CURRENT_TRACK_ROUTE_INFO_ATTRIBUTE.get();
    showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get();
    showStartFinish = settings.CURRENT_TRACK_SHOW_START_FINISH.get();
}
Also used : OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 90 with OsmandSettings

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

the class MapMarkersLayer method runExclusiveAction.

@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
    MapActivity mapActivity = getMapActivity();
    OsmandSettings settings = getApplication().getSettings();
    if (unknownLocation || mapActivity == null || !(o instanceof MapMarker) || !settings.SELECT_MARKER_ON_SINGLE_TAP.get() || !settings.SHOW_MAP_MARKERS.get()) {
        return false;
    }
    final MapMarkersHelper helper = getApplication().getMapMarkersHelper();
    final MapMarker old = helper.getMapMarkers().get(0);
    helper.moveMarkerToTop((MapMarker) o);
    String title = getContext().getString(R.string.marker_activated, helper.getMapMarkers().get(0).getName(getContext()));
    Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_cancel, v -> helper.moveMarkerToTop(old)).show();
    return true;
}
Also used : Rect(android.graphics.Rect) PointF(android.graphics.PointF) ApplyMovedObjectCallback(net.osmand.plus.views.layers.ContextMenuLayer.ApplyMovedObjectCallback) NonNull(androidx.annotation.NonNull) R(net.osmand.plus.R) MapMarker(net.osmand.plus.mapmarkers.MapMarker) Handler(android.os.Handler) Amenity(net.osmand.data.Amenity) Renderable(net.osmand.plus.views.Renderable) Canvas(android.graphics.Canvas) MapUtils(net.osmand.util.MapUtils) ContextCompat(androidx.core.content.ContextCompat) QuadPoint(net.osmand.data.QuadPoint) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) IContextMenuProviderSelection(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProviderSelection) PorterDuff(android.graphics.PorterDuff) OsmandApplication(net.osmand.plus.OsmandApplication) List(java.util.List) Nullable(androidx.annotation.Nullable) Message(android.os.Message) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) TextPaint(android.text.TextPaint) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) Snackbar(com.google.android.material.snackbar.Snackbar) Context(android.content.Context) Path(android.graphics.Path) GestureDetector(android.view.GestureDetector) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GeometryWay(net.osmand.plus.views.layers.geometry.GeometryWay) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) OsmAndFormatter(net.osmand.plus.utils.OsmAndFormatter) MotionEvent(android.view.MotionEvent) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) PathMeasure(android.graphics.PathMeasure) TextUtils(android.text.TextUtils) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmAndConstants(net.osmand.plus.OsmAndConstants) PointDescription(net.osmand.data.PointDescription) Bitmap(android.graphics.Bitmap) MapMarkersWidgetsFactory(net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory) Collections(java.util.Collections) Location(net.osmand.Location) MapActivity(net.osmand.plus.activities.MapActivity) MapMarker(net.osmand.plus.mapmarkers.MapMarker) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapActivity(net.osmand.plus.activities.MapActivity)

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