diff --git a/library/src/main/java/com/dpizarro/autolabel/library/AutoLabelUI.java b/library/src/main/java/com/dpizarro/autolabel/library/AutoLabelUI.java index 81c1987..53852bf 100644 --- a/library/src/main/java/com/dpizarro/autolabel/library/AutoLabelUI.java +++ b/library/src/main/java/com/dpizarro/autolabel/library/AutoLabelUI.java @@ -1,7 +1,5 @@ package com.dpizarro.autolabel.library; -import com.dpizarro.autolabeluilibrary.R; - import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -10,7 +8,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.ViewGroup; - +import com.dpizarro.autolabeluilibrary.R; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -116,6 +114,37 @@ private void getAttributes(AttributeSet attrs) { } + /** + * Method to add a Label with a custom Object tag. + * + * @param textlabel is the text of the label added using a LIST. + * @param tag is the tag used to retrieve the label for later use + */ + public boolean addLabel(String textlabel, Object tag) { + if (!checkLabelsCompleted()) { + Label label = new Label(getContext(), mTextSize, mIconCross, mShowCross, mTextColor, + mBackgroundResource, mLabelsClickables, mLabelPadding); + label.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + label.setText(textlabel); + label.setTag(tag); + label.setOnClickCrossListener(this); + label.setOnLabelClickListener(this); + + increaseLabelsCounter(); + addView(label); + requestLayout(); + + return true; + } + + if (listenerOnLabelsCompleted != null) { + listenerOnLabelsCompleted.onLabelsCompleted(); + ; + } + return false; + } + /** * Method to add a Label if is possible. * @@ -232,6 +261,28 @@ public void onClickLabel(Label label) { } } + /** + * Method to remove a label using a list + * + * @param tag the object used as a tag when creating the label. See {@link #addLabel(String, + * Object)} method + */ + public boolean removeLabel(Object tag) { + Label label = (Label) findViewWithTag(tag); + if (label != null) { + removeView(label); + decreaseLabelsCounter(); + if (getLabelsCounter() == EMPTY) { + if (listenerOnLabelsEmpty != null) { + listenerOnLabelsEmpty.onLabelsEmpty(); + } + } + requestLayout(); + return true; + } + return false; + } + /** * Method to remove a label using a list. *