Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fairytale110 committed Sep 18, 2018
1 parent 1ff9374 commit 3def581
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
12 changes: 6 additions & 6 deletions libwedgesview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.android.sampleMinSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand All @@ -24,10 +24,10 @@ android {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_8
// targetCompatibility JavaVersion.VERSION_1_8
// }
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* @class tech.nicesky.wedgesview.WedgesView
* @date on 2018/9/18-1:12
* @author fairytale110
* @email fairytale110@foxmail.com
* @email fairytale110@foxmail.com
* @description:
*
*/
package tech.nicesky.libwedgesview;

Expand All @@ -25,7 +24,7 @@
* @class tech.nicesky.wedgesview.WedgesView
* @date on 2018/9/18-1:12
* @author fairytale110
* @email fairytale110@foxmail.com
* @email fairytale110@foxmail.com
* @description:
*
*/
Expand All @@ -44,7 +43,7 @@ public class WedgesView extends View {
private float rotateSpeed = 0.5F;
private float sweepAngle = 90.0F;
private float startAngleA = 90F, startAngleB = 0F, startAngleC = -90F, startAngleD = -180F;
private float angle_max = 360F*100000F;
private float angle_max = 360F * 100000F;

public WedgesView(Context context) {
super(context);
Expand Down Expand Up @@ -101,10 +100,10 @@ private void initAttr(Context context, AttributeSet attrs) {
if (attrs != null) {
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.WedgesView);

int backgroundColor = attributes.getColor(R.styleable.WedgesView_wv_background, Color.parseColor("#FFFFFF"));
wedgeDiameter = (int) attributes.getDimension(R.styleable.WedgesView_wv_wedge_diameter, context.getResources().getDimension(R.dimen.dp_200));
rotateSpeed = attributes.getFloat(R.styleable.WedgesView_wv_rotate_speed, 0.5F);
float wedgeAlpha = attributes.getFloat(R.styleable.WedgesView_wv_wedge_alpha, 0.8F);
int backgroundColor = attributes.getColor(R.styleable.WedgesView_wv_background, Color.parseColor("#FFFFFF"));
wedgeDiameter = (int) attributes.getDimension(R.styleable.WedgesView_wv_wedge_diameter, context.getResources().getDimension(R.dimen.dp_200));
rotateSpeed = attributes.getFloat(R.styleable.WedgesView_wv_rotate_speed, 0.5F);
float wedgeAlpha = attributes.getFloat(R.styleable.WedgesView_wv_wedge_alpha, 0.8F);

setBackgroundColor(backgroundColor);
setWedgeAlpha(wedgeAlpha);
Expand All @@ -123,12 +122,12 @@ private void initAttr(Context context, AttributeSet attrs) {
* Set wedges's color
* @param colors int array, and its length must be 4
*/
public void setColors(int...colors) {
if (colors == null){
throw new IllegalArgumentException("colors cant not be null");
public void setColors(int... colors) {
if (colors == null) {
throw new IllegalArgumentException("colors cant not be null");
}
if (colors.length < 4){
throw new IllegalArgumentException("colors's length must be 4");
if (colors.length < 4) {
throw new IllegalArgumentException("colors's length must be 4");
}
this.colorA = colors[0];
this.colorB = colors[1];
Expand All @@ -155,19 +154,19 @@ private void initStartAngle() {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

int width = getMySize(diameterDefault, widthMeasureSpec);
int width = getMySize(diameterDefault, widthMeasureSpec);
int height = getMySize(diameterDefault, heightMeasureSpec);

if (width < height) {
if (width < height) {
height = width;
} else {
width = height;
width = height;
}
if (wedgeDiameter > width) {
wedgeDiameter = width;
}
if (diameterDefault > width) {
wedgeDiameter = width;
wedgeDiameter = width;
}
rectF.set(0, 0, wedgeDiameter, wedgeDiameter);
setMeasuredDimension(width, height);
Expand All @@ -177,10 +176,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

mPaddingStart = getPaddingStart();
mPaddingEnd = getPaddingEnd();
mPaddingTop = getPaddingTop();
mPaddingBottom = getPaddingBottom();
mPaddingStart = getPaddingStart();
mPaddingEnd = getPaddingEnd();
mPaddingTop = getPaddingTop();
mPaddingBottom = getPaddingBottom();

rectF.set(mPaddingStart, mPaddingTop, wedgeDiameter - mPaddingEnd, wedgeDiameter - mPaddingBottom);
}
Expand Down Expand Up @@ -214,17 +213,19 @@ private void anim() {
animator = ValueAnimator.ofInt(0);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(animation -> {

//Prevent infinity
if (startAngleD > angle_max || startAngleA > angle_max){
initStartAngle();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//Prevent infinity
if (startAngleD > angle_max || startAngleA > angle_max) {
initStartAngle();
}
startAngleD = startAngleD + rotateSpeed * 10F;
startAngleC = startAngleC + rotateSpeed * 8F;
startAngleB = startAngleB + rotateSpeed * 6F;
startAngleA = startAngleA + rotateSpeed * 4F;
postInvalidate();
}
startAngleD = startAngleD + rotateSpeed * 10F;
startAngleC = startAngleC + rotateSpeed * 8F;
startAngleB = startAngleB + rotateSpeed * 6F;
startAngleA = startAngleA + rotateSpeed * 4F;
postInvalidate();
});
ValueAnimatorUtil.resetDurationScale();
reStart();
Expand Down Expand Up @@ -278,11 +279,11 @@ public float getRotateSpeed() {
}

public void setWedgeAlpha(float wedgeAlpha) {
if (wedgeAlpha < 0.1F ){
if (wedgeAlpha < 0.1F) {
wedgeAlpha = 0.1F;
}

if (wedgeAlpha > 1.0F ){
if (wedgeAlpha > 1.0F) {
wedgeAlpha = 1.0F;
}
this.paintAlpha = (int) (255F * wedgeAlpha);
Expand All @@ -304,7 +305,7 @@ public void reStart() {
/**
* Stop the animation
*/
public void stop(){
public void stop() {
initStartAngle();
if (animator == null) return;
if (animator.isRunning()) {
Expand Down

0 comments on commit 3def581

Please sign in to comment.