Search in sources :

Example 6 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener in project Osmand by osmandapp.

the class AvailableGPXFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    SearchView searchView = new SearchView(getActivity());
    FavoritesActivity.updateSearchView(getActivity(), searchView);
    MenuItemCompat.setActionView(mi, searchView);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            allGpxAdapter.getFilter().filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            allGpxAdapter.getFilter().filter(newText);
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(mi, new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Needed to hide intermediate progress bar after closing action mode
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    hideProgressBar();
                }
            }, 100);
            return true;
        }
    });
    if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
        menu = ((FavoritesActivity) getActivity()).getClearToolbar(true).getMenu();
    } else {
        ((FavoritesActivity) getActivity()).getClearToolbar(false);
    }
    ((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
    // TODO Rewrite without ContextMenuAdapter
    optionsMenuAdapter = new ContextMenuAdapter();
    ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, final int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (itemId == R.string.local_index_mi_reload) {
                reloadTracks();
            } else if (itemId == R.string.shared_string_show_on_map) {
                openShowOnMapMode();
            } else if (itemId == R.string.shared_string_delete) {
                openSelectionMode(itemId, R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_dark, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        doAction(itemId);
                    }
                });
            } else if (itemId == R.string.gpx_add_track) {
                addTrack();
            }
            return true;
        }
    };
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.gpx_add_track, getActivity()).setIcon(R.drawable.ic_action_plus).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity()).setIcon(R.drawable.ic_show_on_map).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getActivity()).setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_reload, getActivity()).setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
    OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter);
    for (int j = 0; j < optionsMenuAdapter.length(); j++) {
        final MenuItem item;
        ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
        item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    onOptionsItemSelected(item);
                    return true;
                }
            });
        }
        if (contextMenuItem.getIcon() != -1) {
            item.setIcon(contextMenuItem.getIcon());
        }
    }
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) Handler(android.os.Handler) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) SearchView(android.support.v7.widget.SearchView) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener in project Osmand by osmandapp.

the class OsmEditingPlugin method optionsMenuFragment.

@Override
public void optionsMenuFragment(final Activity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
    if (fragment instanceof AvailableGPXFragment) {
        final AvailableGPXFragment f = ((AvailableGPXFragment) fragment);
        optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity).setIcon(R.drawable.ic_action_export).setColor(R.color.color_white).setListener(new ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                f.openSelectionMode(R.string.local_index_mi_upload_gpx, R.drawable.ic_action_export, R.drawable.ic_action_export, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<GpxInfo> selectedItems = f.getSelectedItems();
                        sendGPXFiles(activity, f, selectedItems.toArray(new GpxInfo[selectedItems.size()]));
                    }
                });
                return true;
            }
        }).setPosition(5).createItem());
    }
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) List(java.util.List) AvailableGPXFragment(net.osmand.plus.myplaces.AvailableGPXFragment) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener in project Osmand by osmandapp.

the class LocalIndexesFragment method basicFileOperation.

private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
    ItemClickListener listener = new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
            return performBasicOperation(resId, info);
        }
    };
    if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA || info.getType() == LocalIndexType.WIKI_DATA) {
        if (!info.isBackupedData()) {
            adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_backup, getContext()).setListener(listener).setPosition(1).createItem());
        }
    }
    if (info.isBackupedData()) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_restore, getContext()).setListener(listener).setPosition(2).createItem());
    }
    if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA && info.getType() != LocalIndexType.FONT_DATA) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_rename, getContext()).setListener(listener).setPosition(3).createItem());
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getContext()).setListener(listener).setPosition(4).createItem());
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ArrayAdapter(android.widget.ArrayAdapter)

Example 9 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener in project Osmand by osmandapp.

the class LocalIndexesFragment method onCreateOptionsMenu.

@SuppressWarnings("deprecation")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!this.isAdded()) {
        return;
    }
    // Next line throws NPE in some circumstances when called from dashboard and listAdpater=null is not checked for. (Checking !this.isAdded above is not sufficient!)
    if (listAdapter != null && listAdapter.getGroupCount() == 0 && getDownloadActivity().getLocalIndexInfos().size() > 0) {
        for (LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()) {
            listAdapter.addLocalIndexInfo(info);
        }
        listAdapter.sortData();
        getExpandableListView().setAdapter(listAdapter);
        expandAllGroups();
    }
    ActionBar actionBar = getDownloadActivity().getSupportActionBar();
    // hide action bar from downloadindexfragment
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    optionsMenuAdapter = new ContextMenuAdapter();
    ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            localOptionsMenu(itemId);
            return true;
        }
    };
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_reload, getContext()).setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getContext()).setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_backup, getContext()).setListener(listener).createItem());
    optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_restore, getContext()).setListener(listener).createItem());
    // doesn't work correctly
    // int max =  getResources().getInteger(R.integer.abs__max_action_buttons);
    int max = 3;
    SubMenu split = null;
    for (int j = 0; j < optionsMenuAdapter.length(); j++) {
        MenuItem item;
        ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
        if (j + 1 >= max && optionsMenuAdapter.length() > max) {
            if (split == null) {
                split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
                split.setIcon(R.drawable.ic_overflow_menu_white);
                split.getItem();
                MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
            }
            item = split.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        } else {
            item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        }
        if (contextMenuItem.getIcon() != -1) {
            item.setIcon(contextMenuItem.getIcon());
        }
    }
    if (operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED) {
        menu.setGroupVisible(0, true);
    } else {
        menu.setGroupVisible(0, false);
    }
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) ActionBar(android.support.v7.app.ActionBar) ArrayAdapter(android.widget.ArrayAdapter)

Example 10 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener 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

ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)12 ArrayAdapter (android.widget.ArrayAdapter)10 ContextMenuItem (net.osmand.plus.ContextMenuItem)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 DialogInterface (android.content.DialogInterface)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)2 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)2