Skip to content

Commit

Permalink
Merge pull request #18 from Jilberta/master
Browse files Browse the repository at this point in the history
Added Label Text Styles to the Library.
  • Loading branch information
linger1216 authored Feb 9, 2017
2 parents 010aafc + 4949539 commit fa16bdc
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/lid/labelview/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lid.labelview;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
Expand Down Expand Up @@ -42,6 +43,7 @@ public View getItemView(int position, View convertView, ViewHolder holder) {
LabelImageView imageView = holder.getView(R.id.image);
imageView.setImageResource(Integer.parseInt(item.image));
imageView.setLabelText("LID " + position);
imageView.setLabelTextStyle(Typeface.BOLD);

return convertView;
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
app:label_height="20dp"
app:label_orientation="RIGHT_TOP"
app:label_text="HD"
app:label_textSize="12sp" />
app:label_textSize="12sp"
app:label_textStyle="BOLD"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -44,7 +45,8 @@
android:src="@mipmap/image1"
app:label_backgroundColor="#C2185B"
app:label_orientation="LEFT_TOP"
app:label_text="CHINA" />
app:label_text="CHINA"
app:label_textStyle="ITALIC"/>


<com.lid.lib.LabelImageView
Expand Down Expand Up @@ -75,7 +77,8 @@
app:label_distance="15dp"
app:label_orientation="LEFT_TOP"
app:label_text="POP"
app:label_textSize="10sp" />
app:label_textSize="10sp"
app:label_textStyle="BOLD_ITALIC"/>


<com.lid.lib.LabelButtonView
Expand Down
8 changes: 8 additions & 0 deletions lib/src/main/java/com/lid/lib/LabelButtonView.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public int getLabelTextSize() {
public void setLabelTextSize(int textSize) {
utils.setLabelTextSize(this, textSize);
}

public int getLabelTextStyle(){
return utils.getLabelTextStyle();
}

public void setLabelTextStyle(int textStyle){
utils.setLabelTextStyle(this, textStyle);
}
}


8 changes: 8 additions & 0 deletions lib/src/main/java/com/lid/lib/LabelImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public int getLabelTextSize() {
public void setLabelTextSize(int textSize) {
utils.setLabelTextSize(this, textSize);
}

public int getLabelTextStyle(){
return utils.getLabelTextStyle();
}

public void setLabelTextStyle(int textStyle){
utils.setLabelTextStyle(this, textStyle);
}
}


8 changes: 8 additions & 0 deletions lib/src/main/java/com/lid/lib/LabelTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public int getLabelTextSize() {
public void setLabelTextSize(int textSize) {
utils.setLabelTextSize(this, textSize);
}

public int getLabelTextStyle(){
return utils.getLabelTextStyle();
}

public void setLabelTextStyle(int textStyle){
utils.setLabelTextStyle(this, textStyle);
}
}


15 changes: 15 additions & 0 deletions lib/src/main/java/com/lid/lib/LabelViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
Expand All @@ -26,6 +27,7 @@ public class LabelViewHelper {
private static final int DEFAULT_STROKE_COLOR = 0xFFFFFFFF;
private static final int DEFAULT_TEXT_COLOR = 0xFFFFFFFF;
private static final int DEFAULT_ORIENTATION = LEFT_TOP;
private static final int DEFAULT_TEXT_STYLE = 0;

private int distance;
private int height;
Expand All @@ -34,6 +36,7 @@ public class LabelViewHelper {
private int backgroundColor;
private int strokeColor;
private int textSize;
private int textStyle;
private int textColor;
private boolean visual;
private int orientation;
Expand Down Expand Up @@ -66,6 +69,7 @@ public LabelViewHelper(Context context, AttributeSet attrs, int defStyleAttr) {
backgroundColor = attributes.getColor(R.styleable.LabelView_label_backgroundColor, DEFAULT_BACKGROUND_COLOR);
strokeColor = attributes.getColor(R.styleable.LabelView_label_strokeColor, DEFAULT_STROKE_COLOR);
textSize = attributes.getDimensionPixelSize(R.styleable.LabelView_label_textSize, dip2Px(DEFAULT_TEXT_SIZE));
textStyle = attributes.getInt(R.styleable.LabelView_label_textStyle, DEFAULT_TEXT_STYLE);
textColor = attributes.getColor(R.styleable.LabelView_label_textColor, DEFAULT_TEXT_COLOR);
visual = attributes.getBoolean(R.styleable.LabelView_label_visual, true);
orientation = attributes.getInteger(R.styleable.LabelView_label_orientation, DEFAULT_ORIENTATION);
Expand Down Expand Up @@ -118,6 +122,7 @@ public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) {
textPaint.setTextSize(textSize);
textPaint.setColor(textColor);
textPaint.getTextBounds(text, 0, text.length(), textBound);
textPaint.setTypeface(Typeface.defaultFromStyle(textStyle));

float begin_w_offset = (1.4142135f * actualDistance) / 2 - textBound.width() / 2;
if (begin_w_offset < 0) begin_w_offset = 0;
Expand Down Expand Up @@ -322,4 +327,14 @@ public void setLabelTextSize(View view, int textSize) {
view.invalidate();
}
}

public int getLabelTextStyle(){
return textStyle;
}

public void setLabelTextStyle(View view, int textStyle){
if(this.textStyle == textStyle) return;
this.textStyle = textStyle;
view.invalidate();
}
}
6 changes: 6 additions & 0 deletions lib/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<attr name="label_strokeColor" format="color"/>
<attr name="label_text" format="string"/>
<attr name="label_textSize" format="dimension" />
<attr name="label_textStyle" format="enum" >
<enum name="NORMAL" value="0"/>
<enum name="BOLD" value="1"/>
<enum name="ITALIC" value="2"/>
<enum name="BOLD_ITALIC" value="3"/>
</attr>
<attr name="label_textColor" format="color"/>
<attr name="label_visual" format="boolean"/>
<attr name="label_orientation" format="enum">
Expand Down

0 comments on commit fa16bdc

Please sign in to comment.