com.google.android.material.chip.Chip Java Examples
The following examples show how to use
com.google.android.material.chip.Chip.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrgUnitCascadeDialog.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void showChips(List<OrganisationUnit> orgUnits) { binding.results.removeAllViews(); for (OrganisationUnit ou : orgUnits) { Chip chip = new Chip(getContext()); String level = ""; OrganisationUnitLevel ouLevel = d2.organisationUnitModule().organisationUnitLevels().byLevel().eq(ou.level()).one().blockingGet(); if (ouLevel != null) { level = ouLevel.displayName() + " : "; } else level = "Lvl. " + ou.level() + " : "; chip.setText(String.format("%s%s", level, ou.displayName())); chip.setOnClickListener(view -> { callbacks.textChangedConsumer(ou.uid(), ou.displayName()); dismiss(); }); chip.setChipMinHeightResource(R.dimen.chip_minHeight); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { chip.setElevation(6f); } chip.setChipBackgroundColorResource(R.color.white); binding.results.addView(chip); } }
Example #2
Source File: BindingAdapters.java From PopularMovies with MIT License | 6 votes |
@BindingAdapter("items") public static void setItems(ChipGroup view, List<Genre> genres) { if (genres == null // Since we are using liveData to observe data, any changes in that table(favorites) // will trigger the observer and hence rebinding data, which can lead to duplicates. || view.getChildCount() > 0) return; // dynamically create & add genre chips Context context = view.getContext(); for (Genre genre : genres) { Chip chip = new Chip(context); chip.setText(genre.getName()); chip.setChipStrokeWidth(UiUtils.dipToPixels(context, 1)); chip.setChipStrokeColor(ColorStateList.valueOf( context.getResources().getColor(R.color.md_blue_grey_200))); chip.setChipBackgroundColorResource(android.R.color.transparent); view.addView(chip); } }
Example #3
Source File: Tag.java From intra42 with Apache License 2.0 | 6 votes |
public static void setTagForum(Context context, List<Tags> tags, ChipGroup chipViewTags) { chipViewTags.removeAllViews(); if (tags == null || tags.size() == 0) { chipViewTags.setVisibility(View.GONE); return; } else chipViewTags.setVisibility(View.VISIBLE); chipViewTags.setChipSpacingHorizontalResource(R.dimen.chip_group_spacing_horizontal); chipViewTags.setChipSpacingVerticalResource(R.dimen.chip_group_spacing_vertical); for (Tags tag : tags) { Chip chip = new Chip(context); chip.setText(tag.name); chip.setChipBackgroundColorResource(getTagColor(context, tag)); chipViewTags.addView(chip); } }
Example #4
Source File: EditScriptActivity.java From Easer with GNU General Public License v3.0 | 5 votes |
public void setChosenPredecessors(@NonNull Collection<String> chosenPredecessors) { chipGroup.removeAllViews(); this.chosenPredecessors.clear(); this.chosenPredecessors.addAll(chosenPredecessors); for (String predecessor : chosenPredecessors) { Chip chip = new Chip(activity); chip.setText(predecessor); chip.setClickable(false); chipGroup.addView(chip); } }
Example #5
Source File: BackupNameFormatBuilderPartsAdapter.java From SAI with GNU General Public License v3.0 | 5 votes |
public ViewHolder(@NonNull View itemView) { super(itemView); itemView.requestFocus(); ((Chip) itemView).setOnCheckedChangeListener((buttonView, isChecked) -> { if (mPauseCheckedListener) return; int adapterPosition = getAdapterPosition(); if (adapterPosition == RecyclerView.NO_POSITION) return; setSelected(getKeyForPosition(adapterPosition), isChecked); }); }
Example #6
Source File: BackupNameFormatBuilderPartsAdapter.java From SAI with GNU General Public License v3.0 | 5 votes |
void bindTo(BackupNameFormatBuilder.Part part) { ((Chip) itemView).setText(part.getDisplayName(mContext)); mPauseCheckedListener = true; ((Chip) itemView).setChecked(isSelected(part)); mPauseCheckedListener = false; }
Example #7
Source File: ChipTextInputComboView.java From material-components-android with Apache License 2.0 | 5 votes |
public ChipTextInputComboView( @NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater inflater = LayoutInflater.from(context); chip = (Chip) inflater.inflate(R.layout.material_time_chip, this, false); textInputLayout = (TextInputLayout) inflater.inflate(R.layout.material_time_input, this, false); editText = textInputLayout.getEditText(); editText.setVisibility(INVISIBLE); watcher = new HintSetterTextWatcher(); editText.addTextChangedListener(watcher); addView(chip); addView(textInputLayout); }
Example #8
Source File: SearchActivity.java From NClientV2 with Apache License 2.0 | 5 votes |
private Chip createAddChip(TagType type,ChipGroup group){ Chip c=(Chip)getLayoutInflater().inflate(R.layout.chip_layout,group,false); c.setCloseIconVisible(false); c.setChipIconResource(R.drawable.ic_add); c.setText(getString(R.string.add)); c.setOnClickListener(v -> loadTag(type)); Global.setTint(c.getChipIcon()); return c; }
Example #9
Source File: Tag.java From intra42 with Apache License 2.0 | 5 votes |
public static void setTagEvent(Events event, Chip tagView) { String str; Context context = tagView.getContext(); if (event.kind != null) str = event.kind.getString(context); else str = context.getString(R.string.event_kind_unknown); tagView.setText(str); tagView.setChipBackgroundColorResource(event.kind.getColorRes()); tagView.setTextColor(ContextCompat.getColor(tagView.getContext(), R.color.tag_on_event)); }
Example #10
Source File: Tag.java From intra42 with Apache License 2.0 | 5 votes |
public static void setTagUsers(Context context, List<Tags> tags, ChipGroup chipViewTags) { if (tags == null || tags.size() == 0) { chipViewTags.setVisibility(View.GONE); return; } else chipViewTags.setVisibility(View.VISIBLE); for (Tags tag : tags) { Chip chip = new Chip(context); chip.setText(tag.name); chip.setChipBackgroundColor(ColorStateList.valueOf(getUsersTagColor(tag))); chipViewTags.addView(chip); } }
Example #11
Source File: ChipGroupDemoFragment.java From material-components-android with Apache License 2.0 | 5 votes |
private void initChipGroup(ChipGroup chipGroup) { chipGroup.removeAllViews(); boolean singleSelection = singleSelectionSwitch.isChecked(); String[] textArray = getResources().getStringArray(R.array.cat_chip_group_text_array); for (String text : textArray) { Chip chip = (Chip) getLayoutInflater().inflate(getChipGroupItem(singleSelection), chipGroup, false); chip.setText(text); chip.setCloseIconVisible(true); chip.setOnCloseIconClickListener(v -> chipGroup.removeView(chip)); chipGroup.addView(chip); } }
Example #12
Source File: ChipRecyclerviewDemoFragment.java From material-components-android with Apache License 2.0 | 5 votes |
public MyViewHolder(View view, Set<Integer> checkedChipId) { super(view); chip = (Chip) view; chip.setOnClickListener( v -> { Integer chipId = (Integer) v.getTag(); if (chip.isChecked()) { checkedChipId.add(chipId); } else { checkedChipId.remove(chipId); } }); }
Example #13
Source File: EventDetailsActivity.java From NaviBee with GNU General Public License v3.0 | 4 votes |
private void getEventInfo() { ArrayList<String> uidList = new ArrayList<>(); uidList.addAll(eventItem.getUsers().keySet()); // get the user information UserInfoManager.getInstance().getUserInfo(uidList, stringUserInfoMap -> { updateEventInfo(); String holder = stringUserInfoMap.get(eventItem.getHolder()).getName(); ArrayList<UserInfoManager.UserInfo> participants = new ArrayList<>(); userMap = new HashMap<>(); for (int i = 0; i < uidList.size(); i++) { UserInfoManager.UserInfo usr = stringUserInfoMap.get(uidList.get(i)); usr.setUserID(uidList.get(i)); participants.add(usr); // Store user id and name into map userMap.put(uidList.get(i), stringUserInfoMap.get(uidList.get(i)).getName()); } // Event organiser if (eventItem.getHolder() != null) { listItems.add(new SimpleRVTextSecondaryPrimaryStatic( holder, getResources().getString(R.string.event_details_organiser) )); } ArrayList<Chip> chipList = new ArrayList<>(); String myUid = FirebaseAuth.getInstance().getCurrentUser().getUid(); for (UserInfoManager.UserInfo participant : participants) { Chip chip = (Chip) getLayoutInflater().inflate(R.layout.chip_user_profile, null); chip.setText(participant.getName()); chip.setChipIconResource(R.drawable.ic_people_black_24dp); new URLChipCacheLoader(participant.getPhotoUrl(), chip, getResources()).execute(); if (!participant.getUid().equals(myUid)) { chip.setOnClickListener(v -> { Intent intent = new Intent(this, FriendDetail.class); intent.putExtra("FRIEND_ID", participant.getUid()); startActivity(intent); }); } else { chip.setClickable(false); chip.setFocusable(false); } chipList.add(chip); } // Event participants if (eventItem.getUsers() != null) { listItems.add(new SimpleRVUserChips( getResources().getString(R.string.event_details_participants), chipList )); } viewAdapter.notifyDataSetChanged(); }); }
Example #14
Source File: NoteViewHolder.java From nextcloud-notes with GNU General Public License v3.0 | 4 votes |
protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int mainColor) { final boolean isDarkThemeActive = NotesApplication.isDarkThemeActive(context); noteCategory.setVisibility(showCategory && !category.isEmpty() ? View.VISIBLE : View.GONE); noteCategory.setText(category); @ColorInt int categoryForeground; @ColorInt int categoryBackground; if (isDarkThemeActive) { if (isColorDark(mainColor)) { if (contrastRatioIsSufficient(mainColor, Color.BLACK)) { categoryBackground = mainColor; categoryForeground = Color.WHITE; } else { categoryBackground = Color.WHITE; categoryForeground = mainColor; } } else { categoryBackground = mainColor; categoryForeground = Color.BLACK; } } else { categoryForeground = Color.BLACK; if (isColorDark(mainColor) || contrastRatioIsSufficient(mainColor, Color.WHITE)) { categoryBackground = mainColor; } else { categoryBackground = Color.BLACK; } } noteCategory.setTextColor(categoryForeground); if (noteCategory instanceof Chip) { ((Chip) noteCategory).setChipStrokeColor(ColorStateList.valueOf(categoryBackground)); ((Chip) noteCategory).setChipBackgroundColor(ColorStateList.valueOf(isDarkThemeActive ? categoryBackground : Color.TRANSPARENT)); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { DrawableCompat.setTint(noteCategory.getBackground(), categoryBackground); } else { final GradientDrawable drawable = (GradientDrawable) noteCategory.getBackground(); drawable.setStroke(1, categoryBackground); drawable.setColor(isDarkThemeActive ? categoryBackground : Color.TRANSPARENT); } } }
Example #15
Source File: BackupComponentsAdapter.java From SAI with GNU General Public License v3.0 | 4 votes |
ViewHolder(@NonNull View itemView) { super(itemView); itemView.setFocusable(false); mChip = (Chip) itemView; }
Example #16
Source File: BackupAppFeatureAdapter.java From SAI with GNU General Public License v3.0 | 4 votes |
ViewHolder(@NonNull View itemView) { super(itemView); itemView.setFocusable(false); mChip = (Chip) itemView; }
Example #17
Source File: SearchTEViewHolder.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void setEnrollmentInfo(List<Trio<String, String, String>> enrollmentsInfo) { binding.chipContainer.removeAllViews(); Context parentContext = binding.chipContainer.getContext(); for (Trio<String, String, String> enrollmentInfo : enrollmentsInfo) { if (binding.getPresenter().getProgram() == null || !binding.getPresenter().getProgram().displayName().equals(enrollmentInfo.val0())) { Chip chip = new Chip(parentContext); chip.setText(enrollmentInfo.val0()); int color = ColorUtils.getColorFrom(enrollmentInfo.val1(), ColorUtils.getPrimaryColor(parentContext, ColorUtils.ColorType.PRIMARY_LIGHT)); int icon; if (!isEmpty(enrollmentInfo.val2())) { Resources resources = parentContext.getResources(); String iconName = enrollmentInfo.val2().startsWith("ic_") ? enrollmentInfo.val2() : "ic_" + enrollmentInfo.val2(); icon = resources.getIdentifier(iconName, "drawable", parentContext.getPackageName()); } else { icon = R.drawable.ic_program_default; } Drawable iconImage; try { iconImage = AppCompatResources.getDrawable(parentContext, icon); iconImage.mutate(); } catch (Exception e) { Timber.log(1, e); iconImage = AppCompatResources.getDrawable(parentContext, R.drawable.ic_program_default); iconImage.mutate(); } Drawable bgDrawable = AppCompatResources.getDrawable(parentContext, R.drawable.ic_chip_circle_24); Drawable wrappedIcon = DrawableCompat.wrap(iconImage); Drawable wrappedBg = DrawableCompat.wrap(bgDrawable); LayerDrawable finalDrawable = new LayerDrawable(new Drawable[]{wrappedBg, wrappedIcon}); finalDrawable.mutate(); finalDrawable.getDrawable(1).setColorFilter(new PorterDuffColorFilter(ColorUtils.getContrastColor(color), PorterDuff.Mode.SRC_IN)); finalDrawable.getDrawable(0).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); chip.setChipIcon(finalDrawable); binding.chipContainer.addView(chip); binding.chipContainer.invalidate(); } } }