Skip to content

Commit

Permalink
修改色值初始状态101
Browse files Browse the repository at this point in the history
  • Loading branch information
lihangleo2 committed Sep 4, 2020
1 parent 00d9b46 commit 3414a82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
55 changes: 23 additions & 32 deletions shadowLibrary/src/main/java/com/lihang/ShadowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
public class ShadowLayout extends FrameLayout {
//上传不了?
private Drawable clickAbleFalseDrawable;
private int clickAbleFalseColor = -1;
private int clickAbleFalseColor = -101;

private Drawable layoutBackground;
private Drawable layoutBackground_true;
private View firstView;

private int mBackGroundColor;
private int mBackGroundColor_true = -1;
private int mBackGroundColor_true = -101;
private int mShadowColor;
private float mShadowLimit;
private float mCornerRadius;
Expand Down Expand Up @@ -113,7 +113,7 @@ public void changeSwitchClickable() {
//press mode
if (!isClickable) {
//不可点击的状态。
if (clickAbleFalseColor != -1) {
if (clickAbleFalseColor != -101) {
//说明设置了颜色
if (layoutBackground != null) {
//说明此时是设置了图片的模式
Expand Down Expand Up @@ -150,18 +150,19 @@ public void setSelected(boolean selected) {
super.setSelected(selected);
if (selectorType == 2) {
if (selected) {
if (mBackGroundColor_true != -1) {
if (mBackGroundColor_true != -101) {
paint.setColor(mBackGroundColor_true);
}
if (stroke_color_true != -1) {
if (stroke_color_true != -101) {
paint_stroke.setColor(stroke_color_true);
}
if (layoutBackground_true != null) {
setmBackGround(layoutBackground_true);
}
} else {
paint.setColor(mBackGroundColor);
if (stroke_color != -1) {

if (stroke_color != -101) {
paint_stroke.setColor(stroke_color);
}

Expand Down Expand Up @@ -291,7 +292,7 @@ protected void onFinishInflate() {
setmBackGround(layoutBackground);
} else {
setmBackGround(clickAbleFalseDrawable);
if (clickAbleFalseColor != -1) {
if (clickAbleFalseColor != -101) {
paint.setColor(clickAbleFalseColor);
}
}
Expand Down Expand Up @@ -321,7 +322,7 @@ private void initView(Context context, AttributeSet attrs) {
paint_stroke.setAntiAlias(true);
paint_stroke.setStyle(Paint.Style.STROKE);
paint_stroke.setStrokeWidth(stroke_with);
if (stroke_color != -1) {
if (stroke_color != -101) {
paint_stroke.setColor(stroke_color);
}

Expand Down Expand Up @@ -508,16 +509,13 @@ private void initAttributes(AttributeSet attrs) {
if (trueBackground instanceof ColorDrawable) {
ColorDrawable colordDrawableTrue = (ColorDrawable) trueBackground;
mBackGroundColor_true = colordDrawableTrue.getColor();
//因为用了-1为未设置颜色的标志, 刚好白色就为-1!!!。所以给一个稍微一点的透明度
if (mBackGroundColor_true == -1) {
mBackGroundColor_true = getResources().getColor(R.color.default_white_bug);
}

} else {
layoutBackground_true = trueBackground;
}
}

if (mBackGroundColor_true != -1 && layoutBackground != null) {
if (mBackGroundColor_true != -101 && layoutBackground != null) {
throw new UnsupportedOperationException("使用了ShadowLayout_hl_layoutBackground_true属性,必须先设置ShadowLayout_hl_layoutBackground属性。且设置颜色时,必须保持都为颜色");
}

Expand All @@ -526,15 +524,10 @@ private void initAttributes(AttributeSet attrs) {
}

//边框颜色的点击
stroke_color = attr.getColor(R.styleable.ShadowLayout_hl_strokeColor, -1);
if (stroke_color == -1) {
stroke_color = getResources().getColor(R.color.default_white_bug);
}
stroke_color_true = attr.getColor(R.styleable.ShadowLayout_hl_strokeColor_true, -1);
if (stroke_color_true == -1) {
stroke_color_true = getResources().getColor(R.color.default_white_bug);
}
if (stroke_color == -1 && stroke_color_true != -1) {
stroke_color = attr.getColor(R.styleable.ShadowLayout_hl_strokeColor, -101);
stroke_color_true = attr.getColor(R.styleable.ShadowLayout_hl_strokeColor_true, -101);

if (stroke_color == -101 && stroke_color_true != -101) {
throw new UnsupportedOperationException("使用了ShadowLayout_hl_strokeColor_true属性,必须先设置ShadowLayout_hl_strokeColor属性");
}

Expand All @@ -550,9 +543,6 @@ private void initAttributes(AttributeSet attrs) {
if (clickAbleFalseBackground instanceof ColorDrawable) {
ColorDrawable colordDrawableClickableFalse = (ColorDrawable) clickAbleFalseBackground;
clickAbleFalseColor = colordDrawableClickableFalse.getColor();
if (clickAbleFalseColor == -1) {
clickAbleFalseColor = getResources().getColor(R.color.default_white_bug);
}
} else {
clickAbleFalseDrawable = clickAbleFalseBackground;
}
Expand Down Expand Up @@ -683,15 +673,15 @@ protected void onDraw(Canvas canvas) {

//画圆角矩形
canvas.drawRoundRect(rectf, trueHeight / 2, trueHeight / 2, paint);
if (stroke_color != -1) {
if (stroke_color != -101) {
RectF rectFStroke = new RectF(rectf.left + stroke_with / 2, rectf.top + stroke_with / 2, rectf.right - stroke_with / 2, rectf.bottom - stroke_with / 2);
canvas.drawRoundRect(rectFStroke, trueHeight / 2, trueHeight / 2, paint_stroke);
}

} else {

canvas.drawRoundRect(rectf, mCornerRadius, mCornerRadius, paint);
if (stroke_color != -1) {
if (stroke_color != -101) {
RectF rectFStroke = new RectF(rectf.left + stroke_with / 2, rectf.top + stroke_with / 2, rectf.right - stroke_with / 2, rectf.bottom - stroke_with / 2);
canvas.drawRoundRect(rectFStroke, mCornerRadius, mCornerRadius, paint_stroke);
}
Expand Down Expand Up @@ -753,7 +743,7 @@ private void setSpaceCorner(Canvas canvas, int trueHeight) {

float[] outerR = new float[]{leftTop, leftTop, rightTop, rightTop, rightBottom, rightBottom, leftBottom, leftBottom};//左上,右上,右下,左下

if (stroke_color != -1) {
if (stroke_color != -101) {


ShapeDrawable mDrawables = new ShapeDrawable(new RoundRectShape(outerR, null, null));
Expand Down Expand Up @@ -814,17 +804,18 @@ public static int convertToColorInt(String argb)
}



@Override
public boolean onTouchEvent(MotionEvent event) {
if (mBackGroundColor_true != -1 || stroke_color_true != -1 || layoutBackground_true != null) {
if (mBackGroundColor_true != -101 || stroke_color_true != -101 || layoutBackground_true != null) {
if (isClickable) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (selectorType == 1) {
if (mBackGroundColor_true != -1) {
if (mBackGroundColor_true != -101) {
paint.setColor(mBackGroundColor_true);
}
if (stroke_color_true != -1) {
if (stroke_color_true != -101) {
paint_stroke.setColor(stroke_color_true);
}

Expand All @@ -839,7 +830,7 @@ public boolean onTouchEvent(MotionEvent event) {
case MotionEvent.ACTION_UP:
if (selectorType == 1) {
paint.setColor(mBackGroundColor);
if (stroke_color != -1) {
if (stroke_color != -101) {
paint_stroke.setColor(stroke_color);
}

Expand Down
1 change: 0 additions & 1 deletion shadowLibrary/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
<resources>
<color name="default_shadow_color">#2a000000</color>
<color name="default_shadowback_color">#fff</color>
<color name="default_white_bug">#FCFFFFFF</color>
</resources>

0 comments on commit 3414a82

Please sign in to comment.