Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -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 | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 19 | import android.annotation.FloatRange; |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 20 | import android.annotation.IntDef; |
| 21 | import android.annotation.IntRange; |
| 22 | import android.annotation.NonNull; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 24 | import android.annotation.StringRes; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.res.Resources; |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 29 | import android.os.Parcel; |
| 30 | import android.os.Parcelable; |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 31 | import android.service.print.PrintJobInfoProto; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 32 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 33 | import com.android.internal.util.Preconditions; |
| 34 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 35 | import java.lang.annotation.Retention; |
| 36 | import java.lang.annotation.RetentionPolicy; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 37 | import java.util.Arrays; |
| 38 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 39 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 40 | * This class represents the description of a print job. The print job |
| 41 | * state includes properties such as its id, print attributes used for |
| 42 | * generating the content, and so on. Note that the print jobs state may |
| 43 | * change over time and this class represents a snapshot of this state. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 44 | */ |
| 45 | public final class PrintJobInfo implements Parcelable { |
| 46 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 47 | /** @hide */ |
| 48 | @IntDef({ |
| 49 | STATE_CREATED, STATE_QUEUED, STATE_STARTED, STATE_BLOCKED, STATE_COMPLETED, |
| 50 | STATE_FAILED, STATE_CANCELED |
| 51 | }) |
| 52 | @Retention(RetentionPolicy.SOURCE) |
| 53 | public @interface State { |
| 54 | } |
| 55 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Constant for matching any print job state. |
| 58 | * |
| 59 | * @hide |
| 60 | */ |
| 61 | public static final int STATE_ANY = -1; |
| 62 | |
| 63 | /** |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 64 | * Constant for matching any print job state. |
| 65 | * |
| 66 | * @hide |
| 67 | */ |
| 68 | public static final int STATE_ANY_VISIBLE_TO_CLIENTS = -2; |
| 69 | |
| 70 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 71 | * Constant for matching any active print job state. |
| 72 | * |
| 73 | * @hide |
| 74 | */ |
| 75 | public static final int STATE_ANY_ACTIVE = -3; |
| 76 | |
| 77 | /** |
Svetoslav Ganov | 9b6d3a1 | 2013-10-12 12:35:41 -0700 | [diff] [blame] | 78 | * Constant for matching any scheduled, i.e. delivered to a print |
| 79 | * service, print job state. |
| 80 | * |
| 81 | * @hide |
| 82 | */ |
| 83 | public static final int STATE_ANY_SCHEDULED = -4; |
| 84 | |
| 85 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 86 | * Print job state: The print job is being created but not yet |
| 87 | * ready to be printed. |
| 88 | * <p> |
| 89 | * Next valid states: {@link #STATE_QUEUED} |
| 90 | * </p> |
| 91 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 92 | public static final int STATE_CREATED = PrintJobInfoProto.STATE_CREATED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 95 | * Print job state: The print jobs is created, it is ready |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 96 | * to be printed and should be processed. |
| 97 | * <p> |
| 98 | * Next valid states: {@link #STATE_STARTED}, {@link #STATE_FAILED}, |
| 99 | * {@link #STATE_CANCELED} |
| 100 | * </p> |
| 101 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 102 | public static final int STATE_QUEUED = PrintJobInfoProto.STATE_QUEUED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 105 | * Print job state: The print job is being printed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 106 | * <p> |
| 107 | * Next valid states: {@link #STATE_COMPLETED}, {@link #STATE_FAILED}, |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 108 | * {@link #STATE_CANCELED}, {@link #STATE_BLOCKED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 109 | * </p> |
| 110 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 111 | public static final int STATE_STARTED = PrintJobInfoProto.STATE_STARTED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 114 | * Print job state: The print job is blocked. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 115 | * <p> |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 116 | * Next valid states: {@link #STATE_FAILED}, {@link #STATE_CANCELED}, |
| 117 | * {@link #STATE_STARTED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 118 | * </p> |
| 119 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 120 | public static final int STATE_BLOCKED = PrintJobInfoProto.STATE_BLOCKED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 123 | * Print job state: The print job is successfully printed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 124 | * This is a terminal state. |
| 125 | * <p> |
| 126 | * Next valid states: None |
| 127 | * </p> |
| 128 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 129 | public static final int STATE_COMPLETED = PrintJobInfoProto.STATE_COMPLETED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 132 | * Print job state: The print job was printing but printing failed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 133 | * <p> |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 134 | * Next valid states: {@link #STATE_CANCELED}, {@link #STATE_STARTED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 135 | * </p> |
| 136 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 137 | public static final int STATE_FAILED = PrintJobInfoProto.STATE_FAILED; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 140 | * Print job state: The print job is canceled. |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 141 | * This is a terminal state. |
| 142 | * <p> |
| 143 | * Next valid states: None |
| 144 | * </p> |
| 145 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 146 | public static final int STATE_CANCELED = PrintJobInfoProto.STATE_CANCELED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 147 | |
| 148 | /** The unique print job id. */ |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 149 | private PrintJobId mId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 150 | |
| 151 | /** The human readable print job label. */ |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 152 | private String mLabel; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 153 | |
| 154 | /** The unique id of the printer. */ |
| 155 | private PrinterId mPrinterId; |
| 156 | |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 157 | /** The name of the printer - internally used */ |
| 158 | private String mPrinterName; |
| 159 | |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 160 | /** The state of the print job. */ |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 161 | private int mState; |
| 162 | |
| 163 | /** The id of the app that created the job. */ |
| 164 | private int mAppId; |
| 165 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 166 | /** Optional tag assigned by a print service.*/ |
| 167 | private String mTag; |
| 168 | |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 169 | /** The wall time when the print job was created. */ |
| 170 | private long mCreationTime; |
| 171 | |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 172 | /** How many copies to print. */ |
| 173 | private int mCopies; |
| 174 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 175 | /** The pages to print */ |
| 176 | private PageRange[] mPageRanges; |
| 177 | |
| 178 | /** The print job attributes size. */ |
| 179 | private PrintAttributes mAttributes; |
| 180 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 181 | /** Information about the printed document. */ |
| 182 | private PrintDocumentInfo mDocumentInfo; |
| 183 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 184 | /** The progress made on printing this job or -1 if not set. */ |
| 185 | private float mProgress; |
| 186 | |
| 187 | /** A short string describing the status of this job. */ |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 188 | private @Nullable CharSequence mStatus; |
| 189 | |
| 190 | /** A string resource describing the status of this job. */ |
| 191 | private @StringRes int mStatusRes; |
| 192 | private @Nullable CharSequence mStatusResAppPackageName; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 193 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 194 | /** Advanced printer specific options. */ |
| 195 | private Bundle mAdvancedOptions; |
| 196 | |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 197 | /** Whether we are trying to cancel this print job. */ |
| 198 | private boolean mCanceling; |
| 199 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 200 | /** @hide*/ |
| 201 | public PrintJobInfo() { |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 202 | mProgress = -1; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** @hide */ |
| 206 | public PrintJobInfo(PrintJobInfo other) { |
| 207 | mId = other.mId; |
| 208 | mLabel = other.mLabel; |
| 209 | mPrinterId = other.mPrinterId; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 210 | mPrinterName = other.mPrinterName; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 211 | mState = other.mState; |
| 212 | mAppId = other.mAppId; |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 213 | mTag = other.mTag; |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 214 | mCreationTime = other.mCreationTime; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 215 | mCopies = other.mCopies; |
| 216 | mPageRanges = other.mPageRanges; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 217 | mAttributes = other.mAttributes; |
| 218 | mDocumentInfo = other.mDocumentInfo; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 219 | mProgress = other.mProgress; |
| 220 | mStatus = other.mStatus; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 221 | mStatusRes = other.mStatusRes; |
| 222 | mStatusResAppPackageName = other.mStatusResAppPackageName; |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 223 | mCanceling = other.mCanceling; |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 224 | mAdvancedOptions = other.mAdvancedOptions; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 227 | private PrintJobInfo(@NonNull Parcel parcel) { |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 228 | mId = parcel.readParcelable(null); |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 229 | mLabel = parcel.readString(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 230 | mPrinterId = parcel.readParcelable(null); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 231 | mPrinterName = parcel.readString(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 232 | mState = parcel.readInt(); |
| 233 | mAppId = parcel.readInt(); |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 234 | mTag = parcel.readString(); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 235 | mCreationTime = parcel.readLong(); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 236 | mCopies = parcel.readInt(); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 237 | Parcelable[] parcelables = parcel.readParcelableArray(null); |
| 238 | if (parcelables != null) { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 239 | mPageRanges = new PageRange[parcelables.length]; |
| 240 | for (int i = 0; i < parcelables.length; i++) { |
| 241 | mPageRanges[i] = (PageRange) parcelables[i]; |
| 242 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 243 | } |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 244 | mAttributes = (PrintAttributes) parcel.readParcelable(null); |
| 245 | mDocumentInfo = (PrintDocumentInfo) parcel.readParcelable(null); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 246 | mProgress = parcel.readFloat(); |
| 247 | mStatus = parcel.readCharSequence(); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 248 | mStatusRes = parcel.readInt(); |
| 249 | mStatusResAppPackageName = parcel.readCharSequence(); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 250 | mCanceling = (parcel.readInt() == 1); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 251 | mAdvancedOptions = parcel.readBundle(); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 252 | |
| 253 | if (mAdvancedOptions != null) { |
| 254 | Preconditions.checkArgument(!mAdvancedOptions.containsKey(null)); |
| 255 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Gets the unique print job id. |
| 260 | * |
| 261 | * @return The id. |
| 262 | */ |
Philip P. Moltmann | 22f86b4 | 2016-01-15 09:49:00 -0800 | [diff] [blame] | 263 | public @Nullable PrintJobId getId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 264 | return mId; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Sets the unique print job id. |
| 269 | * |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 270 | * @param id The job id. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 271 | * |
| 272 | * @hide |
| 273 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 274 | public void setId(@NonNull PrintJobId id) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 275 | this.mId = id; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Gets the human readable job label. |
| 280 | * |
| 281 | * @return The label. |
| 282 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 283 | public @NonNull String getLabel() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 284 | return mLabel; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Sets the human readable job label. |
| 289 | * |
| 290 | * @param label The label. |
| 291 | * |
| 292 | * @hide |
| 293 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 294 | public void setLabel(@NonNull String label) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 295 | mLabel = label; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Gets the unique target printer id. |
| 300 | * |
| 301 | * @return The target printer id. |
| 302 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 303 | public @Nullable PrinterId getPrinterId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 304 | return mPrinterId; |
| 305 | } |
| 306 | |
| 307 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 308 | * Sets the unique target printer id. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 309 | * |
| 310 | * @param printerId The target printer id. |
| 311 | * |
| 312 | * @hide |
| 313 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 314 | public void setPrinterId(@NonNull PrinterId printerId) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 315 | mPrinterId = printerId; |
| 316 | } |
| 317 | |
| 318 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 319 | * Gets the name of the target printer. |
| 320 | * |
| 321 | * @return The printer name. |
| 322 | * |
| 323 | * @hide |
| 324 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 325 | public @Nullable String getPrinterName() { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 326 | return mPrinterName; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Sets the name of the target printer. |
| 331 | * |
| 332 | * @param printerName The printer name. |
| 333 | * |
| 334 | * @hide |
| 335 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 336 | public void setPrinterName(@NonNull String printerName) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 337 | mPrinterName = printerName; |
| 338 | } |
| 339 | |
| 340 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 341 | * Gets the current job state. |
| 342 | * |
| 343 | * @return The job state. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 344 | * |
| 345 | * @see #STATE_CREATED |
| 346 | * @see #STATE_QUEUED |
| 347 | * @see #STATE_STARTED |
| 348 | * @see #STATE_COMPLETED |
| 349 | * @see #STATE_BLOCKED |
| 350 | * @see #STATE_FAILED |
| 351 | * @see #STATE_CANCELED |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 352 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 353 | public @State int getState() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 354 | return mState; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Sets the current job state. |
| 359 | * |
| 360 | * @param state The job state. |
| 361 | * |
| 362 | * @hide |
| 363 | */ |
| 364 | public void setState(int state) { |
| 365 | mState = state; |
| 366 | } |
| 367 | |
| 368 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 369 | * Sets the progress of the print job. |
| 370 | * |
| 371 | * @param progress the progress of the job |
| 372 | * |
| 373 | * @hide |
| 374 | */ |
| 375 | public void setProgress(@FloatRange(from=0.0, to=1.0) float progress) { |
| 376 | Preconditions.checkArgumentInRange(progress, 0, 1, "progress"); |
| 377 | |
| 378 | mProgress = progress; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Sets the status of the print job. |
| 383 | * |
| 384 | * @param status the status of the job, can be null |
| 385 | * |
| 386 | * @hide |
| 387 | */ |
| 388 | public void setStatus(@Nullable CharSequence status) { |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 389 | mStatusRes = 0; |
| 390 | mStatusResAppPackageName = null; |
| 391 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 392 | mStatus = status; |
| 393 | } |
| 394 | |
| 395 | /** |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 396 | * Sets the status of the print job. |
| 397 | * |
| 398 | * @param status The new status as a string resource |
| 399 | * @param appPackageName App package name the resource belongs to |
| 400 | * |
| 401 | * @hide |
| 402 | */ |
| 403 | public void setStatus(@StringRes int status, @NonNull CharSequence appPackageName) { |
| 404 | mStatus = null; |
| 405 | |
| 406 | mStatusRes = status; |
| 407 | mStatusResAppPackageName = appPackageName; |
| 408 | } |
| 409 | |
| 410 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 411 | * Sets the owning application id. |
| 412 | * |
| 413 | * @return The owning app id. |
| 414 | * |
| 415 | * @hide |
| 416 | */ |
| 417 | public int getAppId() { |
| 418 | return mAppId; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Sets the owning application id. |
| 423 | * |
| 424 | * @param appId The owning app id. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public void setAppId(int appId) { |
| 429 | mAppId = appId; |
| 430 | } |
| 431 | |
| 432 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 433 | * Gets the optional tag assigned by a print service. |
| 434 | * |
| 435 | * @return The tag. |
Svetoslav | b450d0d | 2013-10-04 16:20:00 -0700 | [diff] [blame] | 436 | * |
| 437 | * @hide |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 438 | */ |
| 439 | public String getTag() { |
| 440 | return mTag; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Sets the optional tag assigned by a print service. |
| 445 | * |
| 446 | * @param tag The tag. |
| 447 | * |
| 448 | * @hide |
| 449 | */ |
| 450 | public void setTag(String tag) { |
| 451 | mTag = tag; |
| 452 | } |
| 453 | |
| 454 | /** |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 455 | * Gets the wall time in millisecond when this print job was created. |
| 456 | * |
| 457 | * @return The creation time in milliseconds. |
| 458 | */ |
| 459 | public long getCreationTime() { |
| 460 | return mCreationTime; |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Sets the wall time in milliseconds when this print job was created. |
| 465 | * |
| 466 | * @param creationTime The creation time in milliseconds. |
| 467 | * |
| 468 | * @hide |
| 469 | */ |
| 470 | public void setCreationTime(long creationTime) { |
| 471 | if (creationTime < 0) { |
| 472 | throw new IllegalArgumentException("creationTime must be non-negative."); |
| 473 | } |
| 474 | mCreationTime = creationTime; |
| 475 | } |
| 476 | |
| 477 | /** |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 478 | * Gets the number of copies. |
| 479 | * |
| 480 | * @return The number of copies or zero if not set. |
| 481 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 482 | public @IntRange(from = 0) int getCopies() { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 483 | return mCopies; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Sets the number of copies. |
| 488 | * |
| 489 | * @param copyCount The number of copies. |
| 490 | * |
| 491 | * @hide |
| 492 | */ |
| 493 | public void setCopies(int copyCount) { |
| 494 | if (copyCount < 1) { |
| 495 | throw new IllegalArgumentException("Copies must be more than one."); |
| 496 | } |
| 497 | mCopies = copyCount; |
| 498 | } |
| 499 | |
| 500 | /** |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 501 | * Gets the included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 502 | * |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 503 | * @return The included pages or <code>null</code> if not set. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 504 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 505 | public @Nullable PageRange[] getPages() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 506 | return mPageRanges; |
| 507 | } |
| 508 | |
| 509 | /** |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 510 | * Sets the included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 511 | * |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 512 | * @param pageRanges The included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 513 | * |
| 514 | * @hide |
| 515 | */ |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 516 | public void setPages(PageRange[] pageRanges) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 517 | mPageRanges = pageRanges; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Gets the print job attributes. |
| 522 | * |
| 523 | * @return The attributes. |
| 524 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 525 | public @NonNull PrintAttributes getAttributes() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 526 | return mAttributes; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Sets the print job attributes. |
| 531 | * |
| 532 | * @param attributes The attributes. |
| 533 | * |
| 534 | * @hide |
| 535 | */ |
| 536 | public void setAttributes(PrintAttributes attributes) { |
| 537 | mAttributes = attributes; |
| 538 | } |
| 539 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Gets the info describing the printed document. |
| 542 | * |
| 543 | * @return The document info. |
| 544 | * |
| 545 | * @hide |
| 546 | */ |
| 547 | public PrintDocumentInfo getDocumentInfo() { |
| 548 | return mDocumentInfo; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 551 | /** |
| 552 | * Sets the info describing the printed document. |
| 553 | * |
| 554 | * @param info The document info. |
| 555 | * |
| 556 | * @hide |
| 557 | */ |
| 558 | public void setDocumentInfo(PrintDocumentInfo info) { |
| 559 | mDocumentInfo = info; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 562 | /** |
| 563 | * Gets whether this print is being cancelled. |
| 564 | * |
| 565 | * @return True if the print job is being cancelled. |
| 566 | * |
| 567 | * @hide |
| 568 | */ |
| 569 | public boolean isCancelling() { |
| 570 | return mCanceling; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Sets whether this print is being cancelled. |
| 575 | * |
| 576 | * @param cancelling True if the print job is being cancelled. |
| 577 | * |
| 578 | * @hide |
| 579 | */ |
| 580 | public void setCancelling(boolean cancelling) { |
| 581 | mCanceling = cancelling; |
| 582 | } |
| 583 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 584 | /** |
| 585 | * Gets whether this job has a given advanced (printer specific) print |
| 586 | * option. |
| 587 | * |
| 588 | * @param key The option key. |
| 589 | * @return Whether the option is present. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 590 | */ |
| 591 | public boolean hasAdvancedOption(String key) { |
| 592 | return mAdvancedOptions != null && mAdvancedOptions.containsKey(key); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Gets the value of an advanced (printer specific) print option. |
| 597 | * |
| 598 | * @param key The option key. |
| 599 | * @return The option value. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 600 | */ |
| 601 | public String getAdvancedStringOption(String key) { |
| 602 | if (mAdvancedOptions != null) { |
| 603 | return mAdvancedOptions.getString(key); |
| 604 | } |
| 605 | return null; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Gets the value of an advanced (printer specific) print option. |
| 610 | * |
| 611 | * @param key The option key. |
| 612 | * @return The option value. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 613 | */ |
| 614 | public int getAdvancedIntOption(String key) { |
| 615 | if (mAdvancedOptions != null) { |
| 616 | return mAdvancedOptions.getInt(key); |
| 617 | } |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Gets the advanced options. |
| 623 | * |
| 624 | * @return The advanced options. |
| 625 | * |
| 626 | * @hide |
| 627 | */ |
| 628 | public Bundle getAdvancedOptions() { |
| 629 | return mAdvancedOptions; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Sets the advanced options. |
| 634 | * |
| 635 | * @param options The advanced options. |
| 636 | * |
| 637 | * @hide |
| 638 | */ |
| 639 | public void setAdvancedOptions(Bundle options) { |
| 640 | mAdvancedOptions = options; |
| 641 | } |
| 642 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 643 | @Override |
| 644 | public int describeContents() { |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public void writeToParcel(Parcel parcel, int flags) { |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 650 | parcel.writeParcelable(mId, flags); |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 651 | parcel.writeString(mLabel); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 652 | parcel.writeParcelable(mPrinterId, flags); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 653 | parcel.writeString(mPrinterName); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 654 | parcel.writeInt(mState); |
| 655 | parcel.writeInt(mAppId); |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 656 | parcel.writeString(mTag); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 657 | parcel.writeLong(mCreationTime); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 658 | parcel.writeInt(mCopies); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 659 | parcel.writeParcelableArray(mPageRanges, flags); |
| 660 | parcel.writeParcelable(mAttributes, flags); |
| 661 | parcel.writeParcelable(mDocumentInfo, 0); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 662 | parcel.writeFloat(mProgress); |
| 663 | parcel.writeCharSequence(mStatus); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 664 | parcel.writeInt(mStatusRes); |
| 665 | parcel.writeCharSequence(mStatusResAppPackageName); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 666 | parcel.writeInt(mCanceling ? 1 : 0); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 667 | parcel.writeBundle(mAdvancedOptions); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | @Override |
| 671 | public String toString() { |
| 672 | StringBuilder builder = new StringBuilder(); |
| 673 | builder.append("PrintJobInfo{"); |
| 674 | builder.append("label: ").append(mLabel); |
| 675 | builder.append(", id: ").append(mId); |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 676 | builder.append(", state: ").append(stateToString(mState)); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 677 | builder.append(", printer: " + mPrinterId); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 678 | builder.append(", tag: ").append(mTag); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 679 | builder.append(", creationTime: " + mCreationTime); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 680 | builder.append(", copies: ").append(mCopies); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 681 | builder.append(", attributes: " + (mAttributes != null |
| 682 | ? mAttributes.toString() : null)); |
| 683 | builder.append(", documentInfo: " + (mDocumentInfo != null |
| 684 | ? mDocumentInfo.toString() : null)); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 685 | builder.append(", cancelling: " + mCanceling); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 686 | builder.append(", pages: " + (mPageRanges != null |
| 687 | ? Arrays.toString(mPageRanges) : null)); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 688 | builder.append(", hasAdvancedOptions: " + (mAdvancedOptions != null)); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 689 | builder.append(", progress: " + mProgress); |
| 690 | builder.append(", status: " + (mStatus != null |
| 691 | ? mStatus.toString() : null)); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 692 | builder.append(", statusRes: " + mStatusRes); |
| 693 | builder.append(", statusResAppPackageName: " + (mStatusResAppPackageName != null |
| 694 | ? mStatusResAppPackageName.toString() : null)); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 695 | builder.append("}"); |
| 696 | return builder.toString(); |
| 697 | } |
| 698 | |
| 699 | /** @hide */ |
| 700 | public static String stateToString(int state) { |
| 701 | switch (state) { |
| 702 | case STATE_CREATED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 703 | return "STATE_CREATED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 704 | } |
| 705 | case STATE_QUEUED: { |
| 706 | return "STATE_QUEUED"; |
| 707 | } |
| 708 | case STATE_STARTED: { |
| 709 | return "STATE_STARTED"; |
| 710 | } |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 711 | case STATE_BLOCKED: { |
| 712 | return "STATE_BLOCKED"; |
| 713 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 714 | case STATE_FAILED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 715 | return "STATE_FAILED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 716 | } |
| 717 | case STATE_COMPLETED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 718 | return "STATE_COMPLETED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 719 | } |
| 720 | case STATE_CANCELED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 721 | return "STATE_CANCELED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 722 | } |
| 723 | default: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 724 | return "STATE_UNKNOWN"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 729 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 730 | * Get the progress that has been made printing this job. |
| 731 | * |
| 732 | * @return the print progress or -1 if not set |
| 733 | * @hide |
| 734 | */ |
| 735 | @TestApi |
| 736 | public float getProgress() { |
| 737 | return mProgress; |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * Get the status of this job. |
| 742 | * |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 743 | * @param pm Package manager used to resolve the string |
| 744 | * |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 745 | * @return the status of this job or null if not set |
| 746 | * @hide |
| 747 | */ |
| 748 | @TestApi |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 749 | public @Nullable CharSequence getStatus(@NonNull PackageManager pm) { |
| 750 | if (mStatusRes == 0) { |
| 751 | return mStatus; |
| 752 | } else { |
| 753 | try { |
| 754 | return pm.getResourcesForApplication(mStatusResAppPackageName.toString()) |
| 755 | .getString(mStatusRes); |
| 756 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 757 | return null; |
| 758 | } |
| 759 | } |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 763 | * Builder for creating a {@link PrintJobInfo}. |
| 764 | */ |
| 765 | public static final class Builder { |
| 766 | private final PrintJobInfo mPrototype; |
| 767 | |
| 768 | /** |
| 769 | * Constructor. |
| 770 | * |
| 771 | * @param prototype Prototype to use as a starting point. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 772 | * Can be <code>null</code>. |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 773 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 774 | public Builder(@Nullable PrintJobInfo prototype) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 775 | mPrototype = (prototype != null) |
| 776 | ? new PrintJobInfo(prototype) |
| 777 | : new PrintJobInfo(); |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Sets the number of copies. |
| 782 | * |
| 783 | * @param copies The number of copies. |
| 784 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 785 | public void setCopies(@IntRange(from = 1) int copies) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 786 | mPrototype.mCopies = copies; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Sets the print job attributes. |
| 791 | * |
| 792 | * @param attributes The attributes. |
| 793 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 794 | public void setAttributes(@NonNull PrintAttributes attributes) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 795 | mPrototype.mAttributes = attributes; |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Sets the included pages. |
| 800 | * |
| 801 | * @param pages The included pages. |
| 802 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 803 | public void setPages(@NonNull PageRange[] pages) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 804 | mPrototype.mPageRanges = pages; |
| 805 | } |
| 806 | |
| 807 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 808 | * Sets the progress of the print job. |
| 809 | * |
| 810 | * @param progress the progress of the job |
| 811 | * @hide |
| 812 | */ |
| 813 | public void setProgress(@FloatRange(from=0.0, to=1.0) float progress) { |
| 814 | Preconditions.checkArgumentInRange(progress, 0, 1, "progress"); |
| 815 | |
| 816 | mPrototype.mProgress = progress; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * Sets the status of the print job. |
| 821 | * |
| 822 | * @param status the status of the job, can be null |
| 823 | * @hide |
| 824 | */ |
| 825 | public void setStatus(@Nullable CharSequence status) { |
| 826 | mPrototype.mStatus = status; |
| 827 | } |
| 828 | |
| 829 | /** |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 830 | * Puts an advanced (printer specific) option. |
| 831 | * |
| 832 | * @param key The option key. |
| 833 | * @param value The option value. |
| 834 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 835 | public void putAdvancedOption(@NonNull String key, @Nullable String value) { |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 836 | Preconditions.checkNotNull(key, "key cannot be null"); |
| 837 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 838 | if (mPrototype.mAdvancedOptions == null) { |
| 839 | mPrototype.mAdvancedOptions = new Bundle(); |
| 840 | } |
| 841 | mPrototype.mAdvancedOptions.putString(key, value); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Puts an advanced (printer specific) option. |
| 846 | * |
| 847 | * @param key The option key. |
| 848 | * @param value The option value. |
| 849 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 850 | public void putAdvancedOption(@NonNull String key, int value) { |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 851 | if (mPrototype.mAdvancedOptions == null) { |
| 852 | mPrototype.mAdvancedOptions = new Bundle(); |
| 853 | } |
| 854 | mPrototype.mAdvancedOptions.putInt(key, value); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /** |
| 858 | * Creates a new {@link PrintJobInfo} instance. |
| 859 | * |
| 860 | * @return The new instance. |
| 861 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 862 | public @NonNull PrintJobInfo build() { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 863 | return mPrototype; |
| 864 | } |
| 865 | } |
| 866 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 867 | public static final Parcelable.Creator<PrintJobInfo> CREATOR = |
| 868 | new Creator<PrintJobInfo>() { |
| 869 | @Override |
| 870 | public PrintJobInfo createFromParcel(Parcel parcel) { |
| 871 | return new PrintJobInfo(parcel); |
| 872 | } |
| 873 | |
| 874 | @Override |
| 875 | public PrintJobInfo[] newArray(int size) { |
| 876 | return new PrintJobInfo[size]; |
| 877 | } |
| 878 | }; |
| 879 | } |