FileDocCategorySizeDatePackage
PorterDuffColorFilter_Delegate.javaAPI DocAndroid 5.1 API4688Thu Mar 12 22:22:44 GMT 2015android.graphics

PorterDuffColorFilter_Delegate

public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate
Delegate implementing the native methods of android.graphics.PorterDuffColorFilter Through the layoutlib_create tool, the original native methods of PorterDuffColorFilter have been replaced by calls to methods of the same name in this delegate class. This class behaves like the original native implementation, but in Java, keeping previously native data into its own objects and mapping them to int that are sent back and forth between it and the original PorterDuffColorFilter class. Because this extends {@link ColorFilter_Delegate}, there's no need to use a {@link DelegateManager}, as all the Shader classes will be added to the manager owned by {@link ColorFilter_Delegate}.
see
ColorFilter_Delegate

Fields Summary
private final int
mSrcColor
private final android.graphics.PorterDuff.Mode
mMode
Constructors Summary
private PorterDuffColorFilter_Delegate(int srcColor, int mode)

        mSrcColor = srcColor;
        mMode = getCompatibleMode(getPorterDuffMode(mode));
    
Methods Summary
public voidapplyFilter(java.awt.Graphics2D g, int width, int height)

        BufferedImage image = createFilterImage(width, height);
        g.setComposite(getComposite(mMode, 0xFF));
        g.drawImage(image, 0, 0, null);
    
private java.awt.image.BufferedImagecreateFilterImage(int width, int height)

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = image.createGraphics();
        try {
            graphics.setColor(new java.awt.Color(mSrcColor, true /* hasAlpha */));
            graphics.fillRect(0, 0, width, height);
        } finally {
            graphics.dispose();
        }
        return image;
    
private android.graphics.PorterDuff.ModegetCompatibleMode(android.graphics.PorterDuff.Mode mode)

        Mode m = mode;
        // Modes that are directly supported:
        // CLEAR, DST, SRC_IN, DST_IN, DST_OUT, SRC_ATOP, DARKEN, LIGHTEN, MULTIPLY, SCREEN,
        // ADD, OVERLAY
        switch (mode) {
        // Modes that can be mapped to one of the supported modes.
        case SRC:
            m = Mode.SRC_IN;
            break;
        case SRC_OVER:
            m = Mode.SRC_ATOP;
            break;
        case DST_OVER:
            m = Mode.DST;
            break;
        case SRC_OUT:
            m = Mode.CLEAR;
            break;
        case DST_ATOP:
            m = Mode.DST_IN;
            break;
        case XOR:
            m = Mode.DST_OUT;
            break;
        }
        return m;
    
public java.lang.StringgetSupportMessage()

        return "PorterDuff Color Filter is not supported for mode: " + mMode.name() + ".";
    
public booleanisSupported()

        return true;
    
static longnative_CreatePorterDuffFilter(int srcColor, int porterDuffMode)

        PorterDuffColorFilter_Delegate newDelegate =
                new PorterDuffColorFilter_Delegate(srcColor, porterDuffMode);
        return sManager.addNewDelegate(newDelegate);