Search in sources :

Example 1 with SpeedConstants

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

the class OsmAndFormatter method getFormattedSpeed.

public static String getFormattedSpeed(float metersperseconds, OsmandApplication ctx) {
    OsmandSettings settings = ctx.getSettings();
    SpeedConstants mc = settings.SPEED_SYSTEM.get();
    ApplicationMode am = settings.getApplicationMode();
    float kmh = metersperseconds * 3.6f;
    if (mc == SpeedConstants.KILOMETERS_PER_HOUR) {
        // e.g. car case and for high-speeds: Display rounded to 1 km/h (5% precision at 20 km/h)
        if (kmh >= 20 || am.hasFastSpeed()) {
            return ((int) Math.round(kmh)) + " " + mc.toShortString(ctx);
        }
        // for smaller values display 1 decimal digit x.y km/h, (0.5% precision at 20 km/h)
        int kmh10 = (int) Math.round(kmh * 10f);
        return (kmh10 / 10f) + " " + mc.toShortString(ctx);
    } else if (mc == SpeedConstants.MILES_PER_HOUR) {
        float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_MILE;
        if (mph >= 20 || am.hasFastSpeed()) {
            return ((int) Math.round(mph)) + " " + mc.toShortString(ctx);
        } else {
            int mph10 = (int) Math.round(mph * 10f);
            return (mph10 / 10f) + " " + mc.toShortString(ctx);
        }
    } else if (mc == SpeedConstants.NAUTICALMILES_PER_HOUR) {
        float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_NAUTICALMILE;
        if (mph >= 20 || am.hasFastSpeed()) {
            return ((int) Math.round(mph)) + " " + mc.toShortString(ctx);
        } else {
            int mph10 = (int) Math.round(mph * 10f);
            return (mph10 / 10f) + " " + mc.toShortString(ctx);
        }
    } else if (mc == SpeedConstants.MINUTES_PER_KILOMETER) {
        if (metersperseconds < 0.111111111) {
            return "-" + mc.toShortString(ctx);
        }
        float minperkm = METERS_IN_KILOMETER / (metersperseconds * 60);
        if (minperkm >= 10) {
            return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx);
        } else {
            int mph10 = (int) Math.round(minperkm * 10f);
            return (mph10 / 10f) + " " + mc.toShortString(ctx);
        }
    } else if (mc == SpeedConstants.MINUTES_PER_MILE) {
        if (metersperseconds < 0.111111111) {
            return "-" + mc.toShortString(ctx);
        }
        float minperm = (METERS_IN_ONE_MILE) / (metersperseconds * 60);
        if (minperm >= 10) {
            return ((int) Math.round(minperm)) + " " + mc.toShortString(ctx);
        } else {
            int mph10 = (int) Math.round(minperm * 10f);
            return (mph10 / 10f) + " " + mc.toShortString(ctx);
        }
    } else /*if (mc == SpeedConstants.METERS_PER_SECOND) */
    {
        if (metersperseconds >= 10) {
            return ((int) Math.round(metersperseconds)) + " " + SpeedConstants.METERS_PER_SECOND.toShortString(ctx);
        }
        // for smaller values display 1 decimal digit x.y km/h, (0.5% precision at 20 km/h)
        int kmh10 = (int) Math.round(metersperseconds * 10f);
        return (kmh10 / 10f) + " " + SpeedConstants.METERS_PER_SECOND.toShortString(ctx);
    }
}
Also used : SpeedConstants(net.osmand.plus.OsmandSettings.SpeedConstants)

Example 2 with SpeedConstants

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

the class SettingsNavigationActivity method createUI.

private void createUI() {
    addPreferencesFromResource(R.xml.navigation_settings);
    PreferenceScreen screen = getPreferenceScreen();
    settings = getMyApplication().getSettings();
    routerServicePreference = (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId());
    RouteService[] vls = RouteService.getAvailableRouters(getMyApplication());
    String[] entries = new String[vls.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = vls[i].getName();
    }
    registerListPreference(settings.ROUTER_SERVICE, screen, entries, vls);
    registerBooleanPreference(settings.SNAP_TO_ROAD, screen);
    Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90 };
    entries = new String[intValues.length];
    entries[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < intValues.length; i++) {
        entries[i] = (int) intValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.AUTO_FOLLOW_ROUTE, screen, entries, intValues);
    autoZoom = screen.findPreference("auto_zoom_map_on_off");
    autoZoom.setOnPreferenceClickListener(this);
    // keep informing option:
    Integer[] keepInformingValues = new Integer[] { 0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30 };
    String[] keepInformingNames = new String[keepInformingValues.length];
    keepInformingNames[0] = getString(R.string.keep_informing_never);
    for (int i = 1; i < keepInformingValues.length; i++) {
        keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min);
    }
    registerListPreference(settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);
    SpeedConstants[] speedValues = SpeedConstants.values();
    String[] speedNamesVls = new String[speedValues.length];
    for (int i = 0; i < speedValues.length; i++) {
        speedNamesVls[i] = speedValues[i].toHumanString(this);
    }
    ;
    registerListPreference(settings.SPEED_SYSTEM, screen, speedNamesVls, speedValues);
    // screen power save option:
    Integer[] screenPowerSaveValues = new Integer[] { 0, 5, 10, 15, 20, 30, 45, 60 };
    String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
    screenPowerSaveNames[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < screenPowerSaveValues.length; i++) {
        screenPowerSaveNames[i] = screenPowerSaveValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.WAKE_ON_VOICE_INT, screen, screenPowerSaveNames, screenPowerSaveValues);
    // registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);
    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);
    speakAlarms = (Preference) screen.findPreference("speak_routing_alarms");
    speakAlarms.setOnPreferenceClickListener(this);
    Float[] arrivalValues = new Float[] { 1.5f, 1f, 0.5f, 0.25f };
    String[] arrivalNames = new String[] { getString(R.string.arrival_distance_factor_early), getString(R.string.arrival_distance_factor_normally), getString(R.string.arrival_distance_factor_late), getString(R.string.arrival_distance_factor_at_last) };
    registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues);
    // array size should be equal!
    Float[] speedLimitsKm = new Float[] { -10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f };
    Float[] speedLimitsMiles = new Float[] { -7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f };
    if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
        String[] speedNames = new String[speedLimitsKm.length];
        for (int i = 0; i < speedLimitsKm.length; i++) {
            speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h);
        }
        registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
        registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNames, speedLimitsKm);
    } else {
        String[] speedNames = new String[speedLimitsKm.length];
        for (int i = 0; i < speedNames.length; i++) {
            speedNames[i] = speedLimitsMiles[i] + " " + getString(R.string.mile_per_hour);
        }
        registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
        registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNames, speedLimitsKm);
    }
    PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
    speedLimitExceed = (ListPreference) category.findPreference("speed_limit_exceed");
    ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
    if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        category.removePreference(speedLimitExceed);
    }
    if (getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
        setSelectedAppMode(settings.getApplicationMode());
    } else {
        profileDialog();
    }
    addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SpeedConstants(net.osmand.plus.OsmandSettings.SpeedConstants) ApplicationMode(net.osmand.plus.ApplicationMode) PreferenceCategory(android.preference.PreferenceCategory) RouteService(net.osmand.plus.routing.RouteProvider.RouteService)

Aggregations

SpeedConstants (net.osmand.plus.OsmandSettings.SpeedConstants)2 PreferenceCategory (android.preference.PreferenceCategory)1 PreferenceScreen (android.preference.PreferenceScreen)1 ApplicationMode (net.osmand.plus.ApplicationMode)1 RouteService (net.osmand.plus.routing.RouteProvider.RouteService)1