From 7be27acac922b5ea66ec6b464ded6f057bd6f1e5 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Mon, 30 Sep 2013 09:04:50 -0700 Subject: Print attributes hint not honored. 1. Initially we have a single printer, the fake PDF printer, and wait for printers to be discovered. This printer was handling only a couple of media sizes. Hence, if the app provides a media size hint and the PDF printer does not support it, we were essentially ignoring the suggested media size since it was not supported by the selected printer and we fell back to the default paper size for that printer. The fake PDF printer should support all predefined media sizes. 2. The list of available paper sizes was shown in the order they are added ignoring the current locale. It is much better user experience if the media sizes used in the current locale are shown at the top and all others after that. Also the media sizes for the current locale should be alphabetically ordered so the user can quickly find the desired one. 3. The orientation was reset on media size or printer change. bug:10564537 Change-Id: Iaa0d42242730ce69cea3effd4d0f4bc087068804 --- packages/PrintSpooler/res/values-be/arrays.xml | 33 +++++ .../PrintSpooler/res/values-be/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values-en-rCA/arrays.xml | 33 +++++ .../res/values-en-rCA/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values-en-rUS/arrays.xml | 33 +++++ .../res/values-en-rUS/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values-es-rUS/arrays.xml | 33 +++++ .../res/values-es-rUS/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values-ja/arrays.xml | 42 ++++++ .../PrintSpooler/res/values-ja/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values-zh-rCN/arrays.xml | 37 +++++ .../res/values-zh-rCN/donottranslate.xml | 22 +++ packages/PrintSpooler/res/values/arrays.xml | 158 +++++++++++++++++++++ .../PrintSpooler/res/values/donottranslate.xml | 28 ++++ .../com/android/printspooler/MediaSizeUtils.java | 99 +++++++++++++ .../printspooler/PrintJobConfigActivity.java | 140 +++++++----------- 16 files changed, 678 insertions(+), 90 deletions(-) create mode 100644 packages/PrintSpooler/res/values-be/arrays.xml create mode 100644 packages/PrintSpooler/res/values-be/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values-en-rCA/arrays.xml create mode 100644 packages/PrintSpooler/res/values-en-rCA/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values-en-rUS/arrays.xml create mode 100644 packages/PrintSpooler/res/values-en-rUS/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values-es-rUS/arrays.xml create mode 100644 packages/PrintSpooler/res/values-es-rUS/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values-ja/arrays.xml create mode 100644 packages/PrintSpooler/res/values-ja/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values-zh-rCN/arrays.xml create mode 100644 packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml create mode 100644 packages/PrintSpooler/res/values/arrays.xml create mode 100644 packages/PrintSpooler/res/values/donottranslate.xml create mode 100644 packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java (limited to 'packages/PrintSpooler') diff --git a/packages/PrintSpooler/res/values-be/arrays.xml b/packages/PrintSpooler/res/values-be/arrays.xml new file mode 100644 index 0000000..d40278c --- /dev/null +++ b/packages/PrintSpooler/res/values-be/arrays.xml @@ -0,0 +1,33 @@ + + + + + + NA_LETTER + NA_GOVT_LETTER + NA_LEGAL + NA_JUNIOR_LEGAL + NA_LEDGER + NA_TABLOID + NA_INDEX_3X5 + NA_INDEX_4X6 + NA_INDEX_5X8 + NA_MONARCH + NA_QUARTO + NA_FOOLSCAP + + + diff --git a/packages/PrintSpooler/res/values-be/donottranslate.xml b/packages/PrintSpooler/res/values-be/donottranslate.xml new file mode 100644 index 0000000..7537aa5 --- /dev/null +++ b/packages/PrintSpooler/res/values-be/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + NA_LETTER + @string/mediasize_standard_north_america + + diff --git a/packages/PrintSpooler/res/values-en-rCA/arrays.xml b/packages/PrintSpooler/res/values-en-rCA/arrays.xml new file mode 100644 index 0000000..d40278c --- /dev/null +++ b/packages/PrintSpooler/res/values-en-rCA/arrays.xml @@ -0,0 +1,33 @@ + + + + + + NA_LETTER + NA_GOVT_LETTER + NA_LEGAL + NA_JUNIOR_LEGAL + NA_LEDGER + NA_TABLOID + NA_INDEX_3X5 + NA_INDEX_4X6 + NA_INDEX_5X8 + NA_MONARCH + NA_QUARTO + NA_FOOLSCAP + + + diff --git a/packages/PrintSpooler/res/values-en-rCA/donottranslate.xml b/packages/PrintSpooler/res/values-en-rCA/donottranslate.xml new file mode 100644 index 0000000..fb1f5d6 --- /dev/null +++ b/packages/PrintSpooler/res/values-en-rCA/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + NA_LETTER + @string/mediasize_standard_north_america + + diff --git a/packages/PrintSpooler/res/values-en-rUS/arrays.xml b/packages/PrintSpooler/res/values-en-rUS/arrays.xml new file mode 100644 index 0000000..d40278c --- /dev/null +++ b/packages/PrintSpooler/res/values-en-rUS/arrays.xml @@ -0,0 +1,33 @@ + + + + + + NA_LETTER + NA_GOVT_LETTER + NA_LEGAL + NA_JUNIOR_LEGAL + NA_LEDGER + NA_TABLOID + NA_INDEX_3X5 + NA_INDEX_4X6 + NA_INDEX_5X8 + NA_MONARCH + NA_QUARTO + NA_FOOLSCAP + + + diff --git a/packages/PrintSpooler/res/values-en-rUS/donottranslate.xml b/packages/PrintSpooler/res/values-en-rUS/donottranslate.xml new file mode 100644 index 0000000..fb1f5d6 --- /dev/null +++ b/packages/PrintSpooler/res/values-en-rUS/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + NA_LETTER + @string/mediasize_standard_north_america + + diff --git a/packages/PrintSpooler/res/values-es-rUS/arrays.xml b/packages/PrintSpooler/res/values-es-rUS/arrays.xml new file mode 100644 index 0000000..d40278c --- /dev/null +++ b/packages/PrintSpooler/res/values-es-rUS/arrays.xml @@ -0,0 +1,33 @@ + + + + + + NA_LETTER + NA_GOVT_LETTER + NA_LEGAL + NA_JUNIOR_LEGAL + NA_LEDGER + NA_TABLOID + NA_INDEX_3X5 + NA_INDEX_4X6 + NA_INDEX_5X8 + NA_MONARCH + NA_QUARTO + NA_FOOLSCAP + + + diff --git a/packages/PrintSpooler/res/values-es-rUS/donottranslate.xml b/packages/PrintSpooler/res/values-es-rUS/donottranslate.xml new file mode 100644 index 0000000..fb1f5d6 --- /dev/null +++ b/packages/PrintSpooler/res/values-es-rUS/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + NA_LETTER + @string/mediasize_standard_north_america + + diff --git a/packages/PrintSpooler/res/values-ja/arrays.xml b/packages/PrintSpooler/res/values-ja/arrays.xml new file mode 100644 index 0000000..57088c8 --- /dev/null +++ b/packages/PrintSpooler/res/values-ja/arrays.xml @@ -0,0 +1,42 @@ + + + + + + JIS_B10 + JIS_B9 + JIS_B8 + JIS_B7 + JIS_b6 + JIS_b5 + JIS_b4 + JIS_b3 + JIS_b2 + JIS_b1 + JIS_b0 + JIS_EXEC + JPN_CHOU4 + JPN_CHOU3 + JPN_CHOU2 + JPN_HAGAKI + JPN_OUFUKU + JPN_KAHU + JPN_KAKU2 + JPN_YOU4 + + + + diff --git a/packages/PrintSpooler/res/values-ja/donottranslate.xml b/packages/PrintSpooler/res/values-ja/donottranslate.xml new file mode 100644 index 0000000..d334ddd --- /dev/null +++ b/packages/PrintSpooler/res/values-ja/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + JIS_B5 + @string/mediasize_standard_japan + + diff --git a/packages/PrintSpooler/res/values-zh-rCN/arrays.xml b/packages/PrintSpooler/res/values-zh-rCN/arrays.xml new file mode 100644 index 0000000..4fc75db --- /dev/null +++ b/packages/PrintSpooler/res/values-zh-rCN/arrays.xml @@ -0,0 +1,37 @@ + + + + + + ROC_8K + ROC_16K + PRC_1 + PRC_2 + PRC_3 + PRC_4 + PRC_5 + PRC_6 + PRC_7 + PRC_8 + PRC_9 + PRC_10 + PRC_16K + OM_PA_KAI + OM_DAI_PA_KAI + OM_JUURO_KU_KAI + + + diff --git a/packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml b/packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml new file mode 100644 index 0000000..f069da3 --- /dev/null +++ b/packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml @@ -0,0 +1,22 @@ + + + + + + PRC_9 + @string/mediasize_standard_china + + diff --git a/packages/PrintSpooler/res/values/arrays.xml b/packages/PrintSpooler/res/values/arrays.xml new file mode 100644 index 0000000..afe3c71 --- /dev/null +++ b/packages/PrintSpooler/res/values/arrays.xml @@ -0,0 +1,158 @@ + + + + + + + NA_LETTER + @string/mediasize_standard_north_america + NA_GOVT_LETTER + @string/mediasize_standard_north_america + NA_LEGAL + @string/mediasize_standard_north_america + NA_JUNIOR_LEGAL + @string/mediasize_standard_north_america + NA_LEDGER + @string/mediasize_standard_north_america + NA_TABLOID + @string/mediasize_standard_north_america + NA_INDEX_3X5 + @string/mediasize_standard_north_america + NA_INDEX_4X6 + @string/mediasize_standard_north_america + NA_INDEX_5X8 + @string/mediasize_standard_north_america + NA_MONARCH + @string/mediasize_standard_north_america + NA_QUARTO + @string/mediasize_standard_north_america + NA_FOOLSCAP + @string/mediasize_standard_north_america + + + ROC_8K + @string/mediasize_standard_china + ROC_16K + @string/mediasize_standard_china + PRC_1 + @string/mediasize_standard_china + PRC_2 + @string/mediasize_standard_china + PRC_3 + @string/mediasize_standard_china + PRC_4 + @string/mediasize_standard_china + PRC_5 + @string/mediasize_standard_china + PRC_6 + @string/mediasize_standard_china + PRC_7 + @string/mediasize_standard_china + PRC_8 + @string/mediasize_standard_china + PRC_9 + @string/mediasize_standard_china + PRC_10 + @string/mediasize_standard_china + PRC_16K + @string/mediasize_standard_china + OM_PA_KAI + @string/mediasize_standard_china + OM_DAI_PA_KAI + @string/mediasize_standard_china + OM_JUURO_KU_KAI + @string/mediasize_standard_china + + + JIS_B10 + @string/mediasize_standard_japan + JIS_B9 + @string/mediasize_standard_japan + JIS_B8 + @string/mediasize_standard_japan + JIS_B7 + @string/mediasize_standard_japan + JIS_B6 + @string/mediasize_standard_japan + JIS_B5 + @string/mediasize_standard_japan + JIS_B4 + @string/mediasize_standard_japan + JIS_B3 + @string/mediasize_standard_japan + JIS_B2 + @string/mediasize_standard_japan + JIS_B1 + @string/mediasize_standard_japan + JIS_B0 + @string/mediasize_standard_japan + JIS_EXEC + @string/mediasize_standard_japan + JPN_CHOU4 + @string/mediasize_standard_japan + JPN_CHOU3 + @string/mediasize_standard_japan + JPN_CHOU2 + @string/mediasize_standard_japan + JPN_HAGAKI + @string/mediasize_standard_japan + JPN_OUFUKU + @string/mediasize_standard_japan + JPN_KAHU + @string/mediasize_standard_japan + JPN_KAKU2 + @string/mediasize_standard_japan + JPN_YOU4 + @string/mediasize_standard_japan + + + + + + ISO_A0 + ISO_A1 + ISO_A2 + ISO_A3 + ISO_A4 + ISO_A5 + ISO_A6 + ISO_A7 + ISO_A8 + ISO_A9 + ISO_A10 + ISO_B1 + ISO_B2 + ISO_B3 + ISO_B4 + ISO_B5 + ISO_B6 + ISO_B7 + ISO_B8 + ISO_B9 + ISO_B10 + ISO_C1 + ISO_C2 + ISO_C3 + ISO_C4 + ISO_C5 + ISO_C6 + ISO_C7 + ISO_C8 + ISO_C9 + ISO_C10 + + + diff --git a/packages/PrintSpooler/res/values/donottranslate.xml b/packages/PrintSpooler/res/values/donottranslate.xml new file mode 100644 index 0000000..8069a1d --- /dev/null +++ b/packages/PrintSpooler/res/values/donottranslate.xml @@ -0,0 +1,28 @@ + + + + + + 0 + 1 + 2 + 3 + + + ISO_A4 + @string/mediasize_standard_iso + + diff --git a/packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java b/packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java new file mode 100644 index 0000000..ac27562 --- /dev/null +++ b/packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.printspooler; + +import android.content.Context; +import android.print.PrintAttributes.MediaSize; +import android.util.ArrayMap; + +import java.util.Comparator; +import java.util.Map; + +/** + * Utility functions and classes for dealing with media sizes. + */ +public class MediaSizeUtils { + + private static Map sMediaSizeToStandardMap; + + /** + * Gets the default media size for the current locale. + * + * @param context Context for accessing resources. + * @return The default media size. + */ + public static MediaSize getDefault(Context context) { + String mediaSizeId = context.getString(R.string.mediasize_default); + return MediaSize.getStandardMediaSizeById(mediaSizeId); + } + + private static String getStandardForMediaSize(Context context, MediaSize mediaSize) { + if (sMediaSizeToStandardMap == null) { + sMediaSizeToStandardMap = new ArrayMap(); + String[] mediaSizeToStandardMapValues = context.getResources() + .getStringArray(R.array.mediasize_to_standard_map); + final int mediaSizeToStandardCount = mediaSizeToStandardMapValues.length; + for (int i = 0; i < mediaSizeToStandardCount; i += 2) { + String mediaSizeId = mediaSizeToStandardMapValues[i]; + MediaSize key = MediaSize.getStandardMediaSizeById(mediaSizeId); + String value = mediaSizeToStandardMapValues[i + 1]; + sMediaSizeToStandardMap.put(key, value); + } + } + String standard = sMediaSizeToStandardMap.get(mediaSize); + return (standard != null) ? standard : context.getString( + R.string.mediasize_standard_iso); + } + + /** + * Comparator for ordering standard media sizes. The ones for the current + * standard go to the top and the ones for the other standards follow grouped + * by standard. Media sizes of the same standard are ordered alphabetically. + */ + public static final class MediaSizeComparator implements Comparator { + private final Context mContext; + + public MediaSizeComparator(Context context) { + mContext = context; + } + + @Override + public int compare(MediaSize lhs, MediaSize rhs) { + String currentStandard = mContext.getString(R.string.mediasize_standard); + String lhsStandard = getStandardForMediaSize(mContext, lhs); + String rhsStandard = getStandardForMediaSize(mContext, rhs); + + // The current standard always wins. + if (lhsStandard.equals(currentStandard)) { + if (!rhsStandard.equals(currentStandard)) { + return -1; + } + } else if (rhsStandard.equals(currentStandard)) { + return 1; + } + + if (!lhsStandard.equals(rhsStandard)) { + // Different standards - use the standard ordering. + return lhsStandard.compareTo(rhsStandard); + } else { + // Same standard - sort alphabetically by label. + return lhs.getLabel(mContext.getPackageManager()). + compareTo(rhs.getLabel(mContext.getPackageManager())); + } + } + } +} diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java index 0c593ef..293be1b 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java @@ -57,7 +57,6 @@ import android.text.TextUtils; import android.text.TextUtils.SimpleStringSplitter; import android.text.TextWatcher; import android.util.ArrayMap; -import android.util.ArraySet; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -80,6 +79,8 @@ import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; +import com.android.printspooler.MediaSizeUtils.MediaSizeComparator; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -89,9 +90,9 @@ import java.io.OutputStream; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -151,26 +152,6 @@ public class PrintJobConfigActivity extends Activity { "[\\s]*[0-9]*[\\s]*[\\-]?[\\s]*[0-9]*[\\s]*?(([,])" + "[\\s]*[0-9]*[\\s]*[\\-]?[\\s]*[0-9]*[\\s]*|[\\s]*)+"); - // The list of countries where Letter is the default paper size. Culled from - // the OpenOffice wiki at http://wiki.openoffice.org/wiki/DefaultPaperSize. - private static final Set sLetterDefaultCountries = new ArraySet(); - static { - sLetterDefaultCountries.add("US"); - sLetterDefaultCountries.add("CA"); - sLetterDefaultCountries.add("BZ"); - sLetterDefaultCountries.add("CL"); - sLetterDefaultCountries.add("CR"); - sLetterDefaultCountries.add("GT"); - sLetterDefaultCountries.add("NI"); - sLetterDefaultCountries.add("PA"); - sLetterDefaultCountries.add("PR"); - sLetterDefaultCountries.add("SV"); - sLetterDefaultCountries.add("VE"); - sLetterDefaultCountries.add("MX"); - sLetterDefaultCountries.add("CO"); - sLetterDefaultCountries.add("PH"); - } - public static final PageRange[] ALL_PAGES_ARRAY = new PageRange[] {PageRange.ALL_PAGES}; private final PrintAttributes mOldPrintAttributes = new PrintAttributes.Builder().build(); @@ -826,6 +807,8 @@ public class PrintJobConfigActivity extends Activity { private PrinterInfo mCurrentPrinter; + private final MediaSizeComparator mMediaSizeComparator; + private final OnItemSelectedListener mOnItemSelectedListener = new AdapterView.OnItemSelectedListener() { @Override @@ -872,7 +855,11 @@ public class PrintJobConfigActivity extends Activity { return; } SpinnerItem mediaItem = mMediaSizeSpinnerAdapter.getItem(position); - mCurrPrintAttributes.setMediaSize(mediaItem.value); + if (mOrientationSpinner.getSelectedItemPosition() == 0) { + mCurrPrintAttributes.setMediaSize(mediaItem.value.asPortrait()); + } else { + mCurrPrintAttributes.setMediaSize(mediaItem.value.asLandscape()); + } if (!hasErrors()) { mController.update(); } @@ -971,18 +958,22 @@ public class PrintJobConfigActivity extends Activity { private void updatePrintAttributes(PrinterCapabilitiesInfo capabilities) { PrintAttributes defaults = capabilities.getDefaults(); + // Sort the media sizes based on the current locale. + List sortedMediaSizes = new ArrayList( + capabilities.getMediaSizes()); + Collections.sort(sortedMediaSizes, mMediaSizeComparator); + // Media size. MediaSize currMediaSize = mCurrPrintAttributes.getMediaSize(); if (currMediaSize == null) { mCurrPrintAttributes.setMediaSize(defaults.getMediaSize()); } else { MediaSize currMediaSizePortrait = currMediaSize.asPortrait(); - List mediaSizes = capabilities.getMediaSizes(); - final int mediaSizeCount = mediaSizes.size(); + final int mediaSizeCount = sortedMediaSizes.size(); for (int i = 0; i < mediaSizeCount; i++) { - MediaSize mediaSize = mediaSizes.get(i); + MediaSize mediaSize = sortedMediaSizes.get(i); if (currMediaSizePortrait.equals(mediaSize.asPortrait())) { - mCurrPrintAttributes.setMediaSize(mediaSize); + mCurrPrintAttributes.setMediaSize(currMediaSize); break; } } @@ -1148,6 +1139,7 @@ public class PrintJobConfigActivity extends Activity { public Editor() { // Destination. + mMediaSizeComparator = new MediaSizeComparator(PrintJobConfigActivity.this); mDestinationSpinnerAdapter = new DestinationAdapter(); mDestinationSpinnerAdapter.registerDataSetObserver(new DataSetObserver() { @Override @@ -1702,54 +1694,13 @@ public class PrintJobConfigActivity extends Activity { } if (!allOptionsEnabled) { - String minCopiesString = String.valueOf(MIN_COPIES); - if (!TextUtils.equals(mCopiesEditText.getText(), minCopiesString)) { - mIgnoreNextCopiesChange = true; - mCopiesEditText.setText(minCopiesString); - } mCopiesEditText.setEnabled(false); - - // Media size - if (mMediaSizeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) { - mOldMediaSizeSelectionIndex = AdapterView.INVALID_POSITION; - mMediaSizeSpinner.setSelection(AdapterView.INVALID_POSITION); - } mMediaSizeSpinner.setEnabled(false); - - // Color mode - if (mColorModeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) { - mOldColorModeSelectionIndex = AdapterView.INVALID_POSITION; - mColorModeSpinner.setSelection(AdapterView.INVALID_POSITION); - } mColorModeSpinner.setEnabled(false); - - // Orientation - if (mOrientationSpinner.getSelectedItemPosition() != 0) { - mIgnoreNextOrientationChange = true; - mOrientationSpinner.setSelection(0); - } mOrientationSpinner.setEnabled(false); - - // Range - if (mRangeOptionsSpinner.getSelectedItemPosition() != 0) { - mIgnoreNextRangeOptionChange = true; - mRangeOptionsSpinner.setSelection(0); - } mRangeOptionsSpinner.setEnabled(false); - mRangeOptionsTitle.setText(getString(R.string.label_pages, - getString(R.string.page_count_unknown))); - if (!TextUtils.equals(mPageRangeEditText.getText(), "")) { - mIgnoreNextRangeChange = true; - mPageRangeEditText.setText(""); - } - mPageRangeEditText.setEnabled(false); - mPageRangeEditText.setVisibility(View.INVISIBLE); - mPageRangeTitle.setVisibility(View.INVISIBLE); - - // Print mPrintButton.setEnabled(false); - return false; } else { boolean someAttributeSelectionChanged = false; @@ -1759,7 +1710,9 @@ public class PrintJobConfigActivity extends Activity { PrintAttributes defaultAttributes = printer.getCapabilities().getDefaults(); // Media size. - List mediaSizes = capabilities.getMediaSizes(); + // Sort the media sizes based on the current locale. + List mediaSizes = new ArrayList(capabilities.getMediaSizes()); + Collections.sort(mediaSizes, mMediaSizeComparator); // If the media sizes changed, we update the adapter and the spinner. boolean mediaSizesChanged = false; @@ -1783,7 +1736,7 @@ public class PrintJobConfigActivity extends Activity { mMediaSizeSpinnerAdapter.clear(); for (int i = 0; i < mediaSizeCount; i++) { MediaSize mediaSize = mediaSizes.get(i); - if (mediaSize.equals(oldMediaSize)) { + if (mediaSize.asPortrait().equals(oldMediaSize.asPortrait())) { // Update the index of the old selection. oldMediaSizeNewIndex = i; } @@ -1801,8 +1754,13 @@ public class PrintJobConfigActivity extends Activity { final int mediaSizeIndex = Math.max(mediaSizes.indexOf( defaultAttributes.getMediaSize()), 0); setMediaSizeSpinnerSelectionNoCallback(mediaSizeIndex); - mCurrPrintAttributes.setMediaSize(mMediaSizeSpinnerAdapter - .getItem(mediaSizeIndex).value); + if (oldMediaSize.isPortrait()) { + mCurrPrintAttributes.setMediaSize(mMediaSizeSpinnerAdapter + .getItem(mediaSizeIndex).value.asPortrait()); + } else { + mCurrPrintAttributes.setMediaSize(mMediaSizeSpinnerAdapter + .getItem(mediaSizeIndex).value.asLandscape()); + } someAttributeSelectionChanged = true; } } @@ -2266,31 +2224,33 @@ public class PrintJobConfigActivity extends Activity { notifyDataSetInvalidated(); } + private PrinterInfo createFakePdfPrinter() { - final MediaSize defaultMediaSize; - String currentCountry = getResources().getConfiguration().locale.getCountry(); - if (sLetterDefaultCountries.contains(currentCountry)) { - defaultMediaSize = MediaSize.NA_LETTER; - } else { - defaultMediaSize = MediaSize.ISO_A4; - } + MediaSize defaultMediaSize = MediaSizeUtils.getDefault(PrintJobConfigActivity.this); PrinterId printerId = new PrinterId(getComponentName(), "PDF printer"); - PrinterCapabilitiesInfo capabilities = - new PrinterCapabilitiesInfo.Builder(printerId) - .addMediaSize(MediaSize.ISO_A4, MediaSize.ISO_A4 == defaultMediaSize) - .addMediaSize(MediaSize.NA_LETTER, MediaSize.NA_LETTER == defaultMediaSize) - .addResolution(new Resolution("PDF resolution", "PDF resolution", - 300, 300), true) - .setColorModes(PrintAttributes.COLOR_MODE_COLOR - | PrintAttributes.COLOR_MODE_MONOCHROME, - PrintAttributes.COLOR_MODE_COLOR) - .build(); + PrinterCapabilitiesInfo.Builder builder = + new PrinterCapabilitiesInfo.Builder(printerId); + + String[] mediaSizeIds = getResources().getStringArray( + R.array.pdf_printer_media_sizes); + final int mediaSizeIdCount = mediaSizeIds.length; + for (int i = 0; i < mediaSizeIdCount; i++) { + String id = mediaSizeIds[i]; + MediaSize mediaSize = MediaSize.getStandardMediaSizeById(id); + builder.addMediaSize(mediaSize, mediaSize.equals(defaultMediaSize)); + } + + builder.addResolution(new Resolution("PDF resolution", "PDF resolution", + 300, 300), true); + builder.setColorModes(PrintAttributes.COLOR_MODE_COLOR + | PrintAttributes.COLOR_MODE_MONOCHROME, + PrintAttributes.COLOR_MODE_COLOR); return new PrinterInfo.Builder(printerId, getString(R.string.save_as_pdf), PrinterInfo.STATUS_IDLE) - .setCapabilities(capabilities) + .setCapabilities(builder.build()) .build(); } } -- cgit v1.1