Skip to content

Commit

Permalink
1.7.3 新增bl_shape_alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
肖琪(融汇/产品技术中心) committed Dec 18, 2021
1 parent af5d5c2 commit 3683cfa
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
6 changes: 6 additions & 0 deletions BackgroundLibrary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<option name="XML" value="true" />
</context>
</template>
<template name="bl_shape_alpha" value="app:bl_shape_alpha=&quot;$value$&quot;" description="shape透明度" toReformat="false" toShortenFQNames="true">
<variable name="value" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="XML" value="true" />
</context>
</template>
<template name="bl_solid_color" value="app:bl_solid_color=&quot;$value$&quot;" description="填充颜色" toReformat="true" toShortenFQNames="true">
<variable name="value" expression="" defaultValue="" alwaysStopAt="true" />
<context>
Expand Down
12 changes: 12 additions & 0 deletions library/src/main/java/com/noober/background/BackgroundFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ private static void setBackground(Drawable drawable, View view, TypedArray typed
((LayerDrawable) drawable).setLayerInset(0, (int) leftValue, (int) topValue, (int) rightValue, (int) bottomValue);
}

if(typedArray.hasValue(R.styleable.background_bl_shape_alpha)){
float alpha = typedArray.getFloat(R.styleable.background_bl_shape_alpha, 0f);
if(alpha >= 1){
alpha = 255;
}else if(alpha <= 0){
alpha = 0;
}else {
alpha = alpha * 255;
}
drawable.setAlpha((int) alpha);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static class Builder {
private Integer unPressedTextColor;
private Integer unFocusedTextColor;
private int textColorCount;
private float alpha = -1;

private boolean hasSelectDrawable = false;

Expand All @@ -150,6 +151,11 @@ public Builder setShape(Shape shape) {
return this;
}

public Builder setShapeAlpha(float alpha) {
this.alpha = alpha;
return this;
}

public Builder setSolidColor(int solidColor) {
this.solidColor = solidColor;
return this;
Expand Down Expand Up @@ -528,8 +534,19 @@ public Drawable build() {
return resultDrawable;
}
}
Drawable result = drawable == null ? stateListDrawable : drawable;

return drawable == null ? stateListDrawable : drawable;
if(alpha != -1){
if(alpha >= 1){
alpha = 255;
}else if(alpha <= 0){
alpha = 0;
}else {
alpha = alpha * 255;
}
result.setAlpha((int) alpha);
}
return result;
}

public ColorStateList buildTextColor() {
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<enum name="ring" value="3" />
</attr>

<attr name="bl_shape_alpha" format="float" />

<attr name="bl_solid_color" format="color" />

<attr name="bl_corners_radius" format="dimension" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ private static void setBackground(Drawable drawable, View view, TypedArray typed
((LayerDrawable) drawable).setLayerInset(0, (int) leftValue, (int) topValue, (int) rightValue, (int) bottomValue);
}

if(typedArray.hasValue(R.styleable.background_bl_shape_alpha)){
float alpha = typedArray.getFloat(R.styleable.background_bl_shape_alpha, 0f);
if(alpha >= 1){
alpha = 255;
}else if(alpha <= 0){
alpha = 0;
}else {
alpha = alpha * 255;
}
drawable.setAlpha((int) alpha);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static class Builder {
private Integer unPressedTextColor;
private Integer unFocusedTextColor;
private int textColorCount;
private float alpha = -1;

private boolean hasSelectDrawable = false;

Expand All @@ -148,6 +149,11 @@ public Builder setShape(Shape shape) {
return this;
}

public Builder setShapeAlpha(float alpha) {
this.alpha = alpha;
return this;
}

public Builder setSolidColor(int solidColor) {
this.solidColor = solidColor;
return this;
Expand Down Expand Up @@ -527,7 +533,19 @@ public Drawable build() {
}
}

return drawable == null ? stateListDrawable : drawable;
Drawable result = drawable == null ? stateListDrawable : drawable;

if(alpha != -1){
if(alpha >= 1){
alpha = 255;
}else if(alpha <= 0){
alpha = 0;
}else {
alpha = alpha * 255;
}
result.setAlpha((int) alpha);
}
return result;
}

public ColorStateList buildTextColor() {
Expand Down
2 changes: 2 additions & 0 deletions libraryx/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<enum name="ring" value="3" />
</attr>

<attr name="bl_shape_alpha" format="float" />

<attr name="bl_solid_color" format="color" />

<attr name="bl_corners_radius" format="dimension" />
Expand Down

0 comments on commit 3683cfa

Please sign in to comment.