FileDocCategorySizeDatePackage
ViewGroup_Delegate.javaAPI DocAndroid 5.1 API8442Thu Mar 12 22:22:44 GMT 2015android.view

ViewGroup_Delegate

public class ViewGroup_Delegate extends Object
Delegate used to provide new implementation of a select few methods of {@link ViewGroup}

Through the layoutlib_create tool, the original methods of ViewGroup have been replaced by calls to methods of the same name in this delegate class.

Fields Summary
Constructors Summary
Methods Summary
static booleandrawChild(ViewGroup thisVG, android.graphics.Canvas canvas, View child, long drawingTime)
Overrides the original drawChild call in ViewGroup to draw the shadow.

        boolean retVal = thisVG.drawChild_Original(canvas, child, drawingTime);
        if (child.getZ() > thisVG.getZ()) {
            ViewOutlineProvider outlineProvider = child.getOutlineProvider();
            Outline outline = new Outline();
            outlineProvider.getOutline(child, outline);

            if (outline.mPath != null || (outline.mRect != null && !outline.mRect.isEmpty())) {
                int restoreTo = transformCanvas(thisVG, canvas, child);
                drawShadow(thisVG, canvas, child, outline);
                canvas.restoreToCount(restoreTo);
            }
        }
        return retVal;
    
private static voiddrawShadow(ViewGroup parent, android.graphics.Canvas canvas, View child, android.graphics.Outline outline)

        BufferedImage shadow = null;
        int x = 0;
        if (outline.mRect != null) {
            Shadow s = getRectShadow(parent, canvas, child, outline);
            shadow = s.mShadow;
            x = -s.mShadowWidth;
        } else if (outline.mPath != null) {
            shadow = getPathShadow(child, outline, canvas);
        }
        if (shadow == null) {
            return;
        }
        Bitmap bitmap = Bitmap_Delegate.createBitmap(shadow, false,
                Density.getEnum(canvas.getDensity()));
        Rect clipBounds = canvas.getClipBounds();
        Rect newBounds = new Rect(clipBounds);
        newBounds.left = newBounds.left + x;
        canvas.clipRect(newBounds, Op.REPLACE);
        canvas.drawBitmap(bitmap, x, 0, null);
        canvas.clipRect(clipBounds, Op.REPLACE);
    
private static android.util.DisplayMetricsgetMetrics(View view)

        Context context = view.getContext();
        while (context instanceof ContextThemeWrapper) {
            context = ((ContextThemeWrapper) context).getBaseContext();
        }
        if (context instanceof BridgeContext) {
            return ((BridgeContext) context).getMetrics();
        }
        throw new RuntimeException("View " + view.getClass().getName() + " not created with the " +
                "right context");
    
private static java.awt.image.BufferedImagegetPathShadow(View child, android.graphics.Outline outline, android.graphics.Canvas canvas)

        Rect clipBounds = canvas.getClipBounds();
        BufferedImage image = new BufferedImage(clipBounds.width(), clipBounds.height(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = image.createGraphics();
        graphics.draw(Path_Delegate.getDelegate(outline.mPath.mNativePath).getJavaShape());
        graphics.dispose();
        return ShadowPainter.createDropShadow(image, ((int) child.getZ()));
    
private static android.view.ViewGroup_Delegate$ShadowgetRectShadow(ViewGroup parent, android.graphics.Canvas canvas, View child, android.graphics.Outline outline)

        BufferedImage shadow;
        Rect clipBounds = canvas.getClipBounds();
        if (clipBounds.isEmpty()) {
            return null;
        }
        float height = child.getZ() - parent.getZ();
        // Draw large shadow if difference in z index is more than 10dp
        float largeShadowThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10f,
                getMetrics(child));
        boolean largeShadow = height > largeShadowThreshold;
        int shadowSize = largeShadow ? ShadowPainter.SHADOW_SIZE : ShadowPainter.SMALL_SHADOW_SIZE;
        shadow = new BufferedImage(clipBounds.width() + shadowSize, clipBounds.height(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = shadow.createGraphics();
        Rect rect = outline.mRect;
        if (largeShadow) {
            ShadowPainter.drawRectangleShadow(graphics,
                    rect.left + shadowSize, rect.top, rect.width(), rect.height());
        } else {
            ShadowPainter.drawSmallRectangleShadow(graphics,
                    rect.left + shadowSize, rect.top, rect.width(), rect.height());
        }
        graphics.dispose();
        return new Shadow(shadow, shadowSize);
    
private static inttransformCanvas(ViewGroup thisVG, android.graphics.Canvas canvas, View child)

        final int restoreTo = canvas.save();
        final boolean childHasIdentityMatrix = child.hasIdentityMatrix();
        int flags = thisVG.mGroupFlags;
        Transformation transformToApply = null;
        boolean concatMatrix = false;
        if ((flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
            final Transformation t = thisVG.getChildTransformation();
            final boolean hasTransform = thisVG.getChildStaticTransformation(child, t);
            if (hasTransform) {
                final int transformType = t.getTransformationType();
                transformToApply = transformType != Transformation.TYPE_IDENTITY ? t : null;
                concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0;
            }
        }
        concatMatrix |= childHasIdentityMatrix;

        child.computeScroll();
        int sx = child.mScrollX;
        int sy = child.mScrollY;

        canvas.translate(child.mLeft - sx, child.mTop - sy);
        float alpha = child.getAlpha() * child.getTransitionAlpha();

        if (transformToApply != null || alpha < 1 || !childHasIdentityMatrix) {
            if (transformToApply != null || !childHasIdentityMatrix) {
                int transX = -sx;
                int transY = -sy;

                if (transformToApply != null) {
                    if (concatMatrix) {
                        // Undo the scroll translation, apply the transformation matrix,
                        // then redo the scroll translate to get the correct result.
                        canvas.translate(-transX, -transY);
                        canvas.concat(transformToApply.getMatrix());
                        canvas.translate(transX, transY);
                    }
                    if (!childHasIdentityMatrix) {
                        canvas.translate(-transX, -transY);
                        canvas.concat(child.getMatrix());
                        canvas.translate(transX, transY);
                    }
                }

            }
        }
        return restoreTo;