diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..8dada3edaf50dbc082c9a125058f25def75e625a --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.OPENSOURCE b/README.OPENSOURCE index d0d788a591b1585ed116229c34baaafc246cfb2d..bf04c09e33f657e15af907fe8257f73c7efb629b 100644 --- a/README.OPENSOURCE +++ b/README.OPENSOURCE @@ -4,9 +4,9 @@ "Name": "CircleProgress", - "License": "", + "License": "Apache-2.0 License", - "License File": "", + "License File": "LICENSE", "Version Number": "v1.0", diff --git a/build.gradle b/build.gradle index 2368e1d63380a3fe53798b21625a9e8dc5b1f91a..f0c73f75841a46b558f59b3d99e82c8f916c5dd3 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.huawei.ohos.app' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } @@ -19,13 +19,16 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.7' - classpath 'com.huawei.ohos:decctest:1.0.0.6' + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } allprojects { repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } maven { url 'https://mirrors.huaweicloud.com/repository/maven/' } diff --git a/chandeLog.md b/chandeLog.md index 81eb5b24eb3e1f432d6c98e7a7257b8d0c0b0b9d..43fa2919a332f7f4add48c798deec372c353f05d 100644 --- a/chandeLog.md +++ b/chandeLog.md @@ -1,2 +1,4 @@ -0.0.1-SNAPSHOT +0.0.2-SNAPSHOT +ohos 第2个版本,更新sdk6 +0.0.1-SNAPSHOT ohos 第一个版本,完整实现了原库的全部 api \ No newline at end of file diff --git a/circleprogress/build.gradle b/circleprogress/build.gradle index 45ad141eba4c4e01bbf01a0acfbb6fd2d7921975..a94ea865e15b19dc52056088691cb4dda25282ed 100644 --- a/circleprogress/build.gradle +++ b/circleprogress/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.huawei.ohos.library' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/DialProgress.java b/circleprogress/src/main/java/com/littlejie/circleprogress/DialProgress.java index be923a1d592cb7a45d6b938d92504a4b48bd44ef..315128474e852d4108b730342e7b006d6ac9d459 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/DialProgress.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/DialProgress.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 an 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. @@ -15,10 +15,7 @@ package com.littlejie.circleprogress; -import com.littlejie.circleprogress.utils.AnimatorValueUpdateUtil; -import com.littlejie.circleprogress.utils.Constant; -import com.littlejie.circleprogress.utils.MiscUtil; -import com.littlejie.circleprogress.utils.ViewUtils; +import com.littlejie.circleprogress.utils.*; import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorValue; import ohos.agp.components.AttrSet; @@ -103,7 +100,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo private void init(Context context, AttrSet attrs) { mContext = context; - mDefaultSize = (int) ViewUtils.getInstance().vp2Px(context, (float) Constant.DEFAULT_SIZE); + mDefaultSize = (int) ViewUtils.getInstance().vp2Px(context, Constant.DEFAULT_SIZE); mRectF = new RectFloat(); mCenterPoint = new Point(); initAttrs(attrs); @@ -191,7 +188,8 @@ public class DialProgress extends Component implements Component.DrawTask, Compo /** * 更新圆弧画笔 */ - private void updateArcPaint() { + private void updateArcPaint(int[] setColor) { + mGradientColors = setColor; float[] color = {0, 1f}; Point[] listPoint = {mCenterPoint}; // 设置渐变 @@ -216,24 +214,26 @@ public class DialProgress extends Component implements Component.DrawTask, Compo /** * 初始化坐标点 + * * @param component */ public void initPoint(Component component) { int minSize = Math.min(component.getWidth() - component.getPaddingLeft() - component.getPaddingRight() - 2 * (int) mArcWidth, component.getHeight() - component.getPaddingTop() - component.getPaddingBottom() - 2 * (int) mArcWidth); - mRadius = minSize / 2; - mCenterPoint = new Point(component.getWidth() / 2, component.getHeight() / 2); + mRadius = (float) minSize / 2; + mCenterPoint = new Point((float) component.getWidth() / 2, (float) component.getHeight() / 2); + float halfWidth = mArcWidth / 2; // 绘制圆弧的边界 - mRectF.left = (int) (mCenterPoint.getPointX() - mRadius - mArcWidth / 2); - mRectF.top = (int) (mCenterPoint.getPointY() - mRadius - mArcWidth / 2); - mRectF.right = (int) (mCenterPoint.getPointX() + mRadius + mArcWidth / 2); - mRectF.bottom = (int) (mCenterPoint.getPointY() + mRadius + mArcWidth / 2); + mRectF.left = DecimalUtils.subMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.top = DecimalUtils.subMore(mCenterPoint.getPointY(), mRadius, halfWidth); + mRectF.right = DecimalUtils.addMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.bottom = DecimalUtils.addMore(mCenterPoint.getPointY(), mRadius, halfWidth); - mValueOffset = mCenterPoint.getPointY() + getBaselineOffsetFromY(mValuePaint); - mHintOffset = mCenterPoint.getPointY() - mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mHintPaint); - mUnitOffset = mCenterPoint.getPointY() + mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mUnitPaint); + mValueOffset = DecimalUtils.add(mCenterPoint.getPointY(), getBaselineOffsetFromY(mValuePaint)); + mHintOffset = DecimalUtils.add(DecimalUtils.sub(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius)), getBaselineOffsetFromY(mHintPaint)); + mUnitOffset = DecimalUtils.addMore(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius), getBaselineOffsetFromY(mUnitPaint)); - updateArcPaint(); + updateArcPaint(mGradientColors); HiLog.info(LABEL, "onMeasure: 控件大小 = " + "(" + component.getWidth() + ", " + component.getHeight() + ")" + ";圆心坐标 = " + mCenterPoint.toString() + ";圆半径 = " + mRadius @@ -241,7 +241,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo } private float getBaselineOffsetFromY(Paint paint) { - return MiscUtil.measureTextHeight(paint) / 2; + return (float) MiscUtil.measureTextHeight(paint) / 2; } private void drawArc(Canvas canvas) { @@ -250,7 +250,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo canvas.save(); canvas.rotate(mStartAngle, mCenterPoint.getPointX(), mCenterPoint.getPointY()); Arc bgArc = new Arc(); - bgArc.setArc(currentAngle, mSweepAngle - currentAngle, false); + bgArc.setArc(currentAngle, DecimalUtils.sub(mSweepAngle, currentAngle), false); canvas.drawArc(mRectF, bgArc, mBgArcPaint); // Arc arc = new Arc(); @@ -263,12 +263,16 @@ public class DialProgress extends Component implements Component.DrawTask, Compo /** * 画扇形进度条 + * * @param canvas */ private void updateArcPaint(Canvas canvas) { float angle = mPercent * 270; float[] color = {0.1f, 0.7f}; - Point[] pointsL = new Point[]{new Point(mCenterPoint.getPointX() + 50, mCenterPoint.getPointY() + mRadius), new Point(mCenterPoint.getPointX() - mRadius, mCenterPoint.getPointY() - mRadius)}; + Point[] pointsL = new Point[]{new Point(DecimalUtils.add(mCenterPoint.getPointX(), 50), + DecimalUtils.add(mCenterPoint.getPointY(), mRadius)), + new Point(DecimalUtils.sub(mCenterPoint.getPointX(), mRadius), + DecimalUtils.sub(mCenterPoint.getPointY(), mRadius))}; LinearShader linearShaderL = new LinearShader(pointsL, color, mGradientColorList, Shader.TileMode.CLAMP_TILEMODE); @@ -287,7 +291,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo canvas.save(); canvas.rotate(mStartAngle, mCenterPoint.getPointX(), mCenterPoint.getPointY()); for (int i = 0; i <= total; i++) { - Point newLinePoint = new Point(mCenterPoint.getPointX() + mRadius + mArcWidth, mCenterPoint.getPointY()); + Point newLinePoint = new Point(DecimalUtils.addMore(mCenterPoint.getPointX(), mRadius, mArcWidth), mCenterPoint.getPointY()); canvas.drawLine(mCenterPoint, newLinePoint, mDialPaint); canvas.rotate(mDialIntervalDegree, mCenterPoint.getPointX(), mCenterPoint.getPointY()); } @@ -305,7 +309,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo } } - public float getMaxValue() { + public double getMaxValue() { return mMaxValue; } @@ -325,16 +329,16 @@ public class DialProgress extends Component implements Component.DrawTask, Compo if (value > mMaxValue) { value = mMaxValue; } - float start = mPercent; - float end = value / mMaxValue; + double start = mPercent; + double end = value / mMaxValue; mValue = value; startAnimator(start, end, mAnimTime); } - private float exPercent = 0; + private double exPercent = 0; private AnimatorValueUpdateUtil animatorValueUpdateUtil = new AnimatorValueUpdateUtil(); - private void startAnimator(float start, float end, long animTime) { + private void startAnimator(double start, double end, long animTime) { mAnimator = new AnimatorValue(); mAnimator.setDuration(1000); mAnimator.setCurveType(Animator.CurveType.SMOOTH_STEP); @@ -343,7 +347,7 @@ public class DialProgress extends Component implements Component.DrawTask, Compo mAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override public void onUpdate(AnimatorValue animatorValue, float v) { - mPercent = animatorValueUpdateUtil.getValue(v); + mPercent = (float) animatorValueUpdateUtil.getValue(v); // System.out.println("动画改变值 : " + mPercent + "--------------------默认值 = " + v); invalidate(); @@ -353,12 +357,12 @@ public class DialProgress extends Component implements Component.DrawTask, Compo } public int[] getGradientColors() { - return mGradientColors; + int[] returnData = mGradientColors; + return returnData; } public void setGradientColors(int[] gradientColors) { - mGradientColors = gradientColors; - updateArcPaint(); + updateArcPaint(gradientColors); } public void reset() { diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/RoundProgressView.java b/circleprogress/src/main/java/com/littlejie/circleprogress/RoundProgressView.java index f63621fbda6b224f3202ed47ad9b18dedf583bc7..1e1faea5fe5127a6e0c2b6eeadfa3a81a70b9148 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/RoundProgressView.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/RoundProgressView.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 an 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. @@ -15,12 +15,10 @@ package com.littlejie.circleprogress; -import com.littlejie.circleprogress.utils.AnimatorValueUpdateUtil; -import com.littlejie.circleprogress.utils.Constant; -import com.littlejie.circleprogress.utils.MiscUtil; -import com.littlejie.circleprogress.utils.ViewUtils; +import com.littlejie.circleprogress.utils.*; import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorValue; +import ohos.agp.components.Attr; import ohos.agp.components.AttrSet; import ohos.agp.components.Component; import ohos.agp.render.*; @@ -32,6 +30,8 @@ import ohos.app.Context; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; +import java.util.Optional; + /** * 环形或圆形普通进度条 * @@ -76,8 +76,6 @@ public class RoundProgressView extends Component implements Component.DrawTask, private float mArcWidth; private Color mArcColor; private RectFloat mRectF; - //渐变的颜色是360度,如果只显示270,那么则会缺失部分颜色 - private Shader mSweepGradient; private Color[] mGradientColorList = {Color.GREEN, Color.YELLOW, Color.RED}; private Color[] mGradientColorListFir = {Color.GREEN, Color.YELLOW}; private Color[] mGradientColorListSec = {Color.RED, Color.YELLOW}; @@ -99,17 +97,37 @@ public class RoundProgressView extends Component implements Component.DrawTask, public RoundProgressView(Context context) { super(context); - init(context, null, ""); + init(context, new AttrSet() { + @Override + public Optional getStyle() { + return Optional.empty(); + } + + @Override + public int getLength() { + return 0; + } + + @Override + public Optional getAttr(int i) { + return Optional.empty(); + } + + @Override + public Optional getAttr(String s) { + return Optional.empty(); + } + }); } public RoundProgressView(Context context, AttrSet attrSet) { super(context, attrSet); - init(context, attrSet, ""); + init(context, attrSet); } public RoundProgressView(Context context, AttrSet attrSet, String styleName) { super(context, attrSet, styleName); - init(context, attrSet, styleName); + init(context, attrSet); } /** @@ -117,9 +135,8 @@ public class RoundProgressView extends Component implements Component.DrawTask, * * @param context * @param attrSet - * @param styleName */ - public void init(Context context, AttrSet attrSet, String styleName) { + public void init(Context context, AttrSet attrSet) { mContext = context; initAttrs(attrSet); mRectF = new RectFloat(); @@ -231,22 +248,24 @@ public class RoundProgressView extends Component implements Component.DrawTask, /** * 初始化坐标点 + * * @param component */ public void initPoint(Component component) { int minSize = Math.min(component.getWidth() - component.getPaddingLeft() - component.getPaddingRight() - 2 * (int) mArcWidth, component.getHeight() - component.getPaddingTop() - component.getPaddingBottom() - 2 * (int) mArcWidth); - mRadius = minSize / 2; - mCenterPoint = new Point(component.getWidth() / 2, component.getHeight() / 2); + mRadius = (float) minSize / 2; + mCenterPoint = new Point((float) component.getWidth() / 2, (float) component.getHeight() / 2); + float halfWidth = mArcWidth / 2; //绘制圆弧的边界 - mRectF.left = (int) (mCenterPoint.getPointX() - mRadius - mArcWidth / 2); - mRectF.top = (int) (mCenterPoint.getPointY() - mRadius - mArcWidth / 2); - mRectF.right = (int) (mCenterPoint.getPointX() + mRadius + mArcWidth / 2); - mRectF.bottom = (int) (mCenterPoint.getPointY() + mRadius + mArcWidth / 2); + mRectF.left = DecimalUtils.subMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.top = DecimalUtils.subMore(mCenterPoint.getPointY(), mRadius, halfWidth); + mRectF.right = DecimalUtils.addMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.bottom = DecimalUtils.addMore(mCenterPoint.getPointY(), mRadius, halfWidth); - mValueOffset = mCenterPoint.getPointY() + getBaselineOffsetFromY(mValuePaint); - mHintOffset = mCenterPoint.getPointY() - mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mHintPaint); - mUnitOffset = mCenterPoint.getPointY() + mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mUnitPaint); + mValueOffset = DecimalUtils.add(mCenterPoint.getPointY(), getBaselineOffsetFromY(mValuePaint)); + mHintOffset = DecimalUtils.add(DecimalUtils.sub(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius)), getBaselineOffsetFromY(mHintPaint)); + mUnitOffset = DecimalUtils.addMore(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius), getBaselineOffsetFromY(mUnitPaint)); HiLog.info(LABEL, "onMeasure: 控件大小 = " + "(" + component.getWidth() + ", " + component.getHeight() + ")" + ";圆心坐标 = " + mCenterPoint.toString() @@ -265,7 +284,7 @@ public class RoundProgressView extends Component implements Component.DrawTask, canvas.save(); canvas.rotate(mStartAngle, mCenterPoint.getPointX(), mCenterPoint.getPointY()); Arc bgArc = new Arc(); - bgArc.setArc(currentAngle, mSweepAngle - currentAngle, false); + bgArc.setArc(currentAngle, DecimalUtils.sub(mSweepAngle, currentAngle), false); canvas.drawArc(mRectF, bgArc, mBgArcPaint); if (mSweepAngle == 360) { updateArcRound(canvas); @@ -276,13 +295,16 @@ public class RoundProgressView extends Component implements Component.DrawTask, /** * 画扇形进度条 + * * @param canvas */ private void updateArcPaint(Canvas canvas) { float angle = mPercent * 270; float[] color = {0.1f, 0.7f}; - Point[] pointsL = new Point[]{new Point(mCenterPoint.getPointX() + 50, mCenterPoint.getPointY() + mRadius), new Point(mCenterPoint.getPointX() - mRadius, mCenterPoint.getPointY() - mRadius)}; - + Point[] pointsL = new Point[]{new Point(DecimalUtils.add(mCenterPoint.getPointX(), 50), + DecimalUtils.add(mCenterPoint.getPointY(), mRadius)), + new Point(DecimalUtils.sub(mCenterPoint.getPointX(), mRadius), + DecimalUtils.sub(mCenterPoint.getPointY(), mRadius))}; LinearShader linearShaderL = new LinearShader(pointsL, color, mGradientColorList, Shader.TileMode.CLAMP_TILEMODE); mArcPaint.setShader(linearShaderL, Paint.ShaderType.LINEAR_SHADER); @@ -301,8 +323,10 @@ public class RoundProgressView extends Component implements Component.DrawTask, * @param canvas */ private void updateArcRound(Canvas canvas) { - Point[] pointsR = new Point[]{new Point(mCenterPoint.getPointX() + 1300, mCenterPoint.getPointY() + mRadius), new Point(mCenterPoint.getPointX(), mCenterPoint.getPointY() - mRadius)}; - Point[] pointsL = new Point[]{new Point(mCenterPoint.getPointX() + 1000, mCenterPoint.getPointY() - mRadius), new Point(mCenterPoint.getPointX(), mCenterPoint.getPointY() + mRadius)}; + Point[] pointsR = new Point[]{new Point(DecimalUtils.add(mCenterPoint.getPointX(), 1300), DecimalUtils.add(mCenterPoint.getPointY(), mRadius)), + new Point(mCenterPoint.getPointX(), DecimalUtils.sub(mCenterPoint.getPointY(), mRadius))}; + Point[] pointsL = new Point[]{new Point(DecimalUtils.add(mCenterPoint.getPointX(), 1000), DecimalUtils.sub(mCenterPoint.getPointY(), mRadius)), + new Point(mCenterPoint.getPointX(), DecimalUtils.add(mCenterPoint.getPointY(), mRadius))}; LinearShader linearShaderR = new LinearShader(pointsR, null, mGradientColorListFir, Shader.TileMode.CLAMP_TILEMODE); LinearShader linearShaderL = new LinearShader(pointsL, null, mGradientColorListSec, Shader.TileMode.CLAMP_TILEMODE); mArcPaint.setShader(linearShaderR, Paint.ShaderType.LINEAR_SHADER); @@ -310,7 +334,7 @@ public class RoundProgressView extends Component implements Component.DrawTask, Arc arcR = new Arc(0, angle > 180 ? 180 : angle, false); canvas.drawArc(mRectF, arcR, mArcPaint); if (mPercent * 100 > 50) { - angle = (mPercent - 0.5f) * 360; + angle = DecimalUtils.mul(DecimalUtils.sub(mPercent, 0.5f), 360); mArcPaint.setShader(linearShaderL, Paint.ShaderType.LINEAR_SHADER); arcR = new Arc(180, angle, false); canvas.drawArc(mRectF, arcR, mArcPaint); @@ -322,17 +346,19 @@ public class RoundProgressView extends Component implements Component.DrawTask, /** * 绘制内容文字 + * * @param component * @param canvas */ private void drawText(Component component, Canvas canvas) { if (mCenterPoint == null) { - mCenterPoint = new Point(component.getWidth() / 2, component.getHeight() / 2); + mCenterPoint = new Point((float) component.getWidth() / 2, (float) component.getHeight() / 2); } - mValueOffset = mCenterPoint.getPointY() + getBaselineOffsetFromY(mValuePaint); + mValueOffset = DecimalUtils.add(mCenterPoint.getPointY(), getBaselineOffsetFromY(mValuePaint)); canvas.drawText(mValuePaint, String.format(mPrecisionFormat, mValue), mCenterPoint.getPointX(), mValueOffset); - mHintOffset = mCenterPoint.getPointY() - mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mHintPaint); - mUnitOffset = mCenterPoint.getPointY() + mRadius * mTextOffsetPercentInRadius + getBaselineOffsetFromY(mUnitPaint); + mHintOffset = DecimalUtils.add(DecimalUtils.sub(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius)), getBaselineOffsetFromY(mHintPaint)); + mUnitOffset = DecimalUtils.addMore(mCenterPoint.getPointY(), DecimalUtils.mul(mRadius, mTextOffsetPercentInRadius), getBaselineOffsetFromY(mUnitPaint)); + if (mHint != null) { canvas.drawText(mHintPaint, mHint.toString(), mCenterPoint.getPointX(), mHintOffset); } @@ -393,7 +419,7 @@ public class RoundProgressView extends Component implements Component.DrawTask, mAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override public void onUpdate(AnimatorValue animatorValue, float v) { - mPercent = animatorValueUpdateUtil.getValue(v); + mPercent = (float) animatorValueUpdateUtil.getValue(v); // HiLog.info(LABEL, "动画改变值 = " + mPercent + "--------------------默认值 = " + v); // mPercent = end * v; // mValue = end * mMaxValue * v; @@ -405,7 +431,7 @@ public class RoundProgressView extends Component implements Component.DrawTask, } private float getBaselineOffsetFromY(Paint paint) { - return MiscUtil.measureTextHeight(paint) / 2; + return (float) MiscUtil.measureTextHeight(paint) / 2; } public int getProgress() { diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/WaveProgress.java b/circleprogress/src/main/java/com/littlejie/circleprogress/WaveProgress.java index 4d166fee65a7605dcaea32cf52679dc4551f355a..84f36c48ec6e310e0b585a0427c0c4ba51f95351 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/WaveProgress.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/WaveProgress.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 an 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. @@ -15,10 +15,7 @@ package com.littlejie.circleprogress; -import com.littlejie.circleprogress.utils.AnimatorValueUpdateUtil; -import com.littlejie.circleprogress.utils.Constant; -import com.littlejie.circleprogress.utils.MiscUtil; -import com.littlejie.circleprogress.utils.ViewUtils; +import com.littlejie.circleprogress.utils.*; import ohos.agp.animation.AnimatorValue; import ohos.agp.components.AttrSet; import ohos.agp.components.Component; @@ -55,7 +52,7 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo private String mPrecisionFormat; // 中间显示的数字 private Paint mHintPaint; // 绘制提示 - private CharSequence mHint; + // private CharSequence mHint; private Color mHintColor; private int mHintSize; @@ -97,7 +94,7 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo mValue = ViewUtils.getInstance().getFloatValue(attrSet, Constant.ROUNDPROGRESS_VALUE, Constant.DEFAULT_VALUE); mValueSize = ViewUtils.getInstance().getDimensionValue(attrSet, Constant.ROUNDPROGRESS_VALUESIZE, Constant.DEFAULT_VALUE_SIZE); mValueColor = ViewUtils.getInstance().getAttrColorValue(attrSet, Constant.ROUNDPROGRESS_VALUECOLOR, Color.BLACK); - mHint = ViewUtils.getInstance().getAttrStringValue(attrSet, Constant.ROUNDPROGRESS_HINT, ""); + // mHint = ViewUtils.getInstance().getAttrStringValue(attrSet, Constant.ROUNDPROGRESS_HINT, ""); mHintColor = ViewUtils.getInstance().getAttrColorValue(attrSet, Constant.ROUNDPROGRESS_HINTCOLOR, Color.BLACK); mHintSize = ViewUtils.getInstance().getAttrIntValue(attrSet, Constant.ROUNDPROGRESS_HINTSIZE, Constant.DEFAULT_HINT_SIZE); mCircleWidth = ViewUtils.getInstance().getDimensionValue(attrSet, Constant.WAVEPROGRESS_CIRCLEWIDTH, Constant.DEFAULT_ARC_WIDTH); @@ -154,13 +151,14 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo public void initPoint(Component component) { int minSize = Math.min(component.getWidth() - component.getPaddingLeft() - component.getPaddingRight() - 2 * (int) mCircleWidth, component.getHeight() - component.getPaddingTop() - component.getPaddingBottom() - 2 * (int) mCircleWidth); - mRadius = minSize / 2; - mCenterPoint = new Point(component.getWidth() / 2, component.getHeight() / 2); + mRadius = (float) minSize / 2; + mCenterPoint = new Point((float) component.getWidth() / 2, (float) component.getHeight() / 2); + float halfWidth = mCircleWidth / 2; //绘制圆弧的边界 - mRectF.left = (int) (mCenterPoint.getPointX() - mRadius - mCircleWidth / 2); - mRectF.top = (int) (mCenterPoint.getPointY() - mRadius - mCircleWidth / 2); - mRectF.right = (int) (mCenterPoint.getPointX() + mRadius + mCircleWidth / 2); - mRectF.bottom = (int) (mCenterPoint.getPointY() + mRadius + mCircleWidth / 2); + mRectF.left = DecimalUtils.subMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.top = DecimalUtils.subMore(mCenterPoint.getPointY(), mRadius, halfWidth); + mRectF.right = DecimalUtils.addMore(mCenterPoint.getPointX(), mRadius, halfWidth); + mRectF.bottom = DecimalUtils.addMore(mCenterPoint.getPointY(), mRadius, halfWidth); System.out.println("onMeasure: 控件大小 = " + "(" + component.getWidth() + ", " + component.getHeight() + ")" + ";圆心坐标 = " + mCenterPoint.toString() + ";圆半径 = " + mRadius @@ -188,7 +186,7 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo private float defaultWaterLevel; private void updateWaveShader(Canvas canvas) { - float wavePercent = 1f - mPercent; + float wavePercent = DecimalUtils.sub(1f, mPercent); float canvasSize = mRadius * 2; double defaultAngularFrequency = 2.0f * Math.PI / 1.0f / canvasSize; float defaultAmplitude = canvasSize * 0.06f; @@ -258,7 +256,7 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo } private float getBaselineOffsetFromY(Paint paint) { - return MiscUtil.measureTextHeight(paint) / 2; + return (float) MiscUtil.measureTextHeight(paint) / 2; } public float getMaxValue() { @@ -303,7 +301,7 @@ public class WaveProgress extends Component implements Component.DrawTask, Compo mProgressAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override public void onUpdate(AnimatorValue animatorValue, float v) { - mPercent = animatorValueUpdateUtil.getValue(v); + mPercent = (float) animatorValueUpdateUtil.getValue(v); } }); mProgressAnimator.start(); diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/AnimatorValueUpdateUtil.java b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/AnimatorValueUpdateUtil.java index 4da7f3ad4be062006c4c8311510b91049b60ad2f..e759cce60b7462adb852dee4d6a2a82f8ebd15e3 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/AnimatorValueUpdateUtil.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/AnimatorValueUpdateUtil.java @@ -23,11 +23,11 @@ package com.littlejie.circleprogress.utils; */ public class AnimatorValueUpdateUtil { private static final String TAG = "AnimatorValueUtil"; - private final int rateSize = 2; - private final int negative = -1; - private float[] values; - private float[][] rate; - private float currentValue; + private int rateSize = 2; + private int negative = -1; + private double[] values; + private double[][] rate; + private double currentValue; /** * 如传一个参数,则getValue 返回值与传入的 V 值一致 @@ -36,18 +36,18 @@ public class AnimatorValueUpdateUtil { * * @param tempValues 说明 */ - public void ofFloat(float... tempValues) { + public void ofFloat(double... tempValues) { this.values = tempValues; - rate = new float[this.values.length - 1][rateSize]; + rate = new double[this.values.length - 1][rateSize]; float sum = 0; for (int ii = 1; ii < this.values.length; ii++) { sum += Math.abs(this.values[ii] - this.values[ii - 1]); } for (int ii = 0; ii < rate.length; ii++) { // 计算每个变化值的占比和达到该变化值系数 - float tempRate = Math.abs((this.values[ii + 1] - this.values[ii]) / sum); + double tempRate = Math.abs((this.values[ii + 1] - this.values[ii]) / sum); rate[ii][0] = tempRate + (ii == 0 ? 0 : rate[ii - 1][0]); - float tempDuration = this.values[ii + 1] - this.values[ii]; + double tempDuration = this.values[ii + 1] - this.values[ii]; rate[ii][1] = (this.values[ii] > this.values[ii + 1] ? negative : 1) * Math.abs(tempDuration / tempRate); } } @@ -58,7 +58,7 @@ public class AnimatorValueUpdateUtil { * @param value 属性动画中的value * @return 通过计算后的值 */ - public float getValue(float value) { + public double getValue(double value) { currentValue = value; for (int ii = 0; ii < rate.length; ii++) { // 如果是进入当前变化值占比,则按当前系数进行计算实际值(bounce回弹效果最后v会大于1) @@ -70,7 +70,7 @@ public class AnimatorValueUpdateUtil { return value; } - public float getCurrentValue() { + public double getCurrentValue() { return currentValue; } } diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/DecimalUtils.java b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/DecimalUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..d67757fdc73b920cb8240ebf7530c0a914fc7801 --- /dev/null +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/DecimalUtils.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 an 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.littlejie.circleprogress.utils; + +import java.math.BigDecimal; + +/** + * DecimalUtils + * + * @since 2021-04-28 + */ +public final class DecimalUtils { + private static final int DEF_DIV_SCALE = 10; + + private DecimalUtils() { + } + + /** + * 提供精确的加法运算。 + * + * @param v1 被加数 + * @param v2 加数 + * @return 两个参数的和 + */ + public static Float add(float v1, float v2) { + BigDecimal b1 = new BigDecimal(Float.toString(v1)); + BigDecimal b2 = new BigDecimal(Float.toString(v2)); + return b1.add(b2).floatValue(); + } + + /** + * 提供精确的减法运算。 + * + * @param v1 被减数 + * @param v2 减数 + * @return 两个参数的差 + */ + public static float sub(float v1, float v2) { + BigDecimal b1 = new BigDecimal(Float.toString(v1)); + BigDecimal b2 = new BigDecimal(Float.toString(v2)); + return b1.subtract(b2).floatValue(); + } + + /** + * 多个相加。 + * + * @param floats 多个加数 + * @return 多个参数的和 + */ + public static Float addMore(float... floats) { + BigDecimal returnData = new BigDecimal(Float.toString(0)); + if (floats == null) { + return 0F; + } + for (int i = 0; i < floats.length; i++) { + BigDecimal bb = new BigDecimal(Float.toString(floats[i])); + returnData = returnData.add(bb); + } + return returnData.floatValue(); + } + + /** + * 多个相减。 + * + * @param floats 减数 + * @return 多个参数的差 + */ + public static Float subMore(float... floats) { + BigDecimal returnData = null; + if (floats == null) { + return 0F; + } + for (int i = 0; i < floats.length; i++) { + BigDecimal bb = new BigDecimal(Float.toString(floats[i])); + if (returnData == null) { + returnData = bb; + } else { + returnData = returnData.subtract(bb); + } + } + return returnData.floatValue(); + } + + /** + * 提供精确的乘法运算。 + * + * @param v1 被乘数 + * @param v2 乘数 + * @return 两个参数的积 + */ + public static Float mul(float v1, float v2) { + BigDecimal b1 = new BigDecimal(Float.toString(v1)); + BigDecimal b2 = new BigDecimal(Float.toString(v2)); + return b1.multiply(b2).floatValue(); + } + + /** + * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 + * 小数点以后10位,以后的数字四舍五入。 + * + * @param v1 被除数 + * @param v2 除数 + * @return 两个参数的商 + */ + public static double div(double v1, double v2) { + return div(v1, v2, DEF_DIV_SCALE); + } + + /** + * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 + * 定精度,以后的数字四舍五入。 + * + * @param v1 被除数 + * @param v2 除数 + * @param scale 表示表示需要精确到小数点以后几位。 + * @return 两个参数的商 + */ + public static double div(double v1, double v2, int scale) { + int mScale; + mScale = scale; + if (scale < 0) { + mScale = 0; + } + BigDecimal b1 = new BigDecimal(Double.toString(v1)); + BigDecimal b2 = new BigDecimal(Double.toString(v2)); + return b1.divide(b2, mScale, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 提供精确的小数位四舍五入处理。 + * + * @param val 需要四舍五入的数字 + * @param scale 小数点后保留几位 + * @return 四舍五入后的结果 + */ + public static double round(double val, int scale) { + int mScale; + mScale = scale; + if (scale < 0) { + mScale = 0; + } + BigDecimal bd = new BigDecimal(Double.toString(val)); + BigDecimal one = new BigDecimal("1"); + return bd.divide(one, mScale, BigDecimal.ROUND_HALF_UP).doubleValue(); + } +} diff --git a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/MiscUtil.java b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/MiscUtil.java index e46ba06668de503291793426971e2e0096e4dc9f..4129bb2b4c5341b2fbf570ec0263fbf4201bb355 100644 --- a/circleprogress/src/main/java/com/littlejie/circleprogress/utils/MiscUtil.java +++ b/circleprogress/src/main/java/com/littlejie/circleprogress/utils/MiscUtil.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 an 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. @@ -79,10 +79,10 @@ public class MiscUtil { /** * 测量文字高度 * @param paint - * @return float + * @return double */ - public static float measureTextHeight(Paint paint) { + public static double measureTextHeight(Paint paint) { Paint.FontMetrics fontMetrics = paint.getFontMetrics(); - return (Math.abs(fontMetrics.ascent) - fontMetrics.descent); + return DecimalUtils.sub(Math.abs(fontMetrics.ascent), fontMetrics.descent); } } \ No newline at end of file diff --git a/entry/build.gradle b/entry/build.gradle index a9377bbac7d3f52e8e4c742db40f458a29bd51c3..14a8d929f12efec0831271cd667ae91300da950d 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,7 +1,8 @@ apply plugin: 'com.huawei.ohos.hap' apply plugin: 'com.huawei.ohos.decctest' + ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } @@ -13,14 +14,14 @@ ohos { } } } - + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13' - compile project(path: ':circleprogress') - ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200' + implementation ('com.gitee.chinasoft_ohos:CircleProgress:0.0.1-SNAPSHOT') } decc { supportType = ['html','xml'] diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 2039482a54ed265fceebf3557501003a5cab785a..e8a18033bb765ae42894ffc9e8fc5358c9137569 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -40,7 +40,6 @@ "name": "com.littlejie.app.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", - "label": "CircleProgress", "type": "page", "launchType": "standard" } diff --git a/entry/src/main/java/com/littlejie/app/slice/MainAbilitySlice.java b/entry/src/main/java/com/littlejie/app/slice/MainAbilitySlice.java index 5449cebe6f66b2080d50fbbfaacffab14466ad17..0ae381babc6336912b63d29ea3e5f6507c6835d3 100644 --- a/entry/src/main/java/com/littlejie/app/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/littlejie/app/slice/MainAbilitySlice.java @@ -131,4 +131,8 @@ public class MainAbilitySlice extends AbilitySlice implements Component.ClickedL waveProgress.setValue(0); } } + + public void showTest(){ + System.out.println("test"); + } } diff --git a/entry/src/test/java/com/littlejie/app/ExampleTest.java b/entry/src/test/java/com/littlejie/app/ExampleTest.java index 2865fdb6dac27f097890f07a349871faa545adbf..78d950d2a482f984ceb98a625e524f8a9cd8c016 100644 --- a/entry/src/test/java/com/littlejie/app/ExampleTest.java +++ b/entry/src/test/java/com/littlejie/app/ExampleTest.java @@ -1,9 +1,35 @@ package com.littlejie.app; +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; import org.junit.Test; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; + public class ExampleTest { @Test - public void onStart() { + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.littlejie.app", actualBundleName); + } + + @Test + public void logDebug() { + try { + Class mainAbilitySlice = Class.forName("com.littlejie.app.slice.MainAbilitySlice"); + Method logDebug = mainAbilitySlice.getMethod("showTest"); + Object obj = mainAbilitySlice.getConstructor().newInstance(); + logDebug.invoke(obj); + } catch (ClassNotFoundException | NoSuchMethodException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } } diff --git a/readme.md b/readme.md index 22da59f6ea62b7143122cf72ee477fae1782dded..7f66281db99caf087ceafb866b7307c55effc2e9 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,14 @@ # CIRCLEPROGRESS ------- -**本项目是基于开源项目CircleProgress进行openharmony的移植和开发的,可以通过项目标签以及github地址 (https://github.com/MyLifeMyTravel/CircleProgress) 追踪到原项目版本** ## 项目介绍 -> * 项目名称:CircleProgress -> * 所属系列:openharmony的第三方组件适配移植 -> * 功能:实现自定义弧形与圆形进度条,以及水波纹圆形进度 -> * 项目移植状态:已完成 -> * 调用差异:无 -> * 开发版本:sdk5,DevEco Studio2.1 beta3 -> * 基线版本:release 1.0.0 + * 项目名称:CircleProgress + * 所属系列:openharmony的第三方组件适配移植 + * 功能:实现自定义弧形与圆形进度条,以及水波纹圆形进度 + * 项目移植状态:已完成 + * 调用差异:无 + * 开发版本:sdk6,DevEco Studio2.2 Beta1 + * 基线版本:release 1.0.0 ## 效果演示 @@ -24,22 +22,18 @@ allprojects { repositories { maven { - url 'https://mirrors.huaweicloud.com/repository/maven/' + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } - maven { - url 'https://developer.huawei.com/repo/' - } - jcenter() } ``` 在entry模块中的build.gradle文件中 ``` dependencies { - implementation (`com.gitee.chinasoft_ohos:circleprogress:0.0.1-SNAPSHOT`) + implementation ('com.gitee.chinasoft_ohos:CircleProgress:0.0.1-SNAPSHOT') ···· } ``` -在sdk5,DevEco Studio2.1 beta3下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 +在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 ## 使用说明 环形与圆形进度条使用此组件 @@ -131,9 +125,9 @@ CodeCheck代码测试无异常 CloudTest代码测试无异常 -火绒安全病毒安全检测通过 +病毒安全检测通过 当前版本demo功能与原组件基本无差异 ``` ## 版本迭代 -> * 0.0.1_SNAPSHOT +> * 0.0.2-SNAPSHOT