FileDocCategorySizeDatePackage
BackgroundFallback.javaAPI DocAndroid 5.1 API3517Thu Mar 12 22:22:10 GMT 2015com.android.internal.widget

BackgroundFallback

public class BackgroundFallback extends Object
Helper class for drawing a fallback background in framework decor layouts. Useful for when an app has not set a window background but we're asked to draw an uncovered area.

Fields Summary
private android.graphics.drawable.Drawable
mBackgroundFallback
Constructors Summary
Methods Summary
public voiddraw(android.view.ViewGroup root, android.graphics.Canvas c, android.view.View content)

        if (!hasFallback()) {
            return;
        }

        // Draw the fallback in the padding.
        final int width = root.getWidth();
        final int height = root.getHeight();
        int left = width;
        int top = height;
        int right = 0;
        int bottom = 0;

        final int childCount = root.getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = root.getChildAt(i);
            final Drawable childBg = child.getBackground();
            if (child == content) {
                // We always count the content view container unless it has no background
                // and no children.
                if (childBg == null && child instanceof ViewGroup &&
                        ((ViewGroup) child).getChildCount() == 0) {
                    continue;
                }
            } else if (child.getVisibility() != View.VISIBLE || childBg == null ||
                    childBg.getOpacity() != PixelFormat.OPAQUE) {
                // Potentially translucent or invisible children don't count, and we assume
                // the content view will cover the whole area if we're in a background
                // fallback situation.
                continue;
            }
            left = Math.min(left, child.getLeft());
            top = Math.min(top, child.getTop());
            right = Math.max(right, child.getRight());
            bottom = Math.max(bottom, child.getBottom());
        }

        if (left >= right || top >= bottom) {
            // No valid area to draw in.
            return;
        }

        if (top > 0) {
            mBackgroundFallback.setBounds(0, 0, width, top);
            mBackgroundFallback.draw(c);
        }
        if (left > 0) {
            mBackgroundFallback.setBounds(0, top, left, height);
            mBackgroundFallback.draw(c);
        }
        if (right < width) {
            mBackgroundFallback.setBounds(right, top, width, height);
            mBackgroundFallback.draw(c);
        }
        if (bottom < height) {
            mBackgroundFallback.setBounds(left, bottom, right, height);
            mBackgroundFallback.draw(c);
        }
    
public booleanhasFallback()

        return mBackgroundFallback != null;
    
public voidsetDrawable(android.graphics.drawable.Drawable d)

        mBackgroundFallback = d;