-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b958877
commit 0f1cbae
Showing
4 changed files
with
184 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
funnellib/src/main/java/jie/com/funnellib/CustomLabelCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
package jie.com.funnellib; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
|
||
/** | ||
* Created by hj on 2019/2/22. | ||
* 说明:开放自定义描述绘制画笔 | ||
*/ | ||
public interface CustomLabelCallback { | ||
/** | ||
* 循环绘制线后面的文字 | ||
* @param canvas 画布 | ||
* @param mPaintLabel 画笔 | ||
* @param labelX 文字开始X坐标 | ||
* @param labelY 文字开始Y坐标 | ||
* @param mHelper 描述文字辅助类 | ||
* @param index 绘制下标 | ||
* 注意:绘制顺序是从下往上绘制!!! | ||
*/ | ||
void drawText(Canvas canvas, Paint mPaintLabel,float labelX, float labelY,int index); | ||
void drawText(LabelHelper mHelper,int index); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
funnellib/src/main/java/jie/com/funnellib/LabelHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package jie.com.funnellib; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.support.annotation.NonNull; | ||
import android.text.TextUtils; | ||
|
||
/** | ||
* Created by huangjie on 2019/12/2. | ||
* 说明:描述文字辅助类 | ||
*/ | ||
public final class LabelHelper { | ||
private float mLabelX; | ||
private float mLabelY; | ||
private Canvas mCanvas; | ||
private Paint mPaint; | ||
private Builder mBuilder; | ||
|
||
protected void setDrawBasicParameters(Canvas mCanvas, Paint mPaint) { | ||
this.mCanvas = mCanvas; | ||
this.mPaint = mPaint; | ||
} | ||
|
||
protected void updateXY(float mLabelX, float mLabelY) { | ||
this.mLabelX = mLabelX; | ||
this.mLabelY = mLabelY; | ||
} | ||
|
||
public float getLabelX() { | ||
return mLabelX; | ||
} | ||
|
||
public float getLabelY() { | ||
return mLabelY; | ||
} | ||
|
||
public Canvas getCanvas() { | ||
return mCanvas; | ||
} | ||
|
||
public Paint getPaint() { | ||
return mPaint; | ||
} | ||
|
||
public void build(@NonNull Builder builder) { | ||
String mFirstHalfText = builder.mFirstHalfText; | ||
float mFirstHalfX = 0; | ||
if (!TextUtils.isEmpty(mFirstHalfText)) { | ||
mPaint.setColor(builder.mFirstHalfTextColor); | ||
mPaint.setFakeBoldText(builder.mFirstHalfFakeBoldText); | ||
mCanvas.drawText(mFirstHalfText, mLabelX, mLabelY, mPaint); | ||
mFirstHalfX = Util.getTextWidth(mPaint, mFirstHalfText); | ||
} | ||
String mCenterHalfText = builder.mCenterHalfText; | ||
float mCenterHalfX = 0; | ||
if (!TextUtils.isEmpty(mCenterHalfText)) { | ||
mPaint.setColor(builder.mCenterHalfTextColor); | ||
mPaint.setFakeBoldText(builder.mCenterHalfFakeBoldText); | ||
mCanvas.drawText(mCenterHalfText, mLabelX + mFirstHalfX, mLabelY, mPaint); | ||
mCenterHalfX = Util.getTextWidth(mPaint, mCenterHalfText); | ||
} | ||
String mFooterHalfText = builder.mFooterHalfText; | ||
if (!TextUtils.isEmpty(mFooterHalfText)) { | ||
mPaint.setColor(builder.mFooterTextColor); | ||
mPaint.setFakeBoldText(builder.mFooterHalfFakeBoldText); | ||
mCanvas.drawText(mFooterHalfText, mLabelX + mCenterHalfX + mFirstHalfX, mLabelY, mPaint); | ||
} | ||
} | ||
|
||
public Builder getBuild() { | ||
if (mBuilder == null) { | ||
mBuilder = new Builder(); | ||
} | ||
return mBuilder; | ||
} | ||
|
||
public final static class Builder { | ||
//内容 | ||
private String mFirstHalfText; | ||
private String mCenterHalfText; | ||
private String mFooterHalfText; | ||
//字体颜色 | ||
private int mFirstHalfTextColor; | ||
private int mCenterHalfTextColor; | ||
private int mFooterTextColor; | ||
//是否加粗 | ||
private boolean mFirstHalfFakeBoldText; | ||
private boolean mCenterHalfFakeBoldText; | ||
private boolean mFooterHalfFakeBoldText; | ||
|
||
public Builder setFirstHalfText(String mFirstHalfText) { | ||
this.mFirstHalfText = mFirstHalfText; | ||
return this; | ||
} | ||
|
||
public Builder setCenterHalfText(String mCenterHalfText) { | ||
this.mCenterHalfText = mCenterHalfText; | ||
return this; | ||
} | ||
|
||
public Builder setFooterHalfText(String mFooterHalfText) { | ||
this.mFooterHalfText = mFooterHalfText; | ||
return this; | ||
} | ||
|
||
public Builder setFirstHalfTextStyle(int mFirstHalfTextColor) { | ||
return setFirstHalfTextStyle(mFirstHalfTextColor,false); | ||
} | ||
|
||
public Builder setFirstHalfTextStyle(int mFirstHalfTextColor,boolean mFirstHalfFakeBoldText) { | ||
this.mFirstHalfTextColor = mFirstHalfTextColor; | ||
this.mFirstHalfFakeBoldText = mFirstHalfFakeBoldText; | ||
return this; | ||
} | ||
|
||
public Builder setCenterHalfTextStyle(int mCenterHalfTextColor) { | ||
return setCenterHalfTextStyle(mCenterHalfTextColor,false); | ||
} | ||
|
||
public Builder setCenterHalfTextStyle(int mCenterHalfTextColor,boolean mCenterHalfFakeBoldText) { | ||
this.mCenterHalfTextColor = mCenterHalfTextColor; | ||
this.mCenterHalfFakeBoldText = mCenterHalfFakeBoldText; | ||
return this; | ||
} | ||
|
||
public Builder setFooterTextStyle(int mFooterTextColor) { | ||
return setFooterTextStyle(mFooterTextColor,false); | ||
} | ||
|
||
public Builder setFooterTextStyle(int mFooterTextColor,boolean mFooterHalfFakeBoldText) { | ||
this.mFooterTextColor = mFooterTextColor; | ||
this.mFooterHalfFakeBoldText = mFooterHalfFakeBoldText; | ||
return this; | ||
} | ||
|
||
} | ||
|
||
} |