Search in sources :

Example 6 with ContextMenuAdapter

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

the class DashboardOnMap method updateListAdapter.

private void updateListAdapter() {
    listEmptyTextView.setVisibility(View.GONE);
    listView.setEmptyView(null);
    ContextMenuAdapter cm = null;
    if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
        StableArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, DashboardType.WAYPOINTS_FLAT == visibleType, nightMode);
        OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, listAdapter);
        setDynamicListItems(listView, listAdapter);
        updateListAdapter(listAdapter, listener);
        if (listAdapter.getObjects().size() == 0) {
            listEmptyTextView.setText(mapActivity.getString(R.string.no_waypoints_found));
            if (landscape) {
                listView.setEmptyView(listEmptyTextView);
            } else {
                listEmptyTextView.setVisibility(View.VISIBLE);
            }
        }
    } else {
        if (visibleType == DashboardType.CONFIGURE_SCREEN) {
            cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
        } else if (visibleType == DashboardType.CONFIGURE_MAP) {
            cm = new ConfigureMapMenu().createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.LIST_MENU) {
            cm = mapActivity.getMapActions().createMainOptionsMenu();
        } else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
            RoutePreferencesMenu routePreferencesMenu = new RoutePreferencesMenu(mapActivity);
            ArrayAdapter<LocalRoutingParameter> listAdapter = routePreferencesMenu.getRoutePreferencesDrawerAdapter(nightMode);
            OnItemClickListener listener = routePreferencesMenu.getItemClickListener(listAdapter);
            updateListAdapter(listAdapter, listener);
        } else if (visibleType == DashboardType.UNDERLAY_MAP) {
            cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.UNDERLAY);
        } else if (visibleType == DashboardType.OVERLAY_MAP) {
            cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.OVERLAY);
        } else if (visibleType == DashboardType.CONTOUR_LINES) {
            cm = ContourLinesMenu.createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.HILLSHADE) {
            cm = HillshadeMenu.createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.OSM_NOTES) {
            cm = OsmNotesMenu.createListAdapter(mapActivity);
        }
        if (cm != null) {
            updateListAdapter(cm);
        }
    }
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) ConfigureMapMenu(net.osmand.plus.dialogs.ConfigureMapMenu) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) RoutePreferencesMenu(net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu) ArrayAdapter(android.widget.ArrayAdapter) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter)

Example 7 with ContextMenuAdapter

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

the class ShowHidePoiAction method showSingleChoicePoiFilterDialog.

private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) {
    final PoiFiltersHelper poiFilters = app.getPoiFilters();
    final ContextMenuAdapter adapter = new ContextMenuAdapter();
    final List<PoiUIFilter> list = new ArrayList<>();
    for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
        addFilterToList(adapter, list, f);
    }
    for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
        addFilterToList(adapter, list, f);
    }
    final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String oldTitle = getTitle(filtersAdapter.filters);
            filtersAdapter.addItem(list.get(which));
            if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(activity))) {
                String newTitle = getTitle(filtersAdapter.filters);
                title.setText(newTitle);
            }
        }
    });
    builder.setTitle(R.string.show_poi_over_map);
    builder.setNegativeButton(R.string.shared_string_dismiss, null);
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
            Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect);
            neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
        }
    });
    alertDialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) Button(android.widget.Button)

Example 8 with ContextMenuAdapter

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

the class OsmandRasterMapsPlugin method registerLayerContextMenuActions.

@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            int[] viewCoordinates = AndroidUtils.getCenterViewCoordinates(view);
            if (itemId == R.string.layer_overlay) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP, viewCoordinates);
                return false;
            } else if (itemId == R.string.layer_underlay) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.UNDERLAY_MAP, viewCoordinates);
                return false;
            }
            return true;
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
            switch(itemId) {
                case R.string.layer_overlay:
                    toggleUnderlayState(mapActivity, RasterMapType.OVERLAY, new OnMapSelectedCallback() {

                        @Override
                        public void onMapSelected(boolean canceled) {
                            ContextMenuItem item = adapter.getItem(pos);
                            String overlayMapDescr = settings.MAP_OVERLAY.get();
                            boolean hasOverlayDescription = overlayMapDescr != null;
                            overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
                            item.setDescription(overlayMapDescr);
                            item.setSelected(hasOverlayDescription);
                            item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                            adapter.notifyDataSetChanged();
                        }
                    });
                    return false;
                case R.string.layer_underlay:
                    toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new OnMapSelectedCallback() {

                        @Override
                        public void onMapSelected(boolean canceled) {
                            ContextMenuItem item = adapter.getItem(pos);
                            String underlayMapDescr = settings.MAP_UNDERLAY.get();
                            boolean hasUnderlayDescription = underlayMapDescr != null;
                            underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
                            item.setDescription(underlayMapDescr);
                            item.setSelected(hasUnderlayDescription);
                            item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                            adapter.notifyDataSetChanged();
                            final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
                            hidePolygonsPref.set(hasUnderlayDescription);
                            RasterMapMenu.refreshMapComplete(mapActivity);
                        }
                    });
                    return false;
            }
            return true;
        }
    };
    if (overlayLayer.getMap() == null) {
        settings.MAP_OVERLAY.set(null);
        settings.MAP_OVERLAY_PREVIOUS.set(null);
    }
    if (underlayLayer.getMap() == null) {
        settings.MAP_UNDERLAY.set(null);
        settings.MAP_UNDERLAY_PREVIOUS.set(null);
    }
    String overlayMapDescr = settings.MAP_OVERLAY.get();
    boolean hasOverlayDescription = overlayMapDescr != null;
    overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity).setDescription(overlayMapDescr).setSelected(hasOverlayDescription).setColor(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_top_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(14).createItem());
    String underlayMapDescr = settings.MAP_UNDERLAY.get();
    boolean hasUnderlayDescription = underlayMapDescr != null;
    underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity).setDescription(underlayMapDescr).setSelected(hasUnderlayDescription).setColor(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_bottom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(15).createItem());
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) AdapterView(android.widget.AdapterView) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 9 with ContextMenuAdapter

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

the class ContextMenuLayer method populateObjectContextMenu.

@Override
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
            enterMovingMode(tileBox);
            return true;
        }
    };
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.change_markers_position, activity).setIcon(R.drawable.ic_show_on_map).setOrder(MapActivityActions.CHANGE_POSITION_ITEM_ORDER).setClickable(isObjectMoveable(o)).setListener(listener).createItem());
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) RotatedTileBox(net.osmand.data.RotatedTileBox) ContextMenuItem(net.osmand.plus.ContextMenuItem) ArrayAdapter(android.widget.ArrayAdapter)

Example 10 with ContextMenuAdapter

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

the class MapActivityActions method updateDrawerMenu.

protected void updateDrawerMenu() {
    boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
    if (nightMode) {
        menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_dark));
    } else {
        menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
    }
    menuItemsListView.setDivider(null);
    final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
    contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
    final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, !nightMode);
    menuItemsListView.setAdapter(simpleListAdapter);
    menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mapActivity.dismissCardDialog();
            ContextMenuItem item = contextMenuAdapter.getItem(position);
            ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
            if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(), position, false, AndroidUtils.getCenterViewCoordinates(view))) {
                mapActivity.closeDrawer();
            }
        }
    });
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView)

Aggregations

ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)41 ContextMenuItem (net.osmand.plus.ContextMenuItem)28 ArrayAdapter (android.widget.ArrayAdapter)17 View (android.view.View)15 DialogInterface (android.content.DialogInterface)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 AlertDialog (android.support.v7.app.AlertDialog)11 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)10 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)10 OsmandSettings (net.osmand.plus.OsmandSettings)9 ArrayList (java.util.ArrayList)8 AdapterView (android.widget.AdapterView)7 TextView (android.widget.TextView)7 ListView (android.widget.ListView)6 ImageView (android.widget.ImageView)5 Intent (android.content.Intent)4 Drawable (android.graphics.drawable.Drawable)4 ViewGroup (android.view.ViewGroup)4 CompoundButton (android.widget.CompoundButton)4 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)4