-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
6 changed files
with
156 additions
and
3 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
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/androidx/widget/ExampleInstrumentedTest.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,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()); | ||
} | ||
} |
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
110 changes: 110 additions & 0 deletions
110
app/src/main/java/com/androidx/widget/RadiusProgressView.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,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
17
app/src/test/java/com/androidx/widget/ExampleUnitTest.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,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 not shown.