Search in sources :

Example 1 with ChipItem

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();
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SizePreference(net.osmand.plus.settings.preferences.SizePreference) ImageView(android.widget.ImageView) View(android.view.View) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) ChipItem(net.osmand.plus.widgets.chips.ChipItem) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SuppressLint(android.annotation.SuppressLint)

Example 2 with ChipItem

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();
}
Also used : ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Example 3 with ChipItem

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;
}
Also used : HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Example 4 with ChipItem

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());
}
Also used : ArrayList(java.util.ArrayList) ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Example 5 with ChipItem

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();
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) LayoutParams(android.view.ViewGroup.LayoutParams) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Aggregations

ChipItem (net.osmand.plus.widgets.chips.ChipItem)12 ArrayList (java.util.ArrayList)11 HorizontalChipsView (net.osmand.plus.widgets.chips.HorizontalChipsView)6 View (android.view.View)4 SuppressLint (android.annotation.SuppressLint)3 TextView (android.widget.TextView)3 Drawable (android.graphics.drawable.Drawable)2 LayoutInflater (android.view.LayoutInflater)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 Context (android.content.Context)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ScrollView (android.widget.ScrollView)1 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)1