Search in sources :

Example 6 with ContextMenuItem

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

the class DashboardOnMap method getOptionsMenuOnClickListener.

private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm, final ArrayAdapter<ContextMenuItem> listAdapter) {
    return new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
            ContextMenuItem item = cm.getItem(which);
            ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
            if (click instanceof OnRowItemClick) {
                boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, item.getTitleId(), which);
                if (cl) {
                    hideDashboard();
                }
            } else if (click != null) {
                CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
                if (btn != null && btn.getVisibility() == View.VISIBLE) {
                    btn.setChecked(!btn.isChecked());
                } else {
                    if (click.onContextMenuClick(listAdapter, item.getTitleId(), which, false, null)) {
                        hideDashboard();
                    }
                }
            } else {
                if (!item.isCategory()) {
                    hideDashboard();
                }
            }
        }
    };
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) AdapterView(android.widget.AdapterView) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) ImageView(android.widget.ImageView) DynamicListView(net.osmand.plus.views.controls.DynamicListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ScrollView(android.widget.ScrollView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) CompoundButton(android.widget.CompoundButton)

Example 7 with ContextMenuItem

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

the class DashboardOnMap method onDownloadInProgress.

@SuppressWarnings("unchecked")
public void onDownloadInProgress() {
    if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.HILLSHADE) {
        DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread();
        IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem();
        if (downloadIndexItem != null) {
            int downloadProgress = downloadThread.getCurrentDownloadingItemProgress();
            ArrayAdapter<ContextMenuItem> adapter = (ArrayAdapter<ContextMenuItem>) listAdapter;
            for (int i = 0; i < adapter.getCount(); i++) {
                ContextMenuItem item = adapter.getItem(i);
                if (item != null && item.getProgressListener() != null) {
                    item.getProgressListener().onProgressChanged(downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i);
                }
            }
        }
    }
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) IndexItem(net.osmand.plus.download.IndexItem) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) SuppressLint(android.annotation.SuppressLint) ArrayAdapter(android.widget.ArrayAdapter) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Example 8 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem 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 9 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem 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 10 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem 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)

Aggregations

ContextMenuItem (net.osmand.plus.ContextMenuItem)37 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)27 ArrayAdapter (android.widget.ArrayAdapter)23 View (android.view.View)19 DialogInterface (android.content.DialogInterface)16 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)13 AlertDialog (android.support.v7.app.AlertDialog)12 TextView (android.widget.TextView)11 OsmandApplication (net.osmand.plus.OsmandApplication)11 OsmandSettings (net.osmand.plus.OsmandSettings)11 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)11 AdapterView (android.widget.AdapterView)10 ImageView (android.widget.ImageView)9 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 ListView (android.widget.ListView)6 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)6 Intent (android.content.Intent)5 CompoundButton (android.widget.CompoundButton)5 Drawable (android.graphics.drawable.Drawable)4