[6.4.0][code] 优化代码逻辑
This commit is contained in:
@@ -481,69 +481,119 @@ public class ViewPressedStateLancet {
|
||||
text.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
||||
return true;
|
||||
}
|
||||
|
||||
ColorStateList textColor = text.getTextColors();
|
||||
if (textColor != null) {
|
||||
int current = text.getCurrentTextColor();
|
||||
int pressed = textColor.getColorForState(new int[]{ android.R.attr.state_pressed }, Integer.MIN_VALUE);
|
||||
if (pressed != Integer.MIN_VALUE && pressed != current) {
|
||||
int defaultColor = textColor.getDefaultColor();
|
||||
int pressedColor = Color.argb((int)(Color.alpha(defaultColor) * alpha), Color.red(defaultColor), Color.green(defaultColor), Color.blue(defaultColor));
|
||||
if (!textColor.isStateful()) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- isStateful() => false hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- isStateful() => false hit ---" + "["+text+"]");
|
||||
}*/
|
||||
int[][] states = new int[2][1];
|
||||
int[] colors = new int[2];
|
||||
states[0] = new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused, -android.R.attr.state_active };
|
||||
colors[0] = pressedColor;
|
||||
states[1] = StateSet.WILD_CARD;
|
||||
colors[1] = defaultColor;
|
||||
ColorStateList newColor = new ColorStateList(states, colors);
|
||||
text.setTag(R.id.click_pressed_attr_replaced_color, textColor);
|
||||
text.setTextColor(newColor);
|
||||
return true;
|
||||
}
|
||||
int pressed = textColor.getColorForState(new int[] { android.R.attr.state_pressed }, Integer.MIN_VALUE);
|
||||
if (pressed != Integer.MIN_VALUE && pressed != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- pressed hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- pressed hit ---" + "["+text+"]");
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
int enableColor = textColor.getColorForState(new int[] { android.R.attr.state_enabled }, Integer.MIN_VALUE);
|
||||
int defaultColor = current;
|
||||
if (enableColor == Integer.MIN_VALUE && enableColor != current) {
|
||||
defaultColor = textColor.getDefaultColor();
|
||||
}
|
||||
int pressedColor = Color.argb((int)(Color.alpha(defaultColor) * alpha), Color.red(defaultColor), Color.green(defaultColor), Color.blue(defaultColor));
|
||||
int disableColor = textColor.getColorForState(new int[] { -android.R.attr.state_enabled }, Integer.MIN_VALUE);
|
||||
int size = 2;
|
||||
if (disableColor != Integer.MIN_VALUE && disableColor != current) {
|
||||
size += 1;
|
||||
}
|
||||
boolean hasChecked = false;
|
||||
int disabledColor = textColor.getColorForState(new int[] { -android.R.attr.state_enabled }, Integer.MIN_VALUE);
|
||||
int checkedColor = textColor.getColorForState(new int[] { android.R.attr.state_checked }, Integer.MIN_VALUE);
|
||||
if (checkedColor != Integer.MIN_VALUE && checkedColor != current) {
|
||||
hasChecked = true;
|
||||
size += 1;
|
||||
int unCheckedColor = textColor.getColorForState(new int[] { -android.R.attr.state_checked }, Integer.MIN_VALUE);
|
||||
int selectedColor = textColor.getColorForState(new int[] { android.R.attr.state_enabled }, Integer.MIN_VALUE);
|
||||
int unSelectedColor = textColor.getColorForState(new int[] { -android.R.attr.state_selected }, Integer.MIN_VALUE);
|
||||
int size = 2;
|
||||
if (disabledColor != Integer.MIN_VALUE && disabledColor != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- disabled hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- disabled hit ---" + "["+text+"]");
|
||||
}*/
|
||||
size++;
|
||||
}
|
||||
boolean hasUnChecked = false;
|
||||
int unCheckedColor = textColor.getColorForState(new int[]{ -android.R.attr.state_checked }, Integer.MIN_VALUE);
|
||||
if (unCheckedColor != Integer.MIN_VALUE && unCheckedColor != current) {
|
||||
hasUnChecked = true;
|
||||
size += 1;
|
||||
if (checkedColor != Integer.MIN_VALUE && checkedColor != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- checked hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- checked hit ---" + "["+text+"]");
|
||||
}*/
|
||||
size++;
|
||||
}
|
||||
if (unCheckedColor != Integer.MIN_VALUE && unCheckedColor != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- unchecked hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- unchecked hit ---" + "["+text+"]");
|
||||
}*/
|
||||
size++;
|
||||
}
|
||||
if (selectedColor != Integer.MIN_VALUE && selectedColor != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- selected hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- selected hit ---" + "["+text+"]");
|
||||
}*/
|
||||
size++;
|
||||
}
|
||||
if (unSelectedColor != Integer.MIN_VALUE && unSelectedColor != defaultColor) {
|
||||
/*if (text.getId() != View.NO_ID) {
|
||||
Log.d("ViewPressedStateLancet", "---- unselected hit ---" + "["+text+"->"+text.getResources().getResourceName(text.getId())+"]");
|
||||
} else {
|
||||
Log.d("ViewPressedStateLancet", "---- unselected hit ---" + "["+text+"]");
|
||||
}*/
|
||||
size++;
|
||||
}
|
||||
int[][] states = new int[size][1];
|
||||
int[] colors = new int[size];
|
||||
states[0] = new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused, -android.R.attr.state_active };
|
||||
states[0] = new int[] { android.R.attr.state_pressed };
|
||||
colors[0] = pressedColor;
|
||||
if (size > 2) {
|
||||
states[1] = new int[] { -android.R.attr.state_enabled };
|
||||
colors[1] = disableColor;
|
||||
states[2] = new int[] { android.R.attr.state_enabled };
|
||||
colors[2] = defaultColor;
|
||||
if (hasChecked) {
|
||||
states[3] = new int[] { android.R.attr.state_checked };
|
||||
colors[3] = checkedColor;
|
||||
}
|
||||
if (hasUnChecked) {
|
||||
if (size > 4) {
|
||||
states[4] = new int[] { -android.R.attr.state_checked };
|
||||
colors[4] = unCheckedColor;
|
||||
} else {
|
||||
states[3] = new int[] { -android.R.attr.state_checked };
|
||||
colors[3] = unCheckedColor;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
states[1] = StateSet.WILD_CARD;
|
||||
colors[1] = defaultColor;
|
||||
int index = 1;
|
||||
if (disabledColor != Integer.MIN_VALUE && disabledColor != defaultColor) {
|
||||
states[index] = new int[] { -android.R.attr.state_enabled };
|
||||
colors[index] = disabledColor;
|
||||
index++;
|
||||
}
|
||||
if (checkedColor != Integer.MIN_VALUE && checkedColor != defaultColor) {
|
||||
states[index] = new int[] { android.R.attr.state_checked };
|
||||
colors[index] = checkedColor;
|
||||
index++;
|
||||
}
|
||||
if (unCheckedColor != Integer.MIN_VALUE && unCheckedColor != defaultColor) {
|
||||
states[index] = new int[] { -android.R.attr.state_checked };
|
||||
colors[index] = unCheckedColor;
|
||||
index++;
|
||||
}
|
||||
if (selectedColor != Integer.MIN_VALUE && selectedColor != defaultColor) {
|
||||
states[index] = new int[] { android.R.attr.state_selected };
|
||||
colors[index] = selectedColor;
|
||||
index++;
|
||||
}
|
||||
if (unSelectedColor != Integer.MIN_VALUE && unSelectedColor != defaultColor) {
|
||||
states[index] = new int[] { -android.R.attr.state_selected };
|
||||
colors[index] = unSelectedColor;
|
||||
index++;
|
||||
}
|
||||
states[index] = StateSet.WILD_CARD;
|
||||
colors[index] = defaultColor;
|
||||
ColorStateList newColor = new ColorStateList(states, colors);
|
||||
text.setTag(R.id.click_pressed_attr_replaced_color, textColor);
|
||||
text.setTextColor(newColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (view != null) {
|
||||
|
||||
Reference in New Issue
Block a user