Search in sources :

Example 1 with MetricsConstants

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

the class SettingsGeneralActivity method addLocalPrefs.

private void addLocalPrefs(PreferenceGroup screen) {
    drivingRegionPreference.setTitle(R.string.driving_region);
    drivingRegionPreference.setSummary(R.string.driving_region_descr);
    drivingRegionPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            final AlertDialog.Builder b = new AlertDialog.Builder(SettingsGeneralActivity.this);
            b.setTitle(getString(R.string.driving_region));
            final List<DrivingRegion> drs = new ArrayList<>();
            drs.add(null);
            drs.addAll(Arrays.asList(DrivingRegion.values()));
            int sel = -1;
            DrivingRegion selectedDrivingRegion = settings.DRIVING_REGION.get();
            if (settings.DRIVING_REGION_AUTOMATIC.get()) {
                sel = 0;
            }
            for (int i = 1; i < drs.size(); i++) {
                if (sel == -1 && drs.get(i) == selectedDrivingRegion) {
                    sel = i;
                    break;
                }
            }
            final int selected = sel;
            final ArrayAdapter<DrivingRegion> singleChoiceAdapter = new ArrayAdapter<DrivingRegion>(SettingsGeneralActivity.this, R.layout.single_choice_description_item, R.id.text1, drs) {

                @NonNull
                @Override
                public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                    View v = convertView;
                    if (v == null) {
                        LayoutInflater inflater = SettingsGeneralActivity.this.getLayoutInflater();
                        v = inflater.inflate(R.layout.single_choice_description_item, parent, false);
                    }
                    DrivingRegion item = getItem(position);
                    AppCompatCheckedTextView title = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
                    TextView desc = (TextView) v.findViewById(R.id.description);
                    if (item != null) {
                        title.setText(getString(item.name));
                        desc.setVisibility(View.VISIBLE);
                        desc.setText(item.getDescription(v.getContext()));
                    } else {
                        title.setText(getString(R.string.driving_region_automatic));
                        desc.setVisibility(View.GONE);
                    }
                    title.setChecked(position == selected);
                    return v;
                }
            };
            b.setAdapter(singleChoiceAdapter, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (drs.get(which) == null) {
                        settings.DRIVING_REGION_AUTOMATIC.set(true);
                        MapViewTrackingUtilities mapViewTrackingUtilities = MapActivity.getSingleMapViewTrackingUtilities();
                        if (mapViewTrackingUtilities != null) {
                            mapViewTrackingUtilities.resetDrivingRegionUpdate();
                        }
                    } else {
                        settings.DRIVING_REGION_AUTOMATIC.set(false);
                        settings.DRIVING_REGION.set(drs.get(which));
                    }
                    updateAllSettings();
                }
            });
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.show();
            return true;
        }
    });
    String[] entries;
    String[] entrieValues;
    MetricsConstants[] mvls = MetricsConstants.values();
    entries = new String[mvls.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = mvls[i].toHumanString(getMyApplication());
    }
    registerListPreference(settings.METRIC_SYSTEM, screen, entries, mvls);
    Integer[] cvls = new Integer[5];
    cvls[0] = PointDescription.FORMAT_DEGREES;
    cvls[1] = PointDescription.FORMAT_MINUTES;
    cvls[2] = PointDescription.FORMAT_SECONDS;
    cvls[3] = PointDescription.UTM_FORMAT;
    cvls[4] = PointDescription.OLC_FORMAT;
    entries = new String[5];
    entries[0] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_DEGREES);
    entries[1] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_MINUTES);
    entries[2] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_SECONDS);
    entries[3] = PointDescription.formatToHumanString(this, PointDescription.UTM_FORMAT);
    entries[4] = PointDescription.formatToHumanString(this, PointDescription.OLC_FORMAT);
    registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls);
    // See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
    // Hardy maintenance 2016-05-29:
    // - Include languages if their translation is >= ~10%    (but any language will be visible if it is the device's system locale)
    // - Mark as "incomplete" if                    < ~80%
    String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")";
    // Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
    String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")";
    // getResources().getAssets().getLocales();
    entrieValues = new String[] { "", "en", "af", "ar", "ast", "az", "be", "be_BY", "bg", "ca", "cs", "cy", "da", "de", "el", "en_GB", "eo", "es", "es_AR", "es_US", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hsb", "hu", "hy", "is", "it", "ja", "ka", "kab", "kn", "ko", "lt", "lv", "ml", "mr", "nb", "nl", "nn", "pl", "pt", "pt_BR", "ro", "ru", "sc", "sk", "sl", "sr", "sr+Latn", "sv", "tr", "uk", "vi", "zh_CN", "zh_TW" };
    entries = new String[] { getString(R.string.system_locale) + latinSystemDefaultSuffix, getString(R.string.lang_en), getString(R.string.lang_af) + incompleteSuffix, getString(R.string.lang_ar), getString(R.string.lang_ast) + incompleteSuffix, getString(R.string.lang_az), getString(R.string.lang_be), getString(R.string.lang_be_by), getString(R.string.lang_bg), getString(R.string.lang_ca), getString(R.string.lang_cs), getString(R.string.lang_cy) + incompleteSuffix, getString(R.string.lang_da), getString(R.string.lang_de), getString(R.string.lang_el) + incompleteSuffix, getString(R.string.lang_en_gb), getString(R.string.lang_eo), getString(R.string.lang_es), getString(R.string.lang_es_ar), getString(R.string.lang_es_us), getString(R.string.lang_eu) + incompleteSuffix, getString(R.string.lang_fa), getString(R.string.lang_fi) + incompleteSuffix, getString(R.string.lang_fr), getString(R.string.lang_gl) + incompleteSuffix, getString(R.string.lang_he) + incompleteSuffix, getString(R.string.lang_hr) + incompleteSuffix, getString(R.string.lang_hsb) + incompleteSuffix, getString(R.string.lang_hu), getString(R.string.lang_hy), getString(R.string.lang_is) + incompleteSuffix, getString(R.string.lang_it), getString(R.string.lang_ja), getString(R.string.lang_ka) + incompleteSuffix, getString(R.string.lang_kab) + incompleteSuffix, getString(R.string.lang_kn) + incompleteSuffix, getString(R.string.lang_ko), getString(R.string.lang_lt), getString(R.string.lang_lv), getString(R.string.lang_ml) + incompleteSuffix, getString(R.string.lang_mr) + incompleteSuffix, getString(R.string.lang_nb), getString(R.string.lang_nl), getString(R.string.lang_nn) + incompleteSuffix, getString(R.string.lang_pl), getString(R.string.lang_pt), getString(R.string.lang_pt_br), getString(R.string.lang_ro) + incompleteSuffix, getString(R.string.lang_ru), getString(R.string.lang_sc), getString(R.string.lang_sk), getString(R.string.lang_sl), getString(R.string.lang_sr) + incompleteSuffix, getString(R.string.lang_sr_latn) + incompleteSuffix, getString(R.string.lang_sv), getString(R.string.lang_tr), getString(R.string.lang_uk), getString(R.string.lang_vi) + incompleteSuffix, getString(R.string.lang_zh_cn) + incompleteSuffix, getString(R.string.lang_zh_tw) };
    String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(this, entries, entries);
    String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(this, entrieValues, entries);
    registerListPreference(settings.PREFERRED_LOCALE, screen, valuesPl, idsPl);
    // Add " (Display language)" to menu title in Latin letters for all non-en languages
    if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
        ((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
    }
// This setting now only in "Confgure map" menu
// String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
// String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
// registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) DrivingRegion(net.osmand.plus.OsmandSettings.DrivingRegion) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) NonNull(android.support.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) ViewGroup(android.view.ViewGroup) ListPreference(android.preference.ListPreference) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) View(android.view.View) TextView(android.widget.TextView) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) LayoutInflater(android.view.LayoutInflater) MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants) OnClickListener(android.content.DialogInterface.OnClickListener) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with MetricsConstants

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

the class AbstractPrologCommandPlayer method init.

private void init(String voiceProvider, OsmandSettings settings, String configFile) throws CommandPlayerException {
    prologSystem.clearTheory();
    voiceDir = null;
    if (voiceProvider != null) {
        File parent = ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR);
        voiceDir = new File(parent, voiceProvider);
        if (!voiceDir.exists()) {
            voiceDir = null;
            throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
        }
    }
    // voiceZipFile = null;
    if (voiceDir != null) {
        long time = System.currentTimeMillis();
        boolean wrong = false;
        try {
            InputStream config;
            // if (voiceDir.getName().endsWith(".zip")) { //$NON-NLS-1$
            // voiceZipFile = new ZipFile(voiceDir);
            // config = voiceZipFile.getInputStream(voiceZipFile.getEntry("_config.p")); //$NON-NLS-1$
            // } else {
            // $NON-NLS-1$
            config = new FileInputStream(new File(voiceDir, configFile));
            // }
            MetricsConstants mc = settings.METRIC_SYSTEM.get();
            ApplicationMode m = settings.getApplicationMode();
            if (m.getParent() != null) {
                m = m.getParent();
            }
            settings.APPLICATION_MODE.addListener(this);
            prologSystem.getTheoryManager().assertA(new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey().toLowerCase())), true, "", true);
            prologSystem.addTheory(new Theory("measure('" + mc.toTTSString() + "')."));
            prologSystem.addTheory(new Theory(config));
            config.close();
        } catch (InvalidTheoryException e) {
            // $NON-NLS-1$
            log.error("Loading voice config exception " + voiceProvider, e);
            wrong = true;
        } catch (IOException e) {
            // $NON-NLS-1$
            log.error("Loading voice config exception " + voiceProvider, e);
            wrong = true;
        }
        if (wrong) {
            throw new CommandPlayerException(ctx.getString(R.string.voice_data_corrupted));
        } else {
            Term val = solveSimplePredicate(P_VERSION);
            if (!(val instanceof Number) || Arrays.binarySearch(sortedVoiceVersions, ((Number) val).intValue()) < 0) {
                throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
            }
            currentVersion = ((Number) val).intValue();
        }
        if (log.isInfoEnabled()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            log.info("Initializing voice subsystem  " + voiceProvider + " : " + (System.currentTimeMillis() - time));
        }
    }
}
Also used : Theory(alice.tuprolog.Theory) InvalidTheoryException(alice.tuprolog.InvalidTheoryException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ApplicationMode(net.osmand.plus.ApplicationMode) IOException(java.io.IOException) Term(alice.tuprolog.Term) FileInputStream(java.io.FileInputStream) Struct(alice.tuprolog.Struct) Number(alice.tuprolog.Number) MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants) File(java.io.File)

Example 3 with MetricsConstants

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

the class OsmAndFormatter method getFormattedAlt.

public static String getFormattedAlt(double alt, OsmandApplication ctx) {
    OsmandSettings settings = ctx.getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
    if (!useFeet) {
        return ((int) (alt + 0.5)) + " " + ctx.getString(R.string.m);
    } else {
        return ((int) (alt * FEET_IN_ONE_METER + 0.5)) + " " + ctx.getString(R.string.foot);
    }
}
Also used : MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants)

Example 4 with MetricsConstants

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

the class OsmAndFormatter method calculateRoundedDist.

public static double calculateRoundedDist(double distInMeters, OsmandApplication ctx) {
    OsmandSettings settings = ctx.getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    double mainUnitInMeter = 1;
    double metersInSecondUnit = METERS_IN_KILOMETER;
    if (mc == MetricsConstants.MILES_AND_FEET) {
        mainUnitInMeter = FEET_IN_ONE_METER;
        metersInSecondUnit = METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_METERS) {
        mainUnitInMeter = 1;
        metersInSecondUnit = METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.NAUTICAL_MILES) {
        mainUnitInMeter = 1;
        metersInSecondUnit = METERS_IN_ONE_NAUTICALMILE;
    } else if (mc == MetricsConstants.MILES_AND_YARDS) {
        mainUnitInMeter = YARDS_IN_ONE_METER;
        metersInSecondUnit = METERS_IN_ONE_MILE;
    }
    // 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 ...
    int generator = 1;
    byte pointer = 1;
    double point = mainUnitInMeter;
    double roundDist = 1;
    while (distInMeters * point > generator) {
        roundDist = (generator / point);
        if (pointer++ % 3 == 2) {
            generator = generator * 5 / 2;
        } else {
            generator *= 2;
        }
        if (point == mainUnitInMeter && metersInSecondUnit * mainUnitInMeter * 0.9f <= generator) {
            point = 1 / metersInSecondUnit;
            generator = 1;
            pointer = 1;
        }
    }
    // Miles exceptions: 2000ft->0.5mi, 1000ft->0.25mi, 1000yd->0.5mi, 500yd->0.25mi, 1000m ->0.5mi, 500m -> 0.25mi
    if (mc == MetricsConstants.MILES_AND_METERS && roundDist == 1000) {
        roundDist = 0.5f * METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_METERS && roundDist == 500) {
        roundDist = 0.25f * METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_FEET && roundDist == 2000 / (double) FEET_IN_ONE_METER) {
        roundDist = 0.5f * METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_FEET && roundDist == 1000 / (double) FEET_IN_ONE_METER) {
        roundDist = 0.25f * METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_YARDS && roundDist == 1000 / (double) YARDS_IN_ONE_METER) {
        roundDist = 0.5f * METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_YARDS && roundDist == 500 / (double) YARDS_IN_ONE_METER) {
        roundDist = 0.25f * METERS_IN_ONE_MILE;
    }
    return roundDist;
}
Also used : MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants)

Example 5 with MetricsConstants

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

the class OsmAndFormatter method getFormattedDistance.

public static String getFormattedDistance(float meters, OsmandApplication ctx, boolean forceTrailingZeros) {
    String format1 = forceTrailingZeros ? "{0,number,0.0} " : "{0,number,0.#} ";
    String format2 = forceTrailingZeros ? "{0,number,0.00} " : "{0,number,0.##} ";
    OsmandSettings settings = ctx.getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    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 >= 100 * mainUnitInMeters) {
        // $NON-NLS-1$
        return (int) (meters / mainUnitInMeters + 0.5) + " " + ctx.getString(mainUnitStr);
    } else if (meters > 9.99f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format1 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else if (meters > 0.999f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format2 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else if (mc == MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format2 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else if (mc == MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format2 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else if (mc == MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format2 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else if (mc == MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
        // $NON-NLS-1$
        return MessageFormat.format(format2 + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' ');
    } else {
        if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
            // $NON-NLS-1$
            return ((int) (meters + 0.5)) + " " + ctx.getString(R.string.m);
        } else if (mc == MetricsConstants.MILES_AND_FEET) {
            int feet = (int) (meters * FEET_IN_ONE_METER + 0.5);
            // $NON-NLS-1$
            return feet + " " + ctx.getString(R.string.foot);
        } else if (mc == MetricsConstants.MILES_AND_YARDS) {
            int yards = (int) (meters * YARDS_IN_ONE_METER + 0.5);
            // $NON-NLS-1$
            return yards + " " + ctx.getString(R.string.yard);
        }
        // $NON-NLS-1$
        return ((int) (meters + 0.5)) + " " + ctx.getString(R.string.m);
    }
}
Also used : MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants)

Aggregations

MetricsConstants (net.osmand.plus.OsmandSettings.MetricsConstants)6 InvalidTheoryException (alice.tuprolog.InvalidTheoryException)1 Number (alice.tuprolog.Number)1 Struct (alice.tuprolog.Struct)1 Term (alice.tuprolog.Term)1 Theory (alice.tuprolog.Theory)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1