Example usage for android.graphics.drawable DrawableContainer getConstantState

List of usage examples for android.graphics.drawable DrawableContainer getConstantState

Introduction

In this page you can find the example usage for android.graphics.drawable DrawableContainer getConstantState.

Prototype

@Override
    public ConstantState getConstantState() 

Source Link

Usage

From source file:com.waz.zclient.pages.main.profile.preferences.dialogs.AddPhoneNumberPreferenceDialogFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearColorFilter(@NonNull Drawable drawable) {
    drawable.clearColorFilter();//w  w  w. j  av  a  2 s .  c om

    if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
        // API 21 + 22 have an issue where clearing a color filter on a DrawableContainer
        // will not propagate to all of its children. To workaround this we unwrap the drawable
        // to find any DrawableContainers, and then unwrap those to clear the filter on its
        // children manually
        if (drawable instanceof InsetDrawable) {
            clearColorFilter(((InsetDrawable) drawable).getDrawable());
        } else if (drawable instanceof DrawableWrapper) {
            clearColorFilter(((DrawableWrapper) drawable).getWrappedDrawable());
        } else if (drawable instanceof DrawableContainer) {
            final DrawableContainer container = (DrawableContainer) drawable;
            final DrawableContainer.DrawableContainerState state = (DrawableContainer.DrawableContainerState) container
                    .getConstantState();
            if (state != null) {
                for (int i = 0, count = state.getChildCount(); i < count; i++) {
                    clearColorFilter(state.getChild(i));
                }
            }
        }
    }
}