use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class SettingsNavigationActivity method onPreferenceClick.
@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == avoidRouting || preference == preferRouting) {
List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
String[] vals = new String[prms.size()];
OsmandPreference[] bls = new OsmandPreference[prms.size()];
for (int i = 0; i < prms.size(); i++) {
RoutingParameter p = prms.get(i);
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
}
showBooleanSettings(vals, bls, preference.getTitle());
return true;
} else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)).setSelected(false).createItem());
if (!settings.AUTO_ZOOM_MAP.get()) {
selectedIndex = 0;
}
i++;
for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
adapter.addItem(ContextMenuItem.createBuilder(getString(autoZoomMap.name)).setSelected(false).createItem());
if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(R.string.auto_zoom_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position == 0) {
settings.AUTO_ZOOM_MAP.set(false);
} else {
settings.AUTO_ZOOM_MAP.set(true);
settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position - 1]);
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == reliefFactorRouting) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
for (RoutingParameter p : reliefFactorParameters) {
adapter.addItem(ContextMenuItem.createBuilder(getRoutinParameterTitle(this, p)).setSelected(false).createItem());
if (isRoutingParameterSelected(settings, am, p)) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' ')))).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position >= 0 && position < reliefFactorParameters.size()) {
for (int i = 0; i < reliefFactorParameters.size(); i++) {
setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position);
}
// mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
// updateParameters();
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == showAlarms) {
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
return true;
} else if (preference == speakAlarms) {
AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.announce_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.speak_poi) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, settings.SPEAK_PEDESTRIAN, settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA, settings.ANNOUNCE_WPT, settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI }, preference.getTitle());
final boolean initialSpeedCam = settings.SPEAK_SPEED_CAMERA.get();
final boolean initialFavorites = settings.ANNOUNCE_NEARBY_FAVORITES.get();
final boolean initialPOI = settings.ANNOUNCE_NEARBY_POI.get();
// final boolean initialWpt = settings.ANNOUNCE_WPT.get();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (settings.ANNOUNCE_NEARBY_POI.get() != initialPOI) {
settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
}
if (settings.ANNOUNCE_NEARBY_FAVORITES.get() != initialFavorites) {
settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
}
if (settings.ANNOUNCE_WPT.get()) {
settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
}
if (!initialSpeedCam) {
if (settings.SPEAK_SPEED_CAMERA.get()) {
settings.SPEAK_SPEED_CAMERA.set(false);
confirmSpeedCamerasDlg();
}
}
}
});
return true;
}
return false;
}
use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class MapActivityActions method contextMenuPoint.
public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) {
final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter;
ItemBuilder itemBuilder = new ItemBuilder();
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity).setIcon(R.drawable.ic_action_route_direction_from_here).setOrder(DIRECTIONS_FROM_ITEM_ORDER).createItem());
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity).setIcon(R.drawable.ic_action_search_dark).setOrder(SEARCH_NEAR_ITEM_ORDER).createItem());
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
if (resId == R.string.context_menu_item_add_waypoint) {
mapActivity.getContextMenu().addWptPt();
} else if (resId == R.string.context_menu_item_edit_waypoint) {
mapActivity.getContextMenu().editWptPt();
}
return true;
}
};
if (selectedObj instanceof WptPt && getMyApplication().getSelectedGpxHelper().getSelectedGPXFile((WptPt) selectedObj) != null) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(EDIT_GPX_WAYPOINT_ITEM_ORDER).setListener(listener).createItem());
} else if (!getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles().isEmpty() || (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null)) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_add_waypoint, mapActivity).setIcon(R.drawable.ic_action_gnew_label_dark).setOrder(ADD_GPX_WAYPOINT_ITEM_ORDER).setListener(listener).createItem());
}
adapter.sortItemsByOrder();
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {
@Override
public void onItemClick(int position) {
ContextMenuItem item = adapter.getItem(position);
int standardId = item.getTitleId();
ItemClickListener click = item.getItemClickListener();
if (click != null) {
click.onContextMenuClick(listAdapter, standardId, position, false, null);
} else if (standardId == R.string.context_menu_item_search) {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
mapActivity.getContextMenu().hide();
if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) {
setFirstMapMarkerAsTarget();
}
if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) {
enterRoutePlanningMode(new LatLon(latitude, longitude), mapActivity.getContextMenu().getPointDescription());
} else {
getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude), true, mapActivity.getContextMenu().getPointDescription());
}
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
}
use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class HelpActivity method createSocialItem.
private ContextMenuItem createSocialItem(@StringRes int title, @StringRes int urlRes, @DrawableRes int icon) {
final String url = getString(urlRes);
return new ContextMenuItem.ItemBuilder().setTitle(getString(title)).setDescription(url).setIcon(icon).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return false;
}
}).createItem();
}
use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class MapWidgetRegistry method addControls.
private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
for (final MapWidgetRegInfo r : groupTitle) {
if (!mode.isWidgetAvailable(r.key)) {
continue;
}
final boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
final String desc = mapActivity.getString(R.string.shared_string_collapse);
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder().setIcon(r.getDrawableMenu()).setSelected(selected).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID).setDescription(r.visibleCollapsed(mode) ? desc : null).setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, final View view, final int itemId, final int pos) {
if (r.widget == null) {
setVisibility(adapter, pos, !r.visible(mode), false);
return false;
}
View textWrapper = view.findViewById(R.id.text_wrapper);
IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
MenuInflater inflater = popup.getMenuInflater();
final Menu menu = popup.getMenu();
inflater.inflate(R.menu.widget_visibility_menu, menu);
IconsCache ic = mapActivity.getMyApplication().getIconsCache();
menu.findItem(R.id.action_show).setIcon(ic.getThemedIcon(R.drawable.ic_action_view));
menu.findItem(R.id.action_hide).setIcon(ic.getThemedIcon(R.drawable.ic_action_hide));
menu.findItem(R.id.action_collapse).setIcon(ic.getThemedIcon(R.drawable.ic_action_widget_collapse));
final int[] menuIconIds = r.getDrawableMenuIds();
final int[] menuTitleIds = r.getMessageIds();
final int[] menuItemIds = r.getItemIds();
int checkedId = r.getItemId();
boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
if (menuIconIds != null && menuTitleIds != null && menuItemIds != null && menuIconIds.length == menuTitleIds.length && menuIconIds.length == menuItemIds.length) {
for (int i = 0; i < menuIconIds.length; i++) {
int iconId = menuIconIds[i];
int titleId = menuTitleIds[i];
int id = menuItemIds[i];
MenuItem menuItem = menu.add(R.id.single_selection_group, id, i, titleId).setChecked(id == checkedId);
menuItem.setIcon(menuItem.isChecked() && selected ? ic.getIcon(iconId, R.color.osmand_orange) : ic.getThemedIcon(iconId));
}
menu.setGroupCheckable(R.id.single_selection_group, true, true);
menu.setGroupVisible(R.id.single_selection_group, true);
}
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.action_show:
setVisibility(adapter, pos, true, false);
return true;
case R.id.action_hide:
setVisibility(adapter, pos, false, false);
return true;
case R.id.action_collapse:
setVisibility(adapter, pos, true, true);
return true;
default:
if (menuItemIds != null) {
for (int menuItemId : menuItemIds) {
if (menuItem.getItemId() == menuItemId) {
r.changeState(menuItemId);
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
ContextMenuItem item = adapter.getItem(pos);
item.setIcon(r.getDrawableMenu());
if (r.getMessage() != null) {
item.setTitle(r.getMessage());
} else {
item.setTitle(mapActivity.getResources().getString(r.getMessageId()));
}
adapter.notifyDataSetChanged();
return true;
}
}
}
}
return false;
}
});
popup.show();
return false;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
setVisibility(a, pos, isChecked, false);
return false;
}
private void setVisibility(ArrayAdapter<ContextMenuItem> adapter, int position, boolean visible, boolean collapsed) {
MapWidgetRegistry.this.setVisibility(r, visible, collapsed);
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
ContextMenuItem item = adapter.getItem(position);
item.setSelected(visible);
item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(visible && collapsed ? desc : null);
adapter.notifyDataSetChanged();
}
});
if (r.getMessage() != null) {
itemBuilder.setTitle(r.getMessage());
} else {
itemBuilder.setTitleId(r.getMessageId(), mapActivity);
}
contextMenuAdapter.addItem(itemBuilder.createItem());
}
}
use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class ContourLinesMenu method createLayersItems.
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR);
if (plugin == null || contourLinesProp == null || colorSchemeProp == null) {
return;
}
final String contourWidthName;
final String contourDensityName;
final OsmandSettings.CommonPreference<String> widthPref;
final OsmandSettings.CommonPreference<String> densityPref;
final RenderingRuleProperty contourWidthProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_WIDTH_ATTR);
if (contourWidthProp != null) {
contourWidthName = SettingsActivity.getStringPropertyName(app, contourWidthProp.getAttrName(), contourWidthProp.getName());
widthPref = settings.getCustomRenderProperty(contourWidthProp.getAttrName());
} else {
contourWidthName = null;
widthPref = null;
}
final RenderingRuleProperty contourDensityProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_DENSITY_ATTR);
if (contourDensityProp != null) {
contourDensityName = SettingsActivity.getStringPropertyName(app, contourDensityProp.getAttrName(), contourDensityProp.getName());
densityPref = settings.getCustomRenderProperty(contourDensityProp.getAttrName());
} else {
contourDensityName = null;
densityPref = null;
}
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
final int showZoomLevelStringId = R.string.show_from_zoom_level;
final int colorSchemeStringId = R.string.srtm_color_scheme;
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
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.toggleContourLines(mapActivity, isChecked, new Runnable() {
@Override
public void run() {
mapActivity.getDashboard().refreshContent(true);
SRTMPlugin.refreshMapComplete(mapActivity);
}
});
}
});
} else if (itemId == showZoomLevelStringId) {
plugin.selectPropertyValue(mapActivity, contourLinesProp, pref, new Runnable() {
@Override
public void run() {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(plugin.getPrefDescription(app, contourLinesProp, pref));
adapter.notifyDataSetChanged();
}
SRTMPlugin.refreshMapComplete(mapActivity);
}
});
} else if (itemId == colorSchemeStringId) {
plugin.selectPropertyValue(mapActivity, colorSchemeProp, colorPref, new Runnable() {
@Override
public void run() {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref));
adapter.notifyDataSetChanged();
}
SRTMPlugin.refreshMapComplete(mapActivity);
}
});
} else if (itemId == R.string.srtm_plugin_name) {
Intent intent = new Intent(mapActivity, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
mapActivity.startActivity(intent);
closeDashboard(mapActivity);
} else if (contourWidthProp != null && itemId == contourWidthName.hashCode()) {
plugin.selectPropertyValue(mapActivity, contourWidthProp, widthPref, new Runnable() {
@Override
public void run() {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(plugin.getPrefDescription(app, contourWidthProp, widthPref));
adapter.notifyDataSetChanged();
}
SRTMPlugin.refreshMapComplete(mapActivity);
}
});
} else if (contourDensityProp != null && itemId == contourDensityName.hashCode()) {
plugin.selectPropertyValue(mapActivity, contourDensityProp, densityPref, new Runnable() {
@Override
public void run() {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(plugin.getPrefDescription(app, contourDensityProp, densityPref));
adapter.notifyDataSetChanged();
}
SRTMPlugin.refreshMapComplete(mapActivity);
}
});
}
return false;
}
};
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
int toggleIconColorId;
int toggleIconId;
if (selected) {
toggleIconId = R.drawable.ic_action_view;
toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
} else {
toggleIconId = R.drawable.ic_action_hide;
toggleIconColorId = nightMode ? 0 : R.color.icon_color;
}
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).setIcon(toggleIconId).setColor(toggleIconColorId).setListener(l).setSelected(selected).createItem());
if (selected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(showZoomLevelStringId, mapActivity).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setDescription(plugin.getPrefDescription(app, contourLinesProp, pref)).setListener(l).createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(colorSchemeStringId, mapActivity).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_appearance).setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref)).setListener(l).createItem());
if (contourWidthProp != null) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitle(contourWidthName).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_gpx_width_thin).setDescription(plugin.getPrefDescription(app, contourWidthProp, widthPref)).setListener(l).createItem());
}
if (contourDensityProp != null) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitle(contourDensityName).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_plugin_srtm).setDescription(plugin.getPrefDescription(app, contourDensityProp, densityPref)).setListener(l).createItem());
}
}
if (!srtmEnabled) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.srtm_purchase_header, mapActivity).setCategory(true).setLayout(R.layout.list_group_title_with_switch_light).createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.srtm_plugin_name, mapActivity).setLayout(R.layout.list_item_icon_and_right_btn).setIcon(R.drawable.ic_plugin_srtm).setColor(R.color.osmand_orange).setDescription(app.getString(R.string.shared_string_plugin)).setListener(l).createItem());
} else {
final DownloadIndexesThread downloadThread = app.getDownloadThread();
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
if (settings.isInternetConnectionAvailable()) {
downloadThread.runReloadIndexFiles();
}
}
final boolean downloadIndexes = settings.isInternetConnectionAvailable() && !downloadThread.getIndexes().isDownloadedFromInternet && !downloadThread.getIndexes().downloadFromInternetFailed;
if (downloadIndexes) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setDescription(app.getString(R.string.srtm_menu_download_descr)).setCategory(true).setLayout(R.layout.list_group_title_with_descr).createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setLayout(R.layout.list_item_icon_and_download).setTitleId(R.string.downloading_list_indexes, mapActivity).setLoading(true).setListener(l).createItem());
} else {
try {
IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem();
int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress();
List<IndexItem> srtms = DownloadResources.findIndexItemsAt(app, mapActivity.getMapLocation(), DownloadActivityType.SRTM_COUNTRY_FILE);
if (srtms.size() > 0) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setDescription(app.getString(R.string.srtm_menu_download_descr)).setCategory(true).setLayout(R.layout.list_group_title_with_descr).createItem());
for (final IndexItem indexItem : srtms) {
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder().setLayout(R.layout.list_item_icon_and_download).setTitle(indexItem.getVisibleName(app, app.getRegions(), false)).setDescription(DownloadActivityType.SRTM_COUNTRY_FILE.getString(app) + " • " + indexItem.getSizeDescription(app)).setIcon(DownloadActivityType.SRTM_COUNTRY_FILE.getIconResource()).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
ContextMenuItem item = adapter.getItem(position);
if (downloadThread.isDownloading(indexItem)) {
downloadThread.cancelDownload(indexItem);
if (item != null) {
item.setProgress(ContextMenuItem.INVALID_ID);
item.setLoading(false);
item.setSecondaryIcon(R.drawable.ic_action_import);
adapter.notifyDataSetChanged();
}
} else {
new DownloadValidationManager(app).startDownload(mapActivity, indexItem);
if (item != null) {
item.setProgress(ContextMenuItem.INVALID_ID);
item.setLoading(true);
item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
adapter.notifyDataSetChanged();
}
}
return false;
}
}).setProgressListener(new ContextMenuAdapter.ProgressListener() {
@Override
public boolean onProgressChanged(Object progressObject, int progress, ArrayAdapter<ContextMenuItem> adapter, int itemId, int position) {
if (progressObject != null && progressObject instanceof IndexItem) {
IndexItem progressItem = (IndexItem) progressObject;
if (indexItem.compareTo(progressItem) == 0) {
ContextMenuItem item = adapter.getItem(position);
if (item != null) {
item.setProgress(progress);
item.setLoading(true);
item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
adapter.notifyDataSetChanged();
}
return true;
}
}
return false;
}
});
if (indexItem == currentDownloadingItem) {
itemBuilder.setLoading(true).setProgress(currentDownloadingProgress).setSecondaryIcon(R.drawable.ic_action_remove_dark);
} else {
itemBuilder.setSecondaryIcon(R.drawable.ic_action_import);
}
contextMenuAdapter.addItem(itemBuilder.createItem());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Aggregations