PrintJobInfo.java revision 53f57d162b0553102fbd5c4ccdda87dbfce5b763
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 17package android.print; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22/** 23 * This class represents the description of a print job. 24 */ 25public final class PrintJobInfo implements Parcelable { 26 27 /** Undefined print job id. */ 28 public static final int PRINT_JOB_ID_UNDEFINED = -1; 29 30 /** 31 * Constant for matching any print job state. 32 * 33 * @hide 34 */ 35 public static final int STATE_ANY = -1; 36 37 /** 38 * Print job state: The print job is being created but not yet 39 * ready to be printed. 40 * <p> 41 * Next valid states: {@link #STATE_QUEUED} 42 * </p> 43 */ 44 public static final int STATE_CREATED = 1; 45 46 /** 47 * Print job status: The print jobs is created, it is ready 48 * to be printed and should be processed. 49 * <p> 50 * Next valid states: {@link #STATE_STARTED}, {@link #STATE_FAILED}, 51 * {@link #STATE_CANCELED} 52 * </p> 53 */ 54 public static final int STATE_QUEUED = 2; 55 56 /** 57 * Print job status: The print job is being printed. 58 * <p> 59 * Next valid states: {@link #STATE_COMPLETED}, {@link #STATE_FAILED}, 60 * {@link #STATE_CANCELED} 61 * </p> 62 */ 63 public static final int STATE_STARTED = 3; 64 65 /** 66 * Print job status: The print job was successfully printed. 67 * This is a terminal state. 68 * <p> 69 * Next valid states: None 70 * </p> 71 */ 72 public static final int STATE_COMPLETED = 4; 73 74 /** 75 * Print job status: The print job was printing but printing failed. 76 * This is a terminal state. 77 * <p> 78 * Next valid states: None 79 * </p> 80 */ 81 public static final int STATE_FAILED = 5; 82 83 /** 84 * Print job status: The print job was canceled. 85 * This is a terminal state. 86 * <p> 87 * Next valid states: None 88 * </p> 89 */ 90 public static final int STATE_CANCELED = 6; 91 92 /** The unique print job id. */ 93 private int mId; 94 95 /** The human readable print job label. */ 96 private CharSequence mLabel; 97 98 /** The unique id of the printer. */ 99 private PrinterId mPrinterId; 100 101 /** The status of the print job. */ 102 private int mState; 103 104 /** The id of the app that created the job. */ 105 private int mAppId; 106 107 /** The id of the user that created the job. */ 108 private int mUserId; 109 110 /** Optional tag assigned by a print service.*/ 111 private String mTag; 112 113 /** The pages to print */ 114 private PageRange[] mPageRanges; 115 116 /** The print job attributes size. */ 117 private PrintAttributes mAttributes; 118 119 /** 120 * Gets the unique print job id. 121 * 122 * @return The id. 123 */ 124 public int getId() { 125 return mId; 126 } 127 128 /** 129 * Sets the unique print job id. 130 * 131 * @param The job id. 132 * 133 * @hide 134 */ 135 public void setId(int id) { 136 this.mId = id; 137 } 138 139 /** 140 * Gets the human readable job label. 141 * 142 * @return The label. 143 */ 144 public CharSequence getLabel() { 145 return mLabel; 146 } 147 148 /** 149 * Sets the human readable job label. 150 * 151 * @param label The label. 152 * 153 * @hide 154 */ 155 public void setLabel(CharSequence label) { 156 mLabel = label; 157 } 158 159 /** 160 * Gets the unique target printer id. 161 * 162 * @return The target printer id. 163 */ 164 public PrinterId getPrinterId() { 165 return mPrinterId; 166 } 167 168 /** 169 * Sets the unique target pritner id. 170 * 171 * @param printerId The target printer id. 172 * 173 * @hide 174 */ 175 public void setPrinterId(PrinterId printerId) { 176 mPrinterId = printerId; 177 } 178 179 /** 180 * Gets the current job state. 181 * 182 * @return The job state. 183 */ 184 public int getState() { 185 return mState; 186 } 187 188 /** 189 * Sets the current job state. 190 * 191 * @param state The job state. 192 * 193 * @hide 194 */ 195 public void setState(int state) { 196 mState = state; 197 } 198 199 /** 200 * Sets the owning application id. 201 * 202 * @return The owning app id. 203 * 204 * @hide 205 */ 206 public int getAppId() { 207 return mAppId; 208 } 209 210 /** 211 * Sets the owning application id. 212 * 213 * @param appId The owning app id. 214 * 215 * @hide 216 */ 217 public void setAppId(int appId) { 218 mAppId = appId; 219 } 220 221 /** 222 * Gets the owning user id. 223 * 224 * @return The user id. 225 * 226 * @hide 227 */ 228 public int getUserId() { 229 return mUserId; 230 } 231 232 /** 233 * Sets the owning user id. 234 * 235 * @param userId The user id. 236 * 237 * @hide 238 */ 239 public void setUserId(int userId) { 240 mUserId = userId; 241 } 242 243 /** 244 * Gets the optional tag assigned by a print service. 245 * 246 * @return The tag. 247 */ 248 public String getTag() { 249 return mTag; 250 } 251 252 /** 253 * Sets the optional tag assigned by a print service. 254 * 255 * @param tag The tag. 256 * 257 * @hide 258 */ 259 public void setTag(String tag) { 260 mTag = tag; 261 } 262 263 /** 264 * Gets the included pages. 265 * 266 * @return The included pages or <code>null</code> if not set. 267 */ 268 public PageRange[] getPages() { 269 return mPageRanges; 270 } 271 272 /** 273 * Sets the included pages. 274 * 275 * @return The included pages. 276 * 277 * @hide 278 */ 279 public void setPages(PageRange[] pageRanges) { 280 mPageRanges = pageRanges; 281 } 282 283 /** 284 * Gets the print job attributes. 285 * 286 * @return The attributes. 287 */ 288 public PrintAttributes getAttributes() { 289 return mAttributes; 290 } 291 292 /** 293 * Sets the print job attributes. 294 * 295 * @param attributes The attributes. 296 * 297 * @hide 298 */ 299 public void setAttributes(PrintAttributes attributes) { 300 mAttributes = attributes; 301 } 302 303 /** @hide*/ 304 public PrintJobInfo() { 305 /* do nothing */ 306 } 307 308 /** @hide */ 309 public PrintJobInfo(PrintJobInfo other) { 310 mId = other.mId; 311 mLabel = other.mLabel; 312 mPrinterId = other.mPrinterId; 313 mState = other.mState; 314 mAppId = other.mAppId; 315 mUserId = other.mUserId; 316 mAttributes = other.mAttributes; 317 } 318 319 private PrintJobInfo(Parcel parcel) { 320 mId = parcel.readInt(); 321 mLabel = parcel.readCharSequence(); 322 mPrinterId = parcel.readParcelable(null); 323 mState = parcel.readInt(); 324 mAppId = parcel.readInt(); 325 mUserId = parcel.readInt(); 326 if (parcel.readInt() == 1) { 327 mPageRanges = (PageRange[]) parcel.readParcelableArray(null); 328 } 329 if (parcel.readInt() == 1) { 330 mAttributes = PrintAttributes.CREATOR.createFromParcel(parcel); 331 } 332 } 333 334 @Override 335 public int describeContents() { 336 return 0; 337 } 338 339 @Override 340 public void writeToParcel(Parcel parcel, int flags) { 341 parcel.writeInt(mId); 342 parcel.writeCharSequence(mLabel); 343 parcel.writeParcelable(mPrinterId, flags); 344 parcel.writeInt(mState); 345 parcel.writeInt(mAppId); 346 parcel.writeInt(mUserId); 347 if (mPageRanges != null) { 348 parcel.writeInt(1); 349 parcel.writeParcelableArray(mPageRanges, flags); 350 } else { 351 parcel.writeInt(0); 352 } 353 if (mAttributes != null) { 354 parcel.writeInt(1); 355 mAttributes.writeToParcel(parcel, flags); 356 } else { 357 parcel.writeInt(0); 358 } 359 } 360 361 @Override 362 public String toString() { 363 StringBuilder builder = new StringBuilder(); 364 builder.append("PrintJobInfo{"); 365 builder.append("label: ").append(mLabel); 366 builder.append(", id: ").append(mId); 367 builder.append(", status: ").append(stateToString(mState)); 368 builder.append(", printer: " + mPrinterId); 369 builder.append(", attributes: " + (mAttributes != null ? mAttributes.toString() : null)); 370 builder.append("}"); 371 return builder.toString(); 372 } 373 374 /** @hide */ 375 public static String stateToString(int state) { 376 switch (state) { 377 case STATE_CREATED: { 378 return "STATUS_CREATED"; 379 } 380 case STATE_QUEUED: { 381 return "STATE_QUEUED"; 382 } 383 case STATE_STARTED: { 384 return "STATE_STARTED"; 385 } 386 case STATE_FAILED: { 387 return "STATUS_FAILED"; 388 } 389 case STATE_COMPLETED: { 390 return "STATUS_COMPLETED"; 391 } 392 case STATE_CANCELED: { 393 return "STATUS_CANCELED"; 394 } 395 default: { 396 return "STATUS_UNKNOWN"; 397 } 398 } 399 } 400 401 402 public static final Parcelable.Creator<PrintJobInfo> CREATOR = 403 new Creator<PrintJobInfo>() { 404 @Override 405 public PrintJobInfo createFromParcel(Parcel parcel) { 406 return new PrintJobInfo(parcel); 407 } 408 409 @Override 410 public PrintJobInfo[] newArray(int size) { 411 return new PrintJobInfo[size]; 412 } 413 }; 414} 415