Skip to content

Commit

Permalink
1.update README.md
Browse files Browse the repository at this point in the history
2.添加为充电图标设置颜色的功能
  • Loading branch information
a1266143 committed Aug 28, 2020
1 parent a3e07dd commit 9fcb823
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ That's it
|_batteryTextSize |dimension | 电量文本字体大小 |setBatteryTextSize|
|_batteryTextColor|color |电池电量文本颜色|setBatteryTextColor|
|_batteryLevel |integer |电池电量 |setBattery|
|_chargeIconColor |color |充电图标颜色 |ssetChrgeIconColor|


17 changes: 14 additions & 3 deletions app/src/main/java/com/lee/circlebatteryview/CircleBatteryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class CircleBatteryView extends View {
int mBatteryLevel;
//是否在充电状态
boolean mIsCharge;
//充电图标颜色
int mChargeIconColor;
//--------------------------------------------------------

public CircleBatteryView(Context context) {
Expand Down Expand Up @@ -99,6 +101,7 @@ private void getCustomAttr(Context context, AttributeSet attrs) {
mBatteryTextSize = typedArray.getDimension(R.styleable.CircleBatteryView__batteryTextSize, Utils.dp2px(context, 7));
mBatteryTextColor = typedArray.getColor(R.styleable.CircleBatteryView__batteryTextColor, Color.parseColor("#777777"));
mBatteryLevel = typedArray.getInteger(R.styleable.CircleBatteryView__batteryLevel, 0);
mChargeIconColor = typedArray.getColor(R.styleable.CircleBatteryView__chargeIconColor, Color.WHITE);
typedArray.recycle();
/*Log.e("xiaojun", "获取到的参数," +
"mBackStrokeWidth=" + mBackStrokeWidth +
Expand All @@ -116,8 +119,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
this.mHalfOfWidth = mWidth / 2;
this.mHalfOfHeight = mHeight / 2;
Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.charge);
if (drawable!=null){
mBitmapCharge = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
if (drawable != null) {
drawable.setTint(mChargeIconColor);
if (mBitmapCharge == null)
mBitmapCharge = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mBitmapCharge);
drawable.setBounds(0, 0, mWidth, mHeight);
drawable.draw(canvas);
Expand Down Expand Up @@ -159,8 +164,9 @@ else if (specMode == MeasureSpec.AT_MOST)

/**
* 设置电池电量
*
* @param batteryLevel 电池电量
* @param isCharge 充电状态
* @param isCharge 充电状态
*/
public void setBattery(int batteryLevel, boolean isCharge) {
mIsCharge = isCharge;
Expand Down Expand Up @@ -208,6 +214,11 @@ public void setBatteryTextColor(int color) {
invalidate();
}

public void setChrgeIconColor(int color){
mChargeIconColor = color;
invalidate();
}

/**
* 计算上层电量的显示百分比
*/
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/drawable/charge.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1345dp"
android:height="1024dp"
android:width="24dp"
android:height="20dp"
android:viewportWidth="1345"
android:viewportHeight="1024">

<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M774.063 417.394h205.786l-491.601 590.682
163.867-415.929h-182.919l182.919-491.057h354.411z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2137.938-89.451v0z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2134.763-89.451c0 1.754 1.421 3.175 3.175 3.175s3.175-1.421
3.175-3.175c0-1.754-1.421-3.175-3.175-3.175-1.754 0-3.175 1.421-3.175 3.175z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2134.125-89.451c0 2.105 1.706 3.812 3.812 3.812s3.812-1.706
3.812-3.812c0-2.105-1.706-3.812-3.812-3.812-2.105 0-3.812 1.706-3.812 3.812z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2137.938-89.451v0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0l1.147-9.354z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2130.318-89.451c0 0 0 0 0 0 0 4.21 3.412 7.621 7.621 7.621 4.21 0 7.621-3.412
7.621-7.621 0 0 0 0 0 0 0 0 0 0 0 0 0-4.21-3.412-7.621-7.621-7.621-4.21 0-7.621
3.412-7.621 7.621s0 0 0 0z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2134.125-89.451c0 2.105 1.706 3.812 3.812 3.812s3.812-1.706
3.812-3.812c0-2.105-1.706-3.812-3.812-3.812-2.105 0-3.812 1.706-3.812 3.812z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2134.763-89.451c0 1.754 1.421 3.175 3.175 3.175s3.175-1.421
3.175-3.175c0-1.754-1.421-3.175-3.175-3.175-1.754 0-3.175 1.421-3.175 3.175z" />
<path
android:fillColor="#000000"
android:fillColor="#FFFFFF"
android:pathData="M2137.938-89.451v0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0l1.147-9.354z" />
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
<attr name="_batteryTextColor" format="color" />
<!-- 电池电量 -->
<attr name="_batteryLevel" format="integer" />
<!-- 充电图标颜色 -->
<attr name="_chargeIconColor" format="color" />
</declare-styleable>
</resources>

0 comments on commit 9fcb823

Please sign in to comment.