From e17a761700335afae7694fd176e3deb68f2b1d4b Mon Sep 17 00:00:00 2001 From: lygttpod Date: Thu, 13 May 2021 17:14:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96[issues/164?= =?UTF-8?q?](https://github.com/lygttpod/SuperTextView/issues/164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperButton_Readme.md | 4 ++-- .../src/main/java/com/allen/library/SuperButton.java | 12 ++++++------ .../java/com/allen/library/data/AttributeSetData.kt | 4 ++-- .../com/allen/library/helper/AttributeSetHelper.kt | 4 ++-- .../java/com/allen/library/helper/ShapeBuilder.kt | 12 ++++++------ library/src/main/res/values/attrs.xml | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/SuperButton_Readme.md b/SuperButton_Readme.md index 449350f..98009ed 100644 --- a/SuperButton_Readme.md +++ b/SuperButton_Readme.md @@ -100,8 +100,8 @@ sSizeWidth | dimension | shape的SizeWidth | 默认0dp sSizeHeight | dimension | shape的SizeHeight | 默认0dp sGradientOrientation | enum | 设置渐变类型
TOP_BOTTOM
TR_BL
RIGHT_LEFT
BR_TL
BOTTOM_TOP
BL_TR
LEFT_RIGHT
TL_BR | 默认rectangle sGradientType | enum | 设置渐变类型
linear
radial
sweep | 默认rectangle -sGradientCenterX | dimension | shape的CenterX | 默认0dp -sGradientCenterY | dimension | shape的CenterY | 默认0dp +sGradientCenterX | float | shape的CenterX | 默认0f +sGradientCenterY | float | shape的CenterY | 默认0f sGradientGradientRadius | dimension | shape的GradientRadius | 默认0dp sGradientStartColor | color | shape的StartColor | sGradientCenterColor | color | shape的CenterColor | diff --git a/library/src/main/java/com/allen/library/SuperButton.java b/library/src/main/java/com/allen/library/SuperButton.java index 9aa23eb..bf1166a 100644 --- a/library/src/main/java/com/allen/library/SuperButton.java +++ b/library/src/main/java/com/allen/library/SuperButton.java @@ -50,8 +50,8 @@ public class SuperButton extends AppCompatButton { private int sizeHeight; private int gradientAngle; - private int gradientCenterX; - private int gradientCenterY; + private float gradientCenterX; + private float gradientCenterY; private int gradientGradientRadius; private int gradientStartColor; @@ -149,8 +149,8 @@ private void getAttr(AttributeSet attrs) { sizeHeight = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sSizeHeight, dip2px(mContext, 48)); gradientAngle = (int) typedArray.getFloat(R.styleable.SuperButton_sGradientAngle, -1); - gradientCenterX = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sGradientCenterX, 0); - gradientCenterY = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sGradientCenterY, 0); + gradientCenterX = typedArray.getFloat(R.styleable.SuperButton_sGradientCenterX, 0f); + gradientCenterY = typedArray.getFloat(R.styleable.SuperButton_sGradientCenterY, 0f); gradientGradientRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sGradientGradientRadius, 0); gradientStartColor = typedArray.getColor(R.styleable.SuperButton_sGradientStartColor, -1); @@ -429,7 +429,7 @@ public SuperButton setShapeGradientAngle(int gradientAngle) { * @param gradientCenterX 中心x * @return 对象 */ - public SuperButton setShapeGradientCenterX(int gradientCenterX) { + public SuperButton setShapeGradientCenterX(float gradientCenterX) { this.shapeBuilder.setShapeGradientCenterX(gradientCenterX); return this; } @@ -440,7 +440,7 @@ public SuperButton setShapeGradientCenterX(int gradientCenterX) { * @param gradientCenterY 中心y * @return 对象 */ - public SuperButton setShapeGradientCenterY(int gradientCenterY) { + public SuperButton setShapeGradientCenterY(float gradientCenterY) { this.shapeBuilder.setShapeGradientCenterY(gradientCenterY); return this; } diff --git a/library/src/main/java/com/allen/library/data/AttributeSetData.kt b/library/src/main/java/com/allen/library/data/AttributeSetData.kt index 6f48ace..21dbcbe 100644 --- a/library/src/main/java/com/allen/library/data/AttributeSetData.kt +++ b/library/src/main/java/com/allen/library/data/AttributeSetData.kt @@ -26,8 +26,8 @@ class AttributeSetData { var cornersBottomRightRadius = 0.0f var gradientAngle = -1 - var gradientCenterX: Int = 0 - var gradientCenterY: Int = 0 + var gradientCenterX: Float = 0f + var gradientCenterY: Float = 0f var gradientGradientRadius: Int = 0 var gradientStartColor = -1 var gradientCenterColor = -1 diff --git a/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt b/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt index 6c4c8dd..9130b90 100644 --- a/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt +++ b/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt @@ -51,8 +51,8 @@ class AttributeSetHelper { attributeSetData.sizeHeight = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeSizeHeight, dip2px(context, 48f)) attributeSetData.gradientAngle = typedArray.getFloat(R.styleable.ShapeView_shapeGradientAngle, -1f).toInt() - attributeSetData.gradientCenterX = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeGradientCenterX, 0) - attributeSetData.gradientCenterY = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeGradientCenterY, 0) + attributeSetData.gradientCenterX = typedArray.getFloat(R.styleable.ShapeView_shapeGradientCenterX, 0f) + attributeSetData.gradientCenterY = typedArray.getFloat(R.styleable.ShapeView_shapeGradientCenterY, 0f) attributeSetData.gradientGradientRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeGradientGradientRadius, 0) attributeSetData.gradientStartColor = typedArray.getColor(R.styleable.ShapeView_shapeGradientStartColor, -1) diff --git a/library/src/main/java/com/allen/library/helper/ShapeBuilder.kt b/library/src/main/java/com/allen/library/helper/ShapeBuilder.kt index 77d7145..7194300 100644 --- a/library/src/main/java/com/allen/library/helper/ShapeBuilder.kt +++ b/library/src/main/java/com/allen/library/helper/ShapeBuilder.kt @@ -95,8 +95,8 @@ class ShapeBuilder { * */ private var shapeGradientAngle: ShapeGradientAngle = ShapeGradientAngle.LEFT_RIGHT - private var gradientCenterX: Int = 0 - private var gradientCenterY: Int = 0 + private var gradientCenterX: Float = 0f + private var gradientCenterY: Float = 0f private var gradientGradientRadius: Int = 0 private var gradientStartColor = -1 @@ -230,12 +230,12 @@ class ShapeBuilder { return this } - fun setShapeGradientCenterX(gradientCenterX: Int): ShapeBuilder { + fun setShapeGradientCenterX(gradientCenterX: Float): ShapeBuilder { this.gradientCenterX = gradientCenterX return this } - fun setShapeGradientCenterY(gradientCenterY: Int): ShapeBuilder { + fun setShapeGradientCenterY(gradientCenterY: Float): ShapeBuilder { this.gradientCenterY = gradientCenterY return this } @@ -389,8 +389,8 @@ class ShapeBuilder { } ShapeGradientType.SWEEP -> gradientDrawable.gradientType = GradientDrawable.SWEEP_GRADIENT } - if (gradientCenterX != 0 || gradientCenterY != 0) { - gradientDrawable.setGradientCenter(gradientCenterX.toFloat(), gradientCenterY.toFloat()) + if (gradientCenterX != 0f || gradientCenterY != 0f) { + gradientDrawable.setGradientCenter(gradientCenterX, gradientCenterY) } gradientDrawable.useLevel = gradientUseLevel } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 6da7b64..ab7bdc5 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -280,8 +280,8 @@ - - + + @@ -480,8 +480,8 @@ - - + +