PrintDocumentInfo.java revision 7d7888d1c7daa78ee0ad24a24c8dd54b01749259
1a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov/* 2a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Copyright (C) 2013 The Android Open Source Project 3a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 4a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Licensed under the Apache License, Version 2.0 (the "License"); 5a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * you may not use this file except in compliance with the License. 6a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * You may obtain a copy of the License at 7a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 8a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * http://www.apache.org/licenses/LICENSE-2.0 9a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 10a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Unless required by applicable law or agreed to in writing, software 11a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * distributed under the License is distributed on an "AS IS" BASIS, 12a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * See the License for the specific language governing permissions and 14a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * limitations under the License. 15a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 16a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 17a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganovpackage android.print; 18a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 19a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganovimport android.os.Parcel; 20a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganovimport android.os.Parcelable; 21798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganovimport android.text.TextUtils; 22a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 23a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov/** 24a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * This class encapsulates information about a printed document. 25a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 26a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganovpublic final class PrintDocumentInfo implements Parcelable { 27a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 28a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 29aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * Constant for unknown page count.. 30a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 31a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int PAGE_COUNT_UNKNOWN = -1; 32a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 33a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 34aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * Content type: unknown. 35a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 36a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_UNKNOWN = -1; 37a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 38a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 39a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Content type: document. 40a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 41a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_DOCUMENT = 0; 42a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 43a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 44a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Content type: photo. 45a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 46a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_PHOTO = 1; 47a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 48798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private String mName; 49a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private int mPageCount; 50a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private int mContentType; 51d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov private long mDataSize; 52a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 53a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 54a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 55a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 56a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo() { 57aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov /* do nothing */ 58a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 59a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 60a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 61a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 62a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 63a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param Prototype from which to clone. 64a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 65a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo(PrintDocumentInfo prototype) { 66798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mName = prototype.mName; 67a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPageCount = prototype.mPageCount; 68a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mContentType = prototype.mContentType; 69d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = prototype.mDataSize; 70a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 71a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 72a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 73a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 74a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 75a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param parcel Data from which to initialize. 76a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 77a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo(Parcel parcel) { 78798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mName = parcel.readString(); 79a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPageCount = parcel.readInt(); 80a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mContentType = parcel.readInt(); 81d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = parcel.readLong(); 82a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 83a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 84a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 85798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * Gets the document name. 86798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * 87798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * @return The document name. 88798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov */ 89798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov public String getName() { 90798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return mName; 91798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 92798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 93798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov /** 94a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Gets the total number of pages. 95a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 96a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The number of pages. 97a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 98a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #PAGE_COUNT_UNKNOWN 99a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 100a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int getPageCount() { 101a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return mPageCount; 102a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 103a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 104a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 105a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Gets the content type. 106a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 107a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The content type. 108a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 109a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_UNKNOWN 110a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_DOCUMENT 111a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_PHOTO 112a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 113a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int getContentType() { 114a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return mContentType; 115a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 116a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 117aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov /** 118d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * Gets the document data size in bytes. 119d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 120d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @return The data size. 121d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov */ 122d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov public long getDataSize() { 123d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov return mDataSize; 124d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 125d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov 126d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov /** 127d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * Sets the document data size in bytes. 128d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 129d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @param dataSize The data size. 130d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 131d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @hide 132d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov */ 133d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov public void setDataSize(long dataSize) { 134d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = dataSize; 135d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 136d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov 137a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 138a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int describeContents() { 139a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return 0; 140a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 141a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 142a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 143a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public void writeToParcel(Parcel parcel, int flags) { 144798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov parcel.writeString(mName); 145a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov parcel.writeInt(mPageCount); 146a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov parcel.writeInt(mContentType); 147d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov parcel.writeLong(mDataSize); 148a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 149a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 15088d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov @Override 15185b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov public int hashCode() { 15285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov final int prime = 31; 15385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov int result = 1; 154798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov result = prime * result + ((mName != null) ? mName.hashCode() : 0); 15585b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov result = prime * result + mContentType; 15685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov result = prime * result + mPageCount; 157d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov result = prime * result + (int) mDataSize; 158d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov result = prime * result + (int) mDataSize >> 32; 15985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return result; 16085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 16185b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov 16285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov @Override 16385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov public boolean equals(Object obj) { 16485b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (this == obj) { 16585b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return true; 16685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 16785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (obj == null) { 16885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 16985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 17085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (getClass() != obj.getClass()) { 17185b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 17285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 17385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov PrintDocumentInfo other = (PrintDocumentInfo) obj; 174798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov if (!TextUtils.equals(mName, other.mName)) { 175798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return false; 176798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 17785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (mContentType != other.mContentType) { 17885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 17985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 18085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (mPageCount != other.mPageCount) { 18185b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 18285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 183d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov if (mDataSize != other.mDataSize) { 184d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov return false; 185d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 18685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return true; 18785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 18885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov 18985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov @Override 19088d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov public String toString() { 19188d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov StringBuilder builder = new StringBuilder(); 19288d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov builder.append("PrintDocumentInfo{"); 193798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append("name=").append(mName); 194798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append(", pageCount=").append(mPageCount); 195798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append(", contentType=").append(contentTyepToString(mContentType)); 1967d7888d1c7daa78ee0ad24a24c8dd54b01749259Svetoslav Ganov builder.append(", dataSize=").append(mDataSize); 19788d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov builder.append("}"); 19888d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov return builder.toString(); 19988d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov } 20088d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov 201798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private String contentTyepToString(int contentType) { 202798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov switch (contentType) { 203798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov case CONTENT_TYPE_DOCUMENT: { 204798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_DOCUMENT"; 205798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 206798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov case CONTENT_TYPE_PHOTO: { 207798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_PHOTO"; 208798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 209798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov default: { 210798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_UNKNOWN"; 211798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 212798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 213798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 214798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 215a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 216a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Builder for creating an {@link PrintDocumentInfo}. 217a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 218a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final class Builder { 219798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private final PrintDocumentInfo mPrototype; 220798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 221798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov /** 222798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * Constructor. 223aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 224aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * The values of the relevant properties are initialized with default 225aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * values. Please refer to the documentation of the individual setters 226aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * for information about the default values. 227aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 228aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * 229aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * @param name The document name. Cannot be empty. 230aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov */ 231798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov public Builder(String name) { 232798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov if (TextUtils.isEmpty(name)) { 233798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov throw new IllegalArgumentException("name cannot be empty"); 234798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 235798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mPrototype = new PrintDocumentInfo(); 236798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mPrototype.mName = name; 237798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 238a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 239a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 240a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Sets the total number of pages. 241aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 242aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <strong>Default: </strong> {@link #PAGE_COUNT_UNKNOWN} 243aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 244a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 245a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param pageCount The number of pages. Must be greater than 246a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * or equal to zero or {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}. 247a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 248a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public Builder setPageCount(int pageCount) { 249a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) { 250a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov throw new IllegalArgumentException("pageCount" 251a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov + " must be greater than or euqal to zero or" 252a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov + " DocumentInfo#PAGE_COUNT_UNKNOWN"); 253a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 254a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPrototype.mPageCount = pageCount; 255a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return this; 256a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 257a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 258a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 259a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Sets the content type. 260aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 261aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <strong>Default: </strong> {@link #CONTENT_TYPE_UNKNOWN} 262aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 263a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 264a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param type The content type. 265a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 266a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_UNKNOWN 267a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_DOCUMENT 268a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_PHOTO 269a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 270a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public Builder setContentType(int type) { 271a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPrototype.mContentType = type; 272a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return this; 273a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 274a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 275a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 276a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new {@link PrintDocumentInfo} instance. 277a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 278a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The new instance. 279a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 280651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav public PrintDocumentInfo build() { 281a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo(mPrototype); 282a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 283a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 284a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 285a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final Parcelable.Creator<PrintDocumentInfo> CREATOR = 286a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov new Creator<PrintDocumentInfo>() { 287a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 288a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public PrintDocumentInfo createFromParcel(Parcel parcel) { 289a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo(parcel); 290a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 291a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 292a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 293a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public PrintDocumentInfo[] newArray(int size) { 294a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo[size]; 295a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 296a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov }; 297a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov} 298