Source code
package android.support.v4.widget;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.CompoundButton;
import java.lang.reflect.Field;
class CompoundButtonCompatDonut {
private static final String TAG = "CompoundButtonCompatDonut";
private static Field sButtonDrawableField;
private static boolean sButtonDrawableFieldFetched;
CompoundButtonCompatDonut() {
}
static void setButtonTintList(CompoundButton button, ColorStateList tint) {
if (button instanceof TintableCompoundButton) {
((TintableCompoundButton) button).setSupportButtonTintList(tint);
}
}
static ColorStateList getButtonTintList(CompoundButton button) {
if (button instanceof TintableCompoundButton) {
return ((TintableCompoundButton) button).getSupportButtonTintList();
}
return null;
}
static void setButtonTintMode(CompoundButton button, Mode tintMode) {
if (button instanceof TintableCompoundButton) {
((TintableCompoundButton) button).setSupportButtonTintMode(tintMode);
}
}
static Mode getButtonTintMode(CompoundButton button) {
if (button instanceof TintableCompoundButton) {
return ((TintableCompoundButton) button).getSupportButtonTintMode();
}
return null;
}
static Drawable getButtonDrawable(CompoundButton button) {
if (!sButtonDrawableFieldFetched) {
try {
sButtonDrawableField = CompoundButton.class.getDeclaredField("mButtonDrawable");
sButtonDrawableField.setAccessible(true);
} catch (NoSuchFieldException e) {
Log.i(TAG, "Failed to retrieve mButtonDrawable field", e);
}
sButtonDrawableFieldFetched = true;
}
if (sButtonDrawableField != null) {
try {
return (Drawable) sButtonDrawableField.get(button);
} catch (IllegalAccessException e2) {
Log.i(TAG, "Failed to get button drawable via reflection", e2);
sButtonDrawableField = null;
}
}
return null;
}
}