@Override public void setSelected(boolean selected) { super.setSelected(selected); int state = selected ? Selected : Normal; states.setState(state); updateText(state); updateImage(state); }
@Override public void setHighlighted(boolean highlighted) { super.setHighlighted(highlighted); int state = highlighted ? Highlighted : isSelected() ? Selected : Normal; states.setState(state); updateText(state); updateImage(state); }
void updateText(int state) { if (!states.isInState(state)) return; if (title != null) { title.setText(states.getTitle()); if (states.getTitlecolor() != null) title.setTextColor(states.getTitlecolor()); if (states.getShadowColor() != null) title.setShadowColor(states.getShadowColor()); } }
void updateImage(int state) { if (!states.isInState(state)) return; UIRunner.runSynced( new UIRunner() { @Override public void exec() { UIImage foreimg = states.getFore(); if (foreimg == null && fore != null) { fore.removeFromSuperview(); fore = null; } else if (foreimg != null) { initForeground(); fore.setImage(foreimg); } if (updatableBackImage) { UIImage backimg = states.getBack(); if (backimg != null) xm_model().setBackgroundDrawable(backimg.getModel()); else xm_model().setBackgroundDrawable(null); } } }); }
public void setShowsTouchWhenHighlighted(boolean showsTouchWhenHighlighted) { states.showsTouchWhenHighlighted = showsTouchWhenHighlighted; }
public void setAdjustsImageWhenHighlighted(boolean adjustsImageWhenHighlighted) { states.adjustsImageWhenHighlighted = adjustsImageWhenHighlighted; }
public void setAdjustsImageWhenDisabled(boolean adjustsImageWhenDisabled) { states.adjustsImageWhenDisabled = adjustsImageWhenDisabled; }
public UIColor titleColorForState(int UIControlState) { return states.getTitlecolor(UIControlState); }
public UIImage backgroundImageForState(int UIControlState) { return states.getBack(UIControlState); }
public void setBackgroundImage(UIImage img, int UIControlState) { states.setBack(UIControlState, img); updateImage(UIControlState); }
public UIImage imageForState(int UIControlState) { return states.getFore(UIControlState); }
public void setImage(UIImage img, int UIControlState) { states.setFore(UIControlState, img); updateImage(UIControlState); }
public UIColor titleShadowColorForState(int UIControlState) { return states.getShadowColor(UIControlState); }
public void setTitleShadowColor(UIColor shadowcolor, int UIControlState) { states.setShadowColor(UIControlState, shadowcolor); updateText(UIControlState); }
public void setTitle(String title, int UIControlState) { initText(); states.setTitle(UIControlState, title); updateText(UIControlState); }
public String titleForState(int UIControlState) { return states.getTitle(UIControlState); }
public void setTitleColor(UIColor titleColor, int UIControlState) { states.setTitlecolor(UIControlState, titleColor); updateText(UIControlState); }