Page 203 - MDP2022-2
P. 203
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mOnCheckedChangeListener.onCheckedChanged(compoundButton, b);
}
private void getAttrs(AttributeSet attrs) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.OneClickVi
ew);
setTypeArray(typedArray);
}
private void getAttrs(AttributeSet attrs, int defStyle) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.OneClickVi
ew, defStyle, 0);
setTypeArray(typedArray);
}
private void setTypeArray(TypedArray typedArray) {
int bg_resID = typedArray.getResourceId(R.styleable.OneClickView_bg, R.drawable.shape_
oval_black);
bg.setBackgroundResource(bg_resID);
int symbol_resID = typedArray.getResourceId(R.styleable.OneClickView_symbol, 0);
symbol.setImageResource(symbol_resID);
int textColor = typedArray.getColor(R.styleable.OneClickView_textColor, 0);
text.setTextColor(textColor);
String text_string = typedArray.getString(R.styleable.OneClickView_text);
text.setText(text_string);
boolean isPower = typedArray.getBoolean(R.styleable.OneClickView_isPower, false);
power.setChecked(isPower);
typedArray.recycle();
}
public void setPower(boolean isPower) {
power.setChecked(isPower);
}
public void setBg(int bg_resID) {
bg.setBackgroundResource(bg_resID);
}