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/** 244d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * This class encapsulates information about a document for printing 254d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * purposes. This meta-data is used by the platform and print services, 264d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * components that interact with printers. For example, this class 274d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * contains the number of pages contained in the document it describes and 284d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * this number of pages is shown to the user allowing him/her to select 294d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * the range to print. Also a print service may optimize the printing 304d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * process based on the content type, such as document or photo. 314d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * <p> 324d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Instances of this class are created by the printing application and 334d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * passed to the {@link PrintDocumentAdapter.LayoutResultCallback#onLayoutFinished( 344d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintDocumentInfo, boolean) PrintDocumentAdapter.LayoutResultCallback.onLayoutFinished( 354d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintDocumentInfo, boolean)} callback after successfully laying out the 364d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * content which is performed in {@link PrintDocumentAdapter#onLayout(PrintAttributes, 374d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback, 384d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * android.os.Bundle) PrintDocumentAdapter.onLayout(PrintAttributes, 394d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintAttributes, android.os.CancellationSignal, 404d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle)}. 414d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * </p> 424d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * <p> 434d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * An example usage looks like this: 444d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * <pre> 454d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 464d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * . . . 474d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 484d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, 494d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * CancellationSignal cancellationSignal, LayoutResultCallback callback, 504d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Bundle metadata) { 514d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 524d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * // Assume the app defined a LayoutResult class which contains 534d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * // the layout result data and that the content is a document. 544d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * LayoutResult result = doSomeLayoutWork(); 554d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 564d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * PrintDocumentInfo info = new PrintDocumentInfo 574d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * .Builder("printed_file.pdf") 584d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT) 594d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * .setPageCount(result.getPageCount()) 604d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * .build(); 614d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 624d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * callback.onLayoutFinished(info, result.getContentChanged()); 634d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * } 644d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 654d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * . . . 664d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 674d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * </pre> 684d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * </p> 69a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 70a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganovpublic final class PrintDocumentInfo implements Parcelable { 71a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 72a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 734d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Constant for unknown page count. 74a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 75a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int PAGE_COUNT_UNKNOWN = -1; 76a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 77a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 78aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * Content type: unknown. 79a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 80a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_UNKNOWN = -1; 81a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 82a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 83a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Content type: document. 844d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * <p> 854d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * A print service may use normal paper to print the content instead 864d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * of dedicated photo paper. Also it may use a lower quality printing 874d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * process as the content is not as sensitive to print quality variation 884d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * as a photo is. 894d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * </p> 90a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 91a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_DOCUMENT = 0; 92a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 93a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 94a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Content type: photo. 954d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * <p> 964d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * A print service may use dedicated photo paper to print the content 974d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * instead of normal paper. Also it may use a higher quality printing 984d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * process as the content is more sensitive to print quality variation 994d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * than a document. 1004d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * </p> 101a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 102a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final int CONTENT_TYPE_PHOTO = 1; 103a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 104798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private String mName; 105a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private int mPageCount; 106a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private int mContentType; 107d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov private long mDataSize; 108a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 109a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 110a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 111a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 112a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo() { 113aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov /* do nothing */ 114a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 115a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 116a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 117a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 118a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 119a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param Prototype from which to clone. 120a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 121a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo(PrintDocumentInfo prototype) { 122798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mName = prototype.mName; 123a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPageCount = prototype.mPageCount; 124a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mContentType = prototype.mContentType; 125d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = prototype.mDataSize; 126a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 127a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 128a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 129a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new instance. 130a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 131a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param parcel Data from which to initialize. 132a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 133a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov private PrintDocumentInfo(Parcel parcel) { 134798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mName = parcel.readString(); 135a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPageCount = parcel.readInt(); 136a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mContentType = parcel.readInt(); 137d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = parcel.readLong(); 138a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 139a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 140a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 1414d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Gets the document name. This name may be shown to 1424d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * the user. 143798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * 144798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * @return The document name. 145798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov */ 146798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov public String getName() { 147798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return mName; 148798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 149798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 150798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov /** 151a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Gets the total number of pages. 152a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 153a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The number of pages. 154a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 155a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #PAGE_COUNT_UNKNOWN 156a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 157a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int getPageCount() { 158a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return mPageCount; 159a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 160a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 161a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 162a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Gets the content type. 163a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 164a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The content type. 165a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 166a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_UNKNOWN 167a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_DOCUMENT 168a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_PHOTO 169a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 170a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int getContentType() { 171a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return mContentType; 172a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 173a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 174aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov /** 175d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * Gets the document data size in bytes. 176d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 177d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @return The data size. 178d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov */ 179d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov public long getDataSize() { 180d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov return mDataSize; 181d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 182d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov 183d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov /** 184d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * Sets the document data size in bytes. 185d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 186d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @param dataSize The data size. 187d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * 188d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov * @hide 189d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov */ 190d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov public void setDataSize(long dataSize) { 191d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov mDataSize = dataSize; 192d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 193d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov 194a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 195a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public int describeContents() { 196a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return 0; 197a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 198a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 199a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 200a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public void writeToParcel(Parcel parcel, int flags) { 201798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov parcel.writeString(mName); 202a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov parcel.writeInt(mPageCount); 203a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov parcel.writeInt(mContentType); 204d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov parcel.writeLong(mDataSize); 205a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 206a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 20788d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov @Override 20885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov public int hashCode() { 20985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov final int prime = 31; 21085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov int result = 1; 211798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov result = prime * result + ((mName != null) ? mName.hashCode() : 0); 21285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov result = prime * result + mContentType; 21385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov result = prime * result + mPageCount; 214d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov result = prime * result + (int) mDataSize; 215869d26fda0d612c15eac64f7d7bc6d7a28073498Andreas Gampe result = prime * result + (int) (mDataSize >> 32); 21685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return result; 21785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 21885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov 21985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov @Override 22085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov public boolean equals(Object obj) { 22185b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (this == obj) { 22285b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return true; 22385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 22485b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (obj == null) { 22585b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 22685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 22785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (getClass() != obj.getClass()) { 22885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 22985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 23085b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov PrintDocumentInfo other = (PrintDocumentInfo) obj; 231798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov if (!TextUtils.equals(mName, other.mName)) { 232798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return false; 233798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 23485b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (mContentType != other.mContentType) { 23585b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 23685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 23785b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov if (mPageCount != other.mPageCount) { 23885b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return false; 23985b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 240d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov if (mDataSize != other.mDataSize) { 241d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov return false; 242d26d4898fcc9b78f4b66118895c375384098205eSvetoslav Ganov } 24385b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov return true; 24485b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov } 24585b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov 24685b1f883056a1d74473fd9ce774948878f389ab6Svetoslav Ganov @Override 24788d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov public String toString() { 24888d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov StringBuilder builder = new StringBuilder(); 24988d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov builder.append("PrintDocumentInfo{"); 250798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append("name=").append(mName); 251798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append(", pageCount=").append(mPageCount); 252798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov builder.append(", contentType=").append(contentTyepToString(mContentType)); 2537d7888d1c7daa78ee0ad24a24c8dd54b01749259Svetoslav Ganov builder.append(", dataSize=").append(mDataSize); 25488d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov builder.append("}"); 25588d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov return builder.toString(); 25688d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov } 25788d199130d44c6bacb383a7757e782cf97483c68Svetoslav Ganov 258798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private String contentTyepToString(int contentType) { 259798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov switch (contentType) { 260798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov case CONTENT_TYPE_DOCUMENT: { 261798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_DOCUMENT"; 262798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 263798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov case CONTENT_TYPE_PHOTO: { 264798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_PHOTO"; 265798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 266798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov default: { 267798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov return "CONTENT_TYPE_UNKNOWN"; 268798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 269798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 270798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 271798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 272a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 2734d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Builder for creating a {@link PrintDocumentInfo}. 274a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 275a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final class Builder { 276798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov private final PrintDocumentInfo mPrototype; 277798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov 278798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov /** 279798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov * Constructor. 2804d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * 281aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 2824d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * The values of the relevant properties are initialized with defaults. 2834d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Please refer to the documentation of the individual setters for 2844d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * information about the default values. 285aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 286aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * 2874d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * @param name The document name which may be shown to the user and 2884d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * is the file name if the content it describes is saved as a PDF. 2894d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * Cannot be empty. 290aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov */ 291798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov public Builder(String name) { 292798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov if (TextUtils.isEmpty(name)) { 293798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov throw new IllegalArgumentException("name cannot be empty"); 294798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 295798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mPrototype = new PrintDocumentInfo(); 296798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov mPrototype.mName = name; 297798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov } 298a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 299a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 300a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Sets the total number of pages. 301aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 302aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <strong>Default: </strong> {@link #PAGE_COUNT_UNKNOWN} 303aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 304a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 305a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param pageCount The number of pages. Must be greater than 306a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * or equal to zero or {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}. 307a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 308a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public Builder setPageCount(int pageCount) { 309a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) { 310a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov throw new IllegalArgumentException("pageCount" 3110c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav + " must be greater than or equal to zero or" 312a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov + " DocumentInfo#PAGE_COUNT_UNKNOWN"); 313a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 314a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPrototype.mPageCount = pageCount; 315a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return this; 316a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 317a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 318a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 319a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Sets the content type. 320aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <p> 321aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * <strong>Default: </strong> {@link #CONTENT_TYPE_UNKNOWN} 322aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov * </p> 323a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 324a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @param type The content type. 325a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 326a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_UNKNOWN 327a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_DOCUMENT 328a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @see #CONTENT_TYPE_PHOTO 329a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 330a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public Builder setContentType(int type) { 331a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov mPrototype.mContentType = type; 332a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return this; 333a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 334a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 335a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov /** 336a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * Creates a new {@link PrintDocumentInfo} instance. 337a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * 338a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov * @return The new instance. 339a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov */ 340651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav public PrintDocumentInfo build() { 3410c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav // Zero pages is the same as unknown as in this case 3420c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav // we will have to ask for all pages and look a the 3430c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav // wiritten PDF file for the page count. 3440c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav if (mPrototype.mPageCount == 0) { 3450c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav mPrototype.mPageCount = PAGE_COUNT_UNKNOWN; 3460c126a478b4b1891b275fe424c9f7e37adcdb758Svetoslav } 347a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo(mPrototype); 348a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 349a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 350a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 351a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public static final Parcelable.Creator<PrintDocumentInfo> CREATOR = 352a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov new Creator<PrintDocumentInfo>() { 353a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 354a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public PrintDocumentInfo createFromParcel(Parcel parcel) { 355a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo(parcel); 356a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 357a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov 358a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov @Override 359a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov public PrintDocumentInfo[] newArray(int size) { 360a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov return new PrintDocumentInfo[size]; 361a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov } 362a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov }; 363a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov} 364