Search in sources :

Example 76 with OsmandSettings

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

the class ConfigureMapDialogs method showTextSizeDialog.

protected static void showTextSizeDialog(MapActivity activity, ContextMenuAdapter adapter, int themeRes, boolean nightMode, int pos, ArrayAdapter<ContextMenuItem> ad) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    final OsmandMapTileView view = activity.getMapView();
    AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
    // test old descr as title
    b.setTitle(R.string.text_size);
    final Float[] txtValues = new Float[] { 0.33f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 2f, 3f };
    int selected = -1;
    final String[] txtNames = new String[txtValues.length];
    for (int i = 0; i < txtNames.length; i++) {
        txtNames[i] = (int) (txtValues[i] * 100) + " %";
        if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
            selected = i;
        }
    }
    DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(txtNames, nightMode, selected, app, selectedProfileColor, themeRes, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int which = (int) v.getTag();
            view.getSettings().TEXT_SCALE.set(txtValues[which]);
            activity.refreshMapComplete();
            adapter.getItem(pos).setDescription(ConfigureMapUtils.getScale(activity));
            ad.notifyDataSetInvalidated();
        }
    });
    b.setAdapter(dialogAdapter, null);
    b.setNegativeButton(R.string.shared_string_dismiss, null);
    dialogAdapter.setDialog(b.show());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter)

Example 77 with OsmandSettings

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

the class ConfigureMapDialogs method showMapLanguageDialog.

protected static void showMapLanguageDialog(MapActivity activity, ContextMenuAdapter adapter, int themeRes, boolean nightMode, int pos, ArrayAdapter<ContextMenuItem> ad) {
    int[] selectedLanguageIndex = new int[1];
    boolean[] transliterateNames = new boolean[1];
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    final OsmandMapTileView view = activity.getMapView();
    AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
    b.setTitle(activity.getString(R.string.map_locale));
    final String[] txtIds = ConfigureMapUtils.getSortedMapNamesIds(activity, ConfigureMapUtils.MAP_NAMES_IDS, ConfigureMapUtils.getMapNamesValues(activity, ConfigureMapUtils.MAP_NAMES_IDS));
    final String[] txtValues = ConfigureMapUtils.getMapNamesValues(activity, txtIds);
    int selected = -1;
    for (int i = 0; i < txtIds.length; i++) {
        if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
            selected = i;
            break;
        }
    }
    selectedLanguageIndex[0] = selected;
    transliterateNames[0] = settings.MAP_TRANSLITERATE_NAMES.get();
    final OnCheckedChangeListener translitChangdListener = (buttonView, isChecked) -> transliterateNames[0] = isChecked;
    final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(new ContextThemeWrapper(activity, themeRes), R.layout.single_choice_switch_item, R.id.text1, txtValues) {

        @NonNull
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            AppCompatCheckedTextView checkedTextView = v.findViewById(R.id.text1);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                UiUtilities.setupCompoundButtonDrawable(app, nightMode, selectedProfileColor, checkedTextView.getCheckMarkDrawable());
            }
            if (position == selectedLanguageIndex[0] && position > 0) {
                checkedTextView.setChecked(true);
                v.findViewById(R.id.topDivider).setVisibility(View.VISIBLE);
                v.findViewById(R.id.bottomDivider).setVisibility(View.VISIBLE);
                v.findViewById(R.id.switchLayout).setVisibility(View.VISIBLE);
                TextView switchText = v.findViewById(R.id.switchText);
                switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
                SwitchCompat check = v.findViewById(R.id.check);
                check.setChecked(transliterateNames[0]);
                check.setOnCheckedChangeListener(translitChangdListener);
                UiUtilities.setupCompoundButton(nightMode, selectedProfileColor, check);
            } else {
                checkedTextView.setChecked(position == selectedLanguageIndex[0]);
                v.findViewById(R.id.topDivider).setVisibility(View.GONE);
                v.findViewById(R.id.bottomDivider).setVisibility(View.GONE);
                v.findViewById(R.id.switchLayout).setVisibility(View.GONE);
            }
            return v;
        }
    };
    b.setAdapter(singleChoiceAdapter, null);
    b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            selectedLanguageIndex[0] = which;
            transliterateNames[0] = settings.MAP_TRANSLITERATE_NAMES.isSet() ? transliterateNames[0] : txtIds[which].equals("en");
            ((AlertDialog) dialog).getListView().setSelection(which);
            singleChoiceAdapter.notifyDataSetChanged();
        }
    });
    b.setNegativeButton(R.string.shared_string_cancel, null);
    b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            view.getSettings().MAP_TRANSLITERATE_NAMES.set(selectedLanguageIndex[0] > 0 && transliterateNames[0]);
            AlertDialog dlg = (AlertDialog) dialog;
            int index = dlg.getListView().getCheckedItemPosition();
            view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
            activity.refreshMapComplete();
            String localeDescr = txtIds[index];
            localeDescr = localeDescr == null || localeDescr.isEmpty() ? activity.getString(R.string.local_map_names) : localeDescr;
            adapter.getItem(pos).setDescription(localeDescr);
            ad.notifyDataSetInvalidated();
        }
    });
    b.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Arrays(java.util.Arrays) AlertDialog(androidx.appcompat.app.AlertDialog) MapRendererContext(net.osmand.core.android.MapRendererContext) TIntArrayList(gnu.trove.list.array.TIntArrayList) NonNull(androidx.annotation.NonNull) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) R(net.osmand.plus.R) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) ColorInt(androidx.annotation.ColorInt) ArrayList(java.util.ArrayList) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) UiUtilities(net.osmand.plus.utils.UiUtilities) Locale(java.util.Locale) View(android.view.View) NativeCoreContext(net.osmand.plus.views.corenative.NativeCoreContext) Build(android.os.Build) Algorithms(net.osmand.util.Algorithms) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) DialogInterface(android.content.DialogInterface) AndroidUtils(net.osmand.plus.utils.AndroidUtils) SwitchCompat(androidx.appcompat.widget.SwitchCompat) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) DayNightMode(net.osmand.plus.settings.enums.DayNightMode) ViewGroup(android.view.ViewGroup) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) TextView(android.widget.TextView) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter) MapActivity(net.osmand.plus.activities.MapActivity) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ViewGroup(android.view.ViewGroup) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 78 with OsmandSettings

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

the class ConfigureMapDialogs method showRenderingPropertyDialog.

protected static void showRenderingPropertyDialog(MapActivity activity, ContextMenuAdapter adapter, RenderingRuleProperty p, CommonPreference<String> pref, int pos, boolean nightMode) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    int currentProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    int themeRes = ConfigureMapMenu.getThemeRes(nightMode);
    AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
    String propertyDescr = AndroidUtils.getRenderingStringPropertyDescription(app, p.getAttrName(), p.getName());
    // test old descr as title
    b.setTitle(propertyDescr);
    int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
    if (i >= 0) {
        i++;
    } else if (Algorithms.isEmpty(pref.get())) {
        i = 0;
    }
    String[] possibleValuesString = ConfigureMapUtils.getRenderingPropertyPossibleValues(app, p);
    DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(possibleValuesString, nightMode, i, app, currentProfileColor, themeRes, v -> {
        int which = (int) v.getTag();
        if (which == 0) {
            pref.set("");
        } else {
            pref.set(p.getPossibleValues()[which - 1]);
        }
        activity.refreshMapComplete();
        String description = AndroidUtils.getRenderingStringPropertyValue(activity, pref.get());
        adapter.getItem(pos).setDescription(description);
    });
    b.setNegativeButton(R.string.shared_string_dismiss, null);
    b.setAdapter(dialogAdapter, null);
    dialogAdapter.setDialog(b.show());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 79 with OsmandSettings

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

the class SelectMapStyleBottomSheetDialogFragment method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    OsmandApplication app = getMyApplication();
    RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(selectedStyle);
    if (loaded != null) {
        OsmandMapTileView view = mapActivity.getMapView();
        OsmandSettings settings = view.getSettings();
        settings.RENDERER.set(selectedStyle);
        final CommonPreference<Boolean> pisteRoutesPref = settings.getCustomRenderBooleanProperty(PISTE_ROUTES_ATTR);
        if (pisteRoutesPref.get()) {
            pisteRoutesPref.set(settings.RENDERER.get().equals(RendererRegistry.WINTER_SKI_RENDER));
        }
        app.getRendererRegistry().setCurrentSelectedRender(loaded);
        mapActivity.refreshMapComplete();
        mapActivity.getDashboard().refreshContent(true);
    } else {
        Toast.makeText(mapActivity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
    }
    dismiss();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapActivity(net.osmand.plus.activities.MapActivity)

Example 80 with OsmandSettings

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

the class SendAnalyticsBottomSheetDialogFragment method onRightBottomButtonClick.

@Override
protected void onRightBottomButtonClick() {
    OsmandApplication app = requiredMyApplication();
    OsmandSettings settings = app.getSettings();
    settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(sendAnonymousMapDownloadsData);
    settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(sendAnonymousAppUsageData);
    settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true);
    informAnalyticsPrefsUpdate();
    dismiss();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

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