Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
RelinRan committed Jun 20, 2022
1 parent 626ef08 commit 7f644f7
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ repositories {
2./app/build.grade
```
dependencies {
implementation 'com.github.RelinRan:RadiusProgressView:2022.6.20.1'
implementation 'com.github.RelinRan:RadiusProgressView:2022.6.20.2'
}
```
# xml
~~~
<com.androidx.wiget.RadiusProgressView
<com.androidx.widget.RadiusProgressView
android:layout_width="match_parent"
android:layout_height="20dp"
android:max="100"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.androidx.widget;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.androidx.wiget", appContext.getPackageName());
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.androidx.wiget">
<manifest package="com.androidx.widget">

<application></application>

Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/com/androidx/widget/RadiusProgressView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.androidx.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
* 圆角进度
*/
public class RadiusProgressView extends View {

private Paint paint;
//圆角
private int radius = 90;
//进度值
private int progress = 50;
//进度最大值
private int max = 100;
//背景颜色
private int solidColor = Color.parseColor("#EBEBEB");
//进度颜色
private int progressColor = Color.parseColor("#0347FE");

public RadiusProgressView(Context context) {
super(context);
initAttributeSet(context,null);
}

public RadiusProgressView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initAttributeSet(context,attrs);
}

public RadiusProgressView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initAttributeSet(context,attrs);
}

private void initAttributeSet(Context context, AttributeSet attrs) {
if (attrs != null) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RadiusProgressView);
radius = array.getDimensionPixelSize(R.styleable.RadiusProgressView_android_radius, radius);
progress = array.getInt(R.styleable.RadiusProgressView_android_progress, progress);
solidColor = array.getColor(R.styleable.RadiusProgressView_solidColor, solidColor);
progressColor = array.getColor(R.styleable.RadiusProgressView_progressColor, progressColor);
array.recycle();
}
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(solidColor);
RectF bgRect = new RectF(0, 0, getWidth(), getHeight());
canvas.drawRoundRect(bgRect, radius, radius, paint);
//进度
paint.setColor(progressColor);
RectF psRect = new RectF(0, 0, getWidth() * progress / max, getHeight());
canvas.drawRoundRect(psRect, radius, radius, paint);
}

/**
* 设置最大值
*
* @param max
*/
public void setMax(int max) {
this.max = max;
invalidate();
}

/**
* 设置进度值
*
* @param progress
*/
public void setProgress(int progress) {
this.progress = progress;
invalidate();
}

/**
* 设置进度颜色
*
* @param progressColor
*/
public void setProgressColor(int progressColor) {
this.progressColor = progressColor;
invalidate();
}

/**
* 设置背景颜色
*
* @param solidColor
*/
public void setSolidColor(int solidColor) {
this.solidColor = solidColor;
invalidate();
}

}
17 changes: 17 additions & 0 deletions app/src/test/java/com/androidx/widget/ExampleUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.androidx.widget;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
Binary file modified radius_progress_view.aar
Binary file not shown.

0 comments on commit 7f644f7

Please sign in to comment.