use of net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem in project Osmand by osmandapp.
the class ItemMenuBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
if (recording != null) {
items.add(new TitleItem(recording.getName(getContext(), true)));
BaseBottomSheetItem playItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(recording.isPhoto() ? R.drawable.ic_action_view : R.drawable.ic_play_dark)).setTitle(getString(recording.isPhoto() ? R.string.watch : R.string.recording_context_menu_play)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.playOnClick(recording);
}
dismiss();
}
}).create();
items.add(playItem);
BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.shareOnClick(recording);
}
dismiss();
}
}).create();
items.add(shareItem);
BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.route_descr_lat_lon, recording.getLatitude(), recording.getLongitude())).setIcon(getContentIcon(R.drawable.ic_show_on_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.showOnMapOnClick(recording);
}
dismiss();
}
}).create();
items.add(showOnMapItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem renameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.shared_string_rename)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.renameOnClick(recording);
}
dismiss();
}
}).create();
items.add(renameItem);
BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_delete_dark)).setTitle(getString(R.string.shared_string_delete)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.deleteOnClick(recording);
}
dismiss();
}
}).create();
items.add(deleteItem);
}
}
use of net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem in project Osmand by osmandapp.
the class MenuBottomSheetDialogFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
createMenuItems(savedInstanceState);
OsmandApplication app = getMyApplication();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null);
if (useScrollableItemsContainer()) {
itemsContainer = (LinearLayout) mainView.findViewById(R.id.scrollable_items_container);
} else {
mainView.findViewById(R.id.scroll_view).setVisibility(View.GONE);
itemsContainer = (LinearLayout) mainView.findViewById(R.id.non_scrollable_items_container);
itemsContainer.setVisibility(View.VISIBLE);
}
for (BaseBottomSheetItem item : items) {
item.inflate(app, itemsContainer, nightMode);
}
int bottomDividerColorId = getBottomDividerColorId();
if (bottomDividerColorId != DEFAULT_VALUE) {
mainView.findViewById(R.id.bottom_row_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId));
}
mainView.findViewById(R.id.dismiss_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onDismissButtonClickAction();
dismiss();
}
});
((TextView) mainView.findViewById(R.id.dismiss_button_text)).setText(getDismissButtonTextId());
int rightBottomButtonTextId = getRightBottomButtonTextId();
if (rightBottomButtonTextId != DEFAULT_VALUE) {
View buttonsDivider = mainView.findViewById(R.id.bottom_buttons_divider);
buttonsDivider.setVisibility(View.VISIBLE);
if (bottomDividerColorId != DEFAULT_VALUE) {
buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId));
}
View rightButton = mainView.findViewById(R.id.right_bottom_button);
rightButton.setVisibility(View.VISIBLE);
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onRightBottomButtonClick();
}
});
((TextView) rightButton.findViewById(R.id.right_bottom_button_text)).setText(rightBottomButtonTextId);
}
setupHeightAndBackground(mainView);
return mainView;
}
use of net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem in project Osmand by osmandapp.
the class EditFavoriteGroupDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
FavouritesDbHelper helper = app.getFavorites();
Bundle args = getArguments();
if (args != null) {
String groupName = args.getString(GROUP_NAME_KEY);
if (groupName != null) {
group = helper.getGroup(groupName);
}
}
if (group == null) {
return;
}
items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.edit_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder b = new AlertDialog.Builder(getContext());
b.setTitle(R.string.favorite_group_name);
final EditText nameEditText = new EditText(getContext());
nameEditText.setText(group.name);
b.setView(nameEditText);
b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = nameEditText.getText().toString();
boolean nameChanged = !Algorithms.objectEquals(group.name, name);
if (nameChanged) {
app.getFavorites().editFavouriteGroup(group, name, group.color, group.visible);
updateParentFragment();
}
dismiss();
}
});
b.show();
}
}).create();
items.add(editNameItem);
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.change_fav_color, null);
((ImageView) changeColorView.findViewById(R.id.change_color_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ListPopupWindow popup = new ListPopupWindow(getActivity());
popup.setAnchorView(changeColorView);
popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
popup.setModal(true);
popup.setDropDownGravity(Gravity.END | Gravity.TOP);
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
popup.setVerticalOffset(AndroidUtils.dpToPx(app, 48f));
} else {
popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
}
popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
popup.setAdapter(colorAdapter);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Integer color = colorAdapter.getItem(position);
if (color != null) {
if (color != group.color) {
app.getFavorites().editFavouriteGroup(group, group.name, color, group.visible);
updateParentFragment();
}
}
popup.dismiss();
dismiss();
}
});
popup.show();
}
}).create();
items.add(changeColorItem);
BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(group.visible).setIcon(getContentIcon(R.drawable.ic_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean visible = !group.visible;
app.getFavorites().editFavouriteGroup(group, group.name, group.color, visible);
updateParentFragment();
dismiss();
}
}).create();
items.add(showOnMapItem);
if (group.points.size() > 0) {
items.add(new DividerHalfItem(getContext()));
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark)).setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (synced) {
markersHelper.removeMarkersGroup(markersGr);
} else {
markersHelper.addOrEnableGroup(markersGr);
}
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}).create();
items.add(markersGroupItem);
BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
if (fragment != null) {
fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
}
dismiss();
}
}).create();
items.add(shareItem);
}
}
use of net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem in project Osmand by osmandapp.
the class OrderByBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
Drawable distanceIcon = getContentIcon(R.drawable.ic_action_markers_dark);
Drawable dateIcon = getContentIcon(R.drawable.ic_action_sort_by_date);
items.add(new TitleItem(getString(R.string.sort_by)));
BaseBottomSheetItem byNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_sort_by_name)).setTitle(getString(R.string.shared_string_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_NAME);
}
dismiss();
}
}).create();
items.add(byNameItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem distNearestItem = new SimpleBottomSheetItem.Builder().setIcon(distanceIcon).setTitle(getString(R.string.distance_nearest)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_ASC);
}
dismiss();
}
}).create();
items.add(distNearestItem);
BaseBottomSheetItem distFarthestItem = new SimpleBottomSheetItem.Builder().setIcon(distanceIcon).setTitle(getString(R.string.distance_farthest)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_DESC);
}
dismiss();
}
}).create();
items.add(distFarthestItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem dateAscItem = new SimpleBottomSheetItem.Builder().setIcon(dateIcon).setTitle(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")").setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_ASC);
}
dismiss();
}
}).create();
items.add(dateAscItem);
BaseBottomSheetItem dateDescItem = new SimpleBottomSheetItem.Builder().setIcon(dateIcon).setTitle(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")").setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_DESC);
}
dismiss();
}
}).create();
items.add(dateDescItem);
}
use of net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem in project Osmand by osmandapp.
the class CoordinateInputBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
final OsmandSettings settings = getMyApplication().getSettings();
items.add(new TitleItem(getString(R.string.shared_string_options)));
boolean useOsmandKeyboard = settings.COORDS_INPUT_USE_OSMAND_KEYBOARD.get();
BaseBottomSheetItem useSystemKeyboardItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(!useOsmandKeyboard).setIcon(getContentIcon(R.drawable.ic_action_keyboard)).setTitle(getString(R.string.use_system_keyboard)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onKeyboardChanged();
}
dismiss();
}
}).create();
items.add(useSystemKeyboardItem);
boolean useTwoDigitsLogtitude = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get();
BaseBottomSheetItem twoDigitsLongtitudeItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(useTwoDigitsLogtitude).setIcon(getContentIcon(R.drawable.ic_action_next_field_stroke)).setTitle(getString(R.string.use_two_digits_longitude)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
pref.set(!pref.get());
listener.onInputSettingsChanged();
}
dismiss();
}
}).create();
items.add(twoDigitsLongtitudeItem);
if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get();
BaseBottomSheetItem showNumberPadItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(rightHand ? R.string.shared_string_right : R.string.shared_string_left)).setDescriptionColorId(getActiveColorId()).setIcon(getContentIcon(rightHand ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)).setTitle(getString(R.string.show_number_pad)).setLayoutId(R.layout.bottom_sheet_item_with_right_descr).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_USE_RIGHT_SIDE;
pref.set(!pref.get());
listener.onHandChanged();
}
dismiss();
}
}).create();
items.add(showNumberPadItem);
}
items.add(new SubtitleDividerItem(context));
items.add(new SubtitleItem(getString(R.string.coordinates_format)));
int selectedFormat = settings.COORDS_INPUT_FORMAT.get();
Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude);
View.OnClickListener formatsOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int format = (int) v.getTag();
settings.COORDS_INPUT_FORMAT.set(format);
if (listener != null) {
listener.onInputSettingsChanged();
}
dismiss();
}
};
for (@CoordinateInputFormatDef int format : CoordinateInputFormats.VALUES) {
boolean selectedItem = format == selectedFormat;
BaseBottomSheetItem formatItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(selectedItem).setButtonTintList(selectedItem ? ColorStateList.valueOf(getResolvedColor(getActiveColorId())) : null).setIcon(selectedItem ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon).setTitle(CoordinateInputFormats.formatToHumanString(context, format)).setTitleColorId(selectedItem ? getActiveColorId() : BaseBottomSheetItem.INVALID_ID).setLayoutId(R.layout.bottom_sheet_item_with_radio_btn).setOnClickListener(formatsOnClickListener).setTag(format).create();
items.add(formatItem);
}
}
Aggregations