OSDN Git Service

Print attributes hint not honored.
authorSvetoslav Ganov <svetoslavganov@google.com>
Mon, 30 Sep 2013 16:04:50 +0000 (09:04 -0700)
committerSvetoslav <svetoslavganov@google.com>
Fri, 4 Oct 2013 18:45:15 +0000 (11:45 -0700)
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

18 files changed:
api/current.txt
core/java/android/print/PrintAttributes.java
packages/PrintSpooler/res/values-be/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-be/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-en-rCA/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-en-rCA/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-en-rUS/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-en-rUS/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-es-rUS/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-es-rUS/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-ja/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-ja/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-zh-rCN/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/res/values/arrays.xml [new file with mode: 0644]
packages/PrintSpooler/res/values/donottranslate.xml [new file with mode: 0644]
packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java [new file with mode: 0644]
packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java

index ed0d154..a33e871 100644 (file)
@@ -19302,7 +19302,7 @@ package android.print {
     field public static final android.print.PrintAttributes.MediaSize OM_PA_KAI;
     field public static final android.print.PrintAttributes.MediaSize PRC_1;
     field public static final android.print.PrintAttributes.MediaSize PRC_10;
-    field public static final android.print.PrintAttributes.MediaSize PRC_16k;
+    field public static final android.print.PrintAttributes.MediaSize PRC_16K;
     field public static final android.print.PrintAttributes.MediaSize PRC_2;
     field public static final android.print.PrintAttributes.MediaSize PRC_3;
     field public static final android.print.PrintAttributes.MediaSize PRC_4;
index 959380d..ec979b3 100644 (file)
@@ -22,10 +22,13 @@ import android.content.res.Resources.NotFoundException;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.TextUtils;
+import android.util.ArrayMap;
 import android.util.Log;
 
 import com.android.internal.R;
 
+import java.util.Map;
+
 /**
  * This class represents the attributes of a print job.
  */
@@ -267,6 +270,9 @@ public final class PrintAttributes implements Parcelable {
     public static final class MediaSize {
         private static final String LOG_TAG = "MediaSize";
 
+        private static final Map<String, MediaSize> sIdToMediaSizeMap =
+                new ArrayMap<String, MediaSize>();
+
         /**
          * Unknown media size in portrait mode.
          * <p>
@@ -494,8 +500,8 @@ public final class PrintAttributes implements Parcelable {
                         R.string.mediasize_chinese_prc_10, 12756, 18032);
 
         /** Chinese PRC 16k media size: 146mm x 215mm (5.749" x 8.465") */
-        public static final MediaSize PRC_16k =
-                new MediaSize("PRC_16k", "android",
+        public static final MediaSize PRC_16K =
+                new MediaSize("PRC_16K", "android",
                         R.string.mediasize_chinese_prc_16k, 5749, 8465);
         /** Chinese Pa Kai media size: 267mm x 389mm (10.512" x 15.315") */
         public static final MediaSize OM_PA_KAI =
@@ -651,6 +657,9 @@ public final class PrintAttributes implements Parcelable {
             mWidthMils = widthMils;
             mHeightMils = heightMils;
             mLabel = null;
+
+            // Build this mapping only for predefined media sizes.
+            sIdToMediaSizeMap.put(mId, this);
         }
 
         /**
@@ -854,6 +863,18 @@ public final class PrintAttributes implements Parcelable {
             builder.append("}");
             return builder.toString();
         }
+
+        /**
+         * Gets a standard media size given its id.
+         *
+         * @param id The media size id.
+         * @return The media size for the given id or null.
+         *
+         * @hide
+         */
+        public static MediaSize getStandardMediaSizeById(String id) {
+            return sIdToMediaSizeMap.get(id);
+        }
     }
 
     /**
diff --git a/packages/PrintSpooler/res/values-be/arrays.xml b/packages/PrintSpooler/res/values-be/arrays.xml
new file mode 100644 (file)
index 0000000..d40278c
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>NA_LETTER</item>
+        <item>NA_GOVT_LETTER</item>
+        <item>NA_LEGAL</item>
+        <item>NA_JUNIOR_LEGAL</item>
+        <item>NA_LEDGER</item>
+        <item>NA_TABLOID</item>
+        <item>NA_INDEX_3X5</item>
+        <item>NA_INDEX_4X6</item>
+        <item>NA_INDEX_5X8</item>
+        <item>NA_MONARCH</item>
+        <item>NA_QUARTO</item>
+        <item>NA_FOOLSCAP</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-be/donottranslate.xml b/packages/PrintSpooler/res/values-be/donottranslate.xml
new file mode 100644 (file)
index 0000000..7537aa5
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+    <string name="mediasize_default">NA_LETTER</string>
+    <string name="mediasize_standard">@string/mediasize_standard_north_america</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-en-rCA/arrays.xml b/packages/PrintSpooler/res/values-en-rCA/arrays.xml
new file mode 100644 (file)
index 0000000..d40278c
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>NA_LETTER</item>
+        <item>NA_GOVT_LETTER</item>
+        <item>NA_LEGAL</item>
+        <item>NA_JUNIOR_LEGAL</item>
+        <item>NA_LEDGER</item>
+        <item>NA_TABLOID</item>
+        <item>NA_INDEX_3X5</item>
+        <item>NA_INDEX_4X6</item>
+        <item>NA_INDEX_5X8</item>
+        <item>NA_MONARCH</item>
+        <item>NA_QUARTO</item>
+        <item>NA_FOOLSCAP</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-en-rCA/donottranslate.xml b/packages/PrintSpooler/res/values-en-rCA/donottranslate.xml
new file mode 100644 (file)
index 0000000..fb1f5d6
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <string name="mediasize_default">NA_LETTER</string>
+    <string name="mediasize_standard">@string/mediasize_standard_north_america</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-en-rUS/arrays.xml b/packages/PrintSpooler/res/values-en-rUS/arrays.xml
new file mode 100644 (file)
index 0000000..d40278c
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>NA_LETTER</item>
+        <item>NA_GOVT_LETTER</item>
+        <item>NA_LEGAL</item>
+        <item>NA_JUNIOR_LEGAL</item>
+        <item>NA_LEDGER</item>
+        <item>NA_TABLOID</item>
+        <item>NA_INDEX_3X5</item>
+        <item>NA_INDEX_4X6</item>
+        <item>NA_INDEX_5X8</item>
+        <item>NA_MONARCH</item>
+        <item>NA_QUARTO</item>
+        <item>NA_FOOLSCAP</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-en-rUS/donottranslate.xml b/packages/PrintSpooler/res/values-en-rUS/donottranslate.xml
new file mode 100644 (file)
index 0000000..fb1f5d6
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <string name="mediasize_default">NA_LETTER</string>
+    <string name="mediasize_standard">@string/mediasize_standard_north_america</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-es-rUS/arrays.xml b/packages/PrintSpooler/res/values-es-rUS/arrays.xml
new file mode 100644 (file)
index 0000000..d40278c
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>NA_LETTER</item>
+        <item>NA_GOVT_LETTER</item>
+        <item>NA_LEGAL</item>
+        <item>NA_JUNIOR_LEGAL</item>
+        <item>NA_LEDGER</item>
+        <item>NA_TABLOID</item>
+        <item>NA_INDEX_3X5</item>
+        <item>NA_INDEX_4X6</item>
+        <item>NA_INDEX_5X8</item>
+        <item>NA_MONARCH</item>
+        <item>NA_QUARTO</item>
+        <item>NA_FOOLSCAP</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-es-rUS/donottranslate.xml b/packages/PrintSpooler/res/values-es-rUS/donottranslate.xml
new file mode 100644 (file)
index 0000000..fb1f5d6
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <string name="mediasize_default">NA_LETTER</string>
+    <string name="mediasize_standard">@string/mediasize_standard_north_america</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-ja/arrays.xml b/packages/PrintSpooler/res/values-ja/arrays.xml
new file mode 100644 (file)
index 0000000..57088c8
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>JIS_B10</item>
+        <item>JIS_B9</item>
+        <item>JIS_B8</item>
+        <item>JIS_B7</item>
+        <item>JIS_b6</item>
+        <item>JIS_b5</item>
+        <item>JIS_b4</item>
+        <item>JIS_b3</item>
+        <item>JIS_b2</item>
+        <item>JIS_b1</item>
+        <item>JIS_b0</item>
+        <item>JIS_EXEC</item>
+        <item>JPN_CHOU4</item>
+        <item>JPN_CHOU3</item>
+        <item>JPN_CHOU2</item>
+        <item>JPN_HAGAKI</item>
+        <item>JPN_OUFUKU</item>
+        <item>JPN_KAHU</item>
+        <item>JPN_KAKU2</item>
+        <item>JPN_YOU4</item>
+
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-ja/donottranslate.xml b/packages/PrintSpooler/res/values-ja/donottranslate.xml
new file mode 100644 (file)
index 0000000..d334ddd
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+    <string name="mediasize_default">JIS_B5</string>
+    <string name="mediasize_standard">@string/mediasize_standard_japan</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-zh-rCN/arrays.xml b/packages/PrintSpooler/res/values-zh-rCN/arrays.xml
new file mode 100644 (file)
index 0000000..4fc75db
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>ROC_8K</item>
+        <item>ROC_16K</item>
+        <item>PRC_1</item>
+        <item>PRC_2</item>
+        <item>PRC_3</item>
+        <item>PRC_4</item>
+        <item>PRC_5</item>
+        <item>PRC_6</item>
+        <item>PRC_7</item>
+        <item>PRC_8</item>
+        <item>PRC_9</item>
+        <item>PRC_10</item>
+        <item>PRC_16K</item>
+        <item>OM_PA_KAI</item>
+        <item>OM_DAI_PA_KAI</item>
+        <item>OM_JUURO_KU_KAI</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml b/packages/PrintSpooler/res/values-zh-rCN/donottranslate.xml
new file mode 100644 (file)
index 0000000..f069da3
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <string name="mediasize_default">PRC_9</string>
+    <string name="mediasize_standard">@string/mediasize_standard_china</string>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values/arrays.xml b/packages/PrintSpooler/res/values/arrays.xml
new file mode 100644 (file)
index 0000000..afe3c71
--- /dev/null
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <string-array name="mediasize_to_standard_map" translatable="false">
+        <!-- North America -->
+        <item>NA_LETTER</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_GOVT_LETTER</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_LEGAL</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_JUNIOR_LEGAL</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_LEDGER</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_TABLOID</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_INDEX_3X5</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_INDEX_4X6</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_INDEX_5X8</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_MONARCH</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_QUARTO</item>
+        <item>@string/mediasize_standard_north_america</item>
+        <item>NA_FOOLSCAP</item>
+        <item>@string/mediasize_standard_north_america</item>
+
+        <!-- China -->
+        <item>ROC_8K</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>ROC_16K</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_1</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_2</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_3</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_4</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_5</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_6</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_7</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_8</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_9</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_10</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>PRC_16K</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>OM_PA_KAI</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>OM_DAI_PA_KAI</item>
+        <item>@string/mediasize_standard_china</item>
+        <item>OM_JUURO_KU_KAI</item>
+        <item>@string/mediasize_standard_china</item>
+
+        <!-- Japan -->
+        <item>JIS_B10</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B9</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B8</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B7</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B6</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B5</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B4</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B3</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B2</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B1</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_B0</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JIS_EXEC</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_CHOU4</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_CHOU3</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_CHOU2</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_HAGAKI</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_OUFUKU</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_KAHU</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_KAKU2</item>
+        <item>@string/mediasize_standard_japan</item>
+        <item>JPN_YOU4</item>
+        <item>@string/mediasize_standard_japan</item>
+
+        <!-- Everything else is ISO -->
+    </string-array>
+
+    <string-array name="pdf_printer_media_sizes" translatable="false">
+        <item>ISO_A0</item>
+        <item>ISO_A1</item>
+        <item>ISO_A2</item>
+        <item>ISO_A3</item>
+        <item>ISO_A4</item>
+        <item>ISO_A5</item>
+        <item>ISO_A6</item>
+        <item>ISO_A7</item>
+        <item>ISO_A8</item>
+        <item>ISO_A9</item>
+        <item>ISO_A10</item>
+        <item>ISO_B1</item>
+        <item>ISO_B2</item>
+        <item>ISO_B3</item>
+        <item>ISO_B4</item>
+        <item>ISO_B5</item>
+        <item>ISO_B6</item>
+        <item>ISO_B7</item>
+        <item>ISO_B8</item>
+        <item>ISO_B9</item>
+        <item>ISO_B10</item>
+        <item>ISO_C1</item>
+        <item>ISO_C2</item>
+        <item>ISO_C3</item>
+        <item>ISO_C4</item>
+        <item>ISO_C5</item>
+        <item>ISO_C6</item>
+        <item>ISO_C7</item>
+        <item>ISO_C8</item>
+        <item>ISO_C9</item>
+        <item>ISO_C10</item>
+    </string-array>
+
+</resources>
diff --git a/packages/PrintSpooler/res/values/donottranslate.xml b/packages/PrintSpooler/res/values/donottranslate.xml
new file mode 100644 (file)
index 0000000..8069a1d
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+
+    <!-- Media size standards -->
+    <string name="mediasize_standard_iso">0</string>
+    <string name="mediasize_standard_north_america">1</string>
+    <string name="mediasize_standard_japan">2</string>
+    <string name="mediasize_standard_china">3</string>
+
+    <!-- Locale specific values -->
+    <string name="mediasize_default">ISO_A4</string>
+    <string name="mediasize_standard">@string/mediasize_standard_iso</string>
+
+</resources>
diff --git a/packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java b/packages/PrintSpooler/src/com/android/printspooler/MediaSizeUtils.java
new file mode 100644 (file)
index 0000000..ac27562
--- /dev/null
@@ -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<MediaSize, String> 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<MediaSize, String>();
+            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<MediaSize> {
+        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()));
+            }
+        }
+    }
+}
index 0c593ef..293be1b 100644 (file)
@@ -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<String> sLetterDefaultCountries = new ArraySet<String>();
-    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<MediaSize> 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<MediaSize> sortedMediaSizes = new ArrayList<MediaSize>(
+                    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<MediaSize> 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<MediaSize> mediaSizes = capabilities.getMediaSizes();
+                // Sort the media sizes based on the current locale.
+                List<MediaSize> mediaSizes = new ArrayList<MediaSize>(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();
             }
         }