Skip to content

Commit fa16bdc

Browse files
authored
Merge pull request #18 from Jilberta/master
Added Label Text Styles to the Library.
2 parents 010aafc + 4949539 commit fa16bdc

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

app/src/main/java/com/lid/labelview/ListViewActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lid.labelview;
22

33
import android.content.Context;
4+
import android.graphics.Typeface;
45
import android.os.Bundle;
56
import android.support.v7.app.ActionBarActivity;
67
import android.view.View;
@@ -42,6 +43,7 @@ public View getItemView(int position, View convertView, ViewHolder holder) {
4243
LabelImageView imageView = holder.getView(R.id.image);
4344
imageView.setImageResource(Integer.parseInt(item.image));
4445
imageView.setLabelText("LID " + position);
46+
imageView.setLabelTextStyle(Typeface.BOLD);
4547

4648
return convertView;
4749
}

app/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
app:label_height="20dp"
2929
app:label_orientation="RIGHT_TOP"
3030
app:label_text="HD"
31-
app:label_textSize="12sp" />
31+
app:label_textSize="12sp"
32+
app:label_textStyle="BOLD"/>
3233

3334
<LinearLayout
3435
android:layout_width="match_parent"
@@ -44,7 +45,8 @@
4445
android:src="@mipmap/image1"
4546
app:label_backgroundColor="#C2185B"
4647
app:label_orientation="LEFT_TOP"
47-
app:label_text="CHINA" />
48+
app:label_text="CHINA"
49+
app:label_textStyle="ITALIC"/>
4850

4951

5052
<com.lid.lib.LabelImageView
@@ -75,7 +77,8 @@
7577
app:label_distance="15dp"
7678
app:label_orientation="LEFT_TOP"
7779
app:label_text="POP"
78-
app:label_textSize="10sp" />
80+
app:label_textSize="10sp"
81+
app:label_textStyle="BOLD_ITALIC"/>
7982

8083

8184
<com.lid.lib.LabelButtonView

lib/src/main/java/com/lid/lib/LabelButtonView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public int getLabelTextSize() {
9191
public void setLabelTextSize(int textSize) {
9292
utils.setLabelTextSize(this, textSize);
9393
}
94+
95+
public int getLabelTextStyle(){
96+
return utils.getLabelTextStyle();
97+
}
98+
99+
public void setLabelTextStyle(int textStyle){
100+
utils.setLabelTextStyle(this, textStyle);
101+
}
94102
}
95103

96104

lib/src/main/java/com/lid/lib/LabelImageView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public int getLabelTextSize() {
9595
public void setLabelTextSize(int textSize) {
9696
utils.setLabelTextSize(this, textSize);
9797
}
98+
99+
public int getLabelTextStyle(){
100+
return utils.getLabelTextStyle();
101+
}
102+
103+
public void setLabelTextStyle(int textStyle){
104+
utils.setLabelTextStyle(this, textStyle);
105+
}
98106
}
99107

100108

lib/src/main/java/com/lid/lib/LabelTextView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public int getLabelTextSize() {
9191
public void setLabelTextSize(int textSize) {
9292
utils.setLabelTextSize(this, textSize);
9393
}
94+
95+
public int getLabelTextStyle(){
96+
return utils.getLabelTextStyle();
97+
}
98+
99+
public void setLabelTextStyle(int textStyle){
100+
utils.setLabelTextStyle(this, textStyle);
101+
}
94102
}
95103

96104

lib/src/main/java/com/lid/lib/LabelViewHelper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.graphics.Paint;
88
import android.graphics.Path;
99
import android.graphics.Rect;
10+
import android.graphics.Typeface;
1011
import android.util.AttributeSet;
1112
import android.util.Log;
1213
import android.view.View;
@@ -26,6 +27,7 @@ public class LabelViewHelper {
2627
private static final int DEFAULT_STROKE_COLOR = 0xFFFFFFFF;
2728
private static final int DEFAULT_TEXT_COLOR = 0xFFFFFFFF;
2829
private static final int DEFAULT_ORIENTATION = LEFT_TOP;
30+
private static final int DEFAULT_TEXT_STYLE = 0;
2931

3032
private int distance;
3133
private int height;
@@ -34,6 +36,7 @@ public class LabelViewHelper {
3436
private int backgroundColor;
3537
private int strokeColor;
3638
private int textSize;
39+
private int textStyle;
3740
private int textColor;
3841
private boolean visual;
3942
private int orientation;
@@ -66,6 +69,7 @@ public LabelViewHelper(Context context, AttributeSet attrs, int defStyleAttr) {
6669
backgroundColor = attributes.getColor(R.styleable.LabelView_label_backgroundColor, DEFAULT_BACKGROUND_COLOR);
6770
strokeColor = attributes.getColor(R.styleable.LabelView_label_strokeColor, DEFAULT_STROKE_COLOR);
6871
textSize = attributes.getDimensionPixelSize(R.styleable.LabelView_label_textSize, dip2Px(DEFAULT_TEXT_SIZE));
72+
textStyle = attributes.getInt(R.styleable.LabelView_label_textStyle, DEFAULT_TEXT_STYLE);
6973
textColor = attributes.getColor(R.styleable.LabelView_label_textColor, DEFAULT_TEXT_COLOR);
7074
visual = attributes.getBoolean(R.styleable.LabelView_label_visual, true);
7175
orientation = attributes.getInteger(R.styleable.LabelView_label_orientation, DEFAULT_ORIENTATION);
@@ -118,6 +122,7 @@ public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) {
118122
textPaint.setTextSize(textSize);
119123
textPaint.setColor(textColor);
120124
textPaint.getTextBounds(text, 0, text.length(), textBound);
125+
textPaint.setTypeface(Typeface.defaultFromStyle(textStyle));
121126

122127
float begin_w_offset = (1.4142135f * actualDistance) / 2 - textBound.width() / 2;
123128
if (begin_w_offset < 0) begin_w_offset = 0;
@@ -322,4 +327,14 @@ public void setLabelTextSize(View view, int textSize) {
322327
view.invalidate();
323328
}
324329
}
330+
331+
public int getLabelTextStyle(){
332+
return textStyle;
333+
}
334+
335+
public void setLabelTextStyle(View view, int textStyle){
336+
if(this.textStyle == textStyle) return;
337+
this.textStyle = textStyle;
338+
view.invalidate();
339+
}
325340
}

lib/src/main/res/values/attr.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<attr name="label_strokeColor" format="color"/>
99
<attr name="label_text" format="string"/>
1010
<attr name="label_textSize" format="dimension" />
11+
<attr name="label_textStyle" format="enum" >
12+
<enum name="NORMAL" value="0"/>
13+
<enum name="BOLD" value="1"/>
14+
<enum name="ITALIC" value="2"/>
15+
<enum name="BOLD_ITALIC" value="3"/>
16+
</attr>
1117
<attr name="label_textColor" format="color"/>
1218
<attr name="label_visual" format="boolean"/>
1319
<attr name="label_orientation" format="enum">

0 commit comments

Comments
 (0)