Skip to content

Commit

Permalink
将isSmart改名为smartColor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale committed Apr 28, 2018
1 parent fa27415 commit efdd1ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
injection.pressed.strokeWidth = 10;
break;
case R.id.isSmart_cb:
injection.isSmart = checked;
injection.smartColor = checked;
// 如果不是smart模式,并且没有设置按下的颜色
if (!checked && !((CompoundButton) getView().findViewById(R.id.pressed_color_cb)).isChecked()) {
injection.pressed.color = SelectorInjection.DEFAULT_COLOR;
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/image_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

app:pressedStrokeColor="#259b24"
app:pressedStrokeWidth="8dp"

preview:isPressed="false"
/>

<LinearLayout
Expand Down
18 changes: 6 additions & 12 deletions lib/src/main/java/kale/injection/SelectorInjection.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ public class SelectorInjection {
*/
private StateListDrawable selector = new StateListDrawable();

public SelectorBean normal;

public SelectorBean pressed;

public SelectorBean checked;

public SelectorBean disable;

private View view;

public SelectorBean normal, pressed, checked, disable;

/**
* 是否将drawable设置到src中,如果不是那么默认是background
*/
Expand All @@ -52,7 +46,7 @@ public class SelectorInjection {
/**
* 是否是智能模式,如果是的那么会自动计算按下后的颜色
*/
public boolean isSmart;
public boolean smartColor;

/**
* 是否展示水波纹
Expand All @@ -68,7 +62,7 @@ public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {

TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SelectorInjection, defStyleAttr, 0);

isSmart = a.getBoolean(R.styleable.SelectorInjection_isSmart, true);
smartColor = a.getBoolean(R.styleable.SelectorInjection_smartColor, true);
inSrc = a.getBoolean(R.styleable.SelectorInjection_inSrc, false);
showRipple = a.getBoolean(R.styleable.SelectorInjection_ripple, false);

Expand Down Expand Up @@ -107,13 +101,13 @@ public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
}

public void injection() {
if (pressed.drawable == null && isSmart && normal.drawable != null) {
if (pressed.drawable == null && smartColor && normal.drawable != null) {
// 如果是智能模式,会自动根据normal生成按压时的drawable
pressed.drawable = normal.drawable.getConstantState().newDrawable();
}
if (pressed.drawable != null && pressed.color == DEFAULT_COLOR) {
// 如果没有设置按压效果,那么会自动计算出按压的色值
pressed.color = isSmart ? getPressedColor(normal.color) : pressed.color;
pressed.color = smartColor ? getPressedColor(normal.color) : pressed.color;
}

configDrawable(pressed, false, new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<attr name="disableStrokeWidth" format="dimension" />

<!-- 是否是自动计算按下颜色的的 -->
<attr name="isSmart" format="boolean" />
<attr name="smartColor" format="boolean" />

<!-- 是否将图片设置到src中(仅仅对ImageButton有效) -->
<attr name="inSrc" format="boolean" />
Expand Down

0 comments on commit efdd1ea

Please sign in to comment.