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);
}
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;
}
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();
}
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());
}
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();
}
Aggregations