Source code
package android.support.v4.widget;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.CompoundButton;
public final class CompoundButtonCompat {
private static final CompoundButtonCompatImpl IMPL;
interface CompoundButtonCompatImpl {
Drawable getButtonDrawable(CompoundButton compoundButton);
ColorStateList getButtonTintList(CompoundButton compoundButton);
Mode getButtonTintMode(CompoundButton compoundButton);
void setButtonTintList(CompoundButton compoundButton, ColorStateList colorStateList);
void setButtonTintMode(CompoundButton compoundButton, Mode mode);
}
static class BaseCompoundButtonCompat implements CompoundButtonCompatImpl {
BaseCompoundButtonCompat() {
}
public void setButtonTintList(CompoundButton button, ColorStateList tint) {
CompoundButtonCompatDonut.setButtonTintList(button, tint);
}
public ColorStateList getButtonTintList(CompoundButton button) {
return CompoundButtonCompatDonut.getButtonTintList(button);
}
public void setButtonTintMode(CompoundButton button, Mode tintMode) {
CompoundButtonCompatDonut.setButtonTintMode(button, tintMode);
}
public Mode getButtonTintMode(CompoundButton button) {
return CompoundButtonCompatDonut.getButtonTintMode(button);
}
public Drawable getButtonDrawable(CompoundButton button) {
return CompoundButtonCompatDonut.getButtonDrawable(button);
}
}
static class LollipopCompoundButtonImpl extends BaseCompoundButtonCompat {
LollipopCompoundButtonImpl() {
}
public void setButtonTintList(CompoundButton button, ColorStateList tint) {
CompoundButtonCompatLollipop.setButtonTintList(button, tint);
}
public ColorStateList getButtonTintList(CompoundButton button) {
return CompoundButtonCompatLollipop.getButtonTintList(button);
}
public void setButtonTintMode(CompoundButton button, Mode tintMode) {
CompoundButtonCompatLollipop.setButtonTintMode(button, tintMode);
}
public Mode getButtonTintMode(CompoundButton button) {
return CompoundButtonCompatLollipop.getButtonTintMode(button);
}
}
static class Api23CompoundButtonImpl extends LollipopCompoundButtonImpl {
Api23CompoundButtonImpl() {
}
public Drawable getButtonDrawable(CompoundButton button) {
return CompoundButtonCompatApi23.getButtonDrawable(button);
}
}
static {
int sdk = VERSION.SDK_INT;
if (sdk >= 23) {
IMPL = new Api23CompoundButtonImpl();
} else if (sdk >= 21) {
IMPL = new LollipopCompoundButtonImpl();
} else {
IMPL = new BaseCompoundButtonCompat();
}
}
private CompoundButtonCompat() {
}
public static void setButtonTintList(@NonNull CompoundButton button, @Nullable ColorStateList tint) {
IMPL.setButtonTintList(button, tint);
}
@Nullable
public static ColorStateList getButtonTintList(@NonNull CompoundButton button) {
return IMPL.getButtonTintList(button);
}
public static void setButtonTintMode(@NonNull CompoundButton button, @Nullable Mode tintMode) {
IMPL.setButtonTintMode(button, tintMode);
}
@Nullable
public static Mode getButtonTintMode(@NonNull CompoundButton button) {
return IMPL.getButtonTintMode(button);
}
@Nullable
public static Drawable getButtonDrawable(@NonNull CompoundButton button) {
return IMPL.getButtonDrawable(button);
}
}