Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typeface attribute #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.Gravity;
Expand Down Expand Up @@ -94,6 +96,7 @@ public class BubbleSeekBar extends View {
private long mAlwaysShowBubbleDelay; // the delay duration before bubble shows all the time
private boolean isHideBubble; // hide bubble
private boolean isRtl; // right to left
private Typeface mTypeface; // font of text

private int mBubbleColor;// color of bubble
private int mBubbleTextSize; // text size of bubble-progress
Expand Down Expand Up @@ -192,12 +195,20 @@ public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
isHideBubble = a.getBoolean(R.styleable.BubbleSeekBar_bsb_hide_bubble, false);
isRtl = a.getBoolean(R.styleable.BubbleSeekBar_bsb_rtl, false);
setEnabled(a.getBoolean(R.styleable.BubbleSeekBar_android_enabled, isEnabled()));
String font = a.getString(R.styleable.BubbleSeekBar_bsb_text_typeface);
if (!TextUtils.isEmpty(font)) {
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),font);
if (typeface != null) {
this.mTypeface=typeface;
}
}
a.recycle();

mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setTypeface(mTypeface);

mRectText = new Rect();
mTextSpace = dp2px(2);
Expand Down Expand Up @@ -1475,6 +1486,7 @@ protected void onDraw(Canvas canvas) {

mBubblePaint.setTextSize(mBubbleTextSize);
mBubblePaint.setColor(mBubbleTextColor);
mBubblePaint.setTypeface(mTypeface);
mBubblePaint.getTextBounds(mProgressText, 0, mProgressText.length(), mRect);
Paint.FontMetrics fm = mBubblePaint.getFontMetrics();
float baseline = mBubbleRadius + (fm.descent - fm.ascent) / 2f - fm.descent;
Expand Down
1 change: 1 addition & 0 deletions bubbleseekbar/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<attr name="bsb_always_show_bubble_delay" format="integer"/> <!--the delay duration before bubble shows all the time, default: 200ms-->
<attr name="bsb_hide_bubble" format="boolean"/> <!--hide bubble, default: false-->
<attr name="bsb_rtl" format="boolean"/> <!--right to left, default: false-->
<attr name="bsb_text_typeface" format="string"/> <!--font of text-->
<attr name="android:enabled"/>
</declare-styleable>
</resources>