Search in sources :

Example 1 with HorizontalChipsView

use of net.osmand.plus.widgets.chips.HorizontalChipsView 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 HorizontalChipsView

use of net.osmand.plus.widgets.chips.HorizontalChipsView 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 3 with HorizontalChipsView

use of net.osmand.plus.widgets.chips.HorizontalChipsView 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)

Example 4 with HorizontalChipsView

use of net.osmand.plus.widgets.chips.HorizontalChipsView in project Osmand by osmandapp.

the class IconsCard method setupCategoriesSelector.

@SuppressLint("NotifyDataSetChanged")
private void setupCategoriesSelector() {
    List<ChipItem> items = new ArrayList<>();
    for (String category : iconsCategories.keySet()) {
        ChipItem item = new ChipItem(category);
        if (!category.equals(KEY_LAST_USED_ICONS)) {
            item.title = category;
        }
        items.add(item);
    }
    HorizontalChipsView categorySelector = view.findViewById(R.id.icons_categories_selector);
    categorySelector.setItems(items);
    ChipItem selected = categorySelector.getChipById(selectedIconCategory);
    categorySelector.setSelected(selected);
    categorySelector.setOnSelectChipListener(chip -> {
        selectedIconCategory = chip.id;
        fillIconsSelector();
        reselectIcon(selectedIconId, false);
        categorySelector.notifyDataSetChanged();
        categorySelector.smoothScrollTo(chip);
        return true;
    });
    ChipItem lastUsedCategory = categorySelector.getChipById(KEY_LAST_USED_ICONS);
    if (lastUsedCategory != null) {
        lastUsedCategory.icon = getIcon(R.drawable.ic_action_history);
        lastUsedCategory.iconColor = ColorUtilities.getActiveColor(app, nightMode);
    }
    categorySelector.notifyDataSetChanged();
    categorySelector.scrollTo(selected);
}
Also used : HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) ArrayList(java.util.ArrayList) ChipItem(net.osmand.plus.widgets.chips.ChipItem) SuppressLint(android.annotation.SuppressLint)

Example 5 with HorizontalChipsView

use of net.osmand.plus.widgets.chips.HorizontalChipsView in project Osmand by osmandapp.

the class SendGpxBottomSheetFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    OsmandApplication app = requiredMyApplication();
    plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
    View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
    sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
    if (selectedUploadVisibility == null) {
        selectedUploadVisibility = plugin.OSM_UPLOAD_VISIBILITY.get();
    }
    tagsField = sendGpxView.findViewById(R.id.tags_field);
    messageField = sendGpxView.findViewById(R.id.message_field);
    TextView accountName = sendGpxView.findViewById(R.id.user_name);
    if (!Algorithms.isEmpty(plugin.OSM_USER_DISPLAY_NAME.get())) {
        accountName.setText(plugin.OSM_USER_DISPLAY_NAME.get());
    } else {
        accountName.setText(plugin.OSM_USER_NAME_OR_EMAIL.get());
    }
    final TextView visibilityName = sendGpxView.findViewById(R.id.visibility_name);
    final TextView visibilityDescription = sendGpxView.findViewById(R.id.visibility_description);
    visibilityName.setText(selectedUploadVisibility.getTitleId());
    visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
    List<ChipItem> itemsVisibility = new ArrayList<>();
    for (UploadVisibility visibilityType : UploadVisibility.values()) {
        String title = getString(visibilityType.getTitleId());
        ChipItem item = new ChipItem(title);
        item.title = title;
        item.tag = visibilityType;
        itemsVisibility.add(item);
    }
    HorizontalChipsView chipsView = sendGpxView.findViewById(R.id.selector_view);
    chipsView.setItems(itemsVisibility);
    ChipItem selected = chipsView.getChipById(getString(selectedUploadVisibility.getTitleId()));
    chipsView.setSelected(selected);
    chipsView.setOnSelectChipListener(chip -> {
        selectedUploadVisibility = (UploadVisibility) chip.tag;
        plugin.OSM_UPLOAD_VISIBILITY.set(selectedUploadVisibility);
        visibilityName.setText(selectedUploadVisibility.getTitleId());
        visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
        chipsView.smoothScrollTo(chip);
        return true;
    });
    chipsView.notifyDataSetChanged();
    LinearLayout account = sendGpxView.findViewById(R.id.account_container);
    account.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                showOpenStreetMapScreen(activity);
            }
            dismiss();
        }
    });
    SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder().setCustomView(sendGpxView).create();
    items.add(titleItem);
}
Also used : SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) UploadVisibility(net.osmand.plus.plugins.osmedit.OsmEditingPlugin.UploadVisibility) View(android.view.View) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) TextView(android.widget.TextView) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) ChipItem(net.osmand.plus.widgets.chips.ChipItem) FragmentActivity(androidx.fragment.app.FragmentActivity) HorizontalChipsView(net.osmand.plus.widgets.chips.HorizontalChipsView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

ArrayList (java.util.ArrayList)5 ChipItem (net.osmand.plus.widgets.chips.ChipItem)5 HorizontalChipsView (net.osmand.plus.widgets.chips.HorizontalChipsView)5 View (android.view.View)3 SuppressLint (android.annotation.SuppressLint)2 LayoutInflater (android.view.LayoutInflater)2 TextView (android.widget.TextView)2 Drawable (android.graphics.drawable.Drawable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ScrollView (android.widget.ScrollView)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 OsmandApplication (net.osmand.plus.OsmandApplication)1