Methods Summary |
---|
protected void | drawableStateChanged()
super.drawableStateChanged();
if (mButtonDrawable != null) {
int[] myDrawableState = getDrawableState();
// Set the state of the Drawable
mButtonDrawable.setState(myDrawableState);
invalidate();
}
|
public boolean | isChecked()
return mChecked;
|
protected int[] | onCreateDrawableState(int extraSpace)
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
|
protected void | onDraw(android.graphics.Canvas canvas)
super.onDraw(canvas);
final Drawable buttonDrawable = mButtonDrawable;
if (buttonDrawable != null) {
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
final int height = buttonDrawable.getIntrinsicHeight();
int y = 0;
switch (verticalGravity) {
case Gravity.BOTTOM:
y = getHeight() - height;
break;
case Gravity.CENTER_VERTICAL:
y = (getHeight() - height) / 2;
break;
}
buttonDrawable.setBounds(0, y, buttonDrawable.getIntrinsicWidth(), y + height);
buttonDrawable.draw(canvas);
}
|
public void | onRestoreInstanceState(android.os.Parcelable state)
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
setChecked(ss.checked);
requestLayout();
|
public android.os.Parcelable | onSaveInstanceState()
// Force our ancestor class to save its state
setFreezesText(true);
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss.checked = isChecked();
return ss;
|
public boolean | performClick()
/*
* XXX: These are tiny, need some surrounding 'expanded touch area',
* which will need to be implemented in Button if we only override
* performClick()
*/
/* When clicked, toggle the state */
toggle();
return super.performClick();
|
public void | setButtonDrawable(int resid)Set the background to a given Drawable, identified by its resource id.
if (resid != 0 && resid == mButtonResource) {
return;
}
mButtonResource = resid;
Drawable d = null;
if (mButtonResource != 0) {
d = getResources().getDrawable(mButtonResource);
}
setButtonDrawable(d);
|
public void | setButtonDrawable(android.graphics.drawable.Drawable d)Set the background to a given Drawable
if (d != null) {
if (mButtonDrawable != null) {
mButtonDrawable.setCallback(null);
unscheduleDrawable(mButtonDrawable);
}
d.setCallback(this);
d.setState(getDrawableState());
d.setVisible(getVisibility() == VISIBLE, false);
mButtonDrawable = d;
mButtonDrawable.setState(null);
setMinHeight(mButtonDrawable.getIntrinsicHeight());
}
refreshDrawableState();
|
public void | setChecked(boolean checked)Changes the checked state of this button.
if (mChecked != checked) {
mChecked = checked;
refreshDrawableState();
// Avoid infinite recursions if setChecked() is called from a listener
if (mBroadcasting) {
return;
}
mBroadcasting = true;
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mChecked);
}
if (mOnCheckedChangeWidgetListener != null) {
mOnCheckedChangeWidgetListener.onCheckedChanged(this, mChecked);
}
mBroadcasting = false;
}
|
public void | setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener listener)Register a callback to be invoked when the checked state of this button
changes.
mOnCheckedChangeListener = listener;
|
void | setOnCheckedChangeWidgetListener(android.widget.CompoundButton$OnCheckedChangeListener listener)Register a callback to be invoked when the checked state of this button
changes. This callback is used for internal purpose only.
mOnCheckedChangeWidgetListener = listener;
|
public void | toggle()
setChecked(!mChecked);
|
protected boolean | verifyDrawable(android.graphics.drawable.Drawable who)
return super.verifyDrawable(who) || who == mButtonDrawable;
|