FileDocCategorySizeDatePackage
PrintDocumentInfo.javaAPI DocAndroid 5.1 API11011Thu Mar 12 22:22:10 GMT 2015android.print

PrintDocumentInfo

public final class PrintDocumentInfo extends Object implements android.os.Parcelable
This class encapsulates information about a document for printing purposes. This meta-data is used by the platform and print services, components that interact with printers. For example, this class contains the number of pages contained in the document it describes and this number of pages is shown to the user allowing him/her to select the range to print. Also a print service may optimize the printing process based on the content type, such as document or photo.

Instances of this class are created by the printing application and passed to the {@link PrintDocumentAdapter.LayoutResultCallback#onLayoutFinished( PrintDocumentInfo, boolean) PrintDocumentAdapter.LayoutResultCallback.onLayoutFinished( PrintDocumentInfo, boolean)} callback after successfully laying out the content which is performed in {@link PrintDocumentAdapter#onLayout(PrintAttributes, PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle) PrintDocumentAdapter.onLayout(PrintAttributes, PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle)}.

An example usage looks like this:


. . .

public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
CancellationSignal cancellationSignal, LayoutResultCallback callback,
Bundle metadata) {

// Assume the app defined a LayoutResult class which contains
// the layout result data and that the content is a document.
LayoutResult result = doSomeLayoutWork();

PrintDocumentInfo info = new PrintDocumentInfo
.Builder("printed_file.pdf")
.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
.setPageCount(result.getPageCount())
.build();

callback.onLayoutFinished(info, result.getContentChanged());
}

. . .

Fields Summary
public static final int
PAGE_COUNT_UNKNOWN
Constant for unknown page count.
public static final int
CONTENT_TYPE_UNKNOWN
Content type: unknown.
public static final int
CONTENT_TYPE_DOCUMENT
Content type: document.

A print service may use normal paper to print the content instead of dedicated photo paper. Also it may use a lower quality printing process as the content is not as sensitive to print quality variation as a photo is.

public static final int
CONTENT_TYPE_PHOTO
Content type: photo.

A print service may use dedicated photo paper to print the content instead of normal paper. Also it may use a higher quality printing process as the content is more sensitive to print quality variation than a document.

private String
mName
private int
mPageCount
private int
mContentType
private long
mDataSize
public static final Parcelable.Creator
CREATOR
Constructors Summary
private PrintDocumentInfo()
Creates a new instance.


             
      
        /* do nothing */
    
private PrintDocumentInfo(PrintDocumentInfo prototype)
Creates a new instance.

param
Prototype from which to clone.

        mName = prototype.mName;
        mPageCount = prototype.mPageCount;
        mContentType = prototype.mContentType;
        mDataSize = prototype.mDataSize;
    
private PrintDocumentInfo(android.os.Parcel parcel)
Creates a new instance.

param
parcel Data from which to initialize.

        mName = parcel.readString();
        mPageCount = parcel.readInt();
        mContentType = parcel.readInt();
        mDataSize = parcel.readLong();
    
Methods Summary
private java.lang.StringcontentTyepToString(int contentType)

        switch (contentType) {
            case CONTENT_TYPE_DOCUMENT: {
                return "CONTENT_TYPE_DOCUMENT";
            }
            case CONTENT_TYPE_PHOTO: {
                return "CONTENT_TYPE_PHOTO";
            }
            default: {
                return "CONTENT_TYPE_UNKNOWN";
            }
        }
    
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;
        }
        PrintDocumentInfo other = (PrintDocumentInfo) obj;
        if (!TextUtils.equals(mName, other.mName)) {
            return false;
        }
        if (mContentType != other.mContentType) {
            return false;
        }
        if (mPageCount != other.mPageCount) {
            return false;
        }
        if (mDataSize != other.mDataSize) {
            return false;
        }
        return true;
    
public intgetContentType()
Gets the content type.

return
The content type.
see
#CONTENT_TYPE_UNKNOWN
see
#CONTENT_TYPE_DOCUMENT
see
#CONTENT_TYPE_PHOTO

        return mContentType;
    
public longgetDataSize()
Gets the document data size in bytes.

return
The data size.

        return mDataSize;
    
public java.lang.StringgetName()
Gets the document name. This name may be shown to the user.

return
The document name.

        return mName;
    
public intgetPageCount()
Gets the total number of pages.

return
The number of pages.
see
#PAGE_COUNT_UNKNOWN

        return mPageCount;
    
public inthashCode()

        final int prime = 31;
        int result = 1;
        result = prime * result + ((mName != null) ? mName.hashCode() : 0);
        result = prime * result + mContentType;
        result = prime * result + mPageCount;
        result = prime * result + (int) mDataSize;
        result = prime * result + (int) mDataSize >> 32;
        return result;
    
public voidsetDataSize(long dataSize)
Sets the document data size in bytes.

param
dataSize The data size.
hide

        mDataSize = dataSize;
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();
        builder.append("PrintDocumentInfo{");
        builder.append("name=").append(mName);
        builder.append(", pageCount=").append(mPageCount);
        builder.append(", contentType=").append(contentTyepToString(mContentType));
        builder.append(", dataSize=").append(mDataSize);
        builder.append("}");
        return builder.toString();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        parcel.writeString(mName);
        parcel.writeInt(mPageCount);
        parcel.writeInt(mContentType);
        parcel.writeLong(mDataSize);