diff --git a/ChangeLog.md b/ChangeLog.md index b9aff334553d19c4f4af929939182b35c67ed982..55bebd34a367f431c2219c0d2345a833171e8c24 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,4 +9,7 @@ * 优化代码 ## 0.0.3-SNAPSHOT -* 优化部分demo代码,更新readme \ No newline at end of file +* 优化部分demo代码,更新readme + +## 0.0.4-SNAPSHOT +* 优化部分library代码 \ No newline at end of file diff --git a/README.md b/README.md index 0da29b811e820186ed2d716bd40153ec79db573f..3454be069b3047cd708b3d425417dbca5cbb6131 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - 功能:实现多种UI:圆角、边框、渐变等UI效果 - 项目移植状态:主功能完成 - 调用差异:水波纹有问题,圆形扇形,阴影不符 -- 开发版本:sdk5,DevEco Studio2.1 beta4 +- 开发版本:sdk5,DevEco Studio2.1 Release - 基线版本:Release v0.0.1 ## 效果演示 @@ -30,11 +30,11 @@ ``` dependencies { - implementation('com.gitee.chinasoft_ohos:RWidgetHelper:0.0.3-SNAPSHOT') + implementation('com.gitee.chinasoft_ohos:RWidgetHelper:0.0.4-SNAPSHOT') ...... } ``` - 在sdk5,DevEco Studio2.1 beta4下项目可直接运行 + 在sdk5,DevEco Studio2.1 Release下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 @@ -100,11 +100,10 @@ .setBorderWidthNormal(12) .setCornerRadius(25); ``` - RText + 文字根据状态变色 默认/按下/不可点击/选择` -- [x] `文字根据状态变色 默认/按下/不可点击/选择` -- [x] `设置字体样式` + 设置字体样式 | 属性 |说明 | | ------------- | :-------------| @@ -116,28 +115,14 @@ | icon_with_text | 图片和文本一起居中 true/false | | text_typeface | 字体样式 | - RTextFielde -> RTextFielde 使用方法跟 RText 一致 + RTextFielde 使用方法跟 RText 一致 RDirectionLayout / RDependentLayout / RStackLayout / RComponent / RConstraintLayout RRadioButton / RCheckBox - RImage - -> RImage -> -> 1.圆形图片 -> -> 2.圆角图片 -> -> 3.指定某一方向圆角图片 -> -> 4.边框 -> - | 属性 |说明 | | ------------- | :-------------| | corner_radius | 圆角 四周 | @@ -161,7 +146,7 @@ CloudTest代码测试无异常 ## 版本迭代 -- 0.0.3-SNAPSHOT +- 0.0.4-SNAPSHOT ## 版权和许可信息 diff --git a/app/src/main/config.json b/app/src/main/config.json index 3586be3327190226f68c4fc1a6fd1606150b4416..39817d5c8774e6bcd2abdec6817369fa2aa304ac 100644 --- a/app/src/main/config.json +++ b/app/src/main/config.json @@ -49,7 +49,7 @@ "name": "com.example.rwidgethelper.component.RtextAbility", "icon": "$media:icon", "description": "$string:rtextability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -58,7 +58,7 @@ "name": "com.example.rwidgethelper.component.RimageAbility", "icon": "$media:icon", "description": "$string:rimageability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -67,7 +67,7 @@ "name": "com.example.rwidgethelper.component.RTextFieldAbility", "icon": "$media:icon", "description": "$string:rtextfieldeability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -76,7 +76,7 @@ "name": "com.example.rwidgethelper.component.RCommonAbility", "icon": "$media:icon", "description": "$string:rcomability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -85,7 +85,7 @@ "name": "com.example.rwidgethelper.component.GradientAbility", "icon": "$media:icon", "description": "$string:gradientability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -94,7 +94,7 @@ "name": "com.example.rwidgethelper.component.CheckedAbility", "icon": "$media:icon", "description": "$string:checkedability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -103,7 +103,7 @@ "name": "com.example.rwidgethelper.component.RipperAbility", "icon": "$media:icon", "description": "$string:ripperability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -112,7 +112,7 @@ "name": "com.example.rwidgethelper.component.ShadowAbilty", "icon": "$media:icon", "description": "$string:shadowabilty_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -121,7 +121,7 @@ "name": "com.example.rwidgethelper.component.RComponentAbility", "icon": "$media:icon", "description": "$string:rcomponedability_description", - "label": "entry", + "label": "$string:app_name", "type": "page", "launchType": "standard" } diff --git a/app/src/ohosTest/java/com/example/rwidgethelper/MainAbilityTest.java b/app/src/ohosTest/java/com/example/rwidgethelper/ExampleOhosTest.java similarity index 83% rename from app/src/ohosTest/java/com/example/rwidgethelper/MainAbilityTest.java rename to app/src/ohosTest/java/com/example/rwidgethelper/ExampleOhosTest.java index 70f366dfe858fbfafb01ddf89b3bc8a9675d6fc3..b14db7931ca0f793d9ecda83846959b7c256aa25 100644 --- a/app/src/ohosTest/java/com/example/rwidgethelper/MainAbilityTest.java +++ b/app/src/ohosTest/java/com/example/rwidgethelper/ExampleOhosTest.java @@ -7,8 +7,8 @@ import org.junit.Test; import static org.junit.Assert.*; -public class MainAbilityTest { - // 全UI应用UI不支持单元测试 +public class ExampleOhosTest { + // UI组件不支持单元测试 @Test public void testBundleName() { final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); diff --git a/build.gradle b/build.gradle index 65297cc8d10945f0d0ce2519f0492ca27b006e3d..b6dfeb3dd160aaffa88a40841a99db884849d57f 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:hap:2.4.4.2' classpath 'com.huawei.ohos:decctest:1.0.0.6' } } diff --git a/img/demo.gif b/img/demo.gif index 245dfbb25b9861294a5848d44cf8b6639c160219..3e365dca62dfd3267509a3fd81a8630f6b40af66 100644 Binary files a/img/demo.gif and b/img/demo.gif differ diff --git a/library/src/main/java/com/ruffian/library/widget/clip/ClipHelper.java b/library/src/main/java/com/ruffian/library/widget/clip/ClipHelper.java index 7ad9d97f134571c0c69a1f64455dcfe8d5c20bb6..f1a77ff4a298cf94d8cf941ab62d37ba01297974 100644 --- a/library/src/main/java/com/ruffian/library/widget/clip/ClipHelper.java +++ b/library/src/main/java/com/ruffian/library/widget/clip/ClipHelper.java @@ -43,7 +43,7 @@ public class ClipHelper implements IClip { if (!canClip()) { return; } - clipPaint.setBlendMode(BlendMode.DST_IN); // todo 鸿蒙中不区分版本 所以不确定哪个属性才能正确显示 + clipPaint.setBlendMode(BlendMode.DST_IN); // 设置clip clipPathManager.setClipPathCreator(clipPathCreator); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RCheckBox.java b/library/src/main/java/com/ruffian/library/widget/component/RCheckBox.java index fbc1c239239ca8ac16676eb7da8b966bce2a8ce3..ea031b322336e6fa76735614fe74bdca5b1d7ac7 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RCheckBox.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RCheckBox.java @@ -16,10 +16,21 @@ import ohos.multimodalinput.event.TouchEvent; public class RCheckBox extends Checkbox implements RHelper, Component.TouchEventListener { private RCheckHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RCheckBox(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RCheckBox(Context context, AttrSet attrs) { super(context, attrs); mHelper = new RCheckHelper(context, this, attrs); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RComponent.java b/library/src/main/java/com/ruffian/library/widget/component/RComponent.java index eca9dcce1aa9dec57674e4811c983bf3edd3dac2..d085df9a1e2305335f5b24a0a3d2010015364faf 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RComponent.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RComponent.java @@ -14,14 +14,32 @@ import ohos.app.Context; public class RComponent extends Component implements RHelper { private RBaseHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RComponent(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RComponent(Context context, AttrSet attrs) { this(context, attrs, 0); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + * @param defStyleAttr 默认 + */ public RComponent(Context context, AttrSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mHelper = new RBaseHelper(context, this, attrs); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RConstraintLayout.java b/library/src/main/java/com/ruffian/library/widget/component/RConstraintLayout.java index 5210df98b0a9478874733185ada62b214f080856..dca6e4a63126b7c13e3fe33a2a74c0452dca15a8 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RConstraintLayout.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RConstraintLayout.java @@ -15,14 +15,32 @@ import ohos.app.Context; public class RConstraintLayout extends StackLayout implements RHelper { private RBaseHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RConstraintLayout(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrSet 属性集 + */ public RConstraintLayout(Context context, AttrSet attrSet) { this(context, attrSet, ""); } + /** + * 构造 + * + * @param context 上下文 + * @param attrSet 属性集 + * @param styleName string值 + */ public RConstraintLayout(Context context, AttrSet attrSet, String styleName) { super(context, attrSet, styleName); mHelper = new RBaseHelper<>(context, this, attrSet); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RDependentLayout.java b/library/src/main/java/com/ruffian/library/widget/component/RDependentLayout.java index 4fc596c05e807ac2a4a75437d668c05babf420ab..1a8b0c07fa0ce2d346907b202257f320780fa76d 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RDependentLayout.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RDependentLayout.java @@ -14,14 +14,32 @@ import ohos.app.Context; public class RDependentLayout extends DependentLayout implements RHelper { private RBaseHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RDependentLayout(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RDependentLayout(Context context, AttrSet attrs) { this(context, attrs, ""); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + * @param defStyleAttr 默认 + */ public RDependentLayout(Context context, AttrSet attrs, String defStyleAttr) { super(context, attrs, defStyleAttr); mHelper = new RBaseHelper<>(context, this, attrs); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RDirectionLayout.java b/library/src/main/java/com/ruffian/library/widget/component/RDirectionLayout.java index aa8149e12a27235d26061380490757eef58d4be8..80595868a68860de2447a6c6a5b8516709f998e0 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RDirectionLayout.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RDirectionLayout.java @@ -16,14 +16,32 @@ import ohos.app.Context; public class RDirectionLayout extends DirectionalLayout implements RHelper, Component.DrawTask { private RBaseHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RDirectionLayout(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RDirectionLayout(Context context, AttrSet attrs) { this(context, attrs, ""); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + * @param defStyleAttr 默认值 + */ public RDirectionLayout(Context context, AttrSet attrs, String defStyleAttr) { super(context, attrs, defStyleAttr); addDrawTask(this::onDraw); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RImage.java b/library/src/main/java/com/ruffian/library/widget/component/RImage.java index 23bbd934da02c9dca146c22f4d31d5ac1c35ce1d..993c30b9792078adc028169568db65a0ef5aaee6 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RImage.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RImage.java @@ -17,6 +17,7 @@ public class RImage extends Image implements Component.DrawTask { // 边框 private float mBorderWidth = 0; private Color mBorderColor = Color.BLACK; + // 是否圆形 private boolean mIsCircle = false; private Element mDrawable; @@ -26,11 +27,22 @@ public class RImage extends Image implements Component.DrawTask { private BlendMode mTintMode = BlendMode.SRC_ATOP; private PixelMap bitmap; + /** + * 构造 + * + * @param context 上下文 + */ public RImage(Context context) { this(context, null); addDrawTask(this::onDraw); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RImage(Context context, AttrSet attrs) { super(context, attrs); addDrawTask(this::onDraw); @@ -84,6 +96,12 @@ public class RImage extends Image implements Component.DrawTask { } } + /** + * 构造 + * + * @param isCircle 是否圆 + * @return true类型 + */ public RImage isCircle(boolean isCircle) { this.mIsCircle = isCircle; updateDrawableAttrs(); @@ -99,6 +117,12 @@ public class RImage extends Image implements Component.DrawTask { return mBorderWidth; } + /** + * 构造 + * + * @param borderWidth 宽度 + * @return 宽度值 + */ public RImage setBorderWidth(int borderWidth) { this.mBorderWidth = borderWidth; updateDrawableAttrs(); @@ -109,6 +133,12 @@ public class RImage extends Image implements Component.DrawTask { return mBorderColor; } + /** + * 构造 + * + * @param borderColor 颜色 + * @return 颜色值 + */ public RImage setBorderColor(Color borderColor) { this.mBorderColor = borderColor; updateDrawableAttrs(); diff --git a/library/src/main/java/com/ruffian/library/widget/component/RRadioButton.java b/library/src/main/java/com/ruffian/library/widget/component/RRadioButton.java index 40446801183f3a3c7abd8ba735b52589c1512072..6d234493892a91e18ff531c47cbbb770b4d3460f 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RRadioButton.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RRadioButton.java @@ -16,10 +16,21 @@ import ohos.multimodalinput.event.TouchEvent; public class RRadioButton extends RadioButton implements RHelper, Component.TouchEventListener { private RCheckHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RRadioButton(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RRadioButton(Context context, AttrSet attrs) { super(context, attrs); mHelper = new RCheckHelper(context, this, attrs); @@ -33,24 +44,32 @@ public class RRadioButton extends RadioButton implements RHelper, @Override public void setEnabled(boolean isEnabled) { super.setEnabled(isEnabled); - if (mHelper != null) { mHelper.setEnabled(isEnabled); } + if (mHelper != null) { + mHelper.setEnabled(isEnabled); + } } @Override public boolean onTouchEvent(Component component, TouchEvent event) { - if (mHelper != null) { mHelper.onTouchEvent(component, event); } + if (mHelper != null) { + mHelper.onTouchEvent(component, event); + } return super.getTouchEventListener().onTouchEvent(component, event); } @Override public void setSelected(boolean isSelected) { - if (mHelper != null) { mHelper.setSelected(isSelected); } + if (mHelper != null) { + mHelper.setSelected(isSelected); + } super.setSelected(isSelected); } @Override public void setChecked(boolean isChecked) { - if (mHelper != null) { mHelper.setChecked(isChecked); } + if (mHelper != null) { + mHelper.setChecked(isChecked); + } super.setChecked(isChecked); } } diff --git a/library/src/main/java/com/ruffian/library/widget/component/RText.java b/library/src/main/java/com/ruffian/library/widget/component/RText.java index d9401c5498f63439528d444eb2af7ff052bfc1d8..c90c4db799ed8cd2c2f40ff3f14245d67e37a052 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RText.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RText.java @@ -14,14 +14,32 @@ import ohos.app.Context; public class RText extends Text implements RHelper{ private RTextHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + * @param attrSet 属性集 + * @param styleName string值 + */ public RText(Context context, AttrSet attrSet, String styleName) { super(context, attrSet, styleName); } + /** + * 构造 + * + * @param context 上下文 + */ public RText(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RText(Context context, AttrSet attrs) { super(context, attrs); mHelper = new RTextHelper(context, this, attrs); @@ -35,12 +53,16 @@ public class RText extends Text implements RHelper{ @Override public void setEnabled(boolean isEnabled) { super.setEnabled(isEnabled); - if (mHelper != null) { mHelper.setEnabled(isEnabled); } + if (mHelper != null) { + mHelper.setEnabled(isEnabled); + } } @Override public void setSelected(boolean selected) { - if (mHelper != null) { mHelper.setSelected(selected); } + if (mHelper != null) { + mHelper.setSelected(selected); + } super.setSelected(selected); } @@ -51,7 +73,9 @@ public class RText extends Text implements RHelper{ @Override public void setVisibility(int visibility) { - if (mHelper != null) { mHelper.onVisibilityChanged(null, visibility); } + if (mHelper != null) { + mHelper.onVisibilityChanged(null, visibility); + } super.setVisibility(visibility); } } diff --git a/library/src/main/java/com/ruffian/library/widget/component/RTextFielde.java b/library/src/main/java/com/ruffian/library/widget/component/RTextFielde.java index 606995b05c1dae9281543a449535fd738afe4a0f..e92ff0c96c7f15539b8624b55b891b4920bfe41c 100644 --- a/library/src/main/java/com/ruffian/library/widget/component/RTextFielde.java +++ b/library/src/main/java/com/ruffian/library/widget/component/RTextFielde.java @@ -16,10 +16,21 @@ import ohos.multimodalinput.event.TouchEvent; public class RTextFielde extends TextField implements RHelper,Component.TouchEventListener { private RTextHelper mHelper; + /** + * 构造 + * + * @param context 上下文 + */ public RTextFielde(Context context) { this(context, null); } + /** + * 构造 + * + * @param context 上下文 + * @param attrs 属性集 + */ public RTextFielde(Context context, AttrSet attrs) { super(context, attrs); mHelper = new RTextHelper(context, this, attrs); diff --git a/library/src/main/java/com/ruffian/library/widget/helper/RBaseHelper.java b/library/src/main/java/com/ruffian/library/widget/helper/RBaseHelper.java index e0879214482871f422cf9fe4f3680d493d359123..48b5c44de117b0d875ef508c61248fb695f5b64c 100644 --- a/library/src/main/java/com/ruffian/library/widget/helper/RBaseHelper.java +++ b/library/src/main/java/com/ruffian/library/widget/helper/RBaseHelper.java @@ -200,6 +200,13 @@ public class RBaseHelper implements IClip, Component.Layout private float zj; private Paint paint; + /** + * 构造 + * + * @param context 上下文 + * @param component component + * @param attrs 属性集 + */ public RBaseHelper(Context context, T component, AttrSet attrs) { mComponent = component; mContext = context; @@ -505,6 +512,12 @@ public class RBaseHelper implements IClip, Component.Layout return mGradientType; } + /** + * 构造 + * + * @param gradientRadius 角度 + * @return 返回角度 + */ public RBaseHelper setGradientRadius(float gradientRadius) { this.mGradientRadius = gradientRadius; setGradient(); @@ -512,6 +525,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param gradientCenterX x + * @return 背景 + */ public RBaseHelper setGradientCenterX(float gradientCenterX) { this.mGradientCenterX = gradientCenterX; setGradient(); @@ -519,6 +538,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param gradientCenterY y + * @return 背景 + */ public RBaseHelper setGradientCenterY(float gradientCenterY) { this.mGradientCenterY = gradientCenterY; setGradient(); @@ -542,6 +567,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param orientation 方向 + * @return 背景 + */ public RBaseHelper setGradientOrientation(ShapeElement.Orientation orientation) { this.mGradientOrientation = orientation; setGradient(); @@ -591,6 +622,16 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 背景 + * + * @param normalArray 颜色 + * @param pressedArray 颜色 + * @param unableArray 颜色 + * @param checkedArray 颜色 + * @param selectedArray 颜色 + * @return 颜色集合 + */ public RBaseHelper setStateBackgroundColorArray(Color[] normalArray, Color[] pressedArray, Color[] unableArray, Color[] checkedArray, Color[] selectedArray) { mBackgroundColorNormalArray = normalArray; mBackgroundColorPressedArray = pressedArray; @@ -613,6 +654,16 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 背景 + * + * @param normal 背景 + * @param pressed 背景 + * @param unable 背景 + * @param checked 背景 + * @param selected 背景 + * @return 背景颜色 + */ public RBaseHelper setStateBackgroundColor(Element normal, Element pressed, Element unable, Element checked, Element selected) { mBackgroundNormalBmp = normal; mBackgroundPressedBmp = pressed; @@ -688,6 +739,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBackgroundSelectedBmp; } + /** + * 构造 + * + * @param colorNormal 颜色 + * @return 颜色 + */ public RBaseHelper setBackgroundColorNormal(Color colorNormal) { this.mBackgroundColorNormal = colorNormal; /** @@ -714,6 +771,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorNormalArray 颜色集合 + * @return 背景颜色 + */ public RBaseHelper setBackgroundColorNormalArray(Color[] colorNormalArray) { this.mBackgroundColorNormalArray = colorNormalArray; /** @@ -744,6 +807,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param drawableNormal 背景 + * @return 默认背景 + */ public RBaseHelper setBackgroundDrawableNormal(Element drawableNormal) { this.mBackgroundNormalBmp = drawableNormal; /** @@ -766,6 +835,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorPressed 选中颜色 + * @return 颜色 + */ public RBaseHelper setBackgroundColorPressed(Color colorPressed) { this.mBackgroundColorPressed = colorPressed; this.isHasPressedBgColor = true; @@ -774,6 +849,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorPressedArray 颜色集合 + * @return 颜色 + */ public RBaseHelper setBackgroundColorPressedArray(Color[] colorPressedArray) { this.mBackgroundColorPressedArray = colorPressedArray; this.isHasPressedBgColor = true; @@ -785,6 +866,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param drawablePressed 背景图 + * @return 背景 + */ public RBaseHelper setBackgroundDrawablePressed(Element drawablePressed) { this.mBackgroundPressedBmp = drawablePressed; this.isHasPressedBgBmp = true; @@ -793,6 +880,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorUnable 颜色未选择 + * @return 未选择颜色 + */ public RBaseHelper setBackgroundColorUnable(Color colorUnable) { this.mBackgroundColorUnable = colorUnable; this.isHasUnableBgColor = true; @@ -801,6 +894,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param drawableUnable 未选择图 + * @return 背景 + */ public RBaseHelper setBackgroundDrawableUnable(Element drawableUnable) { this.mBackgroundUnableBmp = drawableUnable; this.isHasUnableBgBmp = true; @@ -809,6 +908,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorUnableArray 集合 + * @return 未选择颜色集合 + */ public RBaseHelper setBackgroundColorUnableArray(Color[] colorUnableArray) { this.mBackgroundColorUnableArray = colorUnableArray; this.isHasUnableBgColor = true; @@ -820,6 +925,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorChecked 颜色 + * @return 选中颜色 + */ public RBaseHelper setBackgroundColorChecked(Color colorChecked) { this.mBackgroundColorChecked = colorChecked; this.isHasCheckedBgColor = true; @@ -832,6 +943,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorSelected 颜色选中 + * @return 选中颜色 + */ public RBaseHelper setBackgroundColorSelected(Color colorSelected) { this.mBackgroundColorSelected = colorSelected; this.isHasSelectedBgColor = true; @@ -840,6 +957,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorCheckedArray 选中 + * @return 颜色集合 + */ public RBaseHelper setBackgroundColorCheckedArray(Color[] colorCheckedArray) { this.mBackgroundColorCheckedArray = colorCheckedArray; this.isHasCheckedBgColor = true; @@ -855,6 +978,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param colorSelectedArray 颜色集合 + * @return 集合 + */ public RBaseHelper setBackgroundColorSelectedArray(Color[] colorSelectedArray) { this.mBackgroundColorSelectedArray = colorSelectedArray; this.isHasSelectedBgColor = true; @@ -866,6 +995,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param drawableChecked 背景 + * @return 选中背景 + */ public RBaseHelper setBackgroundDrawableChecked(Element drawableChecked) { this.mBackgroundCheckedBmp = drawableChecked; this.isHasCheckedBgBmp = true; @@ -877,6 +1012,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param drawableSelected 选中背景 + * @return 背景 + */ public RBaseHelper setBackgroundDrawableSelected(Element drawableSelected) { this.mBackgroundSelectedBmp = drawableSelected; this.isHasSelectedBgBmp = true; @@ -891,6 +1032,7 @@ public class RBaseHelper implements IClip, Component.Layout */ private void refreshStateListDrawable() { mStateBackground = emptyStateListDrawable; + // unable,focused,pressed,checked,selected,normal mStateBackground.addState(states[0], mBackgroundUnableBmp == null ? mBackgroundUnable : mBackgroundUnableBmp); mStateBackground.addState(states[1], mBackgroundPressedBmp == null ? mBackgroundPressed : mBackgroundPressedBmp); @@ -901,17 +1043,17 @@ public class RBaseHelper implements IClip, Component.Layout } private void setBackgroundState() { - boolean hasCustom = false; // 是否存在自定义 - boolean hasCusBg, hasCusBorder = false, hasCusCorner = false; // 存在自定义相关属性 - boolean unHasBgColor = mBackgroundColorNormal == null && mBackgroundColorUnable == null && mBackgroundColorPressed == null && mBackgroundColorChecked == null && mBackgroundColorSelected == null; - boolean unHasBgColorArray = mBackgroundColorNormalArray == null && mBackgroundColorUnableArray == null && mBackgroundColorPressedArray == null && mBackgroundColorCheckedArray == null && mBackgroundColorSelectedArray == null; - boolean unHasBgDrawable = mBackgroundNormalBmp == null && mBackgroundPressedBmp == null && mBackgroundUnableBmp == null && mBackgroundCheckedBmp == null && mBackgroundSelectedBmp == null; + boolean isHasCustom = false; // 是否存在自定义 + boolean isHasCusBg, hasCusBorder = false, hasCusCorner = false; // 存在自定义相关属性 + boolean isUnHasBgColor = mBackgroundColorNormal == null && mBackgroundColorUnable == null && mBackgroundColorPressed == null && mBackgroundColorChecked == null && mBackgroundColorSelected == null; + boolean isUnHasBgColorArray = mBackgroundColorNormalArray == null && mBackgroundColorUnableArray == null && mBackgroundColorPressedArray == null && mBackgroundColorCheckedArray == null && mBackgroundColorSelectedArray == null; + boolean isUnHasBgDrawable = mBackgroundNormalBmp == null && mBackgroundPressedBmp == null && mBackgroundUnableBmp == null && mBackgroundCheckedBmp == null && mBackgroundSelectedBmp == null; // 是否自定义了背景 - if (unHasBgColor && unHasBgColorArray && unHasBgDrawable) { // 未设置自定义背景 - hasCusBg = false; + if (isUnHasBgColor && isUnHasBgColorArray && isUnHasBgDrawable) { // 未设置自定义背景 + isHasCusBg = false; } else { - hasCusBg = true; + isHasCusBg = true; } // 是否自定义了边框 @@ -926,17 +1068,17 @@ public class RBaseHelper implements IClip, Component.Layout hasCusCorner = true; } - if (hasCusBg || hasCusCorner || hasCusBorder) { - hasCustom = true; + if (isHasCusBg || hasCusCorner || hasCusBorder) { + isHasCustom = true; } // 未设置自定义属性,获取原生背景并且设置 - if (!hasCustom && !useRipple()) { + if (!isHasCustom && !useRipple()) { mBackgroundDrawable = mComponentBackground; // 使用原生背景 } else { // 获取drawable - mBackgroundDrawable = getBackgroundDrawable(hasCustom, mRippleColor); + mBackgroundDrawable = getBackgroundDrawable(isHasCustom, mRippleColor); } mComponent.setBackground(mBackgroundDrawable); } @@ -944,24 +1086,23 @@ public class RBaseHelper implements IClip, Component.Layout /** * 获取 BackgroundDrawable * - * @param hasCustom 是否存在自定义背景 + * @param isHasCustom 是否存在自定义背景 * @param rippleColor 水波纹颜色 * @return 获取背景的水波纹颜色 */ - private Element getBackgroundDrawable(boolean hasCustom, Color rippleColor) { + private Element getBackgroundDrawable(boolean isHasCustom, Color rippleColor) { if (!isUseRipple()) { - return mStateBackground; } else { StateElement stateBackground = new StateElement(); int[][] states = new int[6][]; // unable,checked,selected,normal - states[0] = new int[]{COMPONENT_STATE_DISABLED};//unable - states[1] = new int[]{COMPONENT_STATE_CHECKED};//checked - states[2] = new int[]{COMPONENT_STATE_SELECTED};//selected - states[3] = new int[]{COMPONENT_STATE_FOCUSED};//FOUSED - states[4] = new int[]{COMPONENT_STATE_PRESSED};//PRESS - states[5] = new int[]{COMPONENT_STATE_EMPTY};//PRESS + states[0] = new int[]{COMPONENT_STATE_DISABLED}; // unable + states[1] = new int[]{COMPONENT_STATE_CHECKED}; // checked + states[2] = new int[]{COMPONENT_STATE_SELECTED}; // selected + states[3] = new int[]{COMPONENT_STATE_FOCUSED}; // FOUSED + states[4] = new int[]{COMPONENT_STATE_PRESSED}; // PRESS + states[5] = new int[]{COMPONENT_STATE_EMPTY}; // PRESS // unable,checked,normal stateBackground.addState(states[0], mBackgroundUnable); stateBackground.addState(states[1], mBackgroundChecked); @@ -982,6 +1123,12 @@ public class RBaseHelper implements IClip, Component.Layout return mShadowRadius >= 0; } + /** + * 构造 + * + * @param shadowRadius 角度 + * @return 角度 + */ public RBaseHelper setShadowRadius(int shadowRadius) { this.mShadowRadius = shadowRadius; setBackgroundState(); @@ -992,6 +1139,12 @@ public class RBaseHelper implements IClip, Component.Layout return mShadowRadius; } + /** + * 构造 + * + * @param shadowColor 颜色 + * @return 颜色 + */ public RBaseHelper setShadowColor(Color shadowColor) { this.mShadowColor = shadowColor; setBackgroundState(); @@ -1002,6 +1155,12 @@ public class RBaseHelper implements IClip, Component.Layout return mShadowColor; } + /** + * 构造 + * + * @param shadowDx 阴影x + * @return 阴影 + */ public RBaseHelper setShadowDx(int shadowDx) { this.mShadowDx = shadowDx; setBackgroundState(); @@ -1012,6 +1171,12 @@ public class RBaseHelper implements IClip, Component.Layout return mShadowDx; } + /** + * 构造 + * + * @param shadowDy 阴影y + * @return 阴影 + */ public RBaseHelper setShadowDy(int shadowDy) { this.mShadowDy = shadowDy; setBackgroundState(); @@ -1025,20 +1190,31 @@ public class RBaseHelper implements IClip, Component.Layout /** * 波纹 * - * @param useRipple 布尔 + * @param isRipple 布尔 * @return 上下文 */ - public RBaseHelper setUseRipple(boolean useRipple) { - this.isUseRipple = useRipple; + public RBaseHelper setUseRipple(boolean isRipple) { + this.isUseRipple = isRipple; setBackgroundState(); return this; } + /** + * 水波纹 + * + * @return 是否开启 + */ public boolean useRipple() { return isUseRipple; } + /** + * 构造 + * + * @param rippleColor 颜色 + * @return 水波纹颜色 + */ public RBaseHelper setRippleColor(Color rippleColor) { this.mRippleColor = rippleColor; this.isUseRipple = true; @@ -1050,6 +1226,12 @@ public class RBaseHelper implements IClip, Component.Layout return mRippleColor; } + /** + * 构造 + * + * @param rippleMaskDrawable 水波纹背景 + * @return 背景 + */ public RBaseHelper setRippleMaskDrawable(Element rippleMaskDrawable) { this.mRippleMaskDrawable = rippleMaskDrawable; this.isUseRipple = true; @@ -1095,6 +1277,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderWidthNormal; } + /** + * 构造 + * + * @param color 颜色 + * @return 颜色值 + */ public RBaseHelper setBorderColorNormal(Color color) { this.mBorderColorNormal = color; if (!isHasPressedBorderColor) { @@ -1122,6 +1310,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderColorNormal; } + /** + * 构造 + * + * @param width 宽度 + * @return 宽度 + */ public RBaseHelper setBorderWidthPressed(int width) { this.mBorderWidthPressed = width; this.isHasPressedBorderWidth = true; @@ -1133,6 +1327,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderWidthPressed; } + /** + * 构造 + * + * @param color 颜色 + * @return 颜色值 + */ public RBaseHelper setBorderColorPressed(Color color) { this.mBorderColorPressed = color; this.isHasPressedBorderColor = true; @@ -1144,6 +1344,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderColorPressed; } + /** + * 构造 + * + * @param color 颜色 + * @return 颜色值 + */ public RBaseHelper setBorderColorChecked(Color color) { this.mBorderColorChecked = color; this.isHasCheckedBorderColor = true; @@ -1158,6 +1364,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderColorChecked; } + /** + * 构造 + * + * @param color 颜色 + * @return 颜色值 + */ public RBaseHelper setBorderColorSelected(Color color) { this.mBorderColorSelected = color; this.isHasSelectedBorderColor = true; @@ -1169,6 +1381,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderColorSelected; } + /** + * 构造 + * + * @param width 宽度 + * @return 宽度 + */ public RBaseHelper setBorderWidthChecked(int width) { this.mBorderWidthChecked = width; this.isHasCheckedBorderWidth = true; @@ -1183,6 +1401,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderWidthChecked; } + /** + * 构造 + * + * @param width 宽度 + * @return 宽度值 + */ public RBaseHelper setBorderWidthSelected(int width) { this.mBorderWidthSelected = width; this.isHasSelectedBorderWidth = true; @@ -1194,6 +1418,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderWidthSelected; } + /** + * 构造 + * + * @param width 宽度 + * @return 边框宽度 + */ public RBaseHelper setBorderWidthUnable(int width) { this.mBorderWidthUnable = width; this.isHasUnableBorderWidth = true; @@ -1205,6 +1435,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderWidthUnable; } + /** + * 构造 + * + * @param color 颜色 + * @return 值 + */ public RBaseHelper setBorderColorUnable(Color color) { this.mBorderColorUnable = color; this.isHasUnableBorderColor = true; @@ -1216,6 +1452,16 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderColorUnable; } + /** + * 构造 + * + * @param normal 默认 + * @param pressed 选中后 + * @param unable 未选 + * @param checked 选中 + * @param selected 选中 + * @return 宽度 + */ public RBaseHelper setBorderWidth(int normal, int pressed, int unable, int checked, int selected) { this.mBorderWidthNormal = normal; @@ -1231,6 +1477,16 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param normal 默认 + * @param pressed 选中后 + * @param unable 未选 + * @param checked 选中 + * @param selected 选中 + * @return 颜色 + */ public RBaseHelper setBorderColor(Color normal, Color pressed, Color unable, Color checked, Color selected) { this.mBorderColorNormal = normal; @@ -1246,6 +1502,12 @@ public class RBaseHelper implements IClip, Component.Layout return this; } + /** + * 构造 + * + * @param dashWidth 阴影宽度 + * @return 宽度 + */ public RBaseHelper setBorderDashWidth(float dashWidth) { this.mBorderDashWidth = dashWidth; setBorder(); @@ -1256,6 +1518,12 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderDashWidth; } + /** + * 构造 + * + * @param dashGap 值 + * @return 阴影 + */ public RBaseHelper setBorderDashGap(float dashGap) { this.mBorderDashGap = dashGap; setBorder(); @@ -1266,6 +1534,13 @@ public class RBaseHelper implements IClip, Component.Layout return mBorderDashGap; } + /** + * 构造 + * + * @param dashWidth 宽度 + * @param dashGap 值 + * @return 阴影 + */ public RBaseHelper setBorderDash(float dashWidth, float dashGap) { this.mBorderDashWidth = dashWidth; this.mBorderDashGap = dashGap; @@ -1331,6 +1606,12 @@ public class RBaseHelper implements IClip, Component.Layout return mCornerRadius; } + /** + * 构造 + * + * @param topLeft 左上 + * @return 角度 + */ public RBaseHelper setCornerRadiusTopLeft(float topLeft) { this.mCornerRadius = -1; this.mCornerRadiusTopLeft = topLeft; @@ -1342,6 +1623,12 @@ public class RBaseHelper implements IClip, Component.Layout return mCornerRadiusTopLeft; } + /** + * 构造 + * + * @param topRight 右上 + * @return 角度 + */ public RBaseHelper setCornerRadiusTopRight(float topRight) { this.mCornerRadius = -1; this.mCornerRadiusTopRight = topRight; @@ -1353,6 +1640,12 @@ public class RBaseHelper implements IClip, Component.Layout return mCornerRadiusTopRight; } + /** + * 构造 + * + * @param bottomRight 右下 + * @return 角度 + */ public RBaseHelper setCornerRadiusBottomRight(float bottomRight) { this.mCornerRadius = -1; this.mCornerRadiusBottomRight = bottomRight; @@ -1364,6 +1657,12 @@ public class RBaseHelper implements IClip, Component.Layout return mCornerRadiusBottomRight; } + /** + * 构造 + * + * @param bottomLeft 左下 + * @return 角度 + */ public RBaseHelper setCornerRadiusBottomLeft(float bottomLeft) { this.mCornerRadius = -1; this.mCornerRadiusBottomLeft = bottomLeft; @@ -1375,6 +1674,15 @@ public class RBaseHelper implements IClip, Component.Layout return mCornerRadiusBottomLeft; } + /** + * 构造 + * + * @param topLeft 左边 + * @param topRight 右上 + * @param bottomRight 右下 + * @param bottomLeft 左下 + * @return 角度 + */ public RBaseHelper setCornerRadius(float topLeft, float topRight, float bottomRight, float bottomLeft) { this.mCornerRadius = -1; @@ -1433,14 +1741,13 @@ public class RBaseHelper implements IClip, Component.Layout * 设置component大小变化监听,用来更新渐变半径 */ private void addOnGlobalLayoutListener() { - } /** * 获取背景颜色 * * @param attr 属性集 - * @param key 单一颜色 + * @param key 单一颜色 * @return 背景颜色 */ private Object[] getBackgroundInfo(AttrSet attr, String key) { @@ -1468,6 +1775,7 @@ public class RBaseHelper implements IClip, Component.Layout } else if (strBgType.equals("element")) { Log.i("背景是图片"); bgType = BG_TYPE_IMG; + // 图片背景类型 bgElement = AttrUtils.getElement(attr, key, null); Log.i("anananan" + bgElement); @@ -1518,7 +1826,7 @@ public class RBaseHelper implements IClip, Component.Layout * 设置GradientDrawable颜色数组,兼容版本 * * @param element GradientDrawable - * @param colors 颜色数组 + * @param colors 颜色数组 * @return 背景颜色 */ private ShapeElement setColors(ShapeElement element, int[] colors) { @@ -1544,15 +1852,14 @@ public class RBaseHelper implements IClip, Component.Layout * @return 数值 */ protected boolean isOutside(int x, int y) { - boolean flag = false; + boolean isFlag = false; if ((x < 0 - mTouchSlop) || (x >= mComponent.getWidth() + mTouchSlop) || (y < 0 - mTouchSlop) || (y >= mComponent.getHeight() + mTouchSlop)) { - flag = true; + isFlag = true; } - return flag; + return isFlag; } - /** * 是否使用Ripple * @@ -1586,7 +1893,6 @@ public class RBaseHelper implements IClip, Component.Layout mClipHelper.onLayout(left, top, right, bottom); } - @Override public boolean onTouchEvent(Component component, TouchEvent event) { if (isUseRipple && mComponent.isEnabled()) { diff --git a/library/src/main/java/com/ruffian/library/widget/helper/RCheckHelper.java b/library/src/main/java/com/ruffian/library/widget/helper/RCheckHelper.java index af29e445235d95b74ce508ce8d116af25bdd874a..a03fb8d47a5471776c532eb8086d058de8e7fd31 100644 --- a/library/src/main/java/com/ruffian/library/widget/helper/RCheckHelper.java +++ b/library/src/main/java/com/ruffian/library/widget/helper/RCheckHelper.java @@ -22,7 +22,7 @@ import ohos.multimodalinput.event.TouchEvent; public class RCheckHelper extends RTextHelper implements Component.TouchEventListener, Component.DrawTask { // Text private Color mTextColorChecked; - private boolean mHasCheckedTextColor = false; + private boolean isHasCheckedTextColor = false; private Element mIconCheckedLeft; // Icon private Element mIconCheckedRight; private Element mIconCheckedTop; @@ -106,7 +106,7 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis if (checkedId != null) { mIconChecked = checkedId; } - mHasCheckedTextColor = mTextColorChecked != null; + isHasCheckedTextColor = mTextColorChecked != null; setup(); } @@ -119,10 +119,10 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis setIcon(mIconChecked); } - if (!mHasCheckedTextColor) { + if (!isHasCheckedTextColor) { mTextColorChecked = mTextColorNormal; } - initPressedTextColor(mHasCheckedTextColor, mTextColorChecked); + initPressedTextColor(isHasCheckedTextColor, mTextColorChecked); states[0] = new int[]{-ComponentState.COMPONENT_STATE_DISABLED}; // unable @@ -139,21 +139,28 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis // 设置文本颜色 setTextColor(); } + @Override public RCheckHelper setTextColorNormal(Color textColor) { - if (!mHasCheckedTextColor) { + if (!isHasCheckedTextColor) { mTextColorChecked = textColor; } super.setTextColorNormal(textColor); - initPressedTextColor(mHasCheckedTextColor, mTextColorChecked); + initPressedTextColor(isHasCheckedTextColor, mTextColorChecked); setTextColor(); return this; } + /** + * 构造 + * + * @param textColor 文字颜色 + * @return 颜色 + */ public RCheckHelper setTextColorChecked(Color textColor) { this.mTextColorChecked = textColor; - this.mHasCheckedTextColor = true; - initPressedTextColor(mHasCheckedTextColor, mTextColorChecked); + this.isHasCheckedTextColor = true; + initPressedTextColor(isHasCheckedTextColor, mTextColorChecked); setTextColor(); return this; } @@ -162,9 +169,19 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis return mTextColorChecked; } + /** + * 构造 + * + * @param normal 默认 + * @param pressed 选中后 + * @param unable 未选中 + * @param checked 选中 + * @param selected 选中 + * @return 颜色 + */ public RCheckHelper setTextColor(Color normal, Color pressed, Color unable, Color checked, Color selected) { this.mTextColorChecked = checked; - this.mHasCheckedTextColor = true; + this.isHasCheckedTextColor = true; super.setTextColor(normal, pressed, unable, selected); return this; } @@ -176,6 +193,12 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis mComponent.setTextColor(mTextColorNormal); } + /** + * 构造 + * + * @param icon 背景 + * @return 全部背景 + */ @Deprecated public RCheckHelper setIconChecked(Element icon) { this.mIconChecked = icon; @@ -188,24 +211,48 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis return mIconChecked; } + /** + * 构造 + * + * @param icon 背景 + * @return 背景 + */ public RCheckHelper setIconCheckedLeft(Element icon) { this.mIconCheckedLeft = icon; setIconLeft(icon); return this; } + /** + * 构造 + * + * @param icon 背景 + * @return 背景右边 + */ public RCheckHelper setIconCheckedRight(Element icon) { this.mIconCheckedRight = icon; setIconRight(icon); return this; } + /** + * 构造 + * + * @param icon 背景 + * @return 背景上 + */ public RCheckHelper setIconCheckedTop(Element icon) { this.mIconCheckedTop = icon; setIconTop(icon); return this; } + /** + * 构造 + * + * @param icon 背景 + * @return 下背景 + */ public RCheckHelper setIconCheckedBottom(Element icon) { this.mIconCheckedBottom = icon; setIconBottom(icon); @@ -243,7 +290,6 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis animatorValue.start(); isTouch = false; mComponent.setTextColor(mTextColorChecked); - } return true; } @@ -290,7 +336,6 @@ public class RCheckHelper extends RTextHelper implements Component.TouchEventLis zj = v; if (v > 0.85 && isTouch) { paint.setAlpha(0f); - } else { paint.setAlpha(0.2f); } diff --git a/library/src/main/java/com/ruffian/library/widget/helper/RTextHelper.java b/library/src/main/java/com/ruffian/library/widget/helper/RTextHelper.java index 895520b3f3a402eaeceaeda7f21840c40f7cc47c..a0a36d9a334dba75b2ef506d93fdb05efd400ba7 100644 --- a/library/src/main/java/com/ruffian/library/widget/helper/RTextHelper.java +++ b/library/src/main/java/com/ruffian/library/widget/helper/RTextHelper.java @@ -108,6 +108,13 @@ public class RTextHelper extends RBaseHelper implements ITextFeature, Text private Color text_ripple_color; private boolean isRipple; + /** + * 构造 + * + * @param context 上下文 + * @param text 文本 + * @param attrs 属性集 + */ public RTextHelper(Context context, Text text, AttrSet attrs) { super(context, text, attrs); mComponent.setTouchEventListener(this::onTouchEvent); @@ -412,6 +419,12 @@ public class RTextHelper extends RBaseHelper implements ITextFeature, Text return this; } + /** + * 构造 + * + * @param iconWidth 宽度 + * @return 文字边框 + */ @Deprecated public RTextHelper setIconWidth(int iconWidth) { this.mIconWidth = iconWidth; @@ -424,6 +437,12 @@ public class RTextHelper extends RBaseHelper implements ITextFeature, Text return mIconWidth; } + /** + * 构造 + * + * @param iconHeight 高度 + * @return 高度值 + */ @Deprecated public RTextHelper setIconHeight(int iconHeight) { this.mIconHeight = iconHeight; @@ -436,6 +455,12 @@ public class RTextHelper extends RBaseHelper implements ITextFeature, Text return mIconHeight; } + /** + * 构造 + * + * @param iconDirection int + * @return int类型 + */ @Deprecated public RTextHelper setIconDirection(int iconDirection) { this.mIconDirection = iconDirection; diff --git a/library/src/main/java/com/ruffian/library/widget/iface/RHelper.java b/library/src/main/java/com/ruffian/library/widget/iface/RHelper.java index 9ff20b4868171db4baaf7c178d1eae390ca569b5..67f57edc851abf06970fda3a8a0e42ab5d39ff3c 100644 --- a/library/src/main/java/com/ruffian/library/widget/iface/RHelper.java +++ b/library/src/main/java/com/ruffian/library/widget/iface/RHelper.java @@ -8,5 +8,10 @@ import com.ruffian.library.widget.helper.RBaseHelper; * @author ZhongDaFeng */ public interface RHelper { + /** + * 获取帮助 + * + * @return 任意类型 + */ T getHelper(); } diff --git a/library/src/main/java/com/ruffian/library/widget/rounded/RoundDrawable.java b/library/src/main/java/com/ruffian/library/widget/rounded/RoundDrawable.java index 7db7680090156a845b73b1ad959a6fad63da0a62..db9a344d497e300723c7d9187ccbb9da7e6e8a89 100644 --- a/library/src/main/java/com/ruffian/library/widget/rounded/RoundDrawable.java +++ b/library/src/main/java/com/ruffian/library/widget/rounded/RoundDrawable.java @@ -47,13 +47,20 @@ public class RoundDrawable extends ShapeElement implements Component.DrawTask { private float mCornerBottomLeft = 0; private float mCornerBottomRight = 0; private float mCornerRadii[] = new float[8]; - // 边框 + + // 边框 private float mBorderWidth = 0; private Color mBorderColor = Color.BLACK; + // 是否圆形 private boolean isCircle = true; private float mWidthHeight = 2; + /** + * 构造 + * + * @param bitmap 图片 + */ public RoundDrawable(PixelMap bitmap) { mBitmap = bitmap; mBitmapWidth = bitmap.getImageInfo().size.width; @@ -106,13 +113,13 @@ public class RoundDrawable extends ShapeElement implements Component.DrawTask { mPath.addRoundRect(mDrawableRect, mCornerRadii, Path.Direction.COUNTER_CLOCK_WISE); } - // 更新边框路径 + // 更新边框路径 private void updateBorderPath() { mPath.reset(); // must重置 mPath.addRoundRect(mBorderRect, mCornerRadii, Path.Direction.COUNTER_CLOCK_WISE); } - // 根据ScaleType更新ShaderMatrix此函数涉及更新的属性:mBorderWidth || mScaleType || isCircle + // 根据ScaleType更新ShaderMatrix此函数涉及更新的属性:mBorderWidth || mScaleType || isCircle private void updateShaderMatrix() { float scale; float dx = 0, dy = 0; @@ -153,6 +160,7 @@ public class RoundDrawable extends ShapeElement implements Component.DrawTask { height = Math.min(mBounds.getHeight(), mBitmapRect.getHeight()); width = Math.min(mBounds.getWidth(), mBitmapRect.getWidth()); + // 裁剪或者Margin(如果component大,则 margin Bitmap,如果component小则裁剪Bitmap) float cutOrMarginH = mBounds.getHeight() - mBitmapRect.getHeight(); float cutOrMarginW = mBounds.getWidth() - mBitmapRect.getWidth(); @@ -244,6 +252,7 @@ public class RoundDrawable extends ShapeElement implements Component.DrawTask { // borderWidth mBorderWidth = borderWidth; + // borderColor mBorderColor = borderColor; updateBorder(); diff --git a/library/src/main/java/com/ruffian/library/widget/utils/LogUtil.java b/library/src/main/java/com/ruffian/library/widget/utils/LogUtil.java index 9fc8e5e713deb95331375ae0c001d4643f33ce37..450d73e050b474efe0865f694c05f0665b7cf89f 100644 --- a/library/src/main/java/com/ruffian/library/widget/utils/LogUtil.java +++ b/library/src/main/java/com/ruffian/library/widget/utils/LogUtil.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.ruffian.library.widget.utils; import ohos.hiviewdfx.HiLog; diff --git a/library/src/main/java/com/ruffian/library/widget/utils/ShadowDrawable.java b/library/src/main/java/com/ruffian/library/widget/utils/ShadowDrawable.java index 946eda786e563b8fc6befbd5a2c537b8566f5aa2..1a049659e0781913d669076728eb604776244d4c 100644 --- a/library/src/main/java/com/ruffian/library/widget/utils/ShadowDrawable.java +++ b/library/src/main/java/com/ruffian/library/widget/utils/ShadowDrawable.java @@ -25,7 +25,13 @@ import ohos.agp.utils.Point; import ohos.agp.utils.RectFloat; public class ShadowDrawable extends ShapeElement { + /** + * 阴影 + */ public final static int SHAPE_ROUND = 1; + /** + * 阴影 + */ public final static int SHAPE_CIRCLE = 2; private Paint mShadowPaint; private Paint mBgPaint; @@ -262,6 +268,9 @@ public class ShadowDrawable extends ShapeElement { private int mOffsetY; private int[] mBgColor; + /** + * 构造 + */ public Builder() { mShape = ShadowDrawable.SHAPE_ROUND; mShapeRadius = 12; diff --git a/library/src/main/java/com/ruffian/library/widget/utils/TextUtils.java b/library/src/main/java/com/ruffian/library/widget/utils/TextUtils.java index ec5acd6c85614e2ee8a6c98649ccfb34f65c93f1..5fbd9362564a13b7b6d17f9bae5d641d324acaf0 100644 --- a/library/src/main/java/com/ruffian/library/widget/utils/TextUtils.java +++ b/library/src/main/java/com/ruffian/library/widget/utils/TextUtils.java @@ -51,10 +51,7 @@ public class TextUtils { } paint = new Paint(); float textWidth; - /** - * 1.是否存在\n换行获取宽度最大的值 - * 2.不存在\n获取单行宽度值判断是否自动换行临界值 - */ + String originalText = text.getText(); if (originalText.contains("\n")) { String[] originalTextArray; @@ -94,11 +91,9 @@ public class TextUtils { return 0; } - /** - * 1.单行高度*行数2.最大高度临界值 - */ - + // 1.单行高度行数2.最大高度临界值 Paint paint = new Paint(); + // 单行高度 float singleLineHeight = Math.abs( (paint.getFontMetrics().bottom - paint.getFontMetrics().top)); diff --git a/library/src/main/java/com/ruffian/library/widget/utils/TypedAttrUtils.java b/library/src/main/java/com/ruffian/library/widget/utils/TypedAttrUtils.java index 9d9ed510967f6eaa502b5d43d880df575506401c..faee17f49779354c011fdf8febcf8cbc85948fd2 100644 --- a/library/src/main/java/com/ruffian/library/widget/utils/TypedAttrUtils.java +++ b/library/src/main/java/com/ruffian/library/widget/utils/TypedAttrUtils.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.ruffian.library.widget.utils; import ohos.agp.components.Attr;