use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class GpxUiHelper method setDescripionInDialog.
private static void setDescripionInDialog(final ArrayAdapter<?> adapter, final ContextMenuAdapter cmAdapter, Activity activity, final File dir, String filename, final int position) {
final Application app = activity.getApplication();
final File f = new File(dir, filename);
loadGPXFileInDifferentThread(activity, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
ContextMenuItem item = cmAdapter.getItem(position);
item.setTitle(item.getTitle() + "\n" + getDescription((OsmandApplication) app, result[0], f, false));
adapter.notifyDataSetInvalidated();
return true;
}
}, dir, null, filename);
}
use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.
the class GpxUiHelper method createSingleChoiceDialog.
private static AlertDialog createSingleChoiceDialog(final Activity activity, final boolean showCurrentGpx, final CallbackWithObject<GPXFile[]> callbackWithObject, final List<GPXInfo> list, final ContextMenuAdapter adapter) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final IconsCache iconsCache = app.getIconsCache();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.text1, adapter.getItemNames()) {
@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 = activity.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
Drawable icon;
if (showCurrentGpx && position == 0) {
icon = null;
} else {
icon = iconsCache.getThemedIcon(item.getIcon());
}
tv.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity, 10f));
tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
return v;
}
};
int selectedIndex = 0;
String prevSelectedGpx = app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.get();
if (prevSelectedGpx != null) {
selectedIndex = list.indexOf(prevSelectedGpx);
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(R.string.select_gpx).setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position != -1) {
if (showCurrentGpx && position == 0) {
callbackWithObject.processResult(null);
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
} else {
String fileName = list.get(position).getFileName();
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(fileName);
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
if (selectedGpxFile != null) {
callbackWithObject.processResult(new GPXFile[] { selectedGpxFile.getGpxFile() });
} else {
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
}
}
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
final AlertDialog dlg = builder.create();
dlg.setCanceledOnTouchOutside(false);
dlg.show();
try {
dlg.getListView().setFastScrollEnabled(true);
} catch (Exception e) {
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
// Unknown reason but on some devices fail
}
return dlg;
}
use of net.osmand.plus.ContextMenuItem 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.ContextMenuItem in project Osmand by osmandapp.
the class AdditionalActionsBottomSheetDialogFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Activity activity = getActivity();
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(activity);
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
availableScreenH = AndroidUtils.getScreenHeight(activity) - AndroidUtils.getStatusBarHeight(activity);
if (portrait) {
availableScreenH -= AndroidUtils.getNavBarHeight(activity);
}
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null);
scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view);
cancelRowBgView = mainView.findViewById(R.id.cancel_row_background);
updateBackground(false);
cancelRowBgView.setBackgroundResource(getCancelRowBgResId());
mainView.findViewById(R.id.divider).setBackgroundResource(nightMode ? R.color.route_info_bottom_view_bg_dark : R.color.route_info_divider_light);
View.OnClickListener dismissOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
};
mainView.findViewById(R.id.cancel_row).setOnClickListener(dismissOnClickListener);
mainView.findViewById(R.id.scroll_view_container).setOnClickListener(dismissOnClickListener);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onItemClick((int) view.getTag());
}
dismiss();
}
};
LinearLayout itemsLinearLayout = (LinearLayout) mainView.findViewById(R.id.context_menu_items_container);
LinearLayout row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
int itemsAdded = 0;
for (int i = 0; i < adapter.length(); i++) {
ContextMenuItem item = adapter.getItem(i);
View menuItem = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.grid_menu_item, null);
if (item.getIcon() != ContextMenuItem.INVALID_ID) {
((ImageView) menuItem.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon()));
}
((TextView) menuItem.findViewById(R.id.title)).setText(item.getTitle());
if (item.isClickable()) {
menuItem.setTag(i);
menuItem.setOnClickListener(onClickListener);
} else {
menuItem.setEnabled(false);
menuItem.setAlpha(.5f);
}
((FrameLayout) row.findViewById(getMenuItemContainerId(itemsAdded))).addView(menuItem);
itemsAdded++;
if (itemsAdded == 3 || (i == adapter.length() - 1 && itemsAdded > 0)) {
itemsLinearLayout.addView(row);
row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
itemsAdded = 0;
}
}
final ExtendedBottomSheetBehavior behavior = ExtendedBottomSheetBehavior.from(scrollView);
behavior.setBottomSheetCallback(new BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == ExtendedBottomSheetBehavior.STATE_HIDDEN) {
dismiss();
} else {
updateBackground(newState == ExtendedBottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
if (portrait) {
behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_peek_height));
} else {
getDialog().setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
behavior.setState(ExtendedBottomSheetBehavior.STATE_EXPANDED);
}
});
}
return mainView;
}
use of net.osmand.plus.ContextMenuItem 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());
}
Aggregations