package com.fuzz.indicator.widget;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableContainer;
import android.graphics.drawable.LevelListDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * This class wraps a drawable, exposing (almost) all of its properties.
 * The only practical distinction is that {@link #draw(Canvas)} does nothing.
 *
 * @author Philip Cohn-Cort (Fuzz)
 */
public class UnDrawable extends DrawableContainer {

    /**
     * Note that the constructor for {@link android.graphics.drawable.DrawableContainer.DrawableContainerState}
     * is not publicly accessible. This field is a copy of the DrawableContainerState
     * most recently set on the anonymous LevelListDrawable in {@link #UnDrawable()}.
     */
    private DrawableContainerState extracted;

    /**
     * Create a new {@link UnDrawable} with a state stolen from {@link LevelListDrawable}.
     */
    @SuppressWarnings("deprecation")
    public UnDrawable() {
        Drawable seed = Resources.getSystem().getDrawable(android.R.drawable.btn_plus);
        new LevelListDrawable() {
            @Override
            protected void setConstantState(@NonNull DrawableContainerState state) {
                super.setConstantState(state);
                extracted = state;
            }
        };
        extracted.addChild(seed);
        setConstantState(extracted);
        setInternalDrawable(seed);
    }

    @Override
    public int getChangingConfigurations() {
        int changingConfigurations = 0;
        // The superclass will query the constant state, so be careful around that.
        if (extracted != null) {
            changingConfigurations = super.getChangingConfigurations();
        }
        return changingConfigurations;
    }

    /**
     * The parameter to this method may later be retrieved with {@link #getCurrent()}.
     * If you try to pass in null, a bunch of superclass methods will throw
     * {@link NullPointerException}.
     *
     * @param internalDrawable    provider of all sorts of information
     *                            about this drawable (e.g. size, transparency,
     *                            etc.).
     */
    public void setInternalDrawable(@NonNull Drawable internalDrawable) {
        if (extracted == null) {
            throw new IllegalStateException(
                    "\"setInternalDrawable\" may only be called on UnDrawables with non-null resources."
            );
        }
        if (extracted.getChildCount() <= 0) {
            // We need the state to expand its child array for us
            extracted.addChild(internalDrawable);
        } else {
            // We can modify the array directly.
            Drawable[] children = extracted.getChildren();
            children[0] = internalDrawable;
        }

        selectDrawable(0);
    }

    @Nullable
    @Override
    public Region getTransparentRegion() {
        Drawable current = getCurrent();
        if (current != this) {
            return new Region(current.getBounds());
        } else {
            return super.getTransparentRegion();
        }
    }

    /**
     * For some weird reason, this method is normally protected from objects outside
     * of the DrawableContainer (sub)class. So much of the drawable subsystem is just
     * really clandestine.
     *
     * @param state    where the contained drawables are kept.
     */
    @Override
    public void setConstantState(DrawableContainerState state) {
        super.setConstantState(state);
    }

    /**
     * This override of draw does nothing.
     * {@inheritDoc}
     * @see #reallyDraw(Canvas)
     */
    @Override
    public void draw(Canvas canvas) {
        // Do absolutely nothing.
    }

    /**
     * Utility method that calls through to {@link DrawableContainer#draw(Canvas)},
     * in case you're making a specialised subclass or need to debug something.
     *
     * @param canvas    The canvas to draw into
     */
    @SuppressWarnings("unused")
    public void reallyDraw(Canvas canvas) {
        super.draw(canvas);
    }
}

@@ -33,46 +33,8 @@
 t;%0A%0A
-import android.content.res.Resources;%0A
 impo
@@ -221,21 +221,21 @@
 rawable.
-Level
+State
 ListDraw
@@ -244,51 +244,8 @@
 le;%0A
-import android.support.annotation.NonNull;%0A
 impo
@@ -283,16 +283,46 @@
 ullable;
+%0Aimport android.util.StateSet;
 %0A%0A/**%0A *
@@ -548,1337 +548,27 @@
 nds 
-DrawableContainer %7B%0A%0A    /**%0A     * Note that the constructor for %7B@link android.graphics.drawable.DrawableContainer.DrawableContainerState%7D%0A     * is not publicly accessible. This field is a copy of the DrawableContainerState%0A     * most recently set on the anonymous LevelListDrawable in %7B@link #UnDrawable()%7D.%0A     */%0A    private DrawableContainerState extracted;%0A%0A    /**%0A     * Create a new %7B@link UnDrawable%7D with a state stolen from %7B@link LevelListDrawable%7D.%0A     */%0A    @SuppressWarnings(%22deprecation%22)%0A    public UnDrawable() %7B%0A        Drawable seed = Resources.getSystem().getDrawable(android.R.drawable.btn_plus);%0A        new LevelListDrawable() %7B%0A            @Override%0A            protected void setConstantState(@NonNull DrawableContainerState state) %7B%0A                super.setConstantState(state);%0A                extracted = state;%0A            %7D%0A        %7D;%0A        extracted.addChild(seed);%0A        setConstantState(extracted);%0A        setInternalDrawable(seed);%0A    %7D%0A%0A    @Override%0A    public int getChangingConfigurations() %7B%0A        int changingConfigurations = 0;%0A        // The superclass will query the constant state, so be careful around that.%0A        if (extracted != null) %7B%0A            changingConfigurations = super.getChangingConfigurations();%0A        %7D%0A        return changingConfigurations;%0A    %7D
+StateListDrawable %7B
 %0A%0A  
@@ -1020,17 +1020,8 @@
 ble(
-@NonNull 
 Draw
@@ -1057,25 +1057,32 @@
     if (
-extracted
+internalDrawable
  == null
@@ -1272,312 +1272,36 @@
     
-if (extracted.getChildCount() %3C= 0) %7B%0A            // We need the state to expand its child array for us%0A            extracted.addChild(internalDrawable);%0A        %7D else %7B%0A            // We can modify the array directly.%0A            Drawable%5B%5D children = extracted.getChildren();%0A            children%5B0%5D =
+addState(StateSet.WILD_CARD,
  int
@@ -1313,27 +1313,18 @@
 Drawable
+)
 ;
-%0A        %7D
 %0A%0A      
@@ -1633,417 +1633,8 @@
  %7D%0A%0A
-    /**%0A     * For some weird reason, this method is normally protected from objects outside%0A     * of the DrawableContainer (sub)class. So much of the drawable subsystem is just%0A     * really clandestine.%0A     *%0A     * @param state    where the contained drawables are kept.%0A     */%0A    @Override%0A    public void setConstantState(DrawableContainerState state) %7B%0A        super.setConstantState(state);%0A    %7D%0A%0A
     

Make UnDrawable much simpler - no need for interception or proxies