Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 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 | |
| 17 | package android.print; |
| 18 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.IntRange; |
| 21 | import android.annotation.NonNull; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 24 | import android.text.TextUtils; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 25 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.RetentionPolicy; |
| 28 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 29 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 30 | * This class encapsulates information about a document for printing |
| 31 | * purposes. This meta-data is used by the platform and print services, |
| 32 | * components that interact with printers. For example, this class |
| 33 | * contains the number of pages contained in the document it describes and |
| 34 | * this number of pages is shown to the user allowing him/her to select |
| 35 | * the range to print. Also a print service may optimize the printing |
| 36 | * process based on the content type, such as document or photo. |
| 37 | * <p> |
| 38 | * Instances of this class are created by the printing application and |
| 39 | * passed to the {@link PrintDocumentAdapter.LayoutResultCallback#onLayoutFinished( |
| 40 | * PrintDocumentInfo, boolean) PrintDocumentAdapter.LayoutResultCallback.onLayoutFinished( |
| 41 | * PrintDocumentInfo, boolean)} callback after successfully laying out the |
| 42 | * content which is performed in {@link PrintDocumentAdapter#onLayout(PrintAttributes, |
| 43 | * PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback, |
| 44 | * android.os.Bundle) PrintDocumentAdapter.onLayout(PrintAttributes, |
| 45 | * PrintAttributes, android.os.CancellationSignal, |
| 46 | * PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle)}. |
| 47 | * </p> |
| 48 | * <p> |
| 49 | * An example usage looks like this: |
| 50 | * <pre> |
| 51 | * |
| 52 | * . . . |
| 53 | * |
| 54 | * public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, |
| 55 | * CancellationSignal cancellationSignal, LayoutResultCallback callback, |
| 56 | * Bundle metadata) { |
| 57 | * |
| 58 | * // Assume the app defined a LayoutResult class which contains |
| 59 | * // the layout result data and that the content is a document. |
| 60 | * LayoutResult result = doSomeLayoutWork(); |
| 61 | * |
| 62 | * PrintDocumentInfo info = new PrintDocumentInfo |
| 63 | * .Builder("printed_file.pdf") |
| 64 | * .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT) |
| 65 | * .setPageCount(result.getPageCount()) |
| 66 | * .build(); |
| 67 | * |
| 68 | * callback.onLayoutFinished(info, result.getContentChanged()); |
| 69 | * } |
| 70 | * |
| 71 | * . . . |
| 72 | * |
| 73 | * </pre> |
| 74 | * </p> |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 75 | */ |
| 76 | public final class PrintDocumentInfo implements Parcelable { |
| 77 | |
| 78 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 79 | * Constant for unknown page count. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 80 | */ |
| 81 | public static final int PAGE_COUNT_UNKNOWN = -1; |
| 82 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 83 | /** @hide */ |
| 84 | @Retention(RetentionPolicy.SOURCE) |
| 85 | @IntDef({ |
| 86 | CONTENT_TYPE_UNKNOWN, CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_PHOTO |
| 87 | }) |
| 88 | public @interface ContentType { |
| 89 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 90 | /** |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 91 | * Content type: unknown. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 92 | */ |
| 93 | public static final int CONTENT_TYPE_UNKNOWN = -1; |
| 94 | |
| 95 | /** |
| 96 | * Content type: document. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 97 | * <p> |
| 98 | * A print service may use normal paper to print the content instead |
| 99 | * of dedicated photo paper. Also it may use a lower quality printing |
| 100 | * process as the content is not as sensitive to print quality variation |
| 101 | * as a photo is. |
| 102 | * </p> |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 103 | */ |
| 104 | public static final int CONTENT_TYPE_DOCUMENT = 0; |
| 105 | |
| 106 | /** |
| 107 | * Content type: photo. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 108 | * <p> |
| 109 | * A print service may use dedicated photo paper to print the content |
| 110 | * instead of normal paper. Also it may use a higher quality printing |
| 111 | * process as the content is more sensitive to print quality variation |
| 112 | * than a document. |
| 113 | * </p> |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 114 | */ |
| 115 | public static final int CONTENT_TYPE_PHOTO = 1; |
| 116 | |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 117 | private String mName; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 118 | private int mPageCount; |
| 119 | private int mContentType; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 120 | private long mDataSize; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Creates a new instance. |
| 124 | */ |
| 125 | private PrintDocumentInfo() { |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 126 | /* do nothing */ |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Creates a new instance. |
| 131 | * |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 132 | * @param prototype from which to clone. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 133 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 134 | private PrintDocumentInfo(@NonNull PrintDocumentInfo prototype) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 135 | mName = prototype.mName; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 136 | mPageCount = prototype.mPageCount; |
| 137 | mContentType = prototype.mContentType; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 138 | mDataSize = prototype.mDataSize; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Creates a new instance. |
| 143 | * |
| 144 | * @param parcel Data from which to initialize. |
| 145 | */ |
| 146 | private PrintDocumentInfo(Parcel parcel) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 147 | mName = parcel.readString(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 148 | mPageCount = parcel.readInt(); |
| 149 | mContentType = parcel.readInt(); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 150 | mDataSize = parcel.readLong(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 154 | * Gets the document name. This name may be shown to |
| 155 | * the user. |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 156 | * |
| 157 | * @return The document name. |
| 158 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 159 | public @NonNull String getName() { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 160 | return mName; |
| 161 | } |
| 162 | |
| 163 | /** |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 164 | * Gets the total number of pages. |
| 165 | * |
| 166 | * @return The number of pages. |
| 167 | * |
| 168 | * @see #PAGE_COUNT_UNKNOWN |
| 169 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 170 | public @IntRange(from = -1) int getPageCount() { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 171 | return mPageCount; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Gets the content type. |
| 176 | * |
| 177 | * @return The content type. |
| 178 | * |
| 179 | * @see #CONTENT_TYPE_UNKNOWN |
| 180 | * @see #CONTENT_TYPE_DOCUMENT |
| 181 | * @see #CONTENT_TYPE_PHOTO |
| 182 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 183 | public @ContentType int getContentType() { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 184 | return mContentType; |
| 185 | } |
| 186 | |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 187 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 188 | * Gets the document data size in bytes. |
| 189 | * |
| 190 | * @return The data size. |
| 191 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 192 | public @IntRange(from = 0) long getDataSize() { |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 193 | return mDataSize; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Sets the document data size in bytes. |
| 198 | * |
| 199 | * @param dataSize The data size. |
| 200 | * |
| 201 | * @hide |
| 202 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 203 | public void setDataSize(@IntRange(from = 0) long dataSize) { |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 204 | mDataSize = dataSize; |
| 205 | } |
| 206 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public int describeContents() { |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void writeToParcel(Parcel parcel, int flags) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 214 | parcel.writeString(mName); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 215 | parcel.writeInt(mPageCount); |
| 216 | parcel.writeInt(mContentType); |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 217 | parcel.writeLong(mDataSize); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 220 | @Override |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 221 | public int hashCode() { |
| 222 | final int prime = 31; |
| 223 | int result = 1; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 224 | result = prime * result + ((mName != null) ? mName.hashCode() : 0); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 225 | result = prime * result + mContentType; |
| 226 | result = prime * result + mPageCount; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 227 | result = prime * result + (int) mDataSize; |
Andreas Gampe | 869d26f | 2015-03-15 13:59:50 -0700 | [diff] [blame] | 228 | result = prime * result + (int) (mDataSize >> 32); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 229 | return result; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public boolean equals(Object obj) { |
| 234 | if (this == obj) { |
| 235 | return true; |
| 236 | } |
| 237 | if (obj == null) { |
| 238 | return false; |
| 239 | } |
| 240 | if (getClass() != obj.getClass()) { |
| 241 | return false; |
| 242 | } |
| 243 | PrintDocumentInfo other = (PrintDocumentInfo) obj; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 244 | if (!TextUtils.equals(mName, other.mName)) { |
| 245 | return false; |
| 246 | } |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 247 | if (mContentType != other.mContentType) { |
| 248 | return false; |
| 249 | } |
| 250 | if (mPageCount != other.mPageCount) { |
| 251 | return false; |
| 252 | } |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 253 | if (mDataSize != other.mDataSize) { |
| 254 | return false; |
| 255 | } |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 256 | return true; |
| 257 | } |
| 258 | |
| 259 | @Override |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 260 | public String toString() { |
| 261 | StringBuilder builder = new StringBuilder(); |
| 262 | builder.append("PrintDocumentInfo{"); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 263 | builder.append("name=").append(mName); |
| 264 | builder.append(", pageCount=").append(mPageCount); |
| 265 | builder.append(", contentType=").append(contentTyepToString(mContentType)); |
Svetoslav Ganov | 7d7888d | 2013-10-12 13:18:12 -0700 | [diff] [blame] | 266 | builder.append(", dataSize=").append(mDataSize); |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 267 | builder.append("}"); |
| 268 | return builder.toString(); |
| 269 | } |
| 270 | |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 271 | private String contentTyepToString(int contentType) { |
| 272 | switch (contentType) { |
| 273 | case CONTENT_TYPE_DOCUMENT: { |
| 274 | return "CONTENT_TYPE_DOCUMENT"; |
| 275 | } |
| 276 | case CONTENT_TYPE_PHOTO: { |
| 277 | return "CONTENT_TYPE_PHOTO"; |
| 278 | } |
| 279 | default: { |
| 280 | return "CONTENT_TYPE_UNKNOWN"; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 285 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 286 | * Builder for creating a {@link PrintDocumentInfo}. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 287 | */ |
| 288 | public static final class Builder { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 289 | private final PrintDocumentInfo mPrototype; |
| 290 | |
| 291 | /** |
| 292 | * Constructor. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 293 | * |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 294 | * <p> |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 295 | * The values of the relevant properties are initialized with defaults. |
| 296 | * Please refer to the documentation of the individual setters for |
| 297 | * information about the default values. |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 298 | * </p> |
| 299 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 300 | * @param name The document name which may be shown to the user and |
| 301 | * is the file name if the content it describes is saved as a PDF. |
| 302 | * Cannot be empty. |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 303 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 304 | public Builder(@NonNull String name) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 305 | if (TextUtils.isEmpty(name)) { |
| 306 | throw new IllegalArgumentException("name cannot be empty"); |
| 307 | } |
| 308 | mPrototype = new PrintDocumentInfo(); |
| 309 | mPrototype.mName = name; |
| 310 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 311 | |
| 312 | /** |
| 313 | * Sets the total number of pages. |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 314 | * <p> |
| 315 | * <strong>Default: </strong> {@link #PAGE_COUNT_UNKNOWN} |
| 316 | * </p> |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 317 | * |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 318 | * @param pageCount The number of pages. Must be greater than or equal to zero or |
| 319 | * {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}. |
| 320 | * @return This builder. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 321 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 322 | public @NonNull Builder setPageCount(@IntRange(from = -1) int pageCount) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 323 | if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) { |
| 324 | throw new IllegalArgumentException("pageCount" |
Svetoslav | 0c126a4 | 2014-07-10 17:36:27 -0700 | [diff] [blame] | 325 | + " must be greater than or equal to zero or" |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 326 | + " DocumentInfo#PAGE_COUNT_UNKNOWN"); |
| 327 | } |
| 328 | mPrototype.mPageCount = pageCount; |
| 329 | return this; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Sets the content type. |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 334 | * <p> |
| 335 | * <strong>Default: </strong> {@link #CONTENT_TYPE_UNKNOWN} |
| 336 | * </p> |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 337 | * |
| 338 | * @param type The content type. |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 339 | * @return This builder. |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 340 | * @see #CONTENT_TYPE_UNKNOWN |
| 341 | * @see #CONTENT_TYPE_DOCUMENT |
| 342 | * @see #CONTENT_TYPE_PHOTO |
| 343 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 344 | public @NonNull Builder setContentType(@ContentType int type) { |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 345 | mPrototype.mContentType = type; |
| 346 | return this; |
| 347 | } |
| 348 | |
| 349 | /** |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 350 | * Creates a new {@link PrintDocumentInfo} instance. |
| 351 | * |
| 352 | * @return The new instance. |
| 353 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 354 | public @NonNull PrintDocumentInfo build() { |
Svetoslav | 0c126a4 | 2014-07-10 17:36:27 -0700 | [diff] [blame] | 355 | // Zero pages is the same as unknown as in this case |
| 356 | // we will have to ask for all pages and look a the |
| 357 | // wiritten PDF file for the page count. |
| 358 | if (mPrototype.mPageCount == 0) { |
| 359 | mPrototype.mPageCount = PAGE_COUNT_UNKNOWN; |
| 360 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 361 | return new PrintDocumentInfo(mPrototype); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | public static final Parcelable.Creator<PrintDocumentInfo> CREATOR = |
| 366 | new Creator<PrintDocumentInfo>() { |
| 367 | @Override |
| 368 | public PrintDocumentInfo createFromParcel(Parcel parcel) { |
| 369 | return new PrintDocumentInfo(parcel); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public PrintDocumentInfo[] newArray(int size) { |
| 374 | return new PrintDocumentInfo[size]; |
| 375 | } |
| 376 | }; |
| 377 | } |