Search in sources :

Example 6 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class GPXLayer method updatePaints.

private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) {
    RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
    final boolean isNight = nightMode != null && nightMode.isNightMode();
    int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom());
    if (hsh != cachedHash) {
        cachedHash = hsh;
        cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
        if (rrs != null) {
            RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
            req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight);
            CommonPreference<String> p = view.getSettings().getCustomRenderProperty("currentTrackColor");
            if (p != null && p.isSet()) {
                RenderingRuleProperty ctColor = rrs.PROPS.get("currentTrackColor");
                if (ctColor != null) {
                    req.setStringFilter(ctColor, p.get());
                }
            }
            CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty("currentTrackWidth");
            if (p2 != null && p2.isSet()) {
                RenderingRuleProperty ctWidth = rrs.PROPS.get("currentTrackWidth");
                if (ctWidth != null) {
                    req.setStringFilter(ctWidth, p2.get());
                }
            }
            String additional = "";
            if (routePoints) {
                additional = "routePoints=true";
            }
            if (currentTrack) {
                additional = (additional.length() == 0 ? "" : ";") + "currentTrack=true";
            }
            req.setIntFilter(rrs.PROPS.R_MINZOOM, tileBox.getZoom());
            req.setIntFilter(rrs.PROPS.R_MAXZOOM, tileBox.getZoom());
            if (additional.length() > 0) {
                req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional);
            }
            if (req.searchRenderingAttribute("gpx")) {
                RenderingContext rc = new OsmandRenderer.RenderingContext(view.getContext());
                rc.setDensityValue((float) tileBox.getMapDensity());
                cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR);
                osmandRenderer.updatePaint(req, paint, 0, false, rc);
                isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc);
                isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc);
                isShadowPaint = req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS);
                if (isShadowPaint) {
                    ColorFilter cf = new PorterDuffColorFilter(req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR), Mode.SRC_IN);
                    shadowPaint.setColorFilter(cf);
                    shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS));
                }
            } else {
                System.err.println("Rendering attribute gpx is not found !");
                paint.setStrokeWidth(7 * view.getDensity());
            }
        }
    }
    paint.setColor(color == 0 ? cachedColor : color);
    return cachedColor;
}
Also used : RenderingContext(net.osmand.plus.render.OsmandRenderer.RenderingContext) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) RenderingRuleSearchRequest(net.osmand.render.RenderingRuleSearchRequest) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) Paint(android.graphics.Paint)

Example 7 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class GpxUiHelper method createDialog.

private static AlertDialog createDialog(final Activity activity, final boolean showCurrentGpx, final boolean multipleChoice, final boolean showAppearanceSetting, final CallbackWithObject<GPXFile[]> callbackWithObject, final List<GPXInfo> list, final ContextMenuAdapter adapter) {
    final OsmandApplication app = (OsmandApplication) activity.getApplication();
    final DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(activity);
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final int layout = R.layout.gpx_track_item;
    final Map<String, String> gpxAppearanceParams = new HashMap<>();
    final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title, adapter.getItemNames()) {

        List<GpxDataItem> dataItems = null;

        @Override
        public int getItemViewType(int position) {
            return showCurrentGpx && position == 0 ? 1 : 0;
        }

        @Override
        public int getViewTypeCount() {
            return 2;
        }

        private GpxDataItem getDataItem(GPXInfo info) {
            if (dataItems != null) {
                for (GpxDataItem item : dataItems) {
                    if (item.getFile().getAbsolutePath().endsWith(info.fileName)) {
                        return item;
                    }
                }
            }
            return null;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = convertView;
            boolean checkLayout = getItemViewType(position) == 0;
            if (v == null) {
                v = activity.getLayoutInflater().inflate(layout, null);
            }
            if (dataItems == null) {
                dataItems = app.getGpxDatabase().getItems();
            }
            final ContextMenuItem item = adapter.getItem(position);
            GPXInfo info = list.get(position);
            updateGpxInfoView(v, item, info, getDataItem(info), showCurrentGpx && position == 0, app);
            if (item.getSelected() == null) {
                v.findViewById(R.id.check_item).setVisibility(View.GONE);
                v.findViewById(R.id.check_local_index).setVisibility(View.GONE);
            } else {
                if (checkLayout) {
                    final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_local_index));
                    ch.setVisibility(View.VISIBLE);
                    v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
                    ch.setOnCheckedChangeListener(null);
                    ch.setChecked(item.getSelected());
                    ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            item.setSelected(isChecked);
                        }
                    });
                } else {
                    final SwitchCompat ch = ((SwitchCompat) v.findViewById(R.id.toggle_item));
                    ch.setVisibility(View.VISIBLE);
                    v.findViewById(R.id.toggle_checkbox_item).setVisibility(View.GONE);
                    ch.setOnCheckedChangeListener(null);
                    ch.setChecked(item.getSelected());
                    ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            item.setSelected(isChecked);
                        }
                    });
                }
                v.findViewById(R.id.check_item).setVisibility(View.VISIBLE);
            }
            return v;
        }
    };
    OnClickListener onClickListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int position) {
        }
    };
    builder.setAdapter(listAdapter, onClickListener);
    if (multipleChoice) {
        if (showAppearanceSetting) {
            final RenderingRuleProperty trackWidthProp;
            final RenderingRuleProperty trackColorProp;
            final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
            if (renderer != null) {
                trackWidthProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_WIDTH_ATTR);
                trackColorProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_COLOR_ATTR);
            } else {
                trackWidthProp = null;
                trackColorProp = null;
            }
            if (trackWidthProp == null || trackColorProp == null) {
                builder.setTitle(R.string.show_gpx);
            } else {
                final View apprTitleView = activity.getLayoutInflater().inflate(R.layout.select_gpx_appearance_title, null);
                final OsmandSettings.CommonPreference<String> prefWidth = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
                final OsmandSettings.CommonPreference<String> prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
                updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, prefWidth.get(), prefColor.get());
                apprTitleView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final ListPopupWindow popup = new ListPopupWindow(activity);
                        popup.setAnchorView(apprTitleView);
                        popup.setContentWidth(AndroidUtils.dpToPx(activity, 200f));
                        popup.setModal(true);
                        popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                        popup.setVerticalOffset(AndroidUtils.dpToPx(activity, -48f));
                        popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f));
                        final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(activity, gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get(), GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_WIDTH_COLOR);
                        popup.setAdapter(gpxApprAdapter);
                        popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                AppearanceListItem item = gpxApprAdapter.getItem(position);
                                if (item != null) {
                                    if (item.getAttrName() == CURRENT_TRACK_WIDTH_ATTR) {
                                        gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue());
                                    } else if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
                                        gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue());
                                    }
                                }
                                popup.dismiss();
                                updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, gpxAppearanceParams.containsKey(CURRENT_TRACK_WIDTH_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_WIDTH_ATTR) : prefWidth.get(), gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get());
                            }
                        });
                        popup.show();
                    }
                });
                builder.setCustomTitle(apprTitleView);
            }
        } else {
            builder.setTitle(R.string.show_gpx);
        }
        builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (gpxAppearanceParams.size() > 0) {
                    for (Map.Entry<String, String> entry : gpxAppearanceParams.entrySet()) {
                        final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(entry.getKey());
                        pref.set(entry.getValue());
                    }
                    if (activity instanceof MapActivity) {
                        ConfigureMapMenu.refreshMapComplete((MapActivity) activity);
                    }
                }
                GPXFile currentGPX = null;
                // clear all previously selected files before adding new one
                OsmandApplication app = (OsmandApplication) activity.getApplication();
                if (app != null && app.getSelectedGpxHelper() != null) {
                    app.getSelectedGpxHelper().clearAllGpxFileToShow();
                }
                if (app != null && showCurrentGpx && adapter.getItem(0).getSelected()) {
                    currentGPX = app.getSavingTrackHelper().getCurrentGpx();
                }
                List<String> s = new ArrayList<>();
                for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
                    if (adapter.getItem(i).getSelected()) {
                        s.add(list.get(i).getFileName());
                    }
                }
                dialog.dismiss();
                loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX, s.toArray(new String[s.size()]));
            }
        });
        builder.setNegativeButton(R.string.shared_string_cancel, null);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && list.size() > 1 || !showCurrentGpx && list.size() > 0) {
            builder.setNeutralButton(R.string.gpx_add_track, null);
        }
    }
    final AlertDialog dlg = builder.create();
    dlg.setCanceledOnTouchOutside(true);
    if (list.size() == 0 || showCurrentGpx && list.size() == 1) {
        final View footerView = activity.getLayoutInflater().inflate(R.layout.no_gpx_files_list_footer, null);
        TextView descTextView = (TextView) footerView.findViewById(R.id.descFolder);
        String descPrefix = app.getString(R.string.gpx_no_tracks_title_folder);
        SpannableString spannableDesc = new SpannableString(descPrefix + ": " + dir.getAbsolutePath());
        spannableDesc.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), descPrefix.length() + 1, spannableDesc.length(), 0);
        descTextView.setText(spannableDesc);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            footerView.findViewById(R.id.button).setVisibility(View.GONE);
        } else {
            footerView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    addTrack(activity, dlg);
                }
            });
        }
        dlg.getListView().addFooterView(footerView, null, false);
    }
    dlg.getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (multipleChoice) {
                ContextMenuItem item = adapter.getItem(position);
                item.setSelected(!item.getSelected());
                listAdapter.notifyDataSetInvalidated();
                if (position == 0 && showCurrentGpx && item.getSelected()) {
                    OsmandMonitoringPlugin monitoringPlugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
                    if (monitoringPlugin == null) {
                        AlertDialog.Builder confirm = new AlertDialog.Builder(activity);
                        confirm.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(activity, PluginActivity.class);
                                intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandMonitoringPlugin.ID);
                                activity.startActivity(intent);
                            }
                        });
                        confirm.setNegativeButton(R.string.shared_string_cancel, null);
                        confirm.setMessage(activity.getString(R.string.enable_plugin_monitoring_services));
                        confirm.show();
                    } else if (!app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
                        monitoringPlugin.controlDialog(activity, false);
                    }
                }
            } else {
                dlg.dismiss();
                if (showCurrentGpx && position == 0) {
                    callbackWithObject.processResult(null);
                } else {
                    String fileName = list.get(position).getFileName();
                    SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
                    if (selectedGpxFile != null) {
                        callbackWithObject.processResult(new GPXFile[] { selectedGpxFile.getGpxFile() });
                    } else {
                        loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
                    }
                }
            }
        }
    });
    dlg.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button addTrackButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
            if (addTrackButton != null) {
                addTrackButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        addTrack(activity, dlg);
                    }
                });
            }
        }
    });
    dlg.show();
    try {
        dlg.getListView().setFastScrollEnabled(true);
    } catch (Exception e) {
    // java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
    // Unknown reason but on some devices fail
    }
    return dlg;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) HashMap(java.util.HashMap) SpannableString(android.text.SpannableString) OsmandMonitoringPlugin(net.osmand.plus.monitoring.OsmandMonitoringPlugin) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) OsmandSettings(net.osmand.plus.OsmandSettings) SpannableString(android.text.SpannableString) CheckBox(android.widget.CheckBox) AppCompatCheckBox(android.support.v7.widget.AppCompatCheckBox) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SwitchCompat(android.support.v7.widget.SwitchCompat) DialogInterface(android.content.DialogInterface) AppearanceListItem(net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem) Entry(com.github.mikephil.charting.data.Entry) ListPopupWindow(android.support.v7.widget.ListPopupWindow) GpxAppearanceAdapter(net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter) MapActivity(net.osmand.plus.activities.MapActivity) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) MarkerView(com.github.mikephil.charting.components.MarkerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) DateFormat(java.text.DateFormat) StyleSpan(android.text.style.StyleSpan) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) ArrayAdapter(android.widget.ArrayAdapter) CompoundButton(android.widget.CompoundButton)

Example 8 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class ConfigureMapMenu method showPreferencesDialog.

protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter<?> a, final int pos, final MapActivity activity, String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs, final boolean useDescription, ListStringPreference defaultSettings, boolean useDefault, final List<RenderingRuleProperty> customRulesIncluded) {
    AlertDialog.Builder bld = new AlertDialog.Builder(activity);
    boolean[] checkedItems = new boolean[prefs.size()];
    final boolean[] tempPrefs = new boolean[prefs.size()];
    for (int i = 0; i < prefs.size(); i++) {
        tempPrefs[i] = checkedItems[i] = defaultSettings != null && useDefault ? defaultSettings.containsValue(prefs.get(i).getId()) : prefs.get(i).get();
    }
    final String[] vals = new String[ps.size()];
    for (int i = 0; i < ps.size(); i++) {
        RenderingRuleProperty p = ps.get(i);
        String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
        vals[i] = propertyName;
    }
    bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            tempPrefs[which] = isChecked;
        }
    });
    bld.setTitle(category);
    bld.setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            boolean selected = false;
            for (int i = 0; i < prefs.size(); i++) {
                selected |= prefs.get(i).get();
            }
            adapter.getItem(pos).setSelected(selected);
            adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
            a.notifyDataSetInvalidated();
        }
    });
    bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            boolean selected = false;
            for (int i = 0; i < prefs.size(); i++) {
                prefs.get(i).set(tempPrefs[i]);
                selected |= tempPrefs[i];
            }
            final List<OsmandSettings.CommonPreference<String>> includedPrefs = new ArrayList<>();
            if (customRulesIncluded != null) {
                for (RenderingRuleProperty p : customRulesIncluded) {
                    if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
                        final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
                        includedPrefs.add(pref);
                        if (hikingRouteOSMCValue == 0) {
                            pref.set("");
                        } else {
                            pref.set(p.getPossibleValues()[hikingRouteOSMCValue - 1]);
                            selected = true;
                        }
                        break;
                    }
                }
            }
            if (adapter != null) {
                if (useDescription) {
                    adapter.getItem(pos).setDescription(getDescription(prefs, includedPrefs));
                } else {
                    adapter.getItem(pos).setSelected(selected);
                }
                adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
            }
            a.notifyDataSetInvalidated();
            refreshMapComplete(activity);
            activity.getMapLayers().updateLayers(activity.getMapView());
        }
    });
    final AlertDialog dialog = bld.create();
    if (customRulesIncluded != null) {
        for (RenderingRuleProperty p : customRulesIncluded) {
            if (!p.isBoolean()) {
                final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName());
                LayoutInflater inflater = activity.getLayoutInflater();
                View spinnerView = inflater.inflate(R.layout.spinner_rule_layout, null);
                TextView title = (TextView) spinnerView.findViewById(R.id.title);
                final Spinner spinner = (Spinner) spinnerView.findViewById(R.id.spinner);
                TextView description = (TextView) spinnerView.findViewById(R.id.description);
                String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
                String propertyDescr = SettingsActivity.getStringPropertyDescription(activity, p.getAttrName(), p.getName());
                title.setText(propertyName);
                description.setText(propertyDescr);
                int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
                if (i >= 0) {
                    i++;
                } else if (Algorithms.isEmpty(pref.get())) {
                    i = 0;
                }
                String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
                possibleValuesString[0] = SettingsActivity.getStringPropertyValue(activity, p.getDefaultValueDescription());
                for (int j = 0; j < p.getPossibleValues().length; j++) {
                    possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(activity, p.getPossibleValues()[j]);
                }
                StringSpinnerArrayAdapter arrayAdapter = new StringSpinnerArrayAdapter(activity);
                for (String val : possibleValuesString) {
                    arrayAdapter.add(val);
                }
                spinner.setAdapter(arrayAdapter);
                hikingRouteOSMCValue = i;
                spinner.setSelection(i);
                spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                        hikingRouteOSMCValue = position;
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> parent) {
                    }
                });
                dialog.getListView().addFooterView(spinnerView);
            }
        }
    }
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView)

Example 9 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class ConfigureMapMenu method createLayersItems.

private void createLayersItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter, final MapActivity activity) {
    final OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    LayerMenuListener l = new LayerMenuListener(activity, adapter);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
    boolean selected = settings.SHOW_FAVORITES.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_favorites, activity).setSelected(settings.SHOW_FAVORITES.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_fav_dark).setListener(l).createItem());
    selected = app.getPoiFilters().isShowingAnyPoi();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_poi, activity).setSelected(selected).setDescription(app.getPoiFilters().getSelectedPoiFiltersName()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_info_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    selected = settings.SHOW_POI_LABEL.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_amenity_label, activity).setSelected(settings.SHOW_POI_LABEL.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_text_dark).setListener(l).createItem());
    /*
		ContextMenuItem item = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
				"transport", settings.TRANSPORT_DEFAULT_SETTINGS, adapter, activity, false);
		if (item != null) {
			adapter.addItem(item);
		}
		*/
    final List<RenderingRuleProperty> transportRules = new ArrayList<>();
    final List<OsmandSettings.CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
    Iterator<RenderingRuleProperty> it = customRules.iterator();
    while (it.hasNext()) {
        RenderingRuleProperty p = it.next();
        if ("transport".equals(p.getCategory()) && p.isBoolean()) {
            transportRules.add(p);
            final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
            transportPrefs.add(pref);
            it.remove();
        }
    }
    selected = false;
    for (OsmandSettings.CommonPreference<Boolean> p : transportPrefs) {
        if (p.get()) {
            selected = true;
            break;
        }
    }
    final boolean transportSelected = selected;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_transport, activity).setIcon(R.drawable.ic_action_bus_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(transportSelected).setColor(transportSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setListener(new ContextMenuAdapter.OnRowItemClick() {

        ArrayAdapter<CharSequence> adapter;

        boolean transportSelectedInner = transportSelected;

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (transportSelectedInner) {
                showTransportDialog(adapter, position);
                return false;
            } else {
                CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
                if (btn != null && btn.getVisibility() == View.VISIBLE) {
                    btn.setChecked(!btn.isChecked());
                    adapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                    return false;
                } else {
                    return onContextMenuClick(adapter, itemId, position, false, null);
                }
            }
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            if (transportSelectedInner) {
                for (int i = 0; i < transportPrefs.size(); i++) {
                    transportPrefs.get(i).set(false);
                }
                transportSelectedInner = false;
                ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
                refreshMapComplete(activity);
                activity.getMapLayers().updateLayers(activity.getMapView());
            } else {
                ad.getItem(pos).setColorRes(R.color.osmand_orange);
                showTransportDialog(ad, pos);
            }
            ad.notifyDataSetChanged();
            return false;
        }

        private void showTransportDialog(final ArrayAdapter<ContextMenuItem> ad, final int pos) {
            final AlertDialog.Builder b = new AlertDialog.Builder(activity);
            b.setTitle(activity.getString(R.string.rendering_category_transport));
            final int[] iconIds = new int[transportPrefs.size()];
            final boolean[] checkedItems = new boolean[transportPrefs.size()];
            for (int i = 0; i < transportPrefs.size(); i++) {
                checkedItems[i] = transportPrefs.get(i).get();
            }
            final String[] vals = new String[transportRules.size()];
            for (int i = 0; i < transportRules.size(); i++) {
                RenderingRuleProperty p = transportRules.get(i);
                String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
                vals[i] = propertyName;
                if ("transportStops".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_stop;
                } else if ("publicTransportMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                } else if ("tramTrainRoutes".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_tram;
                } else if ("subwayMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_subway;
                } else {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                }
            }
            adapter = new ArrayAdapter<CharSequence>(activity, R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {

                @NonNull
                @Override
                public View getView(final int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
                    if (checkedItems[position]) {
                        icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                    } else {
                        icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                    }
                    v.findViewById(R.id.divider).setVisibility(View.GONE);
                    v.findViewById(R.id.description).setVisibility(View.GONE);
                    v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
                    final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
                    check.setOnCheckedChangeListener(null);
                    check.setChecked(checkedItems[position]);
                    check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            checkedItems[position] = isChecked;
                            if (checkedItems[position]) {
                                icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                            } else {
                                icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                            }
                        }
                    });
                    return v;
                }
            };
            final ListView listView = new ListView(activity);
            listView.setDivider(null);
            listView.setClickable(true);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new ListView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    checkedItems[position] = !checkedItems[position];
                    adapter.notifyDataSetChanged();
                }
            });
            b.setView(listView);
            b.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    ContextMenuItem item = ad.getItem(pos);
                    if (item != null) {
                        item.setSelected(transportSelectedInner);
                        item.setColorRes(transportSelectedInner ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                        ad.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) {
                    transportSelectedInner = false;
                    for (int i = 0; i < transportPrefs.size(); i++) {
                        transportPrefs.get(i).set(checkedItems[i]);
                        if (!transportSelectedInner && checkedItems[i]) {
                            transportSelectedInner = true;
                        }
                    }
                    refreshMapComplete(activity);
                    activity.getMapLayers().updateLayers(activity.getMapView());
                }
            });
            b.show();
        }
    }).createItem());
    selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_gpx_layer, activity).setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()).setDescription(app.getSelectedGpxHelper().getGpxDescription()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_polygom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map, activity).setIcon(R.drawable.ic_world_globe_dark).setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null).setListener(l).createItem());
    OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
    app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
    boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
    if (srtmDisabled) {
        SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
        if (srtmPlugin != null) {
            srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ListView(android.widget.ListView) ImageView(android.widget.ImageView) SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 10 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class ConfigureMapMenu method createRenderingAttributeItems.

private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules, final ContextMenuAdapter adapter, final MapActivity activity) {
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity).setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            AlertDialog.Builder bld = new AlertDialog.Builder(activity);
            bld.setTitle(R.string.renderers);
            final OsmandApplication app = activity.getMyApplication();
            final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
            boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
            final List<String> visibleNamesList = new ArrayList<>();
            int selected = -1;
            final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
            int i = 0;
            Iterator<String> iterator = items.iterator();
            while (iterator.hasNext()) {
                String item = iterator.next();
                if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
                    iterator.remove();
                } else {
                    if (item.equals(selectedName)) {
                        selected = i;
                    }
                    String translation = RendererRegistry.getTranslatedRendererName(activity, item);
                    visibleNamesList.add(translation != null ? translation : item.replace('_', ' ').replace('-', ' '));
                    i++;
                }
            }
            bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String renderer = items.get(which);
                    RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
                    if (loaded != null) {
                        OsmandMapTileView view = activity.getMapView();
                        view.getSettings().RENDERER.set(renderer);
                        app.getRendererRegistry().setCurrentSelectedRender(loaded);
                        refreshMapComplete(activity);
                    } else {
                        Toast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
                    }
                    adapter.getItem(pos).setDescription(getRenderDescr(activity));
                    activity.getDashboard().refreshContent(true);
                    dialog.dismiss();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity).setDescription(getDayNightDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(getDayNightIcon(activity)).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
            bld.setTitle(R.string.daynight);
            final String[] items = new String[OsmandSettings.DayNightMode.values().length];
            for (int i = 0; i < items.length; i++) {
                items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
            }
            int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
            bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
                    refreshMapComplete(activity);
                    dialog.dismiss();
                    activity.getDashboard().refreshContent(true);
                // adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
                // ad.notifyDataSetInvalidated();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_magnifier, activity).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
            final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
            int p = (int) (mapDensity.get() * 100);
            final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
            final List<String> values = new ArrayList<>();
            int i = -1;
            for (int k = 0; k <= tlist.size(); k++) {
                final boolean end = k == tlist.size();
                if (i == -1) {
                    if ((end || p < tlist.get(k))) {
                        values.add(p + " %");
                        i = k;
                    } else if (p == tlist.get(k)) {
                        i = k;
                    }
                }
                if (k < tlist.size()) {
                    values.add(tlist.get(k) + " %");
                }
            }
            if (values.size() != tlist.size()) {
                tlist.insert(i, p);
            }
            bld.setTitle(R.string.map_magnifier);
            bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int p = tlist.get(which);
                    mapDensity.set(p / 100.0f);
                    view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
                    MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
                    if (mapContext != null) {
                        mapContext.updateMapSettings();
                    }
                    adapter.getItem(pos).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
                    ad.notifyDataSetInvalidated();
                    dialog.dismiss();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    ContextMenuItem props;
    props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR);
    if (props != null) {
        adapter.addItem(props);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity).setDescription(getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_text_size).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
            // test old descr as title
            b.setTitle(R.string.text_size);
            final Float[] txtValues = new Float[] { 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;
                }
            }
            b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    view.getSettings().TEXT_SCALE.set(txtValues[which]);
                    refreshMapComplete(activity);
                    adapter.getItem(pos).setDescription(getScale(activity));
                    ad.notifyDataSetInvalidated();
                    dialog.dismiss();
                }
            });
            b.setNegativeButton(R.string.shared_string_dismiss, null);
            b.show();
            return false;
        }
    }).createItem());
    String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
    localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity).setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_language).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            final AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
            b.setTitle(activity.getString(R.string.map_locale));
            final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds, getMapNamesValues(activity, mapNamesIds));
            final String[] txtValues = 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 = selected;
            transliterateNames = view.getSettings().MAP_TRANSLITERATE_NAMES.get();
            final OnCheckedChangeListener translitChangdListener = new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    transliterateNames = isChecked;
                }
            };
            final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(activity, 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 = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
                    if (position == selectedLanguageIndex && 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 = (TextView) v.findViewById(R.id.switchText);
                        switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
                        SwitchCompat check = (SwitchCompat) v.findViewById(R.id.check);
                        check.setChecked(transliterateNames);
                        check.setOnCheckedChangeListener(translitChangdListener);
                    } else {
                        checkedTextView.setChecked(position == selectedLanguageIndex);
                        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 = which;
                    ((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 && transliterateNames);
                    AlertDialog dlg = (AlertDialog) dialog;
                    int index = dlg.getListView().getCheckedItemPosition();
                    view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
                    refreshMapComplete(activity);
                    String localeDescr = txtIds[index];
                    localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
                    adapter.getItem(pos).setDescription(localeDescr);
                    ad.notifyDataSetInvalidated();
                }
            });
            b.show();
            return false;
        }
    }).createItem());
    props = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark, "transport", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers_dark, "details", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    List<RenderingRuleProperty> customRulesIncluded = new ArrayList<>();
    for (RenderingRuleProperty p : customRules) {
        if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
            customRulesIncluded.add(p);
            break;
        }
    }
    props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes, "routes", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    if (getCustomRenderingPropertiesSize(customRules) > 0) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_others, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
        createCustomRenderingProperties(adapter, activity, customRules);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) NonNull(android.support.annotation.NonNull) Iterator(java.util.Iterator) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) TIntArrayList(gnu.trove.list.array.TIntArrayList) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) MapRendererContext(net.osmand.core.android.MapRendererContext) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)14 OsmandSettings (net.osmand.plus.OsmandSettings)8 View (android.view.View)7 ArrayList (java.util.ArrayList)7 ArrayAdapter (android.widget.ArrayAdapter)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)6 ContextMenuItem (net.osmand.plus.ContextMenuItem)6 CommonPreference (net.osmand.plus.OsmandSettings.CommonPreference)6 RenderingRulesStorage (net.osmand.render.RenderingRulesStorage)6 AdapterView (android.widget.AdapterView)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)4 ListView (android.widget.ListView)4 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 SwitchCompat (android.support.v7.widget.SwitchCompat)3