FileDocCategorySizeDatePackage
PrintAttributes.javaAPI DocAndroid 5.1 API52987Thu Mar 12 22:22:10 GMT 2015android.print

PrintAttributes

public final class PrintAttributes extends Object implements android.os.Parcelable
This class represents the attributes of a print job. These attributes describe how the printed content should be laid out. For example, the print attributes may state that the content should be laid out on a letter size with 300 DPI (dots per inch) resolution, have a margin of 10 mills (thousand of an inch) on all sides, and be black and white.

Fields Summary
public static final int
COLOR_MODE_MONOCHROME
Color mode: Monochrome color scheme, for example one color is used.
public static final int
COLOR_MODE_COLOR
Color mode: Color color scheme, for example many colors are used.
private static final int
VALID_COLOR_MODES
private MediaSize
mMediaSize
private Resolution
mResolution
private Margins
mMinMargins
private int
mColorMode
public static final Parcelable.Creator
CREATOR
Constructors Summary
PrintAttributes()


     
        /* hide constructor */
    
private PrintAttributes(android.os.Parcel parcel)

        mMediaSize = (parcel.readInt() ==  1) ? MediaSize.createFromParcel(parcel) : null;
        mResolution = (parcel.readInt() ==  1) ? Resolution.createFromParcel(parcel) : null;
        mMinMargins = (parcel.readInt() ==  1) ? Margins.createFromParcel(parcel) : null;
        mColorMode = parcel.readInt();
    
Methods Summary
public android.print.PrintAttributesasLandscape()
Gets a new print attributes instance which is in landscape orientation, which is the media size is in landscape and all orientation dependent attributes such as resolution and margins are properly adjusted.

return
New instance in landscape orientation if this one is in portrait, otherwise this instance.
hide

        if (!isPortrait()) {
            return this;
        }

        PrintAttributes attributes = new PrintAttributes();

        // Rotate the media size.
        attributes.setMediaSize(getMediaSize().asLandscape());

        // Rotate the resolution.
        Resolution oldResolution = getResolution();
        Resolution newResolution = new Resolution(
                oldResolution.getId(),
                oldResolution.getLabel(),
                oldResolution.getVerticalDpi(),
                oldResolution.getHorizontalDpi());
        attributes.setResolution(newResolution);

        // Do not rotate the physical margins.
        attributes.setMinMargins(getMinMargins());

        attributes.setColorMode(getColorMode());

        return attributes;
    
public android.print.PrintAttributesasPortrait()
Gets a new print attributes instance which is in portrait orientation, which is the media size is in portrait and all orientation dependent attributes such as resolution and margins are properly adjusted.

return
New instance in portrait orientation if this one is in landscape, otherwise this instance.
hide

        if (isPortrait()) {
            return this;
        }

        PrintAttributes attributes = new PrintAttributes();

        // Rotate the media size.
        attributes.setMediaSize(getMediaSize().asPortrait());

        // Rotate the resolution.
        Resolution oldResolution = getResolution();
        Resolution newResolution = new Resolution(
                oldResolution.getId(),
                oldResolution.getLabel(),
                oldResolution.getVerticalDpi(),
                oldResolution.getHorizontalDpi());
        attributes.setResolution(newResolution);

        // Do not rotate the physical margins.
        attributes.setMinMargins(getMinMargins());

        attributes.setColorMode(getColorMode());

        return attributes;
    
public voidclear()

hide

        mMediaSize = null;
        mResolution = null;
        mMinMargins = null;
        mColorMode = 0;
    
static java.lang.StringcolorModeToString(int colorMode)

        switch (colorMode) {
            case COLOR_MODE_MONOCHROME: {
                return "COLOR_MODE_MONOCHROME";
            }
            case COLOR_MODE_COLOR: {
                return "COLOR_MODE_COLOR";
            }
            default:
                return "COLOR_MODE_UNKNOWN";
        }
    
public voidcopyFrom(android.print.PrintAttributes other)

hide

        mMediaSize = other.mMediaSize;
        mResolution = other.mResolution;
        mMinMargins = other.mMinMargins;
        mColorMode = other.mColorMode;
    
public intdescribeContents()

        return 0;
    
static voidenforceValidColorMode(int colorMode)

        if ((colorMode & VALID_COLOR_MODES) == 0 && Integer.bitCount(colorMode) == 1) {
            throw new IllegalArgumentException("invalid color mode: " + colorMode);
        }
    
public booleanequals(java.lang.Object obj)

        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        PrintAttributes other = (PrintAttributes) obj;
        if (mColorMode != other.mColorMode) {
            return false;
        }
        if (mMinMargins == null) {
            if (other.mMinMargins != null) {
                return false;
            }
        } else if (!mMinMargins.equals(other.mMinMargins)) {
            return false;
        }
        if (mMediaSize == null) {
            if (other.mMediaSize != null) {
                return false;
            }
        } else if (!mMediaSize.equals(other.mMediaSize)) {
            return false;
        }
        if (mResolution == null) {
            if (other.mResolution != null) {
                return false;
            }
        } else if (!mResolution.equals(other.mResolution)) {
            return false;
        }
        return true;
    
public intgetColorMode()
Gets the color mode.

return
The color mode or zero if not set.
see
#COLOR_MODE_COLOR
see
#COLOR_MODE_MONOCHROME

        return mColorMode;
    
public android.print.PrintAttributes$MediaSizegetMediaSize()
Gets the media size.

return
The media size or null if not set.

        return mMediaSize;
    
public android.print.PrintAttributes$MarginsgetMinMargins()
Gets the minimal margins. If the content does not fit these margins it will be clipped.

These margins are physically imposed by the printer and they are not rotated, i.e. they are the same for both portrait and landscape. For example, a printer may not be able to print in a stripe on both left and right sides of the page.

return
The margins or null if not set.

        return mMinMargins;
    
public android.print.PrintAttributes$ResolutiongetResolution()
Gets the resolution.

return
The resolution or null if not set.

        return mResolution;
    
public inthashCode()

        final int prime = 31;
        int result = 1;
        result = prime * result + mColorMode;
        result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode());
        result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode());
        result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode());
        return result;
    
public booleanisPortrait()
Gets whether this print attributes are in portrait orientation, which is the media size is in portrait and all orientation dependent attributes such as resolution and margins are properly adjusted.

return
Whether this print attributes are in portrait.
hide

        return mMediaSize.isPortrait();
    
public voidsetColorMode(int colorMode)
Sets the color mode.

param
The color mode.
see
#COLOR_MODE_MONOCHROME
see
#COLOR_MODE_COLOR
hide

        enforceValidColorMode(colorMode);
        mColorMode = colorMode;
    
public voidsetMediaSize(android.print.PrintAttributes$MediaSize mediaSize)
Sets the media size.

param
The media size.
hide

        mMediaSize = mediaSize;
    
public voidsetMinMargins(android.print.PrintAttributes$Margins margins)
Sets the minimal margins. If the content does not fit these margins it will be clipped.

These margins are physically imposed by the printer and they are not rotated, i.e. they are the same for both portrait and landscape. For example, a printer may not be able to print in a stripe on both left and right sides of the page.

param
The margins.
hide

        mMinMargins = margins;
    
public voidsetResolution(android.print.PrintAttributes$Resolution resolution)
Sets the resolution.

param
The resolution.
hide

        mResolution = resolution;
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();
        builder.append("PrintAttributes{");
        builder.append("mediaSize: ").append(mMediaSize);
        if (mMediaSize != null) {
            builder.append(", orientation: ").append(mMediaSize.isPortrait()
                    ? "portrait" : "landscape");
        } else {
            builder.append(", orientation: ").append("null");
        }
        builder.append(", resolution: ").append(mResolution);
        builder.append(", minMargins: ").append(mMinMargins);
        builder.append(", colorMode: ").append(colorModeToString(mColorMode));
        builder.append("}");
        return builder.toString();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        if (mMediaSize != null) {
            parcel.writeInt(1);
            mMediaSize.writeToParcel(parcel);
        } else {
            parcel.writeInt(0);
        }
        if (mResolution != null) {
            parcel.writeInt(1);
            mResolution.writeToParcel(parcel);
        } else {
            parcel.writeInt(0);
        }
        if (mMinMargins != null) {
            parcel.writeInt(1);
            mMinMargins.writeToParcel(parcel);
        } else {
            parcel.writeInt(0);
        }
        parcel.writeInt(mColorMode);