blob: 6e613bcd981f0add295a8c3c9e9ee4f80d265872 [file] [log] [blame]
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001/*
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
Svetoslav Ganova0027152013-06-25 14:59:53 -0700119 /** Information about the printed document. */
120 private PrintDocumentInfo mDocumentInfo;
121
122 /** @hide*/
123 public PrintJobInfo() {
124 /* do nothing */
125 }
126
127 /** @hide */
128 public PrintJobInfo(PrintJobInfo other) {
129 mId = other.mId;
130 mLabel = other.mLabel;
131 mPrinterId = other.mPrinterId;
132 mState = other.mState;
133 mAppId = other.mAppId;
134 mUserId = other.mUserId;
135 mAttributes = other.mAttributes;
136 mDocumentInfo = other.mDocumentInfo;
137 }
138
139 private PrintJobInfo(Parcel parcel) {
140 mId = parcel.readInt();
141 mLabel = parcel.readCharSequence();
142 mPrinterId = parcel.readParcelable(null);
143 mState = parcel.readInt();
144 mAppId = parcel.readInt();
145 mUserId = parcel.readInt();
146 if (parcel.readInt() == 1) {
147 mPageRanges = (PageRange[]) parcel.readParcelableArray(null);
148 }
149 if (parcel.readInt() == 1) {
150 mAttributes = PrintAttributes.CREATOR.createFromParcel(parcel);
151 }
152 if (parcel.readInt() == 1) {
153 mDocumentInfo = PrintDocumentInfo.CREATOR.createFromParcel(parcel);
154 }
155 }
156
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700157 /**
158 * Gets the unique print job id.
159 *
160 * @return The id.
161 */
162 public int getId() {
163 return mId;
164 }
165
166 /**
167 * Sets the unique print job id.
168 *
169 * @param The job id.
170 *
171 * @hide
172 */
173 public void setId(int id) {
174 this.mId = id;
175 }
176
177 /**
178 * Gets the human readable job label.
179 *
180 * @return The label.
181 */
182 public CharSequence getLabel() {
183 return mLabel;
184 }
185
186 /**
187 * Sets the human readable job label.
188 *
189 * @param label The label.
190 *
191 * @hide
192 */
193 public void setLabel(CharSequence label) {
194 mLabel = label;
195 }
196
197 /**
198 * Gets the unique target printer id.
199 *
200 * @return The target printer id.
201 */
202 public PrinterId getPrinterId() {
203 return mPrinterId;
204 }
205
206 /**
207 * Sets the unique target pritner id.
208 *
209 * @param printerId The target printer id.
210 *
211 * @hide
212 */
213 public void setPrinterId(PrinterId printerId) {
214 mPrinterId = printerId;
215 }
216
217 /**
218 * Gets the current job state.
219 *
220 * @return The job state.
221 */
222 public int getState() {
223 return mState;
224 }
225
226 /**
227 * Sets the current job state.
228 *
229 * @param state The job state.
230 *
231 * @hide
232 */
233 public void setState(int state) {
234 mState = state;
235 }
236
237 /**
238 * Sets the owning application id.
239 *
240 * @return The owning app id.
241 *
242 * @hide
243 */
244 public int getAppId() {
245 return mAppId;
246 }
247
248 /**
249 * Sets the owning application id.
250 *
251 * @param appId The owning app id.
252 *
253 * @hide
254 */
255 public void setAppId(int appId) {
256 mAppId = appId;
257 }
258
259 /**
260 * Gets the owning user id.
261 *
262 * @return The user id.
263 *
264 * @hide
265 */
266 public int getUserId() {
267 return mUserId;
268 }
269
270 /**
271 * Sets the owning user id.
272 *
273 * @param userId The user id.
274 *
275 * @hide
276 */
277 public void setUserId(int userId) {
278 mUserId = userId;
279 }
280
281 /**
282 * Gets the optional tag assigned by a print service.
283 *
284 * @return The tag.
285 */
286 public String getTag() {
287 return mTag;
288 }
289
290 /**
291 * Sets the optional tag assigned by a print service.
292 *
293 * @param tag The tag.
294 *
295 * @hide
296 */
297 public void setTag(String tag) {
298 mTag = tag;
299 }
300
301 /**
Svetoslav53f57d12013-06-22 00:26:49 -0700302 * Gets the included pages.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700303 *
Svetoslav53f57d12013-06-22 00:26:49 -0700304 * @return The included pages or <code>null</code> if not set.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700305 */
Svetoslav53f57d12013-06-22 00:26:49 -0700306 public PageRange[] getPages() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700307 return mPageRanges;
308 }
309
310 /**
Svetoslav53f57d12013-06-22 00:26:49 -0700311 * Sets the included pages.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700312 *
Svetoslav53f57d12013-06-22 00:26:49 -0700313 * @return The included pages.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700314 *
315 * @hide
316 */
Svetoslav53f57d12013-06-22 00:26:49 -0700317 public void setPages(PageRange[] pageRanges) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700318 mPageRanges = pageRanges;
319 }
320
321 /**
322 * Gets the print job attributes.
323 *
324 * @return The attributes.
325 */
326 public PrintAttributes getAttributes() {
327 return mAttributes;
328 }
329
330 /**
331 * Sets the print job attributes.
332 *
333 * @param attributes The attributes.
334 *
335 * @hide
336 */
337 public void setAttributes(PrintAttributes attributes) {
338 mAttributes = attributes;
339 }
340
Svetoslav Ganova0027152013-06-25 14:59:53 -0700341 /**
342 * Gets the info describing the printed document.
343 *
344 * @return The document info.
345 *
346 * @hide
347 */
348 public PrintDocumentInfo getDocumentInfo() {
349 return mDocumentInfo;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700350 }
351
Svetoslav Ganova0027152013-06-25 14:59:53 -0700352 /**
353 * Sets the info describing the printed document.
354 *
355 * @param info The document info.
356 *
357 * @hide
358 */
359 public void setDocumentInfo(PrintDocumentInfo info) {
360 mDocumentInfo = info;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700361 }
362
363 @Override
364 public int describeContents() {
365 return 0;
366 }
367
368 @Override
369 public void writeToParcel(Parcel parcel, int flags) {
370 parcel.writeInt(mId);
371 parcel.writeCharSequence(mLabel);
372 parcel.writeParcelable(mPrinterId, flags);
373 parcel.writeInt(mState);
374 parcel.writeInt(mAppId);
375 parcel.writeInt(mUserId);
376 if (mPageRanges != null) {
377 parcel.writeInt(1);
378 parcel.writeParcelableArray(mPageRanges, flags);
379 } else {
380 parcel.writeInt(0);
381 }
382 if (mAttributes != null) {
383 parcel.writeInt(1);
384 mAttributes.writeToParcel(parcel, flags);
385 } else {
386 parcel.writeInt(0);
387 }
Svetoslav Ganova0027152013-06-25 14:59:53 -0700388 if (mDocumentInfo != null) {
389 parcel.writeInt(1);
390 mDocumentInfo.writeToParcel(parcel, flags);
391 } else {
392 parcel.writeInt(0);
393 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700394 }
395
396 @Override
397 public String toString() {
398 StringBuilder builder = new StringBuilder();
399 builder.append("PrintJobInfo{");
400 builder.append("label: ").append(mLabel);
401 builder.append(", id: ").append(mId);
402 builder.append(", status: ").append(stateToString(mState));
403 builder.append(", printer: " + mPrinterId);
Svetoslav Ganova0027152013-06-25 14:59:53 -0700404 builder.append(", attributes: " + (mAttributes != null
405 ? mAttributes.toString() : null));
406 builder.append(", documentInfo: " + (mDocumentInfo != null
407 ? mDocumentInfo.toString() : null));
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700408 builder.append("}");
409 return builder.toString();
410 }
411
412 /** @hide */
413 public static String stateToString(int state) {
414 switch (state) {
415 case STATE_CREATED: {
416 return "STATUS_CREATED";
417 }
418 case STATE_QUEUED: {
419 return "STATE_QUEUED";
420 }
421 case STATE_STARTED: {
422 return "STATE_STARTED";
423 }
424 case STATE_FAILED: {
425 return "STATUS_FAILED";
426 }
427 case STATE_COMPLETED: {
428 return "STATUS_COMPLETED";
429 }
430 case STATE_CANCELED: {
431 return "STATUS_CANCELED";
432 }
433 default: {
434 return "STATUS_UNKNOWN";
435 }
436 }
437 }
438
439
440 public static final Parcelable.Creator<PrintJobInfo> CREATOR =
441 new Creator<PrintJobInfo>() {
442 @Override
443 public PrintJobInfo createFromParcel(Parcel parcel) {
444 return new PrintJobInfo(parcel);
445 }
446
447 @Override
448 public PrintJobInfo[] newArray(int size) {
449 return new PrintJobInfo[size];
450 }
451 };
452}