Skip to content

Commit

Permalink
Merge branch 'YvesDelcoigne-custom-typeface'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-grabner committed Nov 23, 2015
2 parents db7119b + 9d76578 commit 1e0a81b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ public class CircleProgressView extends View {
private int mTouchEventCount;
private OnProgressChangedListener onProgressChangedListener;
private float previousProgressChangedValue;

// Text typeface
private Typeface textTypeface;
private Typeface unitTextTypeface;
//endregion members
//----------------------------------

Expand Down Expand Up @@ -840,6 +844,22 @@ private void parseAttributes(TypedArray a) {
setBlockScale(a.getFloat(R.styleable.CircleProgressView_cpv_blockScale, 0.9f));
}


if (a.hasValue(R.styleable.CircleProgressView_cpv_textTypeface)) {
try {
textTypeface = Typeface.createFromAsset(getContext().getAssets(), a.getString(R.styleable.CircleProgressView_cpv_textTypeface));
} catch (Exception exception) {
// error while trying to inflate typeface (is the path set correctly?)
}
}
if (a.hasValue(R.styleable.CircleProgressView_cpv_unitTypeface)) {
try {
unitTextTypeface = Typeface.createFromAsset(getContext().getAssets(), a.getString(R.styleable.CircleProgressView_cpv_unitTypeface));
} catch (Exception exception) {
// error while trying to inflate typeface (is the path set correctly?)
}
}

// Recycle
a.recycle();
}
Expand Down Expand Up @@ -1304,6 +1324,9 @@ private void setupContourPaint() {
private void setupUnitTextPaint() {
mUnitTextPaint.setStyle(Style.FILL);
mUnitTextPaint.setAntiAlias(true);
if (unitTextTypeface != null) {
mUnitTextPaint.setTypeface(unitTextTypeface);
}
}

private void setupTextPaint() {
Expand All @@ -1314,6 +1337,11 @@ private void setupTextPaint() {
mTextPaint.setStyle(Style.FILL);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(mTextSize);
if (textTypeface != null) {
mTextPaint.setTypeface(textTypeface);
} else {
mTextPaint.setTypeface(Typeface.MONOSPACE);
}

}

Expand Down
2 changes: 2 additions & 0 deletions CircleProgressView/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<attr name="cpv_unitColor" format="color"/>
<attr name="cpv_showUnit" format="boolean"/>
<attr name="cpv_autoTextColor" format="boolean"/>
<attr name="cpv_textTypeface" format="string"/>
<attr name="cpv_unitTypeface" format="string"/>

<!-- Text sizes-->
<attr name="cpv_textSize" format="dimension"/>
Expand Down
3 changes: 2 additions & 1 deletion ExampleApp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
CircleProgressView:cpv_unitPosition="right_top"
CircleProgressView:cpv_unitScale="1"
CircleProgressView:cpv_textScale="1"
CircleProgressView:cpv_showUnit="true"/>
CircleProgressView:cpv_showUnit="true"
/>


<ScrollView
Expand Down

0 comments on commit 1e0a81b

Please sign in to comment.