Search in sources :

Example 1 with ContextMenuAdapter

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

the class AudioVideoNotesPlugin method registerMapContextMenuActions.

@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, Object selectedObj) {
    if (isRecording()) {
        return;
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app).setIcon(R.drawable.ic_action_micro_dark).setOrder(TAKE_AUDIO_NOTE_ITEM_ORDER).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            recordAudio(latitude, longitude, mapActivity);
            return true;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app).setIcon(R.drawable.ic_action_video_dark).setOrder(TAKE_VIDEO_NOTE_ITEM_ORDER).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            recordVideo(latitude, longitude, mapActivity, false);
            return true;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app).setIcon(R.drawable.ic_action_photo_dark).setOrder(TAKE_PHOTO_NOTE_ITEM_ORDER).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            takePhoto(latitude, longitude, mapActivity, false, false);
            return true;
        }
    }).createItem());
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint)

Example 2 with ContextMenuAdapter

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

the class ConfigureMapMenu method createListAdapter.

public ContextMenuAdapter createListAdapter(final MapActivity ma) {
    ContextMenuAdapter adapter = new ContextMenuAdapter();
    adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.app_modes_choose, ma).setLayout(R.layout.mode_toggles).createItem());
    adapter.setChangeAppModeListener(new OnClickListener() {

        @Override
        public void onClick() {
            ma.getDashboard().updateListAdapter(createListAdapter(ma));
        }
    });
    RenderingRulesStorage renderer = ma.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
    List<RenderingRuleProperty> customRules = new ArrayList<>();
    boolean hasDepthContours = ma.getMyApplication().getResourceManager().hasDepthContours();
    if (renderer != null) {
        for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
            if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory()) && (hasDepthContours || !p.getAttrName().equals("depthContours"))) {
                customRules.add(p);
            }
        }
    }
    createLayersItems(customRules, adapter, ma);
    createRenderingAttributeItems(customRules, adapter, ma);
    return adapter;
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 3 with ContextMenuAdapter

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

the class ConfigureMapMenu method createRenderingProperty.

private ContextMenuItem createRenderingProperty(final ContextMenuAdapter adapter, final MapActivity activity, @DrawableRes final int icon, final RenderingRuleProperty p) {
    final OsmandMapTileView view = activity.getMapView();
    String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName());
    final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(), p.getAttrName(), p.getName());
    if (p.isBoolean()) {
        final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
        return ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                pref.set(!pref.get());
                refreshMapComplete(activity);
                return false;
            }
        }).setSelected(pref.get()).createItem();
    } else {
        final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName());
        final String descr;
        if (!Algorithms.isEmpty(pref.get())) {
            descr = SettingsActivity.getStringPropertyValue(activity, pref.get());
        } else {
            descr = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
        }
        ContextMenuItem.ItemBuilder builder = ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, final int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
                AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
                // test old descr as title
                b.setTitle(propertyDescr);
                int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
                if (i >= 0) {
                    i++;
                } else if (Algorithms.isEmpty(pref.get())) {
                    i = 0;
                }
                String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
                possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
                for (int j = 0; j < p.getPossibleValues().length; j++) {
                    possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getPossibleValues()[j]);
                }
                b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            pref.set("");
                        } else {
                            pref.set(p.getPossibleValues()[which - 1]);
                        }
                        refreshMapComplete(activity);
                        String description = SettingsActivity.getStringPropertyValue(activity, pref.get());
                        adapter.getItem(pos).setDescription(description);
                        dialog.dismiss();
                    }
                });
                b.setNegativeButton(R.string.shared_string_dismiss, null);
                b.show();
                return false;
            }
        }).setDescription(descr).setLayout(R.layout.list_item_single_line_descrition_narrow);
        if (icon != 0) {
            builder.setIcon(icon);
        }
        return builder.createItem();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 4 with ContextMenuAdapter

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

the class RasterMapMenu method createLayersItems.

private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
    assert plugin != null;
    final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
    final OsmandSettings.CommonPreference<String> mapTypePreference;
    final OsmandSettings.CommonPreference<String> exMapTypePreference;
    final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
    @StringRes final int mapTypeString;
    @StringRes final int mapTypeStringTransparency;
    if (type == RasterMapType.OVERLAY) {
        mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
        mapTypePreference = settings.MAP_OVERLAY;
        exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
        mapTypeString = R.string.map_overlay;
        mapTypeStringTransparency = R.string.overlay_transparency;
    } else if (type == RasterMapType.UNDERLAY) {
        mapTransparencyPreference = settings.MAP_TRANSPARENCY;
        mapTypePreference = settings.MAP_UNDERLAY;
        exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
        mapTypeString = R.string.map_underlay;
        mapTypeStringTransparency = R.string.map_transparency;
    } else {
        throw new RuntimeException("Unexpected raster map type");
    }
    final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
    String mapTypeDescr = mapTypePreference.get();
    final boolean selected = mapTypeDescr != null;
    final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
    final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {

        @Override
        public void onMapSelected(boolean canceled) {
            if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
                hidePolygonsPref.set(true);
                refreshMapComplete(mapActivity);
            } else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
                hidePolygonsPref.set(false);
                refreshMapComplete(mapActivity);
            }
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    final MapActivityLayers mapLayers = mapActivity.getMapLayers();
    ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
            if (itemId == mapTypeString) {
                if (selected) {
                    plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
                }
                return false;
            }
            return super.onRowItemClick(adapter, view, itemId, pos);
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
            if (itemId == toggleActionStringId) {
                app.runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
                        refreshMapComplete(mapActivity);
                    }
                });
            } else if (itemId == R.string.show_polygons) {
                hidePolygonsPref.set(!isChecked);
                refreshMapComplete(mapActivity);
            } else if (itemId == R.string.show_transparency_seekbar) {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
                if (isChecked) {
                    mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
                } else {
                    mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
                }
                mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
            }
            return false;
        }
    };
    mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
    if (selected) {
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
        ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {

            @Override
            public boolean onIntegerValueChangedListener(int newValue) {
                mapTransparencyPreference.set(newValue);
                mapActivity.getMapView().refreshMap();
                return false;
            }
        };
        // android:max="255" in layout is expected
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
        if (type == RasterMapType.UNDERLAY) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
        }
        Boolean transparencySwitchState = isSeekbarVisible(app, type);
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) StringRes(android.support.annotation.StringRes) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) ContextMenuItem(net.osmand.plus.ContextMenuItem) LayerTransparencySeekbarMode(net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) OnMapSelectedCallback(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with ContextMenuAdapter

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

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