Search in sources :

Example 11 with ChipItem

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

the class ChartsCard method fillInMenu.

@SuppressLint("NotifyDataSetChanged")
private void fillInMenu() {
    int activeColor = ColorUtilities.getActiveColor(app, nightMode);
    List<ChipItem> items = new ArrayList<>();
    for (ChartType<?> type : chartTypes) {
        if (!type.isAvailable()) {
            continue;
        }
        String title = type.getTitle();
        ChipItem item = new ChipItem(title);
        item.title = title;
        item.tag = type;
        if (type.isCustom()) {
            item.titleColor = activeColor;
        }
        items.add(item);
    }
    graphTypesMenu.setItems(items);
    ChipItem selected = graphTypesMenu.getChipById(visibleType.getTitle());
    graphTypesMenu.setSelected(selected);
    graphTypesMenu.setOnSelectChipListener(chip -> {
        ChartType<?> chosenType = (ChartType<?>) chip.tag;
        if (!isVisibleType(chosenType)) {
            changeVisibleType(chosenType);
        }
        graphTypesMenu.smoothScrollTo(chip);
        return true;
    });
    graphTypesMenu.notifyDataSetChanged();
}
Also used : ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) ChipItem(net.osmand.plus.widgets.chips.ChipItem) SuppressLint(android.annotation.SuppressLint)

Example 12 with ChipItem

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

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