FileDocCategorySizeDatePackage
PrinterCapabilitiesInfo.javaAPI DocAndroid 5.1 API18518Thu Mar 12 22:22:10 GMT 2015android.print

PrinterCapabilitiesInfo

public final class PrinterCapabilitiesInfo extends Object implements android.os.Parcelable
This class represents the capabilities of a printer. Instances of this class are created by a print service to report the capabilities of a printer it manages. The capabilities of a printer specify how it can print content. For example, what are the media sizes supported by the printer, what are the minimal margins of the printer based on its technical design, etc.

Fields Summary
public static final int
DEFAULT_UNDEFINED
Undefined default value.
private static final int
PROPERTY_MEDIA_SIZE
private static final int
PROPERTY_RESOLUTION
private static final int
PROPERTY_COLOR_MODE
private static final int
PROPERTY_COUNT
private static final android.print.PrintAttributes.Margins
DEFAULT_MARGINS
private android.print.PrintAttributes.Margins
mMinMargins
private List
mMediaSizes
private List
mResolutions
private int
mColorModes
private final int[]
mDefaults
public static final Parcelable.Creator
CREATOR
Constructors Summary
public PrinterCapabilitiesInfo()

hide


          
      
        Arrays.fill(mDefaults, DEFAULT_UNDEFINED);
    
public PrinterCapabilitiesInfo(PrinterCapabilitiesInfo prototype)

hide

        copyFrom(prototype);
    
private PrinterCapabilitiesInfo(android.os.Parcel parcel)

        mMinMargins = readMargins(parcel);
        readMediaSizes(parcel);
        readResolutions(parcel);

        mColorModes = parcel.readInt();

        readDefaults(parcel);
    
Methods Summary
private java.lang.StringcolorModesToString()

        StringBuilder builder = new StringBuilder();
        builder.append('[");
        int colorModes = mColorModes;
        while (colorModes != 0) {
            final int colorMode = 1 << Integer.numberOfTrailingZeros(colorModes);
            colorModes &= ~colorMode;
            if (builder.length() > 1) {
                builder.append(", ");
            }
            builder.append(PrintAttributes.colorModeToString(colorMode));
        }
        builder.append(']");
        return builder.toString();
    
public voidcopyFrom(android.print.PrinterCapabilitiesInfo other)

hide

        if (this == other) {
            return;
        }

        mMinMargins = other.mMinMargins;

        if (other.mMediaSizes != null) {
            if (mMediaSizes != null) {
                mMediaSizes.clear();
                mMediaSizes.addAll(other.mMediaSizes);
            } else {
                mMediaSizes = new ArrayList<MediaSize>(other.mMediaSizes);
            }
        } else {
            mMediaSizes = null;
        }

        if (other.mResolutions != null) {
            if (mResolutions != null) {
                mResolutions.clear();
                mResolutions.addAll(other.mResolutions);
            } else {
                mResolutions = new ArrayList<Resolution>(other.mResolutions);
            }
        } else {
            mResolutions = null;
        }

        mColorModes = other.mColorModes;

        final int defaultCount = other.mDefaults.length;
        for (int i = 0; i < defaultCount; i++) {
            mDefaults[i] = other.mDefaults[i];
        }
    
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object obj)

        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        PrinterCapabilitiesInfo other = (PrinterCapabilitiesInfo) obj;
        if (mMinMargins == null) {
            if (other.mMinMargins != null) {
                return false;
            }
        } else if (!mMinMargins.equals(other.mMinMargins)) {
            return false;
        }
        if (mMediaSizes == null) {
            if (other.mMediaSizes != null) {
                return false;
            }
        } else if (!mMediaSizes.equals(other.mMediaSizes)) {
            return false;
        }
        if (mResolutions == null) {
            if (other.mResolutions != null) {
                return false;
            }
        } else if (!mResolutions.equals(other.mResolutions)) {
            return false;
        }
        if (mColorModes != other.mColorModes) {
            return false;
        }
        if (!Arrays.equals(mDefaults, other.mDefaults)) {
            return false;
        }
        return true;
    
public intgetColorModes()
Gets the bit mask of supported color modes.

return
The bit mask of supported color modes.
see
PrintAttributes#COLOR_MODE_COLOR
see
PrintAttributes#COLOR_MODE_MONOCHROME

        return mColorModes;
    
public PrintAttributesgetDefaults()
Gets the default print attributes.

return
The default attributes.

        PrintAttributes.Builder builder = new PrintAttributes.Builder();

        builder.setMinMargins(mMinMargins);

        final int mediaSizeIndex = mDefaults[PROPERTY_MEDIA_SIZE];
        if (mediaSizeIndex >= 0) {
            builder.setMediaSize(mMediaSizes.get(mediaSizeIndex));
        }

        final int resolutionIndex = mDefaults[PROPERTY_RESOLUTION];
        if (resolutionIndex >= 0) {
            builder.setResolution(mResolutions.get(resolutionIndex));
        }

        final int colorMode = mDefaults[PROPERTY_COLOR_MODE];
        if (colorMode > 0) {
            builder.setColorMode(colorMode);
        }

        return builder.build();
    
public java.util.ListgetMediaSizes()
Gets the supported media sizes.

return
The media sizes.

        return Collections.unmodifiableList(mMediaSizes);
    
public android.print.PrintAttributes.MarginsgetMinMargins()
Gets the minimal margins. These are the minimal margins the printer physically supports.

return
The minimal margins.

        return mMinMargins;
    
public java.util.ListgetResolutions()
Gets the supported resolutions.

return
The resolutions.

        return Collections.unmodifiableList(mResolutions);
    
public inthashCode()

        final int prime = 31;
        int result = 1;
        result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode());
        result = prime * result + ((mMediaSizes == null) ? 0 : mMediaSizes.hashCode());
        result = prime * result + ((mResolutions == null) ? 0 : mResolutions.hashCode());
        result = prime * result + mColorModes;
        result = prime * result + Arrays.hashCode(mDefaults);
        return result;
    
private voidreadDefaults(android.os.Parcel parcel)

        final int defaultCount = parcel.readInt();
        for (int i = 0; i < defaultCount; i++) {
            mDefaults[i] = parcel.readInt();
        }
    
private android.print.PrintAttributes.MarginsreadMargins(android.os.Parcel parcel)

        return (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null;
    
private voidreadMediaSizes(android.os.Parcel parcel)

        final int mediaSizeCount = parcel.readInt();
        if (mediaSizeCount > 0 && mMediaSizes == null) {
            mMediaSizes = new ArrayList<MediaSize>();
        }
        for (int i = 0; i < mediaSizeCount; i++) {
            mMediaSizes.add(MediaSize.createFromParcel(parcel));
        }
    
private voidreadResolutions(android.os.Parcel parcel)

        final int resolutionCount = parcel.readInt();
        if (resolutionCount > 0 && mResolutions == null) {
            mResolutions = new ArrayList<Resolution>();
        }
        for (int i = 0; i < resolutionCount; i++) {
            mResolutions.add(Resolution.createFromParcel(parcel));
        }
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();
        builder.append("PrinterInfo{");
        builder.append("minMargins=").append(mMinMargins);
        builder.append(", mediaSizes=").append(mMediaSizes);
        builder.append(", resolutions=").append(mResolutions);
        builder.append(", colorModes=").append(colorModesToString());
        builder.append("\"}");
        return builder.toString();
    
private voidwriteDefaults(android.os.Parcel parcel)

        final int defaultCount = mDefaults.length;
        parcel.writeInt(defaultCount);
        for (int i = 0; i < defaultCount; i++) {
            parcel.writeInt(mDefaults[i]);
        }
    
private voidwriteMargins(android.print.PrintAttributes.Margins margins, android.os.Parcel parcel)

        if (margins == null) {
            parcel.writeInt(0);
        } else {
            parcel.writeInt(1);
            margins.writeToParcel(parcel);
        }
    
private voidwriteMediaSizes(android.os.Parcel parcel)

        if (mMediaSizes == null) {
            parcel.writeInt(0);
            return;
        }
        final int mediaSizeCount = mMediaSizes.size();
        parcel.writeInt(mediaSizeCount);
        for (int i = 0; i < mediaSizeCount; i++) {
            mMediaSizes.get(i).writeToParcel(parcel);
        }
    
private voidwriteResolutions(android.os.Parcel parcel)

        if (mResolutions == null) {
            parcel.writeInt(0);
            return;
        }
        final int resolutionCount = mResolutions.size();
        parcel.writeInt(resolutionCount);
        for (int i = 0; i < resolutionCount; i++) {
            mResolutions.get(i).writeToParcel(parcel);
        }
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        writeMargins(mMinMargins, parcel);
        writeMediaSizes(parcel);
        writeResolutions(parcel);

        parcel.writeInt(mColorModes);

        writeDefaults(parcel);