Skip to content

Commit

Permalink
Merge pull request #16 from smeegoan/master
Browse files Browse the repository at this point in the history
Added alpha support
  • Loading branch information
linger1216 committed May 3, 2016
2 parents fd720b3 + c8efc4e commit ed681b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/src/main/java/com/lid/lib/LabelImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void setLabelBackgroundColor(int backgroundColor) {
utils.setLabelBackgroundColor(this, backgroundColor);
}

public void setLabelBackgroundAlpha(int alpha) {
utils.setLabelBackgroundAlpha(this, alpha);
}

public String getLabelText() {
return utils.getLabelText();
}
Expand Down
16 changes: 14 additions & 2 deletions lib/src/main/java/com/lid/lib/LabelViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LabelViewHelper {
private Rect textBound;

private Context context;
private int alpha;

public LabelViewHelper(Context context, AttributeSet attrs, int defStyleAttr) {

Expand Down Expand Up @@ -80,14 +81,17 @@ public LabelViewHelper(Context context, AttributeSet attrs, int defStyleAttr) {
}

public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) {
if (!visual) {
if (!visual || text == null) {
return;
}

float actualDistance = distance + height / 2;
calcOffset(actualDistance, measuredWidth, measuredHeight);

rectPaint.setColor(backgroundColor);
if (alpha != 0) {
rectPaint.setAlpha(alpha);
}
rectPaint.setStrokeWidth(height);

rectPath.reset();
Expand Down Expand Up @@ -205,12 +209,20 @@ public void setLabelBackgroundColor(View view, int backgroundColor) {
}
}


public void setLabelBackgroundAlpha(View view, int alpha) {
if (this.alpha != alpha) {
this.alpha = alpha;
view.invalidate();
}
}

public String getLabelText() {
return text;
}

public void setLabelText(View view, String text) {
if (!this.text.equals(text)) {
if (this.text == null || !this.text.equals(text)) {
this.text = text;
view.invalidate();
}
Expand Down

0 comments on commit ed681b8

Please sign in to comment.