use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class VehicleParametersBottomSheet method createBottomSheetItem.
@SuppressLint("ClickableViewAccessibility")
private BaseBottomSheetItem createBottomSheetItem(OsmandApplication app) {
final SizePreference preference = (SizePreference) getPreference();
View mainView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_edit_with_chips_view, null);
TextView title = mainView.findViewById(R.id.title);
title.setText(preference.getTitle().toString());
VehicleSizeAssets vehicleSizeAssets = preference.getAssets();
if (vehicleSizeAssets != null) {
ImageView imageView = mainView.findViewById(R.id.image_view);
imageView.setImageDrawable(app.getUIUtilities().getIcon(!nightMode ? vehicleSizeAssets.getDayIconId() : vehicleSizeAssets.getNightIconId()));
TextView description = mainView.findViewById(R.id.description);
description.setText(app.getString(vehicleSizeAssets.getDescriptionRes()));
}
final HorizontalChipsView chipsView = mainView.findViewById(R.id.chips_view);
final TextView metric = mainView.findViewById(R.id.metric);
metric.setText(app.getString(preference.getAssets().getMetricRes()));
final DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.US));
text = mainView.findViewById(R.id.text_edit);
try {
currentValue = Float.parseFloat(preference.getValue());
} catch (NumberFormatException e) {
currentValue = 0.0f;
}
selectedItem = preference.getEntryFromValue(preference.getValue());
String currentValueStr = currentValue == 0.0f ? "" : df.format(currentValue + 0.01f);
text.setText(currentValueStr);
text.clearFocus();
text.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
text.onTouchEvent(event);
text.setSelection(text.getText().length());
return true;
}
});
text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!Algorithms.isEmpty(s)) {
try {
currentValue = Float.parseFloat(s.toString()) - 0.01f;
} catch (NumberFormatException e) {
currentValue = 0.0f;
}
} else {
currentValue = 0.0f;
}
selectedItem = preference.getEntryFromValue(String.valueOf(currentValue));
ChipItem selected = chipsView.getChipById(selectedItem);
chipsView.setSelected(selected);
chipsView.smoothScrollTo(selected);
}
});
List<ChipItem> chips = new ArrayList<>();
for (String entry : preference.getEntries()) {
ChipItem chip = new ChipItem(entry);
chip.title = entry;
chips.add(chip);
}
chipsView.setItems(chips);
chipsView.setOnSelectChipListener(chip -> {
selectedItem = chip.id;
currentValue = preference.getValueFromEntries(selectedItem);
String currentValueStr1 = currentValue == 0.0f ? "" : df.format(currentValue + 0.01f);
text.setText(currentValueStr1);
if (text.hasFocus()) {
text.setSelection(text.getText().length());
}
return true;
});
ChipItem selected = chipsView.getChipById(selectedItem);
chipsView.setSelected(selected);
return new BaseBottomSheetItem.Builder().setCustomView(mainView).create();
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class OnlineRoutingCard method setSelectionMenu.
public void setSelectionMenu(@NonNull List<ChipItem> items, @NonNull String selectedId, @NonNull final CallbackWithObject<ChipItem> callback) {
showElements(chipsView);
chipsView.setItems(items);
ChipItem selected = chipsView.getChipById(selectedId);
chipsView.setSelected(selected);
chipsView.setOnSelectChipListener(chip -> {
chipsView.smoothScrollTo(chip);
callback.processResult(chip);
return true;
});
chipsView.notifyDataSetChanged();
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class TracksToFollowCard method createCategoriesChipsView.
private HorizontalChipsView createCategoriesChipsView() {
LayoutInflater inflater = UiUtilities.getInflater(activity, nightMode);
View view = inflater.inflate(R.layout.gpx_track_select_category_item, null, false);
HorizontalChipsView chipsView = view.findViewById(R.id.track_categories);
List<ChipItem> items = new ArrayList<>();
for (String title : gpxInfoCategories.keySet()) {
ChipItem item = new ChipItem(title);
item.title = title;
}
chipsView.setItems(items);
ChipItem selected = chipsView.getChipById(selectedCategory);
chipsView.setSelected(selected);
chipsView.setOnSelectChipListener(chip -> {
chipsView.smoothScrollTo(chip);
selectedCategory = chip.title;
tracksAdapter.setShowFolderName(showFoldersName());
updateTracksAdapter();
return true;
});
return chipsView;
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method setupExampleCard.
private void setupExampleCard() {
exampleCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode);
exampleCard.build(mapActivity);
exampleCard.setHeaderTitle(getString(R.string.shared_string_example));
exampleCard.hideFieldBoxLabel();
List<ChipItem> locationItems = new ArrayList<>();
for (ExampleLocation location : ExampleLocation.values()) {
String title = location.getName();
ChipItem item = new ChipItem(title);
item.title = title;
item.tag = location;
locationItems.add(item);
}
exampleCard.setSelectionMenu(locationItems, selectedLocation.getName(), result -> {
ExampleLocation location = (ExampleLocation) result.tag;
if (selectedLocation != location) {
selectedLocation = location;
updateCardViews(exampleCard);
return true;
}
return false;
});
exampleCard.setDescription(getString(R.string.online_routing_example_hint));
exampleCard.showFieldBox();
exampleCard.setButton(getString(R.string.test_route_calculation), v -> testEngineWork());
segmentsContainer.addView(exampleCard.getView());
}
use of net.osmand.plus.widgets.chips.ChipItem in project Osmand by osmandapp.
the class PointsGroupsCard method updateContent.
@Override
protected void updateContent() {
HorizontalChipsView chipsView = view.findViewById(R.id.chips_view);
ArrayList<ChipItem> items = new ArrayList<>();
ChipItem categoryAll = new ChipItem(app.getString(R.string.shared_string_all));
categoryAll.title = categoryAll.id;
items.add(categoryAll);
int iconSizePx = getDimen(R.dimen.poi_icon_size);
int iconColorId = ColorUtilities.getSecondaryIconColorId(nightMode);
int smallPadding = getDimen(R.dimen.content_padding_small);
for (GpxDisplayGroup group : displayGroups) {
String categoryDisplayName = Algorithms.isEmpty(group.getName()) ? app.getString(R.string.shared_string_gpx_points) : group.getName();
ChipItem item = new ChipItem(categoryDisplayName);
item.title = categoryDisplayName;
item.tag = group;
item.onAfterViewBoundCallback = (chip, holder) -> {
if (selectedGpxFile.isGroupHidden(chip.id)) {
Drawable image = getColoredIcon(R.drawable.ic_action_hide_16, iconColorId);
holder.image.setImageDrawable(image);
holder.image.setVisibility(View.VISIBLE);
LayoutParams imgLayoutParams = holder.image.getLayoutParams();
imgLayoutParams.height = iconSizePx;
imgLayoutParams.width = iconSizePx;
int top = holder.container.getPaddingTop();
int bottom = holder.container.getPaddingBottom();
holder.container.setPadding(smallPadding, top, smallPadding, bottom);
}
};
items.add(item);
}
chipsView.setItems(items);
String selectedId = categoryAll.id;
if (selectedGroup != null) {
selectedId = selectedGroup.getName();
if (Algorithms.isEmpty(selectedId)) {
selectedId = app.getString(R.string.shared_string_gpx_points);
}
}
ChipItem selected = chipsView.getChipById(selectedId);
chipsView.setSelected(selected);
chipsView.setOnSelectChipListener(chip -> {
selectedGroup = (GpxDisplayGroup) chip.tag;
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(PointsGroupsCard.this, SELECT_GROUP_INDEX);
}
chipsView.smoothScrollTo(chip);
return true;
});
chipsView.notifyDataSetChanged();
}
Aggregations