diff --git a/entry/src/ohosTest/java/io/github/vrivotti/unifiedcircularprogress/sample/ExampleOhosTest.java b/entry/src/ohosTest/java/io/github/vrivotti/unifiedcircularprogress/sample/ExampleOhosTest.java index 3c2063ce99563dd6f66f9bde23dac02cde0b8a28..54b201597e2fa033ddcf875bb238baa6dbbb3ec3 100644 --- a/entry/src/ohosTest/java/io/github/vrivotti/unifiedcircularprogress/sample/ExampleOhosTest.java +++ b/entry/src/ohosTest/java/io/github/vrivotti/unifiedcircularprogress/sample/ExampleOhosTest.java @@ -1,19 +1,18 @@ package io.github.vrivotti.unifiedcircularprogress.sample; import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; + import org.junit.Test; import static org.junit.Assert.assertEquals; public class ExampleOhosTest { + /** + * 单元测试基础方法 + */ @Test public void testBundleName() { final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); assertEquals("io.github.vrivotti.unifiedcircularprogress", actualBundleName); } - - @Test - public void name() { - - } } \ No newline at end of file diff --git a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/ProgressBarExt.java b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/ProgressBarExt.java index 5942da321cf743df80c8cdd161136bf5f2876c98..cbb57125aaba96b55a4f62bff7d18a2feb9269ff 100644 --- a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/ProgressBarExt.java +++ b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/ProgressBarExt.java @@ -37,7 +37,7 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 构造方法 * - * @param context + * @param context 上下文 */ public ProgressBarExt(Context context) { super(context); @@ -47,8 +47,8 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 构造方法 * - * @param context - * @param attrSet + * @param context 上下文 + * @param attrSet 内容 */ public ProgressBarExt(Context context, AttrSet attrSet) { super(context, attrSet); @@ -58,9 +58,9 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 构造方法 * - * @param context - * @param attrSet - * @param styleName + * @param context 上下文 + * @param attrSet 内容 + * @param styleName 样式 */ public ProgressBarExt(Context context, AttrSet attrSet, String styleName) { super(context, attrSet, styleName); @@ -70,9 +70,9 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 构造方法 * - * @param context - * @param attrSet - * @param resId + * @param context 上下文 + * @param attrSet 内容 + * @param resId 资源ID */ public ProgressBarExt(Context context, AttrSet attrSet, int resId) { super(context, attrSet, resId); @@ -107,12 +107,13 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 设置进度 * - * @param progress + * @param progress 进度值 */ public void setProgress(int progress) { - progress = constrain(progress, 0, 100); + int valueProgress = 0; + valueProgress = constrain(progress, 0, 100); int range = 100; - final float scale = range > 0 ? (progress - 0) / (float) range : 0; + final float scale = range > 0 ? (valueProgress - 0) / (float) range : 0; if (scale == mProgress && !mIndeterminate) { return; } @@ -122,7 +123,7 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * 设置进度 * - * @param progress + * @param progress 进度值 */ public void setProgress(float progress) { mProgress = progress; @@ -134,7 +135,7 @@ public class ProgressBarExt extends Component implements Component.DrawTask { /** * setIndeterminate * - * @param indeterminate + * @param indeterminate 布尔值 */ public void setIndeterminate(boolean indeterminate) { if (!indeterminate) { diff --git a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueExt.java b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueExt.java index 1792eaa59127d86dbc74acbd2e2bc6fd51f2c0cf..c569779555a25cb8d57a75deac1f545c9eab0971 100644 --- a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueExt.java +++ b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueExt.java @@ -35,8 +35,8 @@ public class AnimatorValueExt extends AnimatorValue implements AnimatorValue.Val } /** ofFloat - * @param rate - * @param values + * @param rate 起始位置 + * @param values 起始值 * @return AnimatorValueExt */ public static AnimatorValueExt ofFloat(float[] rate, float[] values) { @@ -51,17 +51,25 @@ public class AnimatorValueExt extends AnimatorValue implements AnimatorValue.Val } } + /** + * 获取动画进度 + * @return float + */ public float getAnimatedValue() { return currentValue; } + /** + * 设置动画监听 + * @param lis 动画监听 + */ public void setValueUpdateListener(ValueUpdateListener lis) { this.listener = lis; } public interface ValueUpdateListener { /** onAnimationUpdate - * @param animatorValue + * @param animatorValue 动画值 */ void onAnimationUpdate(AnimatorValueExt animatorValue); } diff --git a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueUtil.java b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueUtil.java index 05b23d9c357089d79659eba6bdc4609a1b07144d..0ba85be0418b113e3ee04b223db26f63a5c4e051 100644 --- a/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueUtil.java +++ b/library/src/main/java/io/github/vrivotti/unifiedcircularprogress/util/AnimatorValueUtil.java @@ -3,9 +3,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,28 +28,28 @@ package io.github.vrivotti.unifiedcircularprogress.util; public class AnimatorValueUtil { private int rateSize = 2; private int negaTive = -1; - private float[]values; - private float[][]rate; + private float[] values; + private float[][] rate; + /** * 如传一个参数,则getValue 返回值与传入的 V 值一致 * 如传入连续两个相同参数,则会出现除0异常 * 传参试例: 0.8f,-1.2f,3.5f,0,5 * - * @param tempRate 说明 - * @param tempValues + * @param tempRate 说明 + * @param tempValues 起始值 */ - public void ofFloat(float tempRate[], float[]tempValues) { + public void ofFloat(float[] tempRate, float[] tempValues) { this.values = tempValues; rate = new float[this.values.length - 1][rateSize]; - // 计算每个变化值的占比和达到该变化值系数 for (int i = 0; i < rate.length; i++) { - float temp = tempRate[i+1]; + float temp = tempRate[i + 1]; rate[i][0] = temp; float tempDuration = this.values[i + 1] - this.values[i]; - rate[i][1] = (this.values[i] > this.values[i + 1] ? negaTive : 1) * Math.abs(tempDuration / (temp - tempRate[i])); + rate[i][1] = (this.values[i] > this.values[i + 1] ? negaTive : 1) * + Math.abs(tempDuration / (temp - tempRate[i])); } - } /** @@ -59,7 +59,6 @@ public class AnimatorValueUtil { * @return 通过计算后的值 */ public float getValue(float value) { - for (int i = 0; i < rate.length; i++) { if (value <= rate[i][0] || value > 1) { return values[i] + (i == 0 ? value : value - rate[i - 1][0]) * rate[i][1]; diff --git a/library/src/test/java/io/github/vrivotti/unifiedcircularprogress/ExampleTest.java b/library/src/test/java/io/github/vrivotti/unifiedcircularprogress/ExampleTest.java index faa69a7b6c7ac1a21036d7d314df7041bd0e0d1a..788f7d2f5aeb68f96bffde9d0e7e14cd84bffd5e 100644 --- a/library/src/test/java/io/github/vrivotti/unifiedcircularprogress/ExampleTest.java +++ b/library/src/test/java/io/github/vrivotti/unifiedcircularprogress/ExampleTest.java @@ -3,6 +3,9 @@ package io.github.vrivotti.unifiedcircularprogress; import org.junit.Test; public class ExampleTest { + /** + * 单元测试 + */ @Test public void onStart() { }