Search in sources :

Example 16 with ContextMenuAdapter

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

the class GpxUiHelper method selectGPXFiles.

public static AlertDialog selectGPXFiles(List<String> selectedGpxList, final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject) {
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(dir, selectedGpxList, false);
    if (allGpxList.isEmpty()) {
        Toast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
    }
    allGpxList.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0));
    final ContextMenuAdapter adapter = createGpxContextMenuAdapter(allGpxList, selectedGpxList, true);
    return createDialog(activity, true, true, true, callbackWithObject, allGpxList, adapter);
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 17 with ContextMenuAdapter

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

the class GpxUiHelper method selectGPXFile.

public static AlertDialog selectGPXFile(final Activity activity, final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject) {
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    final List<GPXInfo> list = getSortedGPXFilesInfo(dir, null, false);
    if (list.isEmpty()) {
        Toast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
    }
    if (!list.isEmpty() || showCurrentGpx) {
        if (showCurrentGpx) {
            list.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0));
        }
        final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx);
        return createDialog(activity, showCurrentGpx, multipleChoice, false, callbackWithObject, list, adapter);
    }
    return null;
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 18 with ContextMenuAdapter

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

the class LocalIndexesFragment method showContextMenu.

private void showContextMenu(final LocalIndexInfo info) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final ContextMenuAdapter adapter = new ContextMenuAdapter();
    basicFileOperation(info, adapter);
    OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
    String[] values = adapter.getItemNames();
    builder.setItems(values, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ContextMenuItem item = adapter.getItem(which);
            if (item.getItemClickListener() != null) {
                item.getItemClickListener().onContextMenuClick(null, item.getTitleId(), which, false, null);
            }
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface)

Example 19 with ContextMenuAdapter

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

the class MapillaryPlugin 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) {
            if (itemId == R.string.mapillary) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
                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();
            if (itemId == R.string.mapillary) {
                OsmandMapTileView mapView = mapActivity.getMapView();
                MapActivityLayers mapLayers = mapActivity.getMapLayers();
                settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
                updateMapLayers(mapView, mapLayers, false);
                ContextMenuItem item = adapter.getItem(pos);
                if (item != null) {
                    item.setSelected(settings.SHOW_MAPILLARY.get());
                    item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                }
            }
            return false;
        }
    };
    if (rasterLayer.getMap() == null) {
        settings.SHOW_MAPILLARY.set(false);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 20 with ContextMenuAdapter

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

the class RoutePreferencesMenu method selectVoiceGuidance.

public static void selectVoiceGuidance(final MapActivity mapActivity, final CallbackWithObject<String> callback) {
    final ContextMenuAdapter adapter = new ContextMenuAdapter();
    String[] entries;
    final String[] entrieValues;
    Set<String> voiceFiles = getVoiceFiles(mapActivity);
    entries = new String[voiceFiles.size() + 2];
    entrieValues = new String[voiceFiles.size() + 2];
    int k = 0;
    int selected = -1;
    String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get();
    entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
    entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use);
    ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
    adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
    if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(selectedValue)) {
        selected = k;
    }
    k++;
    for (String s : voiceFiles) {
        entries[k] = (s.contains("tts") ? mapActivity.getResources().getString(R.string.ttsvoice) + " " : "") + FileNameTranslationHelper.getVoiceName(mapActivity, s);
        entrieValues[k] = s;
        adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
        if (s.equals(selectedValue)) {
            selected = k;
        }
        k++;
    }
    entrieValues[k] = MORE_VALUE;
    entries[k] = mapActivity.getResources().getString(R.string.install_more);
    adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
    AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
    bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String value = entrieValues[which];
            if (MORE_VALUE.equals(value)) {
                final Intent intent = new Intent(mapActivity, DownloadActivity.class);
                intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
                intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
                mapActivity.startActivity(intent);
            } else {
                if (callback != null) {
                    callback.processResult(value);
                }
            }
            dialog.dismiss();
        }
    });
    bld.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) DownloadActivity(net.osmand.plus.download.DownloadActivity) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter)

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