14b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov/*
24b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * Copyright (C) 2013 The Android Open Source Project
34b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov *
44b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * Licensed under the Apache License, Version 2.0 (the "License");
54b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * you may not use this file except in compliance with the License.
64b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * You may obtain a copy of the License at
74b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov *
84b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov *      http://www.apache.org/licenses/LICENSE-2.0
94b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov *
104b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * Unless required by applicable law or agreed to in writing, software
114b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * distributed under the License is distributed on an "AS IS" BASIS,
124b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * See the License for the specific language governing permissions and
144b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov * limitations under the License.
154b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov */
164b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
174b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganovpackage android.print;
184b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
194b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganovimport android.os.Parcel;
204b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganovimport android.os.Parcelable;
21798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganovimport android.text.TextUtils;
224b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
234b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov/**
244d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * This class represents the description of a printer. Instances of
254d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * this class are created by print services to report to the system
264d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * the printers they manage. The information of this class has two
274d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * major components, printer properties such as name, id, status,
284d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * description and printer capabilities which describe the various
294d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov * print modes a printer supports such as media sizes, margins, etc.
304b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov */
314b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganovpublic final class PrinterInfo implements Parcelable {
324b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
33aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    /** Printer status: the printer is idle and ready to print. */
34aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    public static final int STATUS_IDLE = 1;
354b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
36aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    /** Printer status: the printer is busy printing. */
37aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    public static final int STATUS_BUSY = 2;
38aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov
39aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    /** Printer status: the printer is not available. */
40aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov    public static final int STATUS_UNAVAILABLE = 3;
414b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
424b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    private PrinterId mId;
434b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
44798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    private String mName;
454b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
46798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    private int mStatus;
474b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
48798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    private String mDescription;
494b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
50798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    private PrinterCapabilitiesInfo mCapabilities;
51798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov
52798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    private PrinterInfo() {
53798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        /* do nothing */
544b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
554b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
56a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov    private PrinterInfo(PrinterInfo prototype) {
5755b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        copyFrom(prototype);
5855b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    }
5955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov
6055b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    /**
6155b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov     * @hide
6255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov     */
6355b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    public void copyFrom(PrinterInfo other) {
64651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav        if (this == other) {
65651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav            return;
66651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav        }
6755b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        mId = other.mId;
68798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        mName = other.mName;
6955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        mStatus = other.mStatus;
70798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        mDescription = other.mDescription;
71798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        if (other.mCapabilities != null) {
72798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            if (mCapabilities != null) {
73798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov                mCapabilities.copyFrom(other.mCapabilities);
7455b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            } else {
75798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov                mCapabilities = new PrinterCapabilitiesInfo(other.mCapabilities);
7655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            }
7755b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        } else {
78798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            mCapabilities = null;
7955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
80a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov    }
81a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov
824b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    /**
834b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     * Get the globally unique printer id.
844b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     *
854b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     * @return The printer id.
864b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     */
874b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public PrinterId getId() {
884b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        return mId;
894b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
904b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
914b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    /**
92798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * Get the printer name.
934b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     *
94798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * @return The printer name.
954b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     */
96798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    public String getName() {
97798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        return mName;
984b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
994b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
1004b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    /**
101798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * Gets the printer status.
1024b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     *
103798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * @return The status.
1044d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov     *
1054d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov     * @see #STATUS_BUSY
1064d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov     * @see #STATUS_IDLE
1074d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov     * @see #STATUS_UNAVAILABLE
1084b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     */
109798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    public int getStatus() {
110798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        return mStatus;
1114b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
1124b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
1134b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    /**
114798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * Gets the  printer description.
1154b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     *
116798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * @return The description.
1174b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     */
118798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    public String getDescription() {
119798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        return mDescription;
1204b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
1214b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
12255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    /**
123798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * Gets the printer capabilities.
12455b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov     *
125798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * @return The capabilities.
12655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov     */
127798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov    public PrinterCapabilitiesInfo getCapabilities() {
128798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        return mCapabilities;
12955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    }
13055b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov
1314b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    private PrinterInfo(Parcel parcel) {
1324b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        mId = parcel.readParcelable(null);
133798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        mName = parcel.readString();
1344b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        mStatus = parcel.readInt();
135798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        mDescription = parcel.readString();
136798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        mCapabilities = parcel.readParcelable(null);
1374b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
1384b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
1394b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    @Override
1404b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public int describeContents() {
1414b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        return 0;
1424b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
1434b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
1444b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    @Override
1454b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public void writeToParcel(Parcel parcel, int flags) {
1464b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        parcel.writeParcelable(mId, flags);
147798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        parcel.writeString(mName);
1484b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        parcel.writeInt(mStatus);
149798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        parcel.writeString(mDescription);
150798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        parcel.writeParcelable(mCapabilities, flags);
1514b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
1524b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
1534b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    @Override
15455b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    public int hashCode() {
15555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        final int prime = 31;
15655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        int result = 1;
157798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        result = prime * result + ((mId != null) ? mId.hashCode() : 0);
158798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        result = prime * result + ((mName != null) ? mName.hashCode() : 0);
15955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        result = prime * result + mStatus;
160798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        result = prime * result + ((mDescription != null) ? mDescription.hashCode() : 0);
161798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        result = prime * result + ((mCapabilities != null) ? mCapabilities.hashCode() : 0);
16255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        return result;
16355b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    }
16455b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov
16555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    @Override
16655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    public boolean equals(Object obj) {
16755b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        if (this == obj) {
16855b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return true;
16955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
17055b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        if (obj == null) {
17155b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
17255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
17355b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        if (getClass() != obj.getClass()) {
17455b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
17555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
17655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        PrinterInfo other = (PrinterInfo) obj;
17755b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        if (mId == null) {
17855b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            if (other.mId != null) {
17955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov                return false;
18055b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            }
18155b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        } else if (!mId.equals(other.mId)) {
18255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
18355b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
184798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        if (!TextUtils.equals(mName, other.mName)) {
18555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
18655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
187798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        if (mStatus != other.mStatus) {
18855b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
18955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
190798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        if (!TextUtils.equals(mDescription, other.mDescription)) {
19155b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
19255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
193798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        if (mCapabilities == null) {
194798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            if (other.mCapabilities != null) {
19555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov                return false;
19655b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            }
197798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        } else if (!mCapabilities.equals(other.mCapabilities)) {
19855b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov            return false;
19955b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        }
20055b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov        return true;
20155b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    }
20255b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov
20355b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov    @Override
2044b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public String toString() {
2054b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        StringBuilder builder = new StringBuilder();
2064b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        builder.append("PrinterInfo{");
207798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        builder.append("id=").append(mId);
208798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        builder.append(", name=").append(mName);
209798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        builder.append(", status=").append(mStatus);
210798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        builder.append(", description=").append(mDescription);
211798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        builder.append(", capabilities=").append(mCapabilities);
2124b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        builder.append("\"}");
2134b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        return builder.toString();
2144b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
2154b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2164b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    /**
217798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov     * Builder for creating of a {@link PrinterInfo}.
2184b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov     */
2194b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public static final class Builder {
220a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov        private final PrinterInfo mPrototype;
2214b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2224b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
223798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * Constructor.
2244b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
22555b409a97cf6376399a0940313ea852368727d6fSvetoslav Ganov         * @param printerId The printer id. Cannot be null.
226798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * @param name The printer name. Cannot be empty.
227798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * @param status The printer status. Must be a valid status.
2284d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * @throws IllegalArgumentException If the printer id is null, or the
2294d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * printer name is empty or the status is not a valid one.
2304b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
231798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        public Builder(PrinterId printerId, String name, int status) {
2324b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            if (printerId == null) {
2334b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov                throw new IllegalArgumentException("printerId cannot be null.");
2344b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            }
235798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            if (TextUtils.isEmpty(name)) {
236798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov                throw new IllegalArgumentException("name cannot be empty.");
237798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            }
238798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            if (!isValidStatus(status)) {
239798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov                throw new IllegalArgumentException("status is invalid.");
240798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            }
241a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov            mPrototype = new PrinterInfo();
242a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov            mPrototype.mId = printerId;
243798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            mPrototype.mName = name;
244a00271533f639c8ed36429c663889ac9f654bc72Svetoslav Ganov            mPrototype.mStatus = status;
2454b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
2464b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2474b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
248798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * Constructor.
2494b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
250269403b032f965ff3847eb982c2f697229dc5a92Svetoslav         * @param other Other info from which to start building.
2514b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
252269403b032f965ff3847eb982c2f697229dc5a92Svetoslav        public Builder(PrinterInfo other) {
253269403b032f965ff3847eb982c2f697229dc5a92Svetoslav            mPrototype = new PrinterInfo();
254269403b032f965ff3847eb982c2f697229dc5a92Svetoslav            mPrototype.copyFrom(other);
2554b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
2564b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2574b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
258aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * Sets the printer status.
259aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         *
260aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * @param status The status.
261aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * @return This builder.
262aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         *
263aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * @see PrinterInfo#STATUS_IDLE
264aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * @see PrinterInfo#STATUS_BUSY
265aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         * @see PrinterInfo#STATUS_UNAVAILABLE
266aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov         */
267aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov        public Builder setStatus(int status) {
268aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov            mPrototype.mStatus = status;
269aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov            return this;
270aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov        }
271aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov
272aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov        /**
2734d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * Sets the <strong>localized</strong> printer name which
2744d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * is shown to the user
2754b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
276798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * @param name The name.
2774b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         * @return This builder.
2784b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
279798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        public Builder setName(String name) {
280798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            mPrototype.mName = name;
2814b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            return this;
2824b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
2834b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2844b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
2854d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * Sets the <strong>localized</strong> printer description
2864d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * which is shown to the user
2874b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
288798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * @param description The description.
2894b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         * @return This builder.
2904b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
291798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        public Builder setDescription(String description) {
292798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            mPrototype.mDescription = description;
2934b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            return this;
2944b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
2954b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
2964b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
297798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * Sets the printer capabilities.
2984b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
299798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov         * @param capabilities The capabilities.
3004b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         * @return This builder.
3014b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
302798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        public Builder setCapabilities(PrinterCapabilitiesInfo capabilities) {
303798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov            mPrototype.mCapabilities = capabilities;
3044b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            return this;
3054b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
3064b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
3074b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        /**
3084d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov         * Creates a new {@link PrinterInfo}.
3094b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         *
3104b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         * @return A new {@link PrinterInfo}.
3114b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov         */
312651dd4e6ee6510caf9f15c51094a11121af17ec2Svetoslav        public PrinterInfo build() {
3134d4c66dd38e940082e385b49a33f4022ab04c738Svetoslav Ganov            return mPrototype;
3144b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
3154b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
316798bed6cc7d273e72b0253288605db9cd2b57740Svetoslav Ganov        private boolean isValidStatus(int status) {
317aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov            return (status == STATUS_IDLE
318704697b6197262678e930daa831a1916ddee4dcfSvetoslav Ganov                    || status == STATUS_BUSY
319aec1417ca9eb63209668ac17da90cf8a07c6076cSvetoslav Ganov                    || status == STATUS_UNAVAILABLE);
3204b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
3214b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    }
3224b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
3234b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    public static final Parcelable.Creator<PrinterInfo> CREATOR =
3244b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            new Parcelable.Creator<PrinterInfo>() {
3254b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        @Override
3264b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        public PrinterInfo createFromParcel(Parcel parcel) {
3274b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            return new PrinterInfo(parcel);
3284b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
3294b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov
3304b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        @Override
3314b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        public PrinterInfo[] newArray(int size) {
3324b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov            return new PrinterInfo[size];
3334b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov        }
3344b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov    };
3354b9a4d16872bbb50712e007b419ac0b35ff1582dSvetoslav Ganov}
336