Search in sources :

Example 56 with OsmandSettings

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

the class GpxUiHelper method createGPXSpeedDataSet.

public static OrderedLineDataSet createGPXSpeedDataSet(OsmandApplication ctx, LineChart mChart, GPXTrackAnalysis analysis, GPXDataSetAxisType axisType, boolean useRightAxis, boolean drawFilled) {
    OsmandSettings settings = ctx.getSettings();
    boolean light = settings.isLightContent();
    float divX;
    XAxis xAxis = mChart.getXAxis();
    if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
        divX = setupXAxisTime(xAxis, analysis.timeSpan);
    } else {
        divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
    }
    OsmandSettings.SpeedConstants sps = settings.SPEED_SYSTEM.get();
    float mulSpeed = Float.NaN;
    float divSpeed = Float.NaN;
    final String mainUnitY = sps.toShortString(ctx);
    if (sps == OsmandSettings.SpeedConstants.KILOMETERS_PER_HOUR) {
        mulSpeed = 3.6f;
    } else if (sps == OsmandSettings.SpeedConstants.MILES_PER_HOUR) {
        mulSpeed = 3.6f * METERS_IN_KILOMETER / METERS_IN_ONE_MILE;
    } else if (sps == OsmandSettings.SpeedConstants.NAUTICALMILES_PER_HOUR) {
        mulSpeed = 3.6f * METERS_IN_KILOMETER / METERS_IN_ONE_NAUTICALMILE;
    } else if (sps == OsmandSettings.SpeedConstants.MINUTES_PER_KILOMETER) {
        divSpeed = METERS_IN_KILOMETER / 60;
    } else if (sps == OsmandSettings.SpeedConstants.MINUTES_PER_MILE) {
        divSpeed = METERS_IN_ONE_MILE / 60;
    } else {
        mulSpeed = 1f;
    }
    YAxis yAxis;
    if (useRightAxis) {
        yAxis = mChart.getAxisRight();
        yAxis.setEnabled(true);
    } else {
        yAxis = mChart.getAxisLeft();
    }
    if (analysis.hasSpeedInTrack()) {
        yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_orange_label));
        yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_orange_grid));
    } else {
        yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_red_label));
        yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_red_grid));
    }
    yAxis.setAxisMinimum(0f);
    ArrayList<Entry> values = new ArrayList<>();
    List<Speed> speedData = analysis.speedData;
    float nextX = 0;
    float nextY;
    float x;
    for (Speed s : speedData) {
        x = axisType == GPXDataSetAxisType.TIME ? s.time : s.distance;
        if (x > 0) {
            if (axisType == GPXDataSetAxisType.TIME && x > 60) {
                values.add(new Entry(nextX + 1, 0));
                values.add(new Entry(nextX + x - 1, 0));
            }
            nextX += x / divX;
            if (Float.isNaN(divSpeed)) {
                nextY = s.speed * mulSpeed;
            } else {
                nextY = divSpeed / s.speed;
            }
            if (nextY < 0 || Float.isInfinite(nextY)) {
                nextY = 0;
            }
            values.add(new Entry(nextX, nextY));
        }
    }
    OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.SPEED, axisType);
    String format = null;
    if (dataSet.getYMax() < 3) {
        format = "{0,number,0.#} ";
    }
    final String formatY = format;
    yAxis.setValueFormatter(new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            if (!Algorithms.isEmpty(formatY)) {
                return MessageFormat.format(formatY + mainUnitY, value);
            } else {
                return (int) value + " " + mainUnitY;
            }
        }
    });
    if (Float.isNaN(divSpeed)) {
        dataSet.priority = analysis.avgSpeed * mulSpeed;
    } else {
        dataSet.priority = divSpeed / analysis.avgSpeed;
    }
    dataSet.divX = divX;
    if (Float.isNaN(divSpeed)) {
        dataSet.mulY = mulSpeed;
        dataSet.divY = Float.NaN;
    } else {
        dataSet.divY = divSpeed;
        dataSet.mulY = Float.NaN;
    }
    dataSet.units = mainUnitY;
    if (analysis.hasSpeedInTrack()) {
        dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_orange));
    } else {
        dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_red));
    }
    dataSet.setLineWidth(1f);
    if (drawFilled) {
        dataSet.setFillAlpha(128);
        if (analysis.hasSpeedInTrack()) {
            dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_orange));
        } else {
            dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_red));
        }
        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(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
    if (useRightAxis) {
        dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
    }
    return dataSet;
}
Also used : Speed(net.osmand.plus.GPXUtilities.Speed) ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) SpannableString(android.text.SpannableString) AxisBase(com.github.mikephil.charting.components.AxisBase) OsmandSettings(net.osmand.plus.OsmandSettings) XAxis(com.github.mikephil.charting.components.XAxis) Entry(com.github.mikephil.charting.data.Entry) YAxis(com.github.mikephil.charting.components.YAxis)

Example 57 with OsmandSettings

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

the class GpxUiHelper method setupXAxisDistance.

private static float setupXAxisDistance(OsmandApplication ctx, XAxis xAxis, float meters) {
    OsmandSettings settings = ctx.getSettings();
    OsmandSettings.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 == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
        mainUnitStr = R.string.km;
        mainUnitInMeters = METERS_IN_KILOMETER;
    } else if (mc == OsmandSettings.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 == OsmandSettings.MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters || mc == OsmandSettings.MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters || mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters || mc == OsmandSettings.MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
        divX = mainUnitInMeters;
        if (fmt == null) {
            fmt = format2;
            granularity = .01f;
        }
    } else {
        fmt = null;
        granularity = 1f;
        if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS || mc == OsmandSettings.MetricsConstants.MILES_AND_METERS) {
            divX = 1f;
            mainUnitStr = R.string.m;
        } else if (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
            divX = 1f / FEET_IN_ONE_METER;
            mainUnitStr = R.string.foot;
        } else if (mc == OsmandSettings.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);
    xAxis.setGranularity(granularity);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            if (!Algorithms.isEmpty(formatX)) {
                return MessageFormat.format(formatX + mainUnitX, value);
            } else {
                return (int) value + " " + mainUnitX;
            }
        }
    });
    return divX;
}
Also used : IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) SpannableString(android.text.SpannableString) AxisBase(com.github.mikephil.charting.components.AxisBase) OsmandSettings(net.osmand.plus.OsmandSettings) SuppressLint(android.annotation.SuppressLint)

Example 58 with OsmandSettings

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

the class PerformLiveUpdateAsyncTask method tryRescheduleDownload.

public static void tryRescheduleDownload(@NonNull Context context, @NonNull OsmandSettings settings, @NonNull String localIndexFileName) {
    final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference = preferenceUpdateFrequency(localIndexFileName, settings);
    final Integer frequencyOrdinal = updateFrequencyPreference.get();
    if (LiveUpdatesHelper.UpdateFrequency.values()[frequencyOrdinal] == LiveUpdatesHelper.UpdateFrequency.HOURLY) {
        return;
    }
    final Integer retriesLeft = settings.LIVE_UPDATES_RETRIES.get();
    if (retriesLeft > 0) {
        PendingIntent alarmIntent = LiveUpdatesHelper.getPendingIntent(context, localIndexFileName);
        long timeToRetry = System.currentTimeMillis() + AlarmManager.INTERVAL_HOUR;
        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmMgr.set(AlarmManager.RTC, timeToRetry, alarmIntent);
        settings.LIVE_UPDATES_RETRIES.set(retriesLeft - 1);
    } else {
        settings.LIVE_UPDATES_RETRIES.resetToDefault();
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 59 with OsmandSettings

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

the class WakeLockHelper method releaseWakeLocks.

private void releaseWakeLocks() {
    if (wakeLock != null) {
        wakeLock.release();
        wakeLock = null;
    }
    if (mDevicePolicyManager != null && mDeviceAdmin != null) {
        OsmandSettings settings = app.getSettings();
        final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
        if (screenPowerSave > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
            if (mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
                try {
                    mDevicePolicyManager.lockNow();
                } catch (SecurityException e) {
                // Log.d(TAG,
                // "SecurityException: No device admin permission to lock the screen!");
                }
            } else {
            // Log.d(TAG,
            // "No device admin permission to lock the screen!");
            }
        }
    }
}
Also used : OsmandSettings(net.osmand.plus.OsmandSettings)

Example 60 with OsmandSettings

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

the class WakeLockHelper method onStop.

public void onStop(Activity a) {
    this.active = false;
    OsmandSettings settings = app.getSettings();
    if (!a.isFinishing() && (settings.WAKE_ON_VOICE_INT.get() > 0)) {
        VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
        voiceRouter.addVoiceMessageListener(this);
    }
}
Also used : VoiceRouter(net.osmand.plus.routing.VoiceRouter) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

OsmandSettings (net.osmand.plus.OsmandSettings)91 View (android.view.View)27 OsmandApplication (net.osmand.plus.OsmandApplication)25 ArrayList (java.util.ArrayList)20 LatLon (net.osmand.data.LatLon)17 DialogInterface (android.content.DialogInterface)14 ArrayAdapter (android.widget.ArrayAdapter)14 TextView (android.widget.TextView)14 AlertDialog (android.support.v7.app.AlertDialog)11 ImageView (android.widget.ImageView)11 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)8 ContextMenuItem (net.osmand.plus.ContextMenuItem)8 ApplicationMode (net.osmand.plus.ApplicationMode)7 Paint (android.graphics.Paint)6 Pair (android.support.v4.util.Pair)6 ListView (android.widget.ListView)6 SpannableString (android.text.SpannableString)5 CompoundButton (android.widget.CompoundButton)5