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