Search in sources :

Example 6 with MetricsConstants

use of net.osmand.plus.settings.enums.MetricsConstants in project Osmand by osmandapp.

the class OsmandApplication method setupDrivingRegion.

public void setupDrivingRegion(WorldRegion reg) {
    DrivingRegion drg = null;
    WorldRegion.RegionParams params = reg.getParams();
    // boolean americanSigns = "american".equals(params.getRegionRoadSigns());
    boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
    MetricsConstants mc1 = "miles".equals(params.getRegionMetric()) ? MetricsConstants.MILES_AND_FEET : MetricsConstants.KILOMETERS_AND_METERS;
    MetricsConstants mc2 = "miles".equals(params.getRegionMetric()) ? MetricsConstants.MILES_AND_METERS : MetricsConstants.KILOMETERS_AND_METERS;
    for (DrivingRegion r : DrivingRegion.values()) {
        if (r.leftHandDriving == leftHand && (r.defMetrics == mc1 || r.defMetrics == mc2)) {
            drg = r;
            break;
        }
    }
    if (drg != null) {
        osmandSettings.DRIVING_REGION.set(drg);
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) MetricsConstants(net.osmand.plus.settings.enums.MetricsConstants) DrivingRegion(net.osmand.plus.settings.enums.DrivingRegion)

Example 7 with MetricsConstants

use of net.osmand.plus.settings.enums.MetricsConstants in project Osmand by osmandapp.

the class GpxMarkerView method updateXAxisValueWithDistance.

@SuppressLint("SetTextI18n")
private void updateXAxisValueWithDistance(@NonNull OrderedLineDataSet dataSet, @NonNull Entry entry) {
    OsmandApplication app = getMyApplication();
    float meters = entry.getX() * dataSet.getDivX();
    MetricsConstants metricsConstants = app.getSettings().METRIC_SYSTEM.get();
    FormattedValue formattedDistance = OsmAndFormatter.getFormattedDistanceValue(meters, app, true, metricsConstants);
    TextView xAxisValueText = xAxisContainer.findViewById(R.id.x_axis_value);
    TextView xAxisUnitText = xAxisContainer.findViewById(R.id.x_axis_unit);
    xAxisValueText.setText(formattedDistance.value + " ");
    xAxisUnitText.setText(formattedDistance.unit);
    AndroidUiHelper.updateVisibility(xAxisUnitText, true);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MetricsConstants(net.osmand.plus.settings.enums.MetricsConstants) FormattedValue(net.osmand.plus.utils.OsmAndFormatter.FormattedValue) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 8 with MetricsConstants

use of net.osmand.plus.settings.enums.MetricsConstants in project Osmand by osmandapp.

the class GeneralProfileSettingsFragment method setupUnitsOfLengthPref.

private void setupUnitsOfLengthPref() {
    MetricsConstants[] metricsConstants = MetricsConstants.values();
    String[] entries = new String[metricsConstants.length];
    Integer[] entryValues = new Integer[metricsConstants.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = metricsConstants[i].toHumanString(app);
        entryValues[i] = metricsConstants[i].ordinal();
    }
    ListPreferenceEx unitsOfLength = (ListPreferenceEx) findPreference(settings.METRIC_SYSTEM.getId());
    unitsOfLength.setEntries(entries);
    unitsOfLength.setEntryValues(entryValues);
    unitsOfLength.setIcon(getActiveIcon(R.drawable.ic_action_ruler_unit));
}
Also used : ListPreferenceEx(net.osmand.plus.settings.preferences.ListPreferenceEx) MetricsConstants(net.osmand.plus.settings.enums.MetricsConstants)

Example 9 with MetricsConstants

use of net.osmand.plus.settings.enums.MetricsConstants in project Osmand by osmandapp.

the class GpxUiHelper method createGPXElevationDataSet.

public static OrderedLineDataSet createGPXElevationDataSet(@NonNull OsmandApplication ctx, @NonNull LineChart mChart, @NonNull GPXTrackAnalysis analysis, @NonNull GPXDataSetAxisType axisType, boolean useRightAxis, boolean drawFilled, boolean calcWithoutGaps) {
    OsmandSettings settings = ctx.getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
    boolean light = settings.isLightContent();
    final float convEle = useFeet ? 3.28084f : 1.0f;
    float divX;
    XAxis xAxis = mChart.getXAxis();
    if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
        divX = setupXAxisTime(xAxis, calcWithoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan);
    } else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
        divX = setupXAxisTimeOfDay(xAxis, analysis.startTime);
    } else {
        divX = setupAxisDistance(ctx, xAxis, calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance);
    }
    final String mainUnitY = useFeet ? ctx.getString(R.string.foot) : ctx.getString(R.string.m);
    YAxis yAxis;
    if (useRightAxis) {
        yAxis = mChart.getAxisRight();
        yAxis.setEnabled(true);
    } else {
        yAxis = mChart.getAxisLeft();
    }
    yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue_label));
    yAxis.setGranularity(1f);
    yAxis.resetAxisMinimum();
    yAxis.setValueFormatter((value, axis) -> OsmAndFormatter.formatInteger((int) value, mainUnitY, ctx));
    List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true, calcWithoutGaps);
    OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.ALTITUDE, axisType, !useRightAxis);
    dataSet.priority = (float) (analysis.avgElevation - analysis.minElevation) * convEle;
    dataSet.divX = divX;
    dataSet.mulY = convEle;
    dataSet.divY = Float.NaN;
    dataSet.units = mainUnitY;
    dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue));
    dataSet.setLineWidth(1f);
    if (drawFilled) {
        dataSet.setFillAlpha(128);
        dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue));
        dataSet.setDrawFilled(true);
    } else {
        dataSet.setDrawFilled(false);
    }
    dataSet.setDrawValues(false);
    dataSet.setValueTextSize(9f);
    dataSet.setFormLineWidth(1f);
    dataSet.setFormSize(15.f);
    dataSet.setDrawCircles(false);
    dataSet.setDrawCircleHole(false);
    dataSet.setHighlightEnabled(true);
    dataSet.setDrawVerticalHighlightIndicator(true);
    dataSet.setDrawHorizontalHighlightIndicator(false);
    dataSet.setHighLightColor(ColorUtilities.getSecondaryTextColor(mChart.getContext(), !light));
    // dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    dataSet.setFillFormatter((ds, dataProvider) -> dataProvider.getYChartMin());
    if (useRightAxis) {
        dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
    }
    return dataSet;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) MetricsConstants(net.osmand.plus.settings.enums.MetricsConstants) SpannableString(android.text.SpannableString) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 10 with MetricsConstants

use of net.osmand.plus.settings.enums.MetricsConstants in project Osmand by osmandapp.

the class GpxUiHelper method setupAxisDistance.

private static float setupAxisDistance(OsmandApplication ctx, AxisBase axisBase, float meters) {
    OsmandSettings settings = ctx.getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    float divX;
    String format1 = "{0,number,0.#} ";
    String format2 = "{0,number,0.##} ";
    String fmt = null;
    float granularity = 1f;
    int mainUnitStr;
    float mainUnitInMeters;
    if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
        mainUnitStr = R.string.km;
        mainUnitInMeters = METERS_IN_KILOMETER;
    } else if (mc == MetricsConstants.NAUTICAL_MILES) {
        mainUnitStr = R.string.nm;
        mainUnitInMeters = METERS_IN_ONE_NAUTICALMILE;
    } else {
        mainUnitStr = R.string.mile;
        mainUnitInMeters = METERS_IN_ONE_MILE;
    }
    if (meters > 9.99f * mainUnitInMeters) {
        fmt = format1;
        granularity = .1f;
    }
    if (meters >= 100 * mainUnitInMeters || meters > 9.99f * mainUnitInMeters || meters > 0.999f * mainUnitInMeters || mc == MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters || mc == MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters || mc == MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters || mc == MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
        divX = mainUnitInMeters;
        if (fmt == null) {
            fmt = format2;
            granularity = .01f;
        }
    } else {
        fmt = null;
        granularity = 1f;
        if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
            divX = 1f;
            mainUnitStr = R.string.m;
        } else if (mc == MetricsConstants.MILES_AND_FEET) {
            divX = 1f / FEET_IN_ONE_METER;
            mainUnitStr = R.string.foot;
        } else if (mc == MetricsConstants.MILES_AND_YARDS) {
            divX = 1f / YARDS_IN_ONE_METER;
            mainUnitStr = R.string.yard;
        } else {
            divX = 1f;
            mainUnitStr = R.string.m;
        }
    }
    final String formatX = fmt;
    final String mainUnitX = ctx.getString(mainUnitStr);
    axisBase.setGranularity(granularity);
    axisBase.setValueFormatter((value, axis) -> {
        if (!Algorithms.isEmpty(formatX)) {
            return MessageFormat.format(formatX + mainUnitX, value);
        } else {
            return OsmAndFormatter.formatInteger((int) value, mainUnitX, ctx);
        }
    });
    return divX;
}
Also used : MetricsConstants(net.osmand.plus.settings.enums.MetricsConstants) SpannableString(android.text.SpannableString) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Aggregations

MetricsConstants (net.osmand.plus.settings.enums.MetricsConstants)13 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)5 SuppressLint (android.annotation.SuppressLint)3 SpannableString (android.text.SpannableString)3 TextView (android.widget.TextView)2 XAxis (com.github.mikephil.charting.components.XAxis)2 YAxis (com.github.mikephil.charting.components.YAxis)2 BarEntry (com.github.mikephil.charting.data.BarEntry)2 Entry (com.github.mikephil.charting.data.Entry)2 Context (android.content.Context)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 Fragment (androidx.fragment.app.Fragment)1 Slider (com.google.android.material.slider.Slider)1 LatLonPoint (com.jwetherell.openmap.common.LatLonPoint)1 MGRSPoint (com.jwetherell.openmap.common.MGRSPoint)1 ZonedUTMPoint (com.jwetherell.openmap.common.ZonedUTMPoint)1 ArrayList (java.util.ArrayList)1 LatLon (net.osmand.data.LatLon)1 WorldRegion (net.osmand.map.WorldRegion)1