FileDocCategorySizeDatePackage
PorterDuffUtility.javaAPI DocAndroid 5.1 API4517Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.impl

PorterDuffUtility

public final class PorterDuffUtility extends Object
Provides various utility methods for {@link PorterDuffColorFilter_Delegate} and {@link PorterDuffXfermode_Delegate}.

Fields Summary
Constructors Summary
private PorterDuffUtility()

    
Methods Summary
public static java.awt.CompositegetComposite(android.graphics.PorterDuff.Mode mode, int alpha255)
A utility method to get the {@link Composite} that represents the filter for the given PorterDuff mode and the alpha. Defaults to {@link Mode#SRC_OVER} for invalid modes.

        float alpha1 = alpha255 != 0xFF ? alpha255 / 255.f : 1.f;
        switch (mode) {
            case CLEAR:
                return AlphaComposite.getInstance(AlphaComposite.CLEAR, alpha1);
            case SRC:
                return AlphaComposite.getInstance(AlphaComposite.SRC, alpha1);
            case DST:
                return AlphaComposite.getInstance(AlphaComposite.DST, alpha1);
            case SRC_OVER:
                return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha1);
            case DST_OVER:
                return AlphaComposite.getInstance(AlphaComposite.DST_OVER, alpha1);
            case SRC_IN:
                return AlphaComposite.getInstance(AlphaComposite.SRC_IN, alpha1);
            case DST_IN:
                return AlphaComposite.getInstance(AlphaComposite.DST_IN, alpha1);
            case SRC_OUT:
                return AlphaComposite.getInstance(AlphaComposite.SRC_OUT, alpha1);
            case DST_OUT:
                return AlphaComposite.getInstance(AlphaComposite.DST_OUT, alpha1);
            case SRC_ATOP:
                return AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha1);
            case DST_ATOP:
                return AlphaComposite.getInstance(AlphaComposite.DST_ATOP, alpha1);
            case XOR:
                return AlphaComposite.getInstance(AlphaComposite.XOR, alpha1);
            case DARKEN:
                return BlendComposite.getInstance(BlendingMode.DARKEN, alpha1);
            case LIGHTEN:
                return BlendComposite.getInstance(BlendingMode.LIGHTEN, alpha1);
            case MULTIPLY:
                return BlendComposite.getInstance(BlendingMode.MULTIPLY, alpha1);
            case SCREEN:
                return BlendComposite.getInstance(BlendingMode.SCREEN, alpha1);
            case ADD:
                return BlendComposite.getInstance(BlendingMode.ADD, alpha1);
            case OVERLAY:
                return BlendComposite.getInstance(BlendingMode.OVERLAY, alpha1);
            default:
                Bridge.getLog().fidelityWarning(LayoutLog.TAG_BROKEN,
                        String.format("Unsupported PorterDuff Mode: %1$s", mode.name()),
                        null, null /*data*/);

                return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha1);
        }
    
public static android.graphics.PorterDuff.ModegetPorterDuffMode(int porterDuffMode)
Convert the porterDuffMode from the framework to its corresponding enum. This defaults to {@link Mode#SRC_OVER} for invalid modes.

        Mode[] values = Mode.values();
        if (porterDuffMode >= 0 && porterDuffMode < values.length) {
            return values[porterDuffMode];
        }
        Bridge.getLog().error(LayoutLog.TAG_BROKEN,
                String.format("Unknown PorterDuff.Mode: %1$d", porterDuffMode), null /*data*/);
        assert false;
        return Mode.SRC_OVER;