Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down