PrintDocumentInfo.java revision a00271533f639c8ed36429c663889ac9f654bc72
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.print; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22/** 23 * This class encapsulates information about a printed document. 24 */ 25public final class PrintDocumentInfo implements Parcelable { 26 27 /** 28 * Constant for unknown page count (default). 29 */ 30 public static final int PAGE_COUNT_UNKNOWN = -1; 31 32 /** 33 * Content type: unknown (default). 34 */ 35 public static final int CONTENT_TYPE_UNKNOWN = -1; 36 37 /** 38 * Content type: document. 39 */ 40 public static final int CONTENT_TYPE_DOCUMENT = 0; 41 42 /** 43 * Content type: photo. 44 */ 45 public static final int CONTENT_TYPE_PHOTO = 1; 46 47 private int mPageCount; 48 private int mContentType; 49 50 /** 51 * Creates a new instance. 52 */ 53 private PrintDocumentInfo() { 54 mPageCount = PAGE_COUNT_UNKNOWN; 55 mContentType = CONTENT_TYPE_UNKNOWN; 56 } 57 58 /** 59 * Creates a new instance. 60 * 61 * @param Prototype from which to clone. 62 */ 63 private PrintDocumentInfo(PrintDocumentInfo prototype) { 64 mPageCount = prototype.mPageCount; 65 mContentType = prototype.mContentType; 66 } 67 68 /** 69 * Creates a new instance. 70 * 71 * @param parcel Data from which to initialize. 72 */ 73 private PrintDocumentInfo(Parcel parcel) { 74 mPageCount = parcel.readInt(); 75 mContentType = parcel.readInt(); 76 } 77 78 /** 79 * Gets the total number of pages. 80 * 81 * @return The number of pages. 82 * 83 * @see #PAGE_COUNT_UNKNOWN 84 */ 85 public int getPageCount() { 86 return mPageCount; 87 } 88 89 /** 90 * Gets the content type. 91 * 92 * @return The content type. 93 * 94 * @see #CONTENT_TYPE_UNKNOWN 95 * @see #CONTENT_TYPE_DOCUMENT 96 * @see #CONTENT_TYPE_PHOTO 97 */ 98 public int getContentType() { 99 return mContentType; 100 } 101 102 @Override 103 public int describeContents() { 104 return 0; 105 } 106 107 @Override 108 public void writeToParcel(Parcel parcel, int flags) { 109 parcel.writeInt(mPageCount); 110 parcel.writeInt(mContentType); 111 } 112 113 /** 114 * Builder for creating an {@link PrintDocumentInfo}. 115 */ 116 public static final class Builder { 117 private final PrintDocumentInfo mPrototype = new PrintDocumentInfo(); 118 119 /** 120 * Sets the total number of pages. 121 * 122 * @param pageCount The number of pages. Must be greater than 123 * or equal to zero or {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}. 124 */ 125 public Builder setPageCount(int pageCount) { 126 if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) { 127 throw new IllegalArgumentException("pageCount" 128 + " must be greater than or euqal to zero or" 129 + " DocumentInfo#PAGE_COUNT_UNKNOWN"); 130 } 131 mPrototype.mPageCount = pageCount; 132 return this; 133 } 134 135 /** 136 * Sets the content type. 137 * 138 * @param type The content type. 139 * 140 * @see #CONTENT_TYPE_UNKNOWN 141 * @see #CONTENT_TYPE_DOCUMENT 142 * @see #CONTENT_TYPE_PHOTO 143 */ 144 public Builder setContentType(int type) { 145 mPrototype.mContentType = type; 146 return this; 147 } 148 149 /** 150 * Creates a new {@link PrintDocumentInfo} instance. 151 * 152 * @return The new instance. 153 */ 154 public PrintDocumentInfo create() { 155 return new PrintDocumentInfo(mPrototype); 156 } 157 } 158 159 public static final Parcelable.Creator<PrintDocumentInfo> CREATOR = 160 new Creator<PrintDocumentInfo>() { 161 @Override 162 public PrintDocumentInfo createFromParcel(Parcel parcel) { 163 return new PrintDocumentInfo(parcel); 164 } 165 166 @Override 167 public PrintDocumentInfo[] newArray(int size) { 168 return new PrintDocumentInfo[size]; 169 } 170 }; 171} 172