| 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.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
import android.print.PrintAttributes.ColorMode; |
| 24 |
import android.print.PrintAttributes.DuplexMode; |
| 25 |
import android.print.PrintAttributes.Margins; |
| 26 |
import android.print.PrintAttributes.MediaSize; |
| 27 |
import android.print.PrintAttributes.Resolution; |
| 28 |
|
| 29 |
import com.android.internal.util.Preconditions; |
| 30 |
|
| 31 |
import java.util.ArrayList; |
| 32 |
import java.util.Arrays; |
| 33 |
import java.util.Collections; |
| 34 |
import java.util.List; |
| 35 |
import java.util.function.IntConsumer; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public final class PrinterCapabilitiesInfo implements Parcelable { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final int DEFAULT_UNDEFINED = -1; |
| 53 |
|
| 54 |
private static final int PROPERTY_MEDIA_SIZE = 0; |
| 55 |
private static final int PROPERTY_RESOLUTION = 1; |
| 56 |
private static final int PROPERTY_COLOR_MODE = 2; |
| 57 |
private static final int PROPERTY_DUPLEX_MODE = 3; |
| 58 |
private static final int PROPERTY_COUNT = 4; |
| 59 |
|
| 60 |
private static final Margins DEFAULT_MARGINS = new Margins(0, 0, 0, 0); |
| 61 |
|
| 62 |
private @NonNull Margins mMinMargins = DEFAULT_MARGINS; |
| 63 |
private @NonNull List<MediaSize> mMediaSizes; |
| 64 |
private @NonNull List<Resolution> mResolutions; |
| 65 |
|
| 66 |
private int mColorModes; |
| 67 |
private int mDuplexModes; |
| 68 |
|
| 69 |
private final int[] mDefaults = new int[PROPERTY_COUNT]; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public PrinterCapabilitiesInfo() { |
| 75 |
Arrays.fill(mDefaults, DEFAULT_UNDEFINED); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public PrinterCapabilitiesInfo(PrinterCapabilitiesInfo prototype) { |
| 82 |
copyFrom(prototype); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public void copyFrom(PrinterCapabilitiesInfo other) { |
| 89 |
if (this == other) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
mMinMargins = other.mMinMargins; |
| 94 |
|
| 95 |
if (other.mMediaSizes != null) { |
| 96 |
if (mMediaSizes != null) { |
| 97 |
mMediaSizes.clear(); |
| 98 |
mMediaSizes.addAll(other.mMediaSizes); |
| 99 |
} else { |
| 100 |
mMediaSizes = new ArrayList<MediaSize>(other.mMediaSizes); |
| 101 |
} |
| 102 |
} else { |
| 103 |
mMediaSizes = null; |
| 104 |
} |
| 105 |
|
| 106 |
if (other.mResolutions != null) { |
| 107 |
if (mResolutions != null) { |
| 108 |
mResolutions.clear(); |
| 109 |
mResolutions.addAll(other.mResolutions); |
| 110 |
} else { |
| 111 |
mResolutions = new ArrayList<Resolution>(other.mResolutions); |
| 112 |
} |
| 113 |
} else { |
| 114 |
mResolutions = null; |
| 115 |
} |
| 116 |
|
| 117 |
mColorModes = other.mColorModes; |
| 118 |
mDuplexModes = other.mDuplexModes; |
| 119 |
|
| 120 |
final int defaultCount = other.mDefaults.length; |
| 121 |
for (int i = 0; i < defaultCount; i++) { |
| 122 |
mDefaults[i] = other.mDefaults[i]; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public @NonNull List<MediaSize> getMediaSizes() { |
| 132 |
return Collections.unmodifiableList(mMediaSizes); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public @NonNull List<Resolution> getResolutions() { |
| 141 |
return Collections.unmodifiableList(mResolutions); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public @NonNull Margins getMinMargins() { |
| 151 |
return mMinMargins; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public @ColorMode int getColorModes() { |
| 163 |
return mColorModes; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public @DuplexMode int getDuplexModes() { |
| 176 |
return mDuplexModes; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public @NonNull PrintAttributes getDefaults() { |
| 185 |
PrintAttributes.Builder builder = new PrintAttributes.Builder(); |
| 186 |
|
| 187 |
builder.setMinMargins(mMinMargins); |
| 188 |
|
| 189 |
final int mediaSizeIndex = mDefaults[PROPERTY_MEDIA_SIZE]; |
| 190 |
if (mediaSizeIndex >= 0) { |
| 191 |
builder.setMediaSize(mMediaSizes.get(mediaSizeIndex)); |
| 192 |
} |
| 193 |
|
| 194 |
final int resolutionIndex = mDefaults[PROPERTY_RESOLUTION]; |
| 195 |
if (resolutionIndex >= 0) { |
| 196 |
builder.setResolution(mResolutions.get(resolutionIndex)); |
| 197 |
} |
| 198 |
|
| 199 |
final int colorMode = mDefaults[PROPERTY_COLOR_MODE]; |
| 200 |
if (colorMode > 0) { |
| 201 |
builder.setColorMode(colorMode); |
| 202 |
} |
| 203 |
|
| 204 |
final int duplexMode = mDefaults[PROPERTY_DUPLEX_MODE]; |
| 205 |
if (duplexMode > 0) { |
| 206 |
builder.setDuplexMode(duplexMode); |
| 207 |
} |
| 208 |
|
| 209 |
return builder.build(); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
private static void enforceValidMask(int mask, IntConsumer enforceSingle) { |
| 219 |
int current = mask; |
| 220 |
while (current > 0) { |
| 221 |
final int currentMode = (1 << Integer.numberOfTrailingZeros(current)); |
| 222 |
current &= ~currentMode; |
| 223 |
enforceSingle.accept(currentMode); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
private PrinterCapabilitiesInfo(Parcel parcel) { |
| 228 |
mMinMargins = Preconditions.checkNotNull(readMargins(parcel)); |
| 229 |
readMediaSizes(parcel); |
| 230 |
readResolutions(parcel); |
| 231 |
|
| 232 |
mColorModes = parcel.readInt(); |
| 233 |
enforceValidMask(mColorModes, |
| 234 |
(currentMode) -> PrintAttributes.enforceValidColorMode(currentMode)); |
| 235 |
|
| 236 |
mDuplexModes = parcel.readInt(); |
| 237 |
enforceValidMask(mDuplexModes, |
| 238 |
(currentMode) -> PrintAttributes.enforceValidDuplexMode(currentMode)); |
| 239 |
|
| 240 |
readDefaults(parcel); |
| 241 |
Preconditions.checkArgument(mMediaSizes.size() > mDefaults[PROPERTY_MEDIA_SIZE]); |
| 242 |
Preconditions.checkArgument(mResolutions.size() > mDefaults[PROPERTY_RESOLUTION]); |
| 243 |
} |
| 244 |
|
| 245 |
@Override |
| 246 |
public int describeContents() { |
| 247 |
return 0; |
| 248 |
} |
| 249 |
|
| 250 |
@Override |
| 251 |
public void writeToParcel(Parcel parcel, int flags) { |
| 252 |
writeMargins(mMinMargins, parcel); |
| 253 |
writeMediaSizes(parcel); |
| 254 |
writeResolutions(parcel); |
| 255 |
|
| 256 |
parcel.writeInt(mColorModes); |
| 257 |
parcel.writeInt(mDuplexModes); |
| 258 |
|
| 259 |
writeDefaults(parcel); |
| 260 |
} |
| 261 |
|
| 262 |
@Override |
| 263 |
public int hashCode() { |
| 264 |
final int prime = 31; |
| 265 |
int result = 1; |
| 266 |
result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode()); |
| 267 |
result = prime * result + ((mMediaSizes == null) ? 0 : mMediaSizes.hashCode()); |
| 268 |
result = prime * result + ((mResolutions == null) ? 0 : mResolutions.hashCode()); |
| 269 |
result = prime * result + mColorModes; |
| 270 |
result = prime * result + mDuplexModes; |
| 271 |
result = prime * result + Arrays.hashCode(mDefaults); |
| 272 |
return result; |
| 273 |
} |
| 274 |
|
| 275 |
@Override |
| 276 |
public boolean equals(@Nullable Object obj) { |
| 277 |
if (this == obj) { |
| 278 |
return true; |
| 279 |
} |
| 280 |
if (obj == null) { |
| 281 |
return false; |
| 282 |
} |
| 283 |
if (getClass() != obj.getClass()) { |
| 284 |
return false; |
| 285 |
} |
| 286 |
PrinterCapabilitiesInfo other = (PrinterCapabilitiesInfo) obj; |
| 287 |
if (mMinMargins == null) { |
| 288 |
if (other.mMinMargins != null) { |
| 289 |
return false; |
| 290 |
} |
| 291 |
} else if (!mMinMargins.equals(other.mMinMargins)) { |
| 292 |
return false; |
| 293 |
} |
| 294 |
if (mMediaSizes == null) { |
| 295 |
if (other.mMediaSizes != null) { |
| 296 |
return false; |
| 297 |
} |
| 298 |
} else if (!mMediaSizes.equals(other.mMediaSizes)) { |
| 299 |
return false; |
| 300 |
} |
| 301 |
if (mResolutions == null) { |
| 302 |
if (other.mResolutions != null) { |
| 303 |
return false; |
| 304 |
} |
| 305 |
} else if (!mResolutions.equals(other.mResolutions)) { |
| 306 |
return false; |
| 307 |
} |
| 308 |
if (mColorModes != other.mColorModes) { |
| 309 |
return false; |
| 310 |
} |
| 311 |
if (mDuplexModes != other.mDuplexModes) { |
| 312 |
return false; |
| 313 |
} |
| 314 |
if (!Arrays.equals(mDefaults, other.mDefaults)) { |
| 315 |
return false; |
| 316 |
} |
| 317 |
return true; |
| 318 |
} |
| 319 |
|
| 320 |
@Override |
| 321 |
public String toString() { |
| 322 |
StringBuilder builder = new StringBuilder(); |
| 323 |
builder.append("PrinterInfo{"); |
| 324 |
builder.append("minMargins=").append(mMinMargins); |
| 325 |
builder.append(", mediaSizes=").append(mMediaSizes); |
| 326 |
builder.append(", resolutions=").append(mResolutions); |
| 327 |
builder.append(", colorModes=").append(colorModesToString()); |
| 328 |
builder.append(", duplexModes=").append(duplexModesToString()); |
| 329 |
builder.append("\"}"); |
| 330 |
return builder.toString(); |
| 331 |
} |
| 332 |
|
| 333 |
private String colorModesToString() { |
| 334 |
StringBuilder builder = new StringBuilder(); |
| 335 |
builder.append('['); |
| 336 |
int colorModes = mColorModes; |
| 337 |
while (colorModes != 0) { |
| 338 |
final int colorMode = 1 << Integer.numberOfTrailingZeros(colorModes); |
| 339 |
colorModes &= ~colorMode; |
| 340 |
if (builder.length() > 1) { |
| 341 |
builder.append(", "); |
| 342 |
} |
| 343 |
builder.append(PrintAttributes.colorModeToString(colorMode)); |
| 344 |
} |
| 345 |
builder.append(']'); |
| 346 |
return builder.toString(); |
| 347 |
} |
| 348 |
|
| 349 |
private String duplexModesToString() { |
| 350 |
StringBuilder builder = new StringBuilder(); |
| 351 |
builder.append('['); |
| 352 |
int duplexModes = mDuplexModes; |
| 353 |
while (duplexModes != 0) { |
| 354 |
final int duplexMode = 1 << Integer.numberOfTrailingZeros(duplexModes); |
| 355 |
duplexModes &= ~duplexMode; |
| 356 |
if (builder.length() > 1) { |
| 357 |
builder.append(", "); |
| 358 |
} |
| 359 |
builder.append(PrintAttributes.duplexModeToString(duplexMode)); |
| 360 |
} |
| 361 |
builder.append(']'); |
| 362 |
return builder.toString(); |
| 363 |
} |
| 364 |
|
| 365 |
private void writeMediaSizes(Parcel parcel) { |
| 366 |
if (mMediaSizes == null) { |
| 367 |
parcel.writeInt(0); |
| 368 |
return; |
| 369 |
} |
| 370 |
final int mediaSizeCount = mMediaSizes.size(); |
| 371 |
parcel.writeInt(mediaSizeCount); |
| 372 |
for (int i = 0; i < mediaSizeCount; i++) { |
| 373 |
mMediaSizes.get(i).writeToParcel(parcel); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
private void readMediaSizes(Parcel parcel) { |
| 378 |
final int mediaSizeCount = parcel.readInt(); |
| 379 |
if (mediaSizeCount > 0 && mMediaSizes == null) { |
| 380 |
mMediaSizes = new ArrayList<MediaSize>(); |
| 381 |
} |
| 382 |
for (int i = 0; i < mediaSizeCount; i++) { |
| 383 |
mMediaSizes.add(MediaSize.createFromParcel(parcel)); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
private void writeResolutions(Parcel parcel) { |
| 388 |
if (mResolutions == null) { |
| 389 |
parcel.writeInt(0); |
| 390 |
return; |
| 391 |
} |
| 392 |
final int resolutionCount = mResolutions.size(); |
| 393 |
parcel.writeInt(resolutionCount); |
| 394 |
for (int i = 0; i < resolutionCount; i++) { |
| 395 |
mResolutions.get(i).writeToParcel(parcel); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
private void readResolutions(Parcel parcel) { |
| 400 |
final int resolutionCount = parcel.readInt(); |
| 401 |
if (resolutionCount > 0 && mResolutions == null) { |
| 402 |
mResolutions = new ArrayList<Resolution>(); |
| 403 |
} |
| 404 |
for (int i = 0; i < resolutionCount; i++) { |
| 405 |
mResolutions.add(Resolution.createFromParcel(parcel)); |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
private void writeMargins(Margins margins, Parcel parcel) { |
| 410 |
if (margins == null) { |
| 411 |
parcel.writeInt(0); |
| 412 |
} else { |
| 413 |
parcel.writeInt(1); |
| 414 |
margins.writeToParcel(parcel); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
private Margins readMargins(Parcel parcel) { |
| 419 |
return (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null; |
| 420 |
} |
| 421 |
|
| 422 |
private void readDefaults(Parcel parcel) { |
| 423 |
final int defaultCount = parcel.readInt(); |
| 424 |
for (int i = 0; i < defaultCount; i++) { |
| 425 |
mDefaults[i] = parcel.readInt(); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
private void writeDefaults(Parcel parcel) { |
| 430 |
final int defaultCount = mDefaults.length; |
| 431 |
parcel.writeInt(defaultCount); |
| 432 |
for (int i = 0; i < defaultCount; i++) { |
| 433 |
parcel.writeInt(mDefaults[i]); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
public static final class Builder { |
| 448 |
private final PrinterCapabilitiesInfo mPrototype; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public Builder(@NonNull PrinterId printerId) { |
| 458 |
if (printerId == null) { |
| 459 |
throw new IllegalArgumentException("printerId cannot be null."); |
| 460 |
} |
| 461 |
mPrototype = new PrinterCapabilitiesInfo(); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
public @NonNull Builder addMediaSize(@NonNull MediaSize mediaSize, boolean isDefault) { |
| 479 |
if (mPrototype.mMediaSizes == null) { |
| 480 |
mPrototype.mMediaSizes = new ArrayList<MediaSize>(); |
| 481 |
} |
| 482 |
final int insertionIndex = mPrototype.mMediaSizes.size(); |
| 483 |
mPrototype.mMediaSizes.add(mediaSize); |
| 484 |
if (isDefault) { |
| 485 |
throwIfDefaultAlreadySpecified(PROPERTY_MEDIA_SIZE); |
| 486 |
mPrototype.mDefaults[PROPERTY_MEDIA_SIZE] = insertionIndex; |
| 487 |
} |
| 488 |
return this; |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
public @NonNull Builder addResolution(@NonNull Resolution resolution, boolean isDefault) { |
| 507 |
if (mPrototype.mResolutions == null) { |
| 508 |
mPrototype.mResolutions = new ArrayList<Resolution>(); |
| 509 |
} |
| 510 |
final int insertionIndex = mPrototype.mResolutions.size(); |
| 511 |
mPrototype.mResolutions.add(resolution); |
| 512 |
if (isDefault) { |
| 513 |
throwIfDefaultAlreadySpecified(PROPERTY_RESOLUTION); |
| 514 |
mPrototype.mDefaults[PROPERTY_RESOLUTION] = insertionIndex; |
| 515 |
} |
| 516 |
return this; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
public @NonNull Builder setMinMargins(@NonNull Margins margins) { |
| 535 |
if (margins == null) { |
| 536 |
throw new IllegalArgumentException("margins cannot be null"); |
| 537 |
} |
| 538 |
mPrototype.mMinMargins = margins; |
| 539 |
return this; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
public @NonNull Builder setColorModes(@ColorMode int colorModes, |
| 565 |
@ColorMode int defaultColorMode) { |
| 566 |
enforceValidMask(colorModes, |
| 567 |
(currentMode) -> PrintAttributes.enforceValidColorMode(currentMode)); |
| 568 |
PrintAttributes.enforceValidColorMode(defaultColorMode); |
| 569 |
mPrototype.mColorModes = colorModes; |
| 570 |
mPrototype.mDefaults[PROPERTY_COLOR_MODE] = defaultColorMode; |
| 571 |
return this; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
public @NonNull Builder setDuplexModes(@DuplexMode int duplexModes, |
| 592 |
@DuplexMode int defaultDuplexMode) { |
| 593 |
enforceValidMask(duplexModes, |
| 594 |
(currentMode) -> PrintAttributes.enforceValidDuplexMode(currentMode)); |
| 595 |
PrintAttributes.enforceValidDuplexMode(defaultDuplexMode); |
| 596 |
mPrototype.mDuplexModes = duplexModes; |
| 597 |
mPrototype.mDefaults[PROPERTY_DUPLEX_MODE] = defaultDuplexMode; |
| 598 |
return this; |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
public @NonNull PrinterCapabilitiesInfo build() { |
| 616 |
if (mPrototype.mMediaSizes == null || mPrototype.mMediaSizes.isEmpty()) { |
| 617 |
throw new IllegalStateException("No media size specified."); |
| 618 |
} |
| 619 |
if (mPrototype.mDefaults[PROPERTY_MEDIA_SIZE] == DEFAULT_UNDEFINED) { |
| 620 |
throw new IllegalStateException("No default media size specified."); |
| 621 |
} |
| 622 |
if (mPrototype.mResolutions == null || mPrototype.mResolutions.isEmpty()) { |
| 623 |
throw new IllegalStateException("No resolution specified."); |
| 624 |
} |
| 625 |
if (mPrototype.mDefaults[PROPERTY_RESOLUTION] == DEFAULT_UNDEFINED) { |
| 626 |
throw new IllegalStateException("No default resolution specified."); |
| 627 |
} |
| 628 |
if (mPrototype.mColorModes == 0) { |
| 629 |
throw new IllegalStateException("No color mode specified."); |
| 630 |
} |
| 631 |
if (mPrototype.mDefaults[PROPERTY_COLOR_MODE] == DEFAULT_UNDEFINED) { |
| 632 |
throw new IllegalStateException("No default color mode specified."); |
| 633 |
} |
| 634 |
if (mPrototype.mDuplexModes == 0) { |
| 635 |
setDuplexModes(PrintAttributes.DUPLEX_MODE_NONE, |
| 636 |
PrintAttributes.DUPLEX_MODE_NONE); |
| 637 |
} |
| 638 |
if (mPrototype.mMinMargins == null) { |
| 639 |
throw new IllegalArgumentException("margins cannot be null"); |
| 640 |
} |
| 641 |
return mPrototype; |
| 642 |
} |
| 643 |
|
| 644 |
private void throwIfDefaultAlreadySpecified(int propertyIndex) { |
| 645 |
if (mPrototype.mDefaults[propertyIndex] != DEFAULT_UNDEFINED) { |
| 646 |
throw new IllegalArgumentException("Default already specified."); |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
public static final @android.annotation.NonNull Parcelable.Creator<PrinterCapabilitiesInfo> CREATOR = |
| 652 |
new Parcelable.Creator<PrinterCapabilitiesInfo>() { |
| 653 |
@Override |
| 654 |
public PrinterCapabilitiesInfo createFromParcel(Parcel parcel) { |
| 655 |
return new PrinterCapabilitiesInfo(parcel); |
| 656 |
} |
| 657 |
|
| 658 |
@Override |
| 659 |
public PrinterCapabilitiesInfo[] newArray(int size) { |
| 660 |
return new PrinterCapabilitiesInfo[size]; |
| 661 |
} |
| 662 |
}; |
| 663 |
} |