From 2eb7fadcd64120f0e94ebb0f91188900e916c559 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Wed, 1 Oct 2014 17:49:16 -0700 Subject: [PATCH] Custom print settings cannot change resolution. bug:17677133 Change-Id: Ib8a24101f12d431fe221c1e91711d93a6a517273 --- .../printspooler/ui/PrintActivity.java | 84 ++++++++++++------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index 84ada6f45d883..dc76218a6da92 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -686,43 +686,63 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat PrintAttributes currAttributes = mPrintJob.getAttributes(); PrintAttributes newAttributes = printJobInfo.getAttributes(); - // Take the media size only if the current printer supports is. - MediaSize oldMediaSize = currAttributes.getMediaSize(); - MediaSize newMediaSize = newAttributes.getMediaSize(); - if (!oldMediaSize.equals(newMediaSize)) { - final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount(); - MediaSize newMediaSizePortrait = newAttributes.getMediaSize().asPortrait(); - for (int i = 0; i < mediaSizeCount; i++) { - MediaSize supportedSizePortrait = mMediaSizeSpinnerAdapter.getItem(i) - .value.asPortrait(); - if (supportedSizePortrait.equals(newMediaSizePortrait)) { - currAttributes.setMediaSize(newMediaSize); - mMediaSizeSpinner.setSelection(i); - if (currAttributes.getMediaSize().isPortrait()) { - if (mOrientationSpinner.getSelectedItemPosition() != 0) { - mOrientationSpinner.setSelection(0); - } - } else { - if (mOrientationSpinner.getSelectedItemPosition() != 1) { - mOrientationSpinner.setSelection(1); + if (newAttributes != null) { + // Take the media size only if the current printer supports is. + MediaSize oldMediaSize = currAttributes.getMediaSize(); + MediaSize newMediaSize = newAttributes.getMediaSize(); + if (!oldMediaSize.equals(newMediaSize)) { + final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount(); + MediaSize newMediaSizePortrait = newAttributes.getMediaSize().asPortrait(); + for (int i = 0; i < mediaSizeCount; i++) { + MediaSize supportedSizePortrait = mMediaSizeSpinnerAdapter.getItem(i) + .value.asPortrait(); + if (supportedSizePortrait.equals(newMediaSizePortrait)) { + currAttributes.setMediaSize(newMediaSize); + mMediaSizeSpinner.setSelection(i); + if (currAttributes.getMediaSize().isPortrait()) { + if (mOrientationSpinner.getSelectedItemPosition() != 0) { + mOrientationSpinner.setSelection(0); + } + } else { + if (mOrientationSpinner.getSelectedItemPosition() != 1) { + mOrientationSpinner.setSelection(1); + } } + break; } - break; } } - } - // Take the color mode only if the current printer supports it. - final int currColorMode = currAttributes.getColorMode(); - final int newColorMode = newAttributes.getColorMode(); - if (currColorMode != newColorMode) { - final int colorModeCount = mColorModeSpinner.getCount(); - for (int i = 0; i < colorModeCount; i++) { - final int supportedColorMode = mColorModeSpinnerAdapter.getItem(i).value; - if (supportedColorMode == newColorMode) { - currAttributes.setColorMode(newColorMode); - mColorModeSpinner.setSelection(i); - break; + // Take the resolution only if the current printer supports is. + Resolution oldResolution = currAttributes.getResolution(); + Resolution newResolution = newAttributes.getResolution(); + if (!oldResolution.equals(newResolution)) { + PrinterCapabilitiesInfo capabilities = mCurrentPrinter.getCapabilities(); + if (capabilities != null) { + List resolutions = capabilities.getResolutions(); + final int resolutionCount = resolutions.size(); + for (int i = 0; i < resolutionCount; i++) { + Resolution resolution = resolutions.get(i); + if (resolution.equals(newResolution)) { + currAttributes.setResolution(resolution); + break; + } + } + } + } + + // Take the color mode only if the current printer supports it. + final int currColorMode = currAttributes.getColorMode(); + final int newColorMode = newAttributes.getColorMode(); + if (currColorMode != newColorMode) { + final int colorModeCount = mColorModeSpinner.getCount(); + for (int i = 0; i < colorModeCount; i++) { + final int supportedColorMode = mColorModeSpinnerAdapter.getItem(i).value; + if (supportedColorMode == newColorMode) { + currAttributes.setColorMode(newColorMode); + mColorModeSpinner.setSelection(i); + break; + } } } }