Skip to content

Commit

Permalink
代码优化[issues/164](#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
lygttpod committed May 13, 2021
1 parent e363a3f commit e17a761
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions SuperButton_Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ sSizeWidth | dimension | shape的SizeWidth | 默认0dp
sSizeHeight | dimension | shape的SizeHeight | 默认0dp
sGradientOrientation | enum | 设置渐变类型<br>TOP_BOTTOM<br>TR_BL<br>RIGHT_LEFT<br>BR_TL<br>BOTTOM_TOP<br>BL_TR<br>LEFT_RIGHT<br>TL_BR | 默认rectangle
sGradientType | enum | 设置渐变类型<br>linear<br>radial<br>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 |
Expand Down
12 changes: 6 additions & 6 deletions library/src/main/java/com/allen/library/SuperButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions library/src/main/java/com/allen/library/helper/ShapeBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class ShapeBuilder {
* <gradient android:angle="45"/>
*/
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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
<attr name="sSizeHeight" format="dimension" />

<attr name="sGradientAngle" format="float" />
<attr name="sGradientCenterX" format="dimension" />
<attr name="sGradientCenterY" format="dimension" />
<attr name="sGradientCenterX" format="float" />
<attr name="sGradientCenterY" format="float" />
<attr name="sGradientGradientRadius" format="dimension" />
<attr name="sGradientStartColor" format="color" />
<attr name="sGradientCenterColor" format="color" />
Expand Down Expand Up @@ -480,8 +480,8 @@
<enum name="tl_br" value="315" />
</attr>

<attr name="shapeGradientCenterX" format="dimension" />
<attr name="shapeGradientCenterY" format="dimension" />
<attr name="shapeGradientCenterX" format="float" />
<attr name="shapeGradientCenterY" format="float" />
<attr name="shapeGradientGradientRadius" format="dimension" />
<attr name="shapeGradientStartColor" format="color" />
<attr name="shapeGradientCenterColor" format="color" />
Expand Down

0 comments on commit e17a761

Please sign in to comment.