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